PageSourceSearch

https://per4mer.io/assets/SettingsBilling-DnlTI6d8.js

js per4mer.io collected 2026-10-09 22:03:08 UTC 17,743 bytes, 1 lines download raw bytes

1import{am as O,an as ce,ao as oe,j as e,C as h,c as g,l as f,m as N,Z as Q,a3 as E,T as W,ap as me,aq as H,ar as xe,B as o,as as ue,L as x,d as B,at as A,i as V,a5 as J,a6 as Z,g as G,R as X,s as w,au as he,av as ge,aw as je,ax as pe,a0 as Y,a1 as R,e as P,x as S,S as U,ay as fe,az as Ne,z,r as $,I as be,aA as T}from"./index-Cbw7qYFc.js";import{S as q}from"./SettingsLayout-C9bMAWiJ.js";import{T as ve,a as we,b as K,c as y,d as ye,e as _}from"./table-CjrGHa3Y.js";import _e from"./calendar-Dw_7t2ww.js";import M from"./external-link-CLys4UPm.js";import Se from"./users-BjUb81Ub.js";import Ce from"./plus-C1b1L0ev.js";import Pe from"./download-kTXPcKg4.js";import ee from"./circle-check-big-YjCG260i.js";const Te={critical:{wrapper:"bg-destructive/10 border-destructive/30",text:"text-destructive",subtext:"text-destructive/80"},low:{wrapper:"bg-warning/10 border-warning/30",text:"text-warning",subtext:"text-warning/80"}},Ae=(s,n)=>s?"[&>div]:bg-destructive":n?"[&>div]:bg-warning":"[&>div]:bg-info";function De(){const{data:s,isLoading:n}=O(),t=ce(),{isLow:r,isCritical:i}=oe();if(n)return e.jsx(h,{children:e.jsx(g,{className:"pt-6",children:e.jsxs("div",{className:"animate-pulse space-y-3",children:[e.jsx("div",{className:"h-4 bg-gray-200 rounded w-1/2"}),e.jsx("div",{className:"h-8 bg-gray-200 rounded"})]})})});if(!s)return null;if(s.isUnlimited)return e.jsxs(h,{className:"bg-gradient-to-br from-purple-500 to-blue-500 text-white border-0",children:[e.jsx(f,{children:e.jsxs(N,{className:"flex items-center text-white",children:[e.jsx(Q,{className:"w-5 h-5 mr-2"}),"AI Credits"]})}),e.jsx(g,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-bold",children:"Unlimited"}),e.jsx("p",{className:"text-sm text-purple-100 mt-1",children:"Run as many AI analyses as you need"})]}),e.jsx("div",{className:"text-6xl opacity-20",children:"∞"})]})})]});const d=100-t.percentageUsed;return e.jsxs(h,{className:i?"border-destructive border-2":"",children:[e.jsx(f,{children:e.jsxs(N,{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(E,{className:"w-5 h-5 mr-2 text-info"}),"AI Credits"]}),(r||i)&&e.jsx(W,{className:`w-5 h-5 ${i?"text-destructive":"text-warning"}`})]})}),e.jsxs(g,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-3xl font-bold",children:t.remaining}),e.jsxs("p",{className:"text-sm text-gray-500",children:["of ",t.total," credits remaining"]})]}),e.jsx("div",{className:"text-right",children:e.jsxs("p",{className:"text-sm text-gray-500",children:[t.used," used"]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(me,{value:d,className:Ae(i,r)}),e.jsxs("p",{className:"text-xs text-gray-500",children:[Math.round(d),"% remaining"]})]}),t.nextRefillDate&&e.jsxs("div",{className:"flex items-center text-sm text-gray-500 pt-2 border-t",children:[e.jsx(_e,{className:"w-4 h-4 mr-2"}),e.jsxs("span",{children:["Resets on ",t.nextRefillDate.toLocaleDateString()]})]}),e.jsx(Le,{isCritical:i,isLow:r,remaining:t.remaining})]})]})}function Le({isCritical:s,isLow:n,remaining:t}){const{data:r}=H(),{canPurchase:i,isPurchasing:d,purchase:j}=xe(),l=r?.planKey==="solo",u=["free_trial","beta_trial"].includes(r?.planKey||"");if(!s&&!n)return null;const m=Te[s?"critical":"low"],b=s?"Credits running low!":"Running low on credits";return l?e.jsxs("div",{className:`border rounded-lg p-3 ${m.wrapper}`,children:[e.jsx("p",{className:`text-sm font-medium mb-1 ${m.text}`,children:b}),e.jsxs("p",{className:`text-xs mb-3 ${m.subtext}`,children:["You have ",t," credits left."]}),e.jsx(o,{size:"sm",className:"w-full mb-2",onClick:()=>j(),disabled:!i||d,children:d?e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"mr-2 h-4 w-4 animate-spin"}),"Processing..."]}):`Buy AI Top Up – ${ue}`}),e.jsxs("p",{className:`text-xs text-center ${m.subtext}`,children:["or"," ",e.jsx(B,{to:"/settings/billing?upgrade=pro",className:"underline font-medium hover:opacity-80",children:"upgrade to Pro for unlimited credits + unlimited plays"})]})]}):u?e.jsxs("div",{className:`border rounded-lg p-3 ${m.wrapper}`,children:[e.jsx("p",{className:`text-sm font-medium mb-1 ${m.text}`,children:b}),e.jsxs("p",{className:`text-xs mb-3 ${m.subtext}`,children:["You have ",t," credits left. Subscribe to get more credits."]}),e.jsx(o,{asChild:!0,size:"sm",className:"w-full",children:e.jsx(B,{to:"/settings/billing",children:"View Plans"})})]}):null}function Fe(){const{data:s}=A();return V({queryKey:["team-seats",s?.id],queryFn:async()=>
1{if(!s?.id)throw new Error("No organization");const{data:n,error:t}=await w.functions.invoke("manage-team-seats",{body:{organization_id:s.id,action:"get_seats"}});if(t)throw t;return n},enabled:!!s?.id})}function ke(){const{data:s}=A(),n=J();return Z({mutationFn:async t=>{if(!s?.id)throw new Error("No organization");const{data:r,error:i}=await w.functions.invoke("manage-team-seats",{body:{organization_id:s.id,action:"add_seats",quantity:t}});if(i)throw i;return r},onSuccess:()=>{n.invalidateQueries({queryKey:["team-seats"]}),n.invalidateQueries({queryKey:["subscription"]}),X("Seats added successfully")},onError:t=>{G(`Failed to add seats: ${t.message}`)}})}function Ue(){const{data:s}=A(),n=J();return Z({mutationFn:async t=>{if(!s?.id)throw new Error("No organization");const{data:r,error:i}=await w.functions.invoke("manage-team-seats",{body:{organization_id:s.id,action:"remove_seats",quantity:t}});if(i)throw i;return r},onSuccess:()=>{n.invalidateQueries({queryKey:["team-seats"]}),n.invalidateQueries({queryKey:["subscription"]}),X("Seats removed successfully")},onError:t=>{G(`Failed to remove seats: ${t.message}`)}})}const Oe=()=>{const{data:s,isLoading:n}=H(),{data:t,isLoading:r}=he(),{data:i}=O(),{data:d}=A(),{mutate:j,isPending:l}=ge(),{mutate:u,isPending:p}=je(),{isBetaUser:m,daysRemaining:b,shouldOfferDiscount:C,betaDiscountOffered:se}=pe(),ae=s?.planKey==="team",{data:c,isLoading:te}=Fe(),{mutate:ne,isPending:D}=ke(),{mutate:ie,isPending:L}=Ue(),{data:F,isLoading:re}=V({queryKey:["invoices",d?.id],queryFn:async()=>{if(!d?.id)return[];const{data:a,error:k}=await w.from("invoices").select("*").eq("organization_id",d.id).order("created_at",{ascending:!1}).limit(10);if(k)throw k;return a},enabled:!!d?.id}),le=a=>{const I={active:{variant:"default",icon:ee},trialing:{variant:"secondary",icon:P},past_due:{variant:"destructive",icon:W},canceled:{variant:"outline",icon:P}}[a]||{variant:"outline",icon:P},de=I.icon;return e.jsxs(z,{variant:I.variant,className:"gap-1",children:[e.jsx(de,{className:"h-3 w-3"}),a.replace("_"," ")]})};if(n||r)return e.jsx(q,{children:e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(x,{className:"h-8 w-8 animate-spin text-primary"})})});t?.find(a=>a.is_current_plan);const v=t?.filter(a=>a.can_upgrade_to);return e.jsx(q,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-foreground mb-2",children:"Billing & Subscription"}),e.jsx("p",{className:"text-muted-foreground",children:"Manage your subscription, payment methods, and billing history"})]}),m&&b!==null&&e.jsxs(Y,{className:C?"border-warning bg-warning/10":"border-info bg-info/10",children:[e.jsx(E,{className:`h-4 w-4 ${C?"text-warning":"text-info"}`}),e.jsx(R,{className:C?"text-warning":"text-info",children:C?e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Your beta access is ending soon!"})," You have"," ",b," days left.",!se&&e.jsxs("span",{className:"block mt-2",children:["As a thank you for being a beta user, we're offering you"," ",e.jsx("strong",{children:"50% off Pro"})," ($148.50/month) when your beta period ends."]})]}):e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Beta User Status:"})," You have ",b," ","days remaining of free Pro access. Enjoy unlimited AI analysis and all Pro features!"]})})]}),s?.trialEnd&&new Date(s.trialEnd)>new Date&&e.jsx(e.Fragment,{children:Math.ceil((new Date(s.trialEnd).getTime()-Date.now())/(1e3*60*60*24))<=3&&e.jsxs(Y,{className:"border-warning bg-warning/10",children:[e.jsx(P,{className:"h-4 w-4 text-warning"}),e.jsxs(R,{className:"text-warning",children:[e.jsx("strong",{children:"Trial ending soon!"})," Your free trial ends on"," ",new Date(s.trialEnd).toLocaleDateString(),". Add a payment method to continue using Performer."]})]})}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs(h,{children:[e.jsxs(f,{children:[e.jsx(N,{children:"Current Subscription"}),e.jsx(S,{children:"Your active plan and billing information"})]}),e.jsxs(g,{className:"space-y-4",children:[e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Plan"}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsx("p",{className:"text-xl font-bold",children:s?.planName||"Free Trial"}),s?.status&&le(s.status)]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:s?.priceCents===0?e.jsx("span",{className:"text-success font-medium",children:"Free"}):`$${((s?.priceCents||0)/100).toFixed(0)}/month`})]})}),e.jsx(U,{}),e.jsxs("div",{className:"space-y-2",children:[s?.currentPeriodEnd&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Current period ends:"}),e.jsx("span",{className:"font-medium",children:new Date(s.currentPeriodEnd).toLocaleDateString()})]}),s?.hasPaymentMethod&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Payment method:"}),e.jsxs("span",{className:"font-medium flex items-center gap-1",children:[e.jsx(fe,{className:"h-3 w-3"}),"On file"]})]})]}),e.jsx(U,{}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s?.stripeCustomerId&&e.jsx(o,{variant:"outline",className:"flex-1",onClick:()=>u(),disabled:p,children:p?e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"h-4 w-4 mr-2 animate-spin"}),"Opening..."]}):e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"Manage Billing"]})}),v&&v.length>0&&!m&&e.jsx(o,{className:"flex-1",onClick:()=>{const a=v[0];j({planKey:a.plan_key})},disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"h-4 w-4 mr-2 animate-spin"}),"Loading..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Upgrade Plan"]})})]})]})]}),e.jsx(De,{})]}),ae&&e.jsxs(h,{children:[e.jsxs(f,{children:[e.jsxs(N,{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-5 w-5"}),"Team Seats"]}),e.jsxs(S,{children:["Manage your team seats. Your plan includes"," ",c?.included_seats??3," seats. Additional seats are $97/month each."]})]}),e.jsx(g,{children:te?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(x,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):c?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"text-center p-3 bg-muted rounded-lg",children:[e.jsx("p",{className:"text-2xl font-bold",children:c.seats_used}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"In Use"})]}),e.jsxs("div",{className:"text-center p-3 bg-muted rounded-lg",children:[e.jsx("p",{className:"text-2xl font-bold",children:c.total_seats}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total"})]}),e.jsxs("div",{className:"text-center p-3 bg-muted rounded-lg",children:[e.jsx("p",{className:"text-2xl font-bold",children:c.seats_available}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Available"})]})]}),c.additional_seats>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{className:"text-muted-foreground",children:["Additional seats (",c.additional_seats,"):"]}),e.jsxs("span",{className:"font-medium",children:["+$",(c.additional_seats*c.price_per_additional_seat_cents/100).toFixed(0),"/month"]})]}),e.jsx(U,{}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(o,{variant:"outline",size:"sm",onClick:()=>ne(1),disabled:D||L,children:D?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(Ce,{className:"h-4 w-4 mr-1"}),"Add Seat"]})}),c.additional_seats>0&&e.jsx(o,{variant:"outline",size:"sm",onClick:()=>ie(1),disabled:D||L||c.seats_available<1,children:L?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"h-4 w-4 mr-1"}),"Remove Seat"]})}),e.jsx("span",{className:"text-xs text-muted-foreground ml-auto",children:"$97/seat/month"})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Unable to load seat information"})})]}),v&&v.length>0&&e.jsxs(h,{children:[e.jsxs(f,{children:[e.jsx(N,{children:"Available Plans"}),e.jsx(S,{children:"Upgrade to unlock more features and remove limits"})]}),e.jsx(g,{children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:v.map(a=>e.jsxs("div",{className:"border rounded-lg p-4 hover:border-primary transition-colors",children:[e.jsx("div",{className:"flex items-start justify-between mb-2",children:e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:a.display_name}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:a.description})]})}),e.jsxs("div",{className:"mt-4 mb-4",children:[e.jsxs("div",{className:"text-3xl font-bold",children:["$",(a.price_cents/100).toFixed(0)]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["per ",a.billing_interval]})]}),e.jsx(o,{className:"w-full",onClick:()=>j({planKey:a.plan_key}),disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(x,{className:"h-4 w-4 mr-2 animate-spin"}),"Processing..."]}):`Upgrade to ${a.name}`})]},a.plan_key))})})]}),e.jsx($e,{}),e.jsxs(h,{children:[e.jsxs(f,{children:[e.jsx(N,{children:"Billing History"}),e.jsx(S,{children:"View and download past invoices"})]}),e.jsx(g,{children:re?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx(x,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):F&&F.length>0?e.jsx("div",{className:"border rounded-lg overflow-x-auto",children:e.jsxs(ve,{children:[e.jsx(we,{children:e.jsxs(K,{children:[e.jsx(y,{children:"Date"}),e.jsx(y,{children:"Amount"}),e.jsx(y,{children:"Status"}),e.jsx(y,{children:"Period"}),e.jsx(y,{className:"text-right",children:"Invoice"})]})}),e.jsx(ye,{children:F.map(a=>e.jsxs(K,{children:[e.jsx(_,{children:new Date(a.paid_at||a.peri
1od_start).toLocaleDateString()}),e.jsxs(_,{className:"font-medium",children:["$",(a.amount_cents/100).toFixed(2)]}),e.jsx(_,{children:e.jsx(z,{variant:a.status==="paid"?"default":"secondary",children:a.status})}),e.jsxs(_,{className:"text-sm text-muted-foreground",children:[new Date(a.period_start).toLocaleDateString()," ","- ",new Date(a.period_end).toLocaleDateString()]}),e.jsxs(_,{className:"text-right",children:[a.invoice_pdf&&e.jsx(o,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs("a",{href:a.invoice_pdf,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(Pe,{className:"h-4 w-4 mr-2"}),"PDF"]})}),a.hosted_invoice_url&&e.jsx(o,{variant:"ghost",size:"sm",asChild:!0,children:e.jsxs("a",{href:a.hosted_invoice_url,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(M,{className:"h-4 w-4 mr-2"}),"View"]})})]})]},a.id))})]})}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx("p",{children:"No billing history available yet"}),e.jsx("p",{className:"text-sm mt-2",children:"Your invoices will appear here once you have a paid subscription"})]})})]})]})})},$e=()=>{const[s,n]=$.useState(""),[t,r]=$.useState(!1),[i,d]=$.useState(!1),j=async()=>{const l=s.trim();if(!l||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l)){T({title:"Please enter a valid email",variant:"destructive"});return}r(!0);try{const{data:{user:u}}=await w.auth.getUser(),{error:p}=await w.from("waitlist_signups").insert({email:l,user_id:u?.id??null,source:"billing"});if(p)if(p.code==="23505")T({title:"You're already on the list! 🎉"}),d(!0);else throw p;else T({title:"You're on the list! 🎉",description:"We'll notify you when new plans launch."}),d(!0)}catch{T({title:"Something went wrong. Please try again.",variant:"destructive"})}finally{r(!1)}};return e.jsxs(h,{children:[e.jsxs(f,{children:[e.jsx(N,{children:"Upcoming Plans"}),e.jsx(S,{children:"New tiers launching in April — join the waitlist to be notified"})]}),e.jsx(g,{children:e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:[{name:"Top Up",desc:"More AI credits and flexibility for growing sellers."},{name:"Pro",desc:"Unlimited AI power, advanced analytics, and predictive insights."}].map(l=>e.jsxs("div",{className:"border rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h3",{className:"font-semibold",children:l.name}),e.jsx(z,{variant:"secondary",className:"text-xs",children:"Coming April"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:l.desc}),i?e.jsxs(o,{variant:"outline",className:"w-full",disabled:!0,children:[e.jsx(ee,{className:"h-4 w-4 mr-2"}),"You're on the list!"]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx(be,{type:"email",placeholder:"[email protected]",value:s,onChange:u=>n(u.target.value),onKeyDown:u=>u.key==="Enter"&&j(),className:"flex-1"}),e.jsxs(o,{variant:"secondary",onClick:j,disabled:t,children:[t?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsx(E,{className:"h-4 w-4 mr-1"}),"Join"]})]})]},l.name))})})]})};export{Oe as SettingsBilling};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.