PageSourceSearch

https://app.harperflow.io/assets/AgencyBillingPage-oWkmIaTh.js

js harperflow.io collected 2026-09-29 09:34:47 UTC 16,329 bytes, 1 lines download raw bytes

1import{j as e,L as I,R as x}from"./vendor-react-CfjHS-i4.js";import{u as R}from"./useAgencyBilling-DQ4UcsBg.js";import{d as L,a as O,u as _,c as F,e as E,b as K}from"./useBillingMutations-CbIwowfE.js";import{bf as U,r as p,aE as j,ay as f}from"./main-CYwl6bIU.js";import{A as W,S as H}from"./AsyncState-A7xwhBkP.js";import{P as V}from"./pageContainer-CZ9fQBW2.js";import{A as C,c as A,f as w,g as P,d as S,e as T,a as N,b as $}from"./alert-dialog-D8HTp3ck.js";import{u as g}from"./vendor-intl-86zllT5l.js";import{n as q,o as D,al as h,H as B,bb as k,c as G}from"./vendor-icons-WoZ1_kPN.js";import"./vendor-tanstack-CH6rzB3p.js";import"./vendor-di-Dt7Xs26B.js";import"./vendor-zod-D4-NfubC.js";import"./vendor-http-DcNlVx-A.js";import"./vendor-supabase-JOBST33U.js";import"./vendor-motion-BeZSHsoh.js";const u="rounded-xl border border-gray-200 bg-white dark:border-neutral-800 dark:bg-neutral-900",Z=[{value:"",labelKey:"app:accounts.agencyBilling.cadenceAuto"},{value:"weekly",labelKey:"app:accounts.agencyBilling.cadenceWeekly"},{value:"twice_weekly",labelKey:"app:accounts.agencyBilling.cadenceTwiceWeekly"},{value:"three_times_weekly",labelKey:"app:accounts.agencyBilling.cadenceThreeTimesWeekly"},{value:"daily",labelKey:"app:accounts.agencyBilling.cadenceDaily"}];function y(a){const t=(a??0)/100;return Number.isInteger(t)?t.toLocaleString("en-US"):t.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}function v(a){if(!a)return"—";const t=new Date(a);return Number.isNaN(t.getTime())?"—":new Intl.DateTimeFormat(void 0,{month:"long",day:"numeric",year:"numeric",timeZone:"UTC"}).format(t)}function b({label:a,value:t,testid:n}){return e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] tracking-[0.12em] text-gray-400 uppercase",children:a}),e.jsx("div",{"data-testid":n,className:"mt-0.5 text-lg font-semibold tabular-nums",children:t})]})}function J({data:a}){const{t}=g(),n=(a.per_article_cents??0)/100,s=a.per_article_cents??0,i=a.base_cents??0,c=s>0?Math.round(i/s):a.included_articles??0,r=a.included_articles??c,o=r<c,m=a.month_to_date_articles??0;return e.jsxs("section",{className:`${u} p-4`,children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsxs("h2",{className:"text-sm font-semibold",children:[t("app:accounts.agencyBilling.planTitle"),a.tier?t("app:accounts.agencyBilling.tierSuffix",{tier:a.tier}):""]}),e.jsxs("span",{"data-testid":"next-charge",className:"inline-flex items-center gap-1.5 rounded-lg border border-gray-200 px-2.5 py-1 text-xs font-medium text-gray-600 dark:border-neutral-700 dark:text-gray-300",children:[e.jsx(D,{className:"size-3.5"}),a.subscription.active?t("app:accounts.agencyBilling.nextCharge",{date:v(a.subscription.next_charge_at)}):t("app:accounts.agencyBilling.noActiveSubscription")]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 sm:grid-cols-4",children:[e.jsx(b,{label:t("app:accounts.agencyBilling.statBase"),value:t("app:accounts.agencyBilling.usdAmount",{amount:y(a.base_cents)}),testid:"plan-base"}),e.jsx(b,{label:t("app:accounts.agencyBilling.statIncluded"),value:`${c}`,testid:"plan-included"}),e.jsx(b,{label:t("app:accounts.agencyBilling.statThisMonth"),value:`${m}`,testid:"plan-mtd"}),e.jsx(b,{label:t("app:accounts.agencyBilling.statProjectedOverage"),value:t("app:accounts.agencyBilling.usdAmount",{amount:y(a.projected_overage_cents)}),testid:"plan-projected-overage"})]}),e.jsxs("p",{className:"mt-3 text-xs text-gray-500 dark:text-gray-400",children:[t("app:accounts.agencyBilling.baseNarrativePrefix")," ",e.jsx("strong",{children:t("app:accounts.agencyBilling.usdAmount",{amount:y(a.base_cents)})})," ",t("app:accounts.agencyBilling.baseNarrativeIncludes")," ",e.jsx("strong",{children:c}),t("app:accounts.agencyBilling.baseNarrativeArticles",{rate:n.toFixed(2)})," ",e.jsx("strong",{children:t("app:accounts.agencyBilling.usdAmount",{amount:n.toFixed(2)})}),t("app:accounts.agencyBilling.baseNarrativeTail")]}),o&&e.jsxs("p",{"data-testid":"proration-note",className:"mt-2 rounded-lg bg-amber-50 p-2 text-xs text-amber-800 dark:bg-amber-950/30 dark:text-amber-300",children:[t("app:accounts.agencyBilling.prorationPrefix")," ",e.jsx("strong",{children:t("app:accounts.agencyBilling.prorationProrated")}),t("app:accounts.agencyBilling.prorationColon")," ",e.jsx("strong",{children:r}),t("app:accounts.agencyBilling.prorationBody",{amount:y(a.base_cents)}),e.jsx("strong",{children:c}),t("app:accounts.agencyBilling.prorationBegin",{amount:y(a.base_cents)})," ",a.subscription.active?t("app:accounts.agencyBilling.prorationOnDate",{date:v(a.subscription.next_charge_at)}):t("app:accounts.agencyBilling.prorationNextCycle")]})]})}function Q({org:a}){const{t}
1=g(),n=_(),s=F(),i=E(),[c,r]=x.useState(String(a.allocation??0)),[o,m]=x.useState(!1),l=Math.max(0,Math.floor(Number(c)||0)),z=l!==(a.allocation??0),M=a.publish_cadence??"";return e.jsxs("li",{"data-testid":`client-row-${a.org_id}`,className:"flex flex-wrap items-center justify-between gap-2 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:a.name}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("app:accounts.agencyBilling.allocationLine",{used:a.used??0,allocation:a.allocation??0})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400",children:[t("app:accounts.agencyBilling.cadenceLabel"),e.jsx("select",{"data-testid":`cadence-select-${a.org_id}`,"aria-label":t("app:accounts.agencyBilling.cadenceAria",{name:a.name}),value:M,disabled:i.isPending,onChange:d=>i.mutate({orgId:a.org_id,cadence:d.target.value===""?null:d.target.value}),className:"rounded-lg border border-gray-300 bg-white px-2 py-1 text-sm dark:border-neutral-700 dark:bg-neutral-900",children:Z.map(d=>e.jsx("option",{value:d.value,children:t(d.labelKey)},d.value))})]}),e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400",children:[t("app:accounts.agencyBilling.articlesLabel"),e.jsx("input",{"data-testid":`allocation-input-${a.org_id}`,"aria-label":t("app:accounts.agencyBilling.allocationForAria",{name:a.name}),value:c,inputMode:"numeric",onChange:d=>r(d.target.value),className:"w-20 rounded-lg border border-gray-300 bg-white px-2 py-1 text-sm tabular-nums dark:border-neutral-700 dark:bg-neutral-900"})]}),e.jsx(p,{type:"button",size:"sm","data-testid":`save-allocation-${a.org_id}`,disabled:!z||n.isPending,onClick:()=>n.mutate({orgId:a.org_id,allocation:l}),children:n.isPending?e.jsx(h,{className:"size-4 animate-spin"}):t("app:accounts.agencyBilling.save")}),e.jsx(p,{type:"button",variant:"ghost",size:"sm","data-testid":`remove-client-${a.org_id}`,"aria-label":t("app:accounts.agencyBilling.removeAria",{name:a.name}),onClick:()=>m(!0),className:"text-red-600 hover:bg-red-50 hover:text-red-700 dark:text-red-400 dark:hover:bg-red-950/40",children:e.jsx(k,{className:"size-4"})})]}),e.jsx(C,{open:o,onOpenChange:m,children:e.jsxs(A,{children:[e.jsxs(w,{children:[e.jsx(P,{children:t("app:accounts.agencyBilling.removeTitle",{name:a.name})}),e.jsx(S,{children:t("app:accounts.agencyBilling.removeBody")})]}),e.jsxs(T,{children:[e.jsx($,{children:t("app:accounts.agencyBilling.cancel")}),e.jsxs(N,{"data-testid":"confirm-remove-client",className:j(f({variant:"destructive"})),onClick:()=>{s.mutate(a.org_id),m(!1)},children:[e.jsx(k,{className:"size-4"})," ",t("app:accounts.agencyBilling.removeClient")]})]})]})})]})}function X({data:a}){const{t}=g(),n=a.orgs.filter(s=>(s.allocation??0)>0);return e.jsxs("section",{className:`${u} p-4`,children:[e.jsx("h2",{className:"mb-2 text-sm font-semibold",children:t("app:accounts.agencyBilling.clientsTitle")}),n.length===0?e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:t("app:accounts.agencyBilling.clientsEmpty")}):e.jsx("ul",{className:"divide-y divide-gray-100 dark:divide-neutral-800/60",children:n.map(s=>e.jsx(Q,{org:s},s.org_id))})]})}function Y({data:a}){const{t}=g(),n=_(),s=a.orgs.filter(l=>(l.allocation??0)===0&&!l.has_own_subscription),[i,c]=x.useState(""),[r,o]=x.useState("10"),m=()=>{const l=Math.max(0,Math.floor(Number(r)||0));!i||l<=0||(n.mutate({orgId:i,allocation:l}),c(""))};return e.jsxs("section",{className:`${u} p-4`,children:[e.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold",children:[e.jsx(B,{className:"size-4"})," ",t("app:accounts.agencyBilling.assignTitle")]}),s.length===0?e.jsx("p",{className:"mt-2 text-sm text-gray-600 dark:text-gray-300",children:t("app:accounts.agencyBilling.assignAllAllocated")}):e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1 text-xs text-gray-500 dark:text-gray-400",children:[t("app:accounts.agencyBilling.clientLabel"),e.jsxs("select",{"data-testid":"add-client-org-select",value:i,onChange:l=>c(l.target.value),className:"min-w-44 rounded-lg border border-gray-300 bg-white px-2.5 py-1.5 text-sm dark:border-neutral-700 dark:bg-neutral-900",children:[e.jsx("option",{value:"",children:t("app:accounts.agencyBilling.selectClient")}
1),s.map(l=>e.jsx("option",{value:l.org_id,children:l.name},l.org_id))]})]}),e.jsxs("label",{className:"flex flex-col gap-1 text-xs text-gray-500 dark:text-gray-400",children:[t("app:accounts.agencyBilling.articlesPerMonthLabel"),e.jsx("input",{"data-testid":"add-client-allocation","aria-label":t("app:accounts.agencyBilling.allocationAria"),value:r,inputMode:"numeric",onChange:l=>o(l.target.value),className:"w-28 rounded-lg border border-gray-300 bg-white px-2.5 py-1.5 text-sm tabular-nums dark:border-neutral-700 dark:bg-neutral-900"})]}),e.jsxs(p,{type:"button","data-testid":"add-client-submit",disabled:!i||n.isPending,onClick:m,children:[n.isPending?e.jsx(h,{className:"size-4 animate-spin"}):e.jsx(B,{className:"size-4"}),t("app:accounts.agencyBilling.assign")]})]})]})}function ee({org:a}){const{t}=g(),n=K(),[s,i]=x.useState("10"),c=Math.max(0,Math.floor(Number(s)||0)),r=()=>{c<=0||n.mutate({orgId:a.org_id,allocation:c})};return e.jsxs("li",{"data-testid":`solo-site-row-${a.org_id}`,className:"flex flex-wrap items-center justify-between gap-2 py-2.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate font-medium",children:a.name}),e.jsx("div",{"data-testid":`solo-badge-${a.org_id}`,className:"mt-0.5 inline-flex items-center gap-1 rounded-md bg-amber-50 px-1.5 py-0.5 text-xs font-medium text-amber-700 dark:bg-amber-950/40 dark:text-amber-300",children:t("app:accounts.agencyBilling.soloBadge")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-gray-500 dark:text-gray-400",children:[t("app:accounts.agencyBilling.articlesLabel"),e.jsx("input",{"data-testid":`migrate-allocation-${a.org_id}`,"aria-label":t("app:accounts.agencyBilling.allocationForAria",{name:a.name}),value:s,inputMode:"numeric",onChange:o=>i(o.target.value),className:"w-20 rounded-lg border border-gray-300 bg-white px-2 py-1 text-sm tabular-nums dark:border-neutral-700 dark:bg-neutral-900"})]}),e.jsxs(p,{type:"button",size:"sm","data-testid":`migrate-site-${a.org_id}`,disabled:c<=0||n.isPending,onClick:r,children:[n.isPending?e.jsx(h,{className:"size-4 animate-spin"}):e.jsx(G,{className:"size-4"}),t("app:accounts.agencyBilling.moveToAgency")]})]})]})}function ae({data:a}){const{t}=g(),n=a.orgs.filter(s=>s.has_own_subscription===!0);return n.length===0?null:e.jsxs("section",{"data-testid":"solo-sites",className:`${u} p-4`,children:[e.jsx("h2",{className:"text-sm font-semibold",children:t("app:accounts.agencyBilling.soloTitle")}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:t("app:accounts.agencyBilling.soloBody")}),e.jsx("ul",{className:"mt-2 divide-y divide-gray-100 dark:divide-neutral-800/60",children:n.map(s=>e.jsx(ee,{org:s},s.org_id))})]})}function te({data:a,isOwner:t}){const{t:n}=g(),s=L(),i=O(),[c,r]=x.useState(!1);return a.cancel_at_period_end===!0?e.jsxs("section",{"data-testid":"agency-cancel-ending",className:"rounded-xl border border-amber-200 bg-amber-50 p-4 dark:border-amber-900/40 dark:bg-amber-950/30",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-sm font-semibold text-amber-900 dark:text-amber-200",children:[e.jsx(D,{className:"size-4"})," ",n("app:accounts.agencyBilling.endingTitle")]}),e.jsxs("p",{className:"mt-1 text-sm text-amber-900 dark:text-amber-200",children:[n("app:accounts.agencyBilling.endingPrefix")," ",e.jsx("strong",{children:v(a.subscription.next_charge_at)}),n("app:accounts.agencyBilling.endingSuffix")]}),t&&e.jsx(p,{type:"button",size:"sm","data-testid":"reactivate-agency-plan",disabled:s.isPending,onClick:()=>s.mutate({cancel:!1}),className:"mt-3",children:s.isPending?e.jsx(h,{className:"size-4 animate-spin"}):n("app:accounts.agencyBilling.keepMyPlan")})]}):!t||!a.subscription.active?null:e.jsxs("section",{"data-testid":"agency-cancel-control",className:`${u} p-4`,children:[e.jsx("h2",{className:"text-sm font-semibold",children:n("app:accounts.agencyBilling.cancelTitle")}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:n("app:accounts.agencyBilling.cancelBody")}),e.jsx(p,{type:"button",variant:"outline",size:"sm","data-testid":"cancel-agency-plan",onClick:()=>r(!0),className:"mt-3 border-red-300 text-red-600 hover:bg-red-50 hover:text-red-700 dark:border-red-900/60 dark:text-red-400 dark:hover:bg-red-950/40",children:n("app:accounts.agencyBilling.cancelButton")}),e.jsx(C,{open:c,onOpenChange:r,children:e.jsxs(A,{children:[e.jsxs(w,{children:[e.jsx(P,{children:n("app:accounts.agencyBilling.confirmTitle")}),e.jsxs(S,{children:[e.jsx("strong",{children:n("app:accounts.agencyBilling.confirmAtPeriodEnd")}),n("app:accounts.agencyBilling.confirmAtPeriodEndBody"),e.jsx("strong",{children:n("app:accounts.agencyBilling.confirmCancelNow")}),n("app:accounts.agencyBilling.confirmCancelNowBody")," ",e.jsx("strong",{children:n("app:accounts.agencyBilling.confirmNoRefund")}),n("app:accounts.agencyBilling.confirmNoRefundTail")]})]}),e.jsxs(T,{className:"sm:flex-col sm:items-stretch sm:gap-2",children:[e.jsx(N,{"data-testid":"confirm-cancel-agency",className:j(f({variant:"destructive"})),onClick:()=>{s.mutate({cancel:!0}),r(!1)},children:n("app:accounts.agencyBilling.confirmCancelAtPeriodEnd")}),e.jsx(N,{"data-testid":"confirm-cancel-agency-now",className:j(f({variant:"destructive"}),"bg-red-800 hover:bg-red-900"),onClick:()=>{i.mutate(),r(!1)},children:n("app:accounts.agencyBilling.confirmCancelNowButton")}),e.jsx($,{children:n("app:accounts.agencyBilling.keepMyPlan")})]})]})})]})}function he(){const{t:a}=g(),t=R(),s=U().data?.active_account_role==="owner";return e.jsxs("div",{"data-testid":"agency-billing-page",className:`${V} space-y-5`,children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"flex items-center gap-2 text-xl font-semibold tracking-tight",children:[e.jsx(q,{className:"size-5"})," ",a("app:accounts.agencyBilling.pageTitle")]}),e.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-gray-400",children:a("app:accounts.agencyBilling.pageIntro")})]}),e.jsx(W,{query:t,loading:e.jsx(H,{n:4}),children:i=>e.jsx("div",{className:"space-y-5",children:i.account_type!=="agency"?e.jsxs("section",{"data-testid":"agency-not-active",className:`${u} p-4`,children:[e.jsx("h2",{className:"text-sm font-semibold",children:a("app:accounts.agencyBilling.notActiveTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-600 dark:text-gray-300",children:a("app:accounts.agencyBilling.notActiveBody")}),e.jsx(p,{asChild:!0,className:"mt-3",variant:"outline",children:e.jsx(I,{to:"/plan",children:a("app:accounts.agencyBilling.viewPlans")})})]}):i.base_cents==null?e.jsxs("section",{"data-testid":"agency-terms-pending",className:`${u} p-4`,children:[e.jsx("h2",{className:"text-sm font-semibold",children:a("app:accounts.agencyBilling.pendingTitle")}),e.jsx("p",{className:"mt-2 text-sm text-gray-600 dark:text-gray-300",children:a("app:accounts.agencyBilling.pendingBody")})]}):e.jsxs(e.Fragment,{children:[e.jsx(J,{data:i}),e.jsx(te,{data:i,isOwner:s}),e.jsx(X,{data:i}),e.jsx(ae,{data:i}),e.jsx(Y,{data:i})]})})})]})}export{he as default};

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.