PageSourceSearch

https://careerdiary.io/assets/UsageBillingPage-DnR-Quwc.js

js careerdiary.io collected 2026-10-02 01:57:48 UTC 16,519 bytes, 1 lines download raw bytes

1import{r as o,j as e}from"./animation-CddyXVCz.js";import{P as z}from"./PageWrapper-C3-XQErc.js";import{s as k,D as H,m as q,F as W,p as K,S as V,H as Q,y as X,w as Z,h as f,I as ee,B as E,J as te,K as B}from"./index-DnWsV7cE.js";import{C as ae}from"./CreditMeter-DHhVivir.js";import{D as b}from"./billingLimits-4ln6JCGI.js";import{g as se,B as re}from"./billing-qSkzg-yh.js";import"./react-vendor-CbN3pvl2.js";import"./supabase-iKSPld20.js";import"./docgen-Bp8WKBAE.js";import"./query-DPqpbKNH.js";const le={resumes_tailored:0,cover_letters_generated:0,job_searches:0,jobs_viewed:0,member_since:null};function ie(){const[s,t]=o.useState(le),[i,d]=o.useState(!0),[m,a]=o.useState(null),y=o.useCallback(async()=>{var h;d(!0),a(null);try{const u=(h=(k?await k.auth.getSession():{data:{session:null}}).data.session)==null?void 0:h.access_token,x=await fetch("/api/usage/activity",{headers:{...u?{Authorization:`Bearer ${u}`}:{}}});if(!x.ok)throw new Error(`HTTP ${x.status}`);const n=await x.json();t(n)}catch(l){a((l==null?void 0:l.message)||"Failed to load activity")}finally{d(!1)}},[]);o.useEffect(()=>{y()},[y]);const c=o.useCallback(async h=>{var l;try{const x=(l=(k?await k.auth.getSession():{data:{session:null}}).data.session)==null?void 0:l.access_token;await fetch("/api/usage/activity/track",{method:"POST",headers:{"Content-Type":"application/json",...x?{Authorization:`Bearer ${x}`}:{}},body:JSON.stringify({event:h})}),t(n=>({...n,[h]:n[h]+1}))}catch{}},[]);return{stats:s,isLoading:i,error:m,trackEvent:c,refetch:y}}const I=async()=>{var s;try{if(!k)return{};const{data:t}=await k.auth.getSession(),i=(s=t==null?void 0:t.session)==null?void 0:s.access_token;return i?{Authorization:`Bearer ${i}`}:{}}catch{return{}}};async function U(s){try{const t=await s.json();return(t==null?void 0:t.error)||(t==null?void 0:t.message)||`Request failed (${s.status})`}catch{return`Request failed (${s.status})`}}async function de(s="monthly"){const t=await fetch("/api/billing/checkout",{method:"POST",headers:{"Content-Type":"application/json",...await I()},body:JSON.stringify({plan:s})});if(!t.ok)throw new Error(await U(t));return t.json()}async function ne(){const s=await fetch("/api/billing/portal",{method:"POST",headers:{"Content-Type":"application/json",...await I()},body:JSON.stringify({})});if(!s.ok)throw new Error(await U(s));return s.json()}const oe=({icon:s,label:t,value:i,isLoading:d,color:m})=>e.jsxs("div",{className:"rounded-2xl border border-slate-200 bg-white p-6 flex flex-col gap-3 dark:border-slate-700 dark:bg-slate-900",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex items-center justify-center ${m}`,children:s}),d?e.jsx("div",{className:"h-9 w-16 rounded-lg bg-slate-100 animate-pulse dark:bg-slate-800"}):e.jsx("p",{className:"text-4xl font-bold tabular-nums text-slate-900 dark:text-white",children:i.toLocaleString()}),e.jsx("p",{className:"text-sm font-medium text-slate-500 dark:text-slate-400",children:t})]}),ce=s=>s?new Intl.DateTimeFormat("en-US",{month:"long",year:"numeric"}).format(new Date(s)):null,xe=s=>{switch(s){case"paid":return"border-emerald-200 bg-emerald-50/80 ring-1 ring-emerald-200 dark:border-emerald-900/40 dark:bg-emerald-950/20 dark:ring-emerald-900/20";case"signed_in":return"border-indigo-200 bg-indigo-50/80 ring-1 ring-indigo-200 dark:border-indigo-900/40 dark:bg-indigo-950/20 dark:ring-indigo-900/20";default:return"border-slate-200 bg-white dark:border-slate-700 dark:bg-slate-900"}},Ne=()=>{var C,A,_,P,$;const s=H(),{session:t,isGuest:i}=q(),{stats:d,isLoading:m}=ie(),{usage:a,isLoading:y,isTrialActive:c,isTrialExpired:h,trialDaysRemaining:l}=W(),[u,x]=o.useState(!1),[n,N]=o.useState("monthly"),[w,v]=o.useState(null);K({title:"Billing & Usage | CareerDiary",description:"Review your daily AI credits, choose a plan, and upgrade to Pro with Stripe checkout.",canonical:"https://careerdiary.io/app/settings/billing"});const M=o.useMemo(()=>se(a.tier),[a.tier]),D=Math.max(a.limit-a.used,0),j=a.proCreditsExpiresAt?new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(a.proCreditsExpiresAt):null,F=c?Math.max(0,Math.min(100,(7-l)/7*100)):100,R=[{icon:e.jsx(V,{className:"h-5 w-5 text-indigo-600 dark:text-indigo-400"}),label:"Resumes Tailored",value:d.resumes_tailored,isLoading:m,color:"bg-indigo-50 dark:bg-indigo-900/20"},{icon:e.jsx(Q,{className:"h-5 w-5 text-emerald-600 dark:text-emerald-400"}),label:"Cover Letters Generated",value:d.cover_letters_generated,isLoading:m,color:"bg-emerald-50 dark:bg-emerald-900/20"}
1,{icon:e.jsx(X,{className:"h-5 w-5 text-blue-600 dark:text-blue-400"}),label:"Job Searches",value:d.job_searches,isLoading:m,color:"bg-blue-50 dark:bg-blue-900/20"},{icon:e.jsx(Z,{className:"h-5 w-5 text-amber-600 dark:text-amber-400"}),label:"Jobs Opened",value:d.jobs_viewed,isLoading:m,color:"bg-amber-50 dark:bg-amber-900/20"}],S=async()=>{if(v(null),i||!t){s("/auth",{state:{mode:"signup"}});return}x(!0);try{if(a.tier==="paid"){B("subscription_portal_opened",{source:"billing_page"});const{url:g}=await ne();window.location.assign(g);return}B("subscription_started",{source:"billing_page",plan:n});const{url:r}=await de(n);window.location.assign(r)}catch(r){v(r instanceof Error?r.message:"Unable to start billing flow.")}finally{x(!1)}},Y=a.tier==="paid"?"Manage Billing":i||!t?"Create Free Account":"Upgrade to Pro";return e.jsx(z,{title:"Billing & Usage",description:"Monitor your AI credit usage and upgrade to Pro when you're ready.",maxWidth:"4xl",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs(f,{variant:"soft",padding:"lg",children:[e.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-slate-200 bg-white px-3 py-1 text-xs font-semibold text-slate-600 shadow-sm dark:border-slate-700 dark:bg-slate-900 dark:text-slate-300",children:[e.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${a.tier==="paid"?"bg-emerald-500":a.tier==="signed_in"?"bg-indigo-500":"bg-slate-400"}`}),M.name," plan",c&&e.jsx(ee,{label:"Trial",className:"ml-1 border-sky-200 bg-sky-50 text-sky-700 dark:border-sky-900/40 dark:bg-sky-950/30 dark:text-sky-200"})]}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-slate-900 dark:text-white",children:a.tier==="paid"?c?"You’re on a Pro trial":"You’re on Pro":a.tier==="signed_in"?"Free account active":"Guest mode active"}),e.jsx("p",{className:"mt-2 max-w-2xl text-sm leading-6 text-slate-600 dark:text-slate-300",children:c?`You’re on a ${l}-day Pro trial that unlocks the full Pro feature set.`:h?`Your trial ended${j?` on ${j}`:""}. Upgrade to restore Pro features.`:a.tier==="paid"?`You are on Pro with ${b.paid} AI credits per day plus premium intelligence features.`:a.tier==="signed_in"?`You get ${b.signed_in} AI credits per day, 5 saved resumes, and 1 cover letter daily.`:`Guests get ${b.anon} AI credits per day with view-only results until they create an account.`}),a.proCreditsExpiresAt&&e.jsxs("div",{className:"mt-4 space-y-2 rounded-2xl border border-slate-200 bg-white/70 p-4 dark:border-slate-700 dark:bg-slate-900/70",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 text-sm",children:[e.jsx("span",{className:"font-semibold text-slate-700 dark:text-slate-200",children:c?`Pro Trial: ${l} day${l===1?"":"s"} remaining`:`Your trial ended${j?` on ${j}`:""}`}),e.jsx("span",{className:"text-slate-500 dark:text-slate-400",children:a.proCreditsExpiresAt.toLocaleDateString("en-US",{month:"short",day:"numeric"})})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-slate-100 dark:bg-slate-800",children:e.jsx("div",{className:`h-full rounded-full ${c?"bg-gradient-to-r from-sky-500 to-indigo-500":"bg-gradient-to-r from-amber-500 to-orange-500"}`,style:{width:`${F}%`}})}),e.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:c?"Upgrade now to keep Pro after your trial ends.":"Refer a friend for 7 more days free or upgrade to restore Pro."})]})]})]}),e.jsxs("div",{className:"w-full max-w-sm space-y-3 rounded-2xl border border-slate-200 bg-white p-4 shadow-sm dark:border-slate-700 dark:bg-slate-900",children:[e.jsx(ae,{refreshTrigger:`${a.used}-${a.limit}-${a.tier}`,prefillEmail:((C=t==null?void 0:t.user)==null?void 0:C.email)||void 0,prefillName:((_=(A=t==null?void 0:t.user)==null?void 0:A.user_metadata)==null?void 0:_.full_name)||(($=(P=t==null?void 0:t.user)==null?void 0:P.user_metadata)==null?void 0:$.name)||void 0}),e.jsxs("div",{className:"text-xs text-slate-500 dark:text-slate-400",children:[D," credits remaining today. Resets at midnight UTC."]})]})]}),w&&e.jsx("div",{className:"mt-4 rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-950/30 dark:text-red-200",children:w}),e.jsx("div",{className:"mt-6",children:e.jsx(E,{type:"button",variant:"primary",size:"lg",loading:u||y,onClick:S,className:"rounded-full px-8",children:Y})})]}),e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:re.map(r=>{const g=r.id===a.tier,p=r.id==="paid",O=r.id==="anon",G=n==="annual"&&r.annualPriceLabel||r.priceLabel,J=g?p?"Manage Billing":"Current plan":p?i?"Create Free Account":"Upgrade to Pro":O&&i?"Current plan":r.ctaLabel,L=p&&(!g||a.tier==="paid");return e.jsxs(f,{variant:"default",padding:"lg",className:`relative overflow-hidden ${xe(r.id)} ${g?"shadow-lg":"shadow-sm"}`,children:[g&&e.jsx("div",{className:"absolute right-4 top-4 roun
1ded-full bg-slate-900 px-2.5 py-1 text-[10px] font-semibold uppercase tracking-[0.18em] text-white dark:bg-white dark:text-slate-900",children:"Current"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold uppercase tracking-[0.16em] text-slate-500 dark:text-slate-400",children:r.name}),p&&e.jsxs("div",{className:"mt-3 inline-flex rounded-xl border border-slate-200 bg-white p-1 dark:border-slate-700 dark:bg-slate-900",children:[e.jsx("button",{type:"button",className:`rounded-lg px-3 py-1 text-xs font-semibold transition-colors ${n==="monthly"?"bg-slate-900 text-white dark:bg-white dark:text-slate-900":"text-slate-600 dark:text-slate-300"}`,onClick:()=>N("monthly"),children:"Monthly"}),e.jsxs("button",{type:"button",className:`inline-flex items-center gap-2 rounded-lg px-3 py-1 text-xs font-semibold transition-colors ${n==="annual"?"bg-slate-900 text-white dark:bg-white dark:text-slate-900":"text-slate-600 dark:text-slate-300"}`,onClick:()=>N("annual"),children:["Annual",e.jsx("span",{className:"rounded-full bg-emerald-100 px-2 py-0.5 text-[10px] font-bold uppercase tracking-[0.1em] text-emerald-700 dark:bg-emerald-900/50 dark:text-emerald-300",children:"Save 45%"})]})]}),e.jsx("div",{className:"mt-2 flex items-end gap-2",children:e.jsx("span",{className:"text-3xl font-black text-slate-900 dark:text-white",children:p?G:r.priceLabel})}),p&&e.jsx("p",{className:"mt-1 text-xs font-medium text-emerald-700 dark:text-emerald-300",children:n==="annual"?"Billed yearly at $59":"Billed monthly at $9"}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-slate-600 dark:text-slate-300",children:r.description})]}),e.jsx("ul",{className:"space-y-2 text-sm text-slate-700 dark:text-slate-300",children:r.features.map(T=>e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"mt-1 inline-flex h-4 w-4 items-center justify-center rounded-full bg-emerald-100 text-[10px] font-bold text-emerald-700 dark:bg-emerald-900/40 dark:text-emerald-300",children:"✓"}),e.jsx("span",{children:T})]},T))}),e.jsx(E,{type:"button",variant:p||g?"secondary":"primary",size:"md",loading:u&&p,onClick:L?S:void 0,className:"w-full rounded-xl",disabled:!L,children:J})]})]},r.id)})}),e.jsx(f,{variant:"soft",padding:"lg",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-slate-900 dark:text-white",children:"Feature Comparison"}),e.jsx("p",{className:"mt-1 text-sm text-slate-600 dark:text-slate-300",children:"Compare daily limits and premium workflow access across all tiers."})]}),e.jsx("div",{className:"overflow-x-auto rounded-2xl border border-slate-200 dark:border-slate-700",children:e.jsxs("table",{className:"min-w-full bg-white text-sm dark:bg-slate-900",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-slate-50 text-left dark:bg-slate-800/80",children:[e.jsx("th",{className:"px-4 py-3 font-semibold text-slate-700 dark:text-slate-200",children:"Feature"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-slate-700 dark:text-slate-200",children:"Guest"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-slate-700 dark:text-slate-200",children:"Free"}),e.jsx("th",{className:"px-4 py-3 font-semibold text-slate-700 dark:text-slate-200",children:"Pro"})]})}),e.jsxs("tbody",{children:[e.jsxs("tr",{className:"border-t border-slate-200 dark:border-slate-700",children:[e.jsx("td",{className:"px-4 py-3 text-slate-600 dark:text-slate-300",children:"AI tailor credits per day"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:b.anon}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:b.signed_in}),e.jsx("td",{className:"px-4 py-3 text-emerald-700 dark:text-emerald-300",children:b.paid})]}),e.jsxs("tr",{className:"border-t border-slate-200 dark:border-slate-700",children:[e.jsx("td",{className:"px-4 py-3 text-slate-600 dark:text-slate-300",children:"Saved resumes"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"View only"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"Up to 5"}),e.jsx("td",{className:"px-4 py-3 text-emerald-700 dark:text-emerald-300",children:"Unlimited"})]}),e.jsxs("tr",{className:"border-t border-slate-200 dark:border-slate-700",children:[e.jsx("td",{className:"px-4 py-3 text-slate-600 dar
1k:text-slate-300",children:"Cover letters per day"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"None"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"1"}),e.jsx("td",{className:"px-4 py-3 text-emerald-700 dark:text-emerald-300",children:"Unlimited"})]}),e.jsxs("tr",{className:"border-t border-slate-200 dark:border-slate-700",children:[e.jsx("td",{className:"px-4 py-3 text-slate-600 dark:text-slate-300",children:"ATS Simulator"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"No"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"No"}),e.jsx("td",{className:"px-4 py-3 text-emerald-700 dark:text-emerald-300",children:"Yes"})]}),e.jsxs("tr",{className:"border-t border-slate-200 dark:border-slate-700",children:[e.jsx("td",{className:"px-4 py-3 text-slate-600 dark:text-slate-300",children:"Career GPS"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"No"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"No"}),e.jsx("td",{className:"px-4 py-3 text-emerald-700 dark:text-emerald-300",children:"Yes"})]}),e.jsxs("tr",{className:"border-t border-slate-200 dark:border-slate-700",children:[e.jsx("td",{className:"px-4 py-3 text-slate-600 dark:text-slate-300",children:"STAR Builder"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"No"}),e.jsx("td",{className:"px-4 py-3 text-slate-900 dark:text-white",children:"No"}),e.jsx("td",{className:"px-4 py-3 text-emerald-700 dark:text-emerald-300",children:"Yes"})]})]})]})})]})}),e.jsx(f,{variant:"soft",padding:"lg",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[d.member_since&&e.jsxs("p",{className:"text-sm text-slate-600 dark:text-slate-400",children:["Member since ",e.jsx("span",{className:"font-semibold text-slate-900 dark:text-white",children:ce(d.member_since)})]}),e.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-500 mt-1",children:"Stats are tracked from when you signed up and update in real time."})]}),e.jsx(te,{to:"/app/settings",className:"text-sm font-semibold text-indigo-600 hover:text-indigo-700 dark:text-indigo-300 dark:hover:text-indigo-200 whitespace-nowrap",children:"Back to Settings"})]})}),e.jsx("div",{className:"grid grid-cols-2 gap-4 lg:grid-cols-4",children:R.map(r=>e.jsx(oe,{...r},r.label))})]})})};export{Ne as UsageBillingPage};

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.