@arbidocs/blocks 0.5.130 → 0.5.132
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{DocumentReviewCard-M53XFLI2.cjs → DocumentReviewCard-2VI5OOLE.cjs} +3 -3
- package/dist/{DocumentReviewCard-M53XFLI2.cjs.map → DocumentReviewCard-2VI5OOLE.cjs.map} +1 -1
- package/dist/{FilesViewerDialog-EFRMXIM5.cjs → FilesViewerDialog-77YTFIX3.cjs} +4 -4
- package/dist/{FilesViewerDialog-EFRMXIM5.cjs.map → FilesViewerDialog-77YTFIX3.cjs.map} +1 -1
- package/dist/{WorkspaceTableView-QPROJRCF.cjs → WorkspaceTableView-7BMZ2O3Y.cjs} +6 -6
- package/dist/{WorkspaceTableView-QPROJRCF.cjs.map → WorkspaceTableView-7BMZ2O3Y.cjs.map} +1 -1
- package/dist/{chunk-KWHGYHRC.cjs → chunk-KSDTK66A.cjs} +2 -2
- package/dist/{chunk-KWHGYHRC.cjs.map → chunk-KSDTK66A.cjs.map} +1 -1
- package/dist/{chunk-MI3N3ZOT.cjs → chunk-PDDYAY4Z.cjs} +20 -20
- package/dist/{chunk-MI3N3ZOT.cjs.map → chunk-PDDYAY4Z.cjs.map} +1 -1
- package/dist/{chunk-T73BHNQX.cjs → chunk-TBPCG2PV.cjs} +240 -89
- package/dist/chunk-TBPCG2PV.cjs.map +1 -0
- package/dist/{chunk-GOQV6NOK.cjs → chunk-U7KB42OQ.cjs} +4 -4
- package/dist/{chunk-GOQV6NOK.cjs.map → chunk-U7KB42OQ.cjs.map} +1 -1
- package/dist/{chunk-GEZB3OEC.cjs → chunk-XJE7W42L.cjs} +18 -17
- package/dist/chunk-XJE7W42L.cjs.map +1 -0
- package/dist/connect/index.cjs +1413 -653
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/viewer.cjs +1 -1
- package/dist/connection/billing/ChangePlanDialog.d.ts +2 -1
- package/dist/connection/billing/ChangePlanDialog.js +8 -3
- package/dist/connection/billing/ChangePlanDialog.js.map +2 -2
- package/dist/connection/billing/ChangeProPlan.js +4 -4
- package/dist/connection/billing/ChangeProPlan.js.map +2 -2
- package/dist/connection/billing/CollaboratorPlan.js +5 -3
- package/dist/connection/billing/CollaboratorPlan.js.map +2 -2
- package/dist/connection/billing/ConnectedWelcomeDialog.d.ts +5 -13
- package/dist/connection/billing/ConnectedWelcomeDialog.js +38 -19
- package/dist/connection/billing/ConnectedWelcomeDialog.js.map +2 -2
- package/dist/connection/billing/MonthlySpendCap.d.ts +10 -3
- package/dist/connection/billing/MonthlySpendCap.js +103 -11
- package/dist/connection/billing/MonthlySpendCap.js.map +2 -2
- package/dist/connection/billing/NewProjectFlow.js +20 -7
- package/dist/connection/billing/NewProjectFlow.js.map +2 -2
- package/dist/connection/billing/ProjectDetail.js +1 -1
- package/dist/connection/billing/ProjectDetail.js.map +2 -2
- package/dist/connection/billing/ProjectPurchaseOptions.d.ts +14 -3
- package/dist/connection/billing/ProjectPurchaseOptions.js +472 -139
- package/dist/connection/billing/ProjectPurchaseOptions.js.map +2 -2
- package/dist/connection/billing/ProjectUsageCard.js +4 -4
- package/dist/connection/billing/ProjectUsageCard.js.map +2 -2
- package/dist/connection/billing/ReduceAddonDialog.js +2 -2
- package/dist/connection/billing/ReduceAddonDialog.js.map +2 -2
- package/dist/connection/billing/StripeCheckoutModal.js +3 -2
- package/dist/connection/billing/StripeCheckoutModal.js.map +2 -2
- package/dist/connection/billing/SubscriptionPlans.d.ts +5 -1
- package/dist/connection/billing/SubscriptionPlans.js +89 -6
- package/dist/connection/billing/SubscriptionPlans.js.map +2 -2
- package/dist/connection/billing/index.d.ts +1 -1
- package/dist/connection/billing/index.js +2 -2
- package/dist/connection/billing/index.js.map +2 -2
- package/dist/connection/billing/referral-reward.d.ts +2 -3
- package/dist/connection/billing/referral-reward.js +8 -3
- package/dist/connection/billing/referral-reward.js.map +2 -2
- package/dist/connection/billing/tax-quote.d.ts +2 -2
- package/dist/connection/billing/tax-quote.js +1 -0
- package/dist/connection/billing/tax-quote.js.map +2 -2
- package/dist/connection/command/ConnectedCommandPalette.js +2 -0
- package/dist/connection/command/ConnectedCommandPalette.js.map +2 -2
- package/dist/connection/command/actions.js +1 -1
- package/dist/connection/command/actions.js.map +2 -2
- package/dist/connection/contacts/ConnectedAddContacts.d.ts +7 -1
- package/dist/connection/contacts/ConnectedAddContacts.js +33 -17
- package/dist/connection/contacts/ConnectedAddContacts.js.map +2 -2
- package/dist/connection/contacts/ConnectedInviteContactsDialog.js +3 -2
- package/dist/connection/contacts/ConnectedInviteContactsDialog.js.map +2 -2
- package/dist/connection/contacts/ConnectedWelcomeInvitations.d.ts +6 -0
- package/dist/connection/contacts/ConnectedWelcomeInvitations.js +198 -0
- package/dist/connection/contacts/ConnectedWelcomeInvitations.js.map +7 -0
- package/dist/connection/projects/ConnectedProjectsPanel.js +17 -5
- package/dist/connection/projects/ConnectedProjectsPanel.js.map +2 -2
- package/dist/connection/shell/ConnectedWorkspaceSwitcher.js +3 -3
- package/dist/connection/shell/ConnectedWorkspaceSwitcher.js.map +2 -2
- package/dist/connection/workspace-form/ConnectedWorkspaceFormModal.js +2 -2
- package/dist/connection/workspace-form/ConnectedWorkspaceFormModal.js.map +2 -2
- package/dist/connection/workspace-list/ConnectedWorkspaceList.js +1 -1
- package/dist/connection/workspace-list/ConnectedWorkspaceList.js.map +2 -2
- package/dist/connection/workspace-list/useConnectedWorkspaceList.d.ts +1 -1
- package/dist/connection/workspace-list/useConnectedWorkspaceList.js +4 -4
- package/dist/connection/workspace-list/useConnectedWorkspaceList.js.map +2 -2
- package/dist/embed/index.cjs +8 -8
- package/dist/index.cjs +48 -48
- package/dist/index.cjs.map +1 -1
- package/dist/nav/actions.d.ts +2 -0
- package/dist/nav/actions.js.map +2 -2
- package/dist/settings/Billing.d.ts +2 -2
- package/dist/settings/Billing.js +4 -3
- package/dist/settings/Billing.js.map +2 -2
- package/dist/settings/PanelFrame.d.ts +3 -1
- package/dist/settings/PanelFrame.js +3 -2
- package/dist/settings/PanelFrame.js.map +2 -2
- package/dist/settings/SubscriptionParts.d.ts +4 -2
- package/dist/settings/SubscriptionParts.js +22 -3
- package/dist/settings/SubscriptionParts.js.map +2 -2
- package/dist/settings/WelcomeDialog.d.ts +31 -4
- package/dist/settings/WelcomeDialog.js +221 -82
- package/dist/settings/WelcomeDialog.js.map +2 -2
- package/dist/settings/index.cjs +144 -144
- package/dist/styles.css +1 -1
- package/dist/workflow-canvas/index.cjs +7 -7
- package/node_modules/@arbidocs/coedit/package.json +1 -1
- package/package.json +5 -5
- package/src/connection/billing/project-purchase.css +518 -39
- package/dist/chunk-GEZB3OEC.cjs.map +0 -1
- package/dist/chunk-T73BHNQX.cjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/ProjectPurchaseOptions.tsx"],
|
|
4
|
-
"sourcesContent": ["import { useState } from 'react'\nimport { ArrowRight, HardDrive, Minus, Plus, Sparkles, Users } from 'lucide-react'\nimport { MonthlySpendCap } from './MonthlySpendCap'\nimport { usePlanQuote } from '@arbidocs/react'\nimport type { components } from '@arbidocs/client'\nimport { Button } from '@arbidocs/react/ui'\nimport {\n addonPrice,\n findProPrices,\n MAX_CHECKOUT_BLOCKS,\n packPrice,\n type PlanInterval,\n} from './plan-pricing'\nimport { formatMoney, useRewardBalance } from './reward-balance'\nimport { applyReferralReward } from './referral-reward'\nimport type { TaxQuote } from './tax-quote'\n\ntype Product = components['schemas']['ProductResponse']\ntype Price = components['schemas']['ProductPrice']\n\nexport function purchaseNet(\n price: Price | undefined,\n ai: number,\n storage: number,\n collaborators: number\n): number | null {\n const base = packPrice(price)?.amount_ex_vat ?? price?.amount_ex_vat\n if (base == null) return null\n let total = base\n for (const [kind, count] of [\n ['ai_usage', ai],\n ['storage', storage],\n ['collaborators', collaborators],\n ] as const) {\n const block = price?.addon_prices?.find((p) => p.kind === kind)\n if (count && !block) return null\n total += count * (block?.amount_ex_vat ?? 0)\n }\n return total\n}\n\n/** The purchase decision is monthly or annual; both buttons show the actual starting charge. */\nexport function ProjectPurchaseOptions({\n products,\n projectExtId,\n aiBlocks,\n storageBlocks,\n collaboratorBlocks,\n onAiBlocksChange,\n onStorageBlocksChange,\n onCollaboratorBlocksChange,\n disabled,\n busy,\n enabled = true,\n onChoose,\n}: {\n products: Product[] | undefined\n projectExtId?: string\n aiBlocks: number\n storageBlocks: number\n collaboratorBlocks: number\n onAiBlocksChange: (count: number) => void\n onStorageBlocksChange: (count: number) => void\n onCollaboratorBlocksChange: (count: number) => void\n disabled?: boolean\n busy?: boolean\n enabled?: boolean\n onChoose: (interval: PlanInterval, capPence: number, quote?: TaxQuote) => void\n}) {\n const [spendCap, setSpendCap] = useState<number | null>(null)\n const reward = useRewardBalance()\n const prices = findProPrices(products)\n const monthlyNet = purchaseNet(prices.monthly, aiBlocks, storageBlocks, collaboratorBlocks)\n const annualNet = purchaseNet(prices.annual, aiBlocks, storageBlocks, collaboratorBlocks)\n const extras = { ai_usage: aiBlocks, storage: storageBlocks, collaborators: collaboratorBlocks }\n // The saved billing address supplies tax where available. Missing-address errors are left to Checkout.\n const monthlyQuote = usePlanQuote(\n projectExtId,\n enabled && monthlyNet != null ? { plan: 'pro', interval: 'month', addons: extras } : null\n )\n const annualQuote = usePlanQuote(\n projectExtId,\n enabled && annualNet != null ? { plan: 'pro', interval: 'year', addons: extras } : null\n )\n const product = products?.[0]\n const currency = prices.monthly?.currency ?? prices.annual?.currency ?? 'gbp'\n const money = (pence: number) => formatMoney(pence, currency)\n const ai =\n (product?.included_ai_gbp ?? 0) +\n aiBlocks * (addonPrice(prices.monthly, 'ai_usage')?.ai_gbp ?? 0)\n const storage =\n (product?.included_storage_gb ?? 0) +\n storageBlocks * (addonPrice(prices.monthly, 'storage')?.storage_gb ?? 0)\n const collaborators =\n (product?.included_collaborators ?? 0) +\n collaboratorBlocks *\n (prices.monthly?.addon_prices?.find((p) => p.kind === 'collaborators')?.collaborators ?? 0)\n const saving =\n monthlyNet && annualNet != null\n ? Math.max(0, Math.round(100 * (1 - annualNet / (monthlyNet * 12))))\n : 0\n const stepPence = product?.spend_cap_step_pence ?? 2000\n const defaultCap = product?.default_spend_cap_pence ?? 10000\n const maximumCap = product?.maximum_spend_cap_pence ?? 50000\n const cap = Math.max(\n 0,\n Math.min(maximumCap, Math.floor((spendCap ?? defaultCap) / stepPence) * stepPence)\n )\n const monthlyBlock = prices.monthly?.addon_prices?.find(\n (p) => p.kind === 'ai_usage'\n )?.amount_ex_vat\n const annualBlock = prices.annual?.addon_prices?.find((p) => p.kind === 'ai_usage')?.amount_ex_vat\n const annualDefaultCap =\n monthlyBlock && annualBlock != null\n ? Math.max(\n 0,\n Math.floor((defaultCap * annualBlock) / (monthlyBlock * 12) / stepPence) * stepPence\n )\n : cap\n const capFor = (interval: PlanInterval) =>\n interval === 'year' && spendCap == null ? annualDefaultCap : cap\n const quoteFor = (interval: PlanInterval) =>\n interval === 'month' ? monthlyQuote.data : annualQuote.data\n\n const controls = (\n kind: string,\n count: number,\n onChange: (value: number) => void,\n label: string,\n available: boolean\n ) => (\n <dd className=\"project-purchase-allowance-controls\">\n <Button\n type=\"button\"\n size=\"icon\"\n variant=\"outline\"\n aria-label={`Reduce ${label}`}\n disabled={busy || count <= 0}\n onClick={() => onChange(count - 1)}\n data-testid={`checkout-${kind}-blocks-decrement`}\n >\n <Minus size={14} aria-hidden=\"true\" />\n </Button>\n <Button\n type=\"button\"\n size=\"icon\"\n variant=\"outline\"\n aria-label={`Add ${label}`}\n disabled={busy || !available || count >= MAX_CHECKOUT_BLOCKS}\n onClick={() => onChange(count + 1)}\n data-testid={`checkout-${kind}-blocks-increment`}\n >\n <Plus size={14} aria-hidden=\"true\" />\n </Button>\n </dd>\n )\n\n return (\n <div className=\"project-purchase\" data-testid=\"project-purchase-options\">\n <dl className=\"project-purchase-inclusions\" aria-live=\"polite\">\n <div>\n <Sparkles aria-hidden=\"true\" className=\"project-purchase-icon\" />\n <dd className=\"text-xl font-semibold tabular-nums\" data-testid=\"purchase-ai-allowance\">\n {money(ai * 100)}\n </dd>\n <dt className=\"text-xs text-muted-foreground\">AI credits / month</dt>\n {controls(\n 'ai',\n aiBlocks,\n onAiBlocksChange,\n 'AI credits',\n !!addonPrice(prices.monthly, 'ai_usage')\n )}\n </div>\n <div>\n <HardDrive aria-hidden=\"true\" className=\"project-purchase-icon\" />\n <dd\n className=\"text-xl font-semibold tabular-nums\"\n data-testid=\"purchase-storage-allowance\"\n >\n {storage} GB\n </dd>\n <dt className=\"text-xs text-muted-foreground\">Storage</dt>\n {controls(\n 'storage',\n storageBlocks,\n onStorageBlocksChange,\n 'storage',\n !!addonPrice(prices.monthly, 'storage')\n )}\n </div>\n <div>\n <Users aria-hidden=\"true\" className=\"project-purchase-icon\" />\n <dd\n className=\"text-xl font-semibold tabular-nums\"\n data-testid=\"purchase-collaborator-allowance\"\n >\n {collaborators}\n </dd>\n <dt className=\"text-xs text-muted-foreground\">\n {collaborators === 1 ? 'Collaborator' : 'Collaborators'} + you\n </dt>\n {controls(\n 'collaborator',\n collaboratorBlocks,\n onCollaboratorBlocksChange,\n 'collaborator places',\n !!prices.monthly?.addon_prices?.find((p) => p.kind === 'collaborators')\n )}\n </div>\n </dl>\n <div className=\"project-purchase-cap\">\n <MonthlySpendCap\n value={cap}\n minimum={0}\n stepPence={stepPence}\n maximum={product?.maximum_spend_cap_pence}\n onChange={setSpendCap}\n compact\n />\n </div>\n\n <div className=\"project-purchase-prices\">\n {(['month', 'year'] as const).map((interval) => {\n const net = interval === 'month' ? monthlyNet : annualNet\n const quote = quoteFor(interval)\n const recurring = quote?.total_pence ?? net\n const credit = recurring != null ? applyReferralReward(recurring, reward, currency) : null\n const amount = credit?.youPay ?? recurring\n return (\n <button\n type=\"button\"\n key={interval}\n disabled={disabled || busy || amount == null}\n onClick={() => onChoose(interval, capFor(interval), quote)}\n data-testid={`purchase-${interval}`}\n className={`project-purchase-price ${interval === 'year' ? 'project-purchase-price-annual' : ''}`}\n >\n <span className=\"project-purchase-price-heading\">\n <span className=\"project-purchase-period\">\n {interval === 'month' ? 'Monthly' : 'Annual'}\n </span>\n {interval === 'year' && saving > 0 && (\n <span className=\"project-purchase-saving\">Save {saving}%</span>\n )}\n </span>\n {credit && credit.bonus > 0 && recurring != null && (\n <span\n className=\"project-purchase-credit\"\n data-testid={`purchase-${interval}-credit`}\n >\n <span>\n <span>Plan + add-ons{quote && quote.tax_pence > 0 ? ' incl. tax' : ''}</span>\n <span>{money(recurring)}</span>\n </span>\n <span>\n <span>Account credit</span>\n <span>\u2212{money(credit.bonus)}</span>\n </span>\n </span>\n )}\n <span className=\"project-purchase-total\">\n <span className=\"text-xs\">\n {quote\n ? quote.tax_pence > 0\n ? 'Due now incl. tax'\n : 'Due now'\n : 'Due now ex VAT'}\n </span>\n <span className=\"project-purchase-amount\">\n {amount != null ? money(amount) : '\u2014'}\n </span>\n </span>\n <span className=\"mt-1 text-xs text-muted-foreground\">\n {credit && credit.bonus > 0 && recurring != null\n ? `Then ${money(recurring)}/${interval === 'year' ? 'year' : 'month'}`\n : interval === 'year' && recurring != null\n ? `${money(Math.round(recurring / 12))}/month equivalent`\n : 'Renews monthly'}\n </span>\n <span className=\"project-purchase-cta\">\n Choose {interval === 'month' ? 'monthly' : 'annual'}\n <ArrowRight aria-hidden=\"true\" size={14} />\n </span>\n </button>\n )\n })}\n </div>\n\n {busy && (\n <p role=\"status\" className=\"text-sm text-muted-foreground\">\n Opening payment\u2026\n </p>\n )}\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": ";AAmII,SAUI,KAVJ;AAnIJ,SAAS,gBAAgB;AACzB,SAAS,YAAY,WAAW,OAAO,MAAM,UAAU,aAAa;AACpE,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAE7B,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;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DP;AAAA,IAEJ,CAAC,GACH;AAAA,IAEC,QACC,oBAAC,OAAE,MAAK,UAAS,WAAU,iCAAgC,mCAE3D;AAAA,KAEJ;AAEJ;",
|
|
4
|
+
"sourcesContent": ["import { useId, useState } from 'react'\nimport { ArrowRight, ChevronDown, HardDrive, Minus, Plus, Sparkles, Tag, Users } from 'lucide-react'\nimport { MonthlySpendCap } from './MonthlySpendCap'\nimport { usePlanQuote } from '@arbidocs/react'\nimport type { components } from '@arbidocs/client'\nimport { Button, Input, Label, ToggleGroup, ToggleGroupItem } from '@arbidocs/react/ui'\nimport {\n addonPrice,\n findProPrices,\n MAX_CHECKOUT_BLOCKS,\n packPrice,\n type PlanInterval,\n} from './plan-pricing'\nimport { formatMoney, useRewardBalance } from './reward-balance'\nimport { applyReferralReward } from './referral-reward'\nimport { quoteError, type TaxQuote } from './tax-quote'\nimport { DailyCapField } from '../../settings/Billing'\n\ntype Product = components['schemas']['ProductResponse']\ntype Price = components['schemas']['ProductPrice']\n\nexport function purchaseNet(\n price: Price | undefined,\n ai: number,\n storage: number,\n collaborators: number\n): number | null {\n const base = packPrice(price)?.amount_ex_vat ?? price?.amount_ex_vat\n if (base == null) return null\n let total = base\n for (const [kind, count] of [\n ['ai_usage', ai],\n ['storage', storage],\n ['collaborators', collaborators],\n ] as const) {\n const block = price?.addon_prices?.find((p) => p.kind === kind)\n if (count && !block) return null\n total += count * (block?.amount_ex_vat ?? 0)\n }\n return total\n}\n\n/** Free, monthly and annual choices; paid choices show the actual starting charge. */\nexport function ProjectPurchaseOptions({\n products,\n projectExtId,\n aiBlocks,\n storageBlocks,\n collaboratorBlocks,\n onAiBlocksChange,\n onStorageBlocksChange,\n onCollaboratorBlocksChange,\n disabled,\n busy,\n busyLabel = 'Opening payment\u2026',\n enabled = true,\n onChoose,\n onChooseFree,\n promoCode = '',\n onPromoCodeChange,\n dailyCapValue,\n onDailyCapChange,\n onSaveDailyCap,\n canSaveDailyCap,\n dailyCapError,\n currentQuotas,\n}: {\n products: Product[] | undefined\n projectExtId?: string\n aiBlocks: number\n storageBlocks: number\n collaboratorBlocks: number\n onAiBlocksChange: (count: number) => void\n onStorageBlocksChange: (count: number) => void\n onCollaboratorBlocksChange: (count: number) => void\n disabled?: boolean\n busy?: boolean\n busyLabel?: string\n enabled?: boolean\n /** Keep an existing project Free, or create a new project without a subscription. */\n onChooseFree?: () => void\n promoCode?: string\n onPromoCodeChange?: (code: string) => void\n dailyCapValue?: string\n onDailyCapChange?: (value: string) => void\n onSaveDailyCap?: () => void\n canSaveDailyCap?: boolean\n dailyCapError?: string | null\n currentQuotas?: components['schemas']['ProjectQuotas']\n onChoose: (interval: PlanInterval, capPence: number, quote?: TaxQuote) => void\n}) {\n const [spendCap, setSpendCap] = useState<number | null>(null)\n const [adjustment, setAdjustment] = useState<'min' | 'max'>('max')\n const [dailyCapOpen, setDailyCapOpen] = useState(false)\n const dailyCapId = useId()\n const promoId = useId()\n const [promoOpen, setPromoOpen] = useState(false)\n const [activePromo, setActivePromo] = useState('')\n const reward = useRewardBalance()\n const prices = findProPrices(products)\n const monthlyNet = purchaseNet(prices.monthly, aiBlocks, storageBlocks, collaboratorBlocks)\n const annualNet = purchaseNet(prices.annual, aiBlocks, storageBlocks, collaboratorBlocks)\n const extras = { ai_usage: aiBlocks, storage: storageBlocks, collaborators: collaboratorBlocks }\n // The saved billing address supplies tax where available. Missing-address errors are left to Checkout.\n const monthlyQuote = usePlanQuote(\n projectExtId,\n enabled && monthlyNet != null\n ? {\n plan: 'pro',\n interval: 'month',\n addons: extras,\n ...(activePromo ? { promo_code: activePromo } : {}),\n }\n : null\n )\n const annualQuote = usePlanQuote(\n projectExtId,\n enabled && annualNet != null\n ? {\n plan: 'pro',\n interval: 'year',\n addons: extras,\n ...(activePromo ? { promo_code: activePromo } : {}),\n }\n : null\n )\n const promoChecking = !!activePromo && (monthlyQuote.isFetching || annualQuote.isFetching)\n const promoError = activePromo && (monthlyQuote.error || annualQuote.error)\n const promoApplied =\n !!activePromo &&\n [monthlyQuote, annualQuote].some(\n (result) => result.data?.promo_code?.toLowerCase() === activePromo.toLowerCase()\n )\n const product = products?.[0]\n if (!product || !(product.spend_cap_step_pence > 0))\n return <p className=\"text-sm text-muted-foreground\">Prices unavailable. Try again.</p>\n const currency = prices.monthly?.currency ?? prices.annual?.currency ?? 'gbp'\n const money = (pence: number) => formatMoney(pence, currency)\n const ai =\n product.included_ai_gbp + aiBlocks * (addonPrice(prices.monthly, 'ai_usage')?.ai_gbp ?? 0)\n const storage =\n product.included_storage_gb +\n storageBlocks * (addonPrice(prices.monthly, 'storage')?.storage_gb ?? 0)\n const collaborators =\n product.included_collaborators +\n collaboratorBlocks *\n (prices.monthly?.addon_prices?.find((p) => p.kind === 'collaborators')?.collaborators ?? 0)\n const currentAi = currentQuotas?.ai_usage.limit ?? product.free_ai_gbp\n const currentStorage = currentQuotas?.storage_gb.limit ?? product.free_storage_gb\n const currentCollaborators = currentQuotas?.collaborators.limit ?? product.free_collaborators\n const multiplier = (next: number, current: number, extra: string) => {\n if (next === current) return 'Same as now'\n if (current <= 0) return extra\n const ratio = Number((next / current).toFixed(1))\n return ratio > 1 ? `${ratio}\u00D7 more` : `${ratio}\u00D7 current`\n }\n const saving =\n monthlyNet && annualNet != null\n ? Math.max(0, Math.round(100 * (1 - annualNet / (monthlyNet * 12))))\n : 0\n const stepPence = product.spend_cap_step_pence\n const increment = (price: Price | undefined) => {\n const amounts = price?.addon_prices?.map((addon) => addon.amount_ex_vat) ?? []\n if (!amounts.length) return null\n const min = Math.min(...amounts)\n const max = Math.max(...amounts)\n return min === max ? money(min) : `${money(min)}\u2013${money(max)}`\n }\n const monthlyIncrement = increment(prices.monthly)\n const annualIncrement = increment(prices.annual)\n const defaultCap = product.default_spend_cap_pence\n const maximumCap = product.maximum_spend_cap_pence\n const cap = Math.max(\n 0,\n Math.min(maximumCap, Math.floor((spendCap ?? defaultCap) / stepPence) * stepPence)\n )\n // Future upgrades can be AI or storage. Use the higher annual tariff when their discounts differ.\n const annualUpgradeRates = (prices.monthly?.addon_prices ?? []).flatMap((monthly) => {\n if (!['ai_usage', 'storage'].includes(monthly.kind) || monthly.amount_ex_vat <= 0) return []\n const annual = prices.annual?.addon_prices?.find((price) => price.kind === monthly.kind)\n return annual ? [annual.amount_ex_vat / monthly.amount_ex_vat] : []\n })\n const annualCeiling =\n annualNet != null && (cap === 0 || annualUpgradeRates.length > 0)\n ? annualNet + Math.ceil(cap * Math.max(0, ...annualUpgradeRates))\n : undefined\n const changeSpendCap = (next: number) => setSpendCap(next)\n const manualOpen = adjustment === 'min'\n const changeMinimum = (kind: 'ai' | 'storage' | 'collaborator', count: number) => {\n const nextAi = kind === 'ai' ? count : aiBlocks\n const nextStorage = kind === 'storage' ? count : storageBlocks\n const nextCollaborators = kind === 'collaborator' ? count : collaboratorBlocks\n const nextMinimum = purchaseNet(prices.monthly, nextAi, nextStorage, nextCollaborators)\n // Keep the chosen overall ceiling when changing the starting allowances.\n if (monthlyNet != null && nextMinimum != null) {\n const overallMaximum = monthlyNet + cap\n setSpendCap(Math.max(0, Math.floor((overallMaximum - nextMinimum) / stepPence) * stepPence))\n }\n if (kind === 'ai') onAiBlocksChange(count)\n else if (kind === 'storage') onStorageBlocksChange(count)\n else onCollaboratorBlocksChange(count)\n }\n const dailyCapVisible = dailyCapOpen || !!dailyCapError\n const quoteFor = (interval: PlanInterval) =>\n interval === 'month' ? monthlyQuote.data : annualQuote.data\n\n const controls = (\n kind: string,\n count: number,\n onChange: (value: number) => void,\n label: string,\n available: boolean\n ) =>\n manualOpen ? (\n <div className=\"project-purchase-allowance-controls\" role=\"group\" aria-label={label}>\n <Button\n type=\"button\"\n size=\"icon\"\n variant=\"outline\"\n aria-label={`Reduce ${label}`}\n disabled={busy || count <= 0}\n onClick={() => onChange(count - 1)}\n data-testid={`checkout-${kind}-blocks-decrement`}\n >\n <Minus size={14} aria-hidden=\"true\" />\n </Button>\n <Button\n type=\"button\"\n size=\"icon\"\n variant=\"outline\"\n aria-label={`Add ${label}`}\n disabled={busy || !available || count >= MAX_CHECKOUT_BLOCKS}\n onClick={() => onChange(count + 1)}\n data-testid={`checkout-${kind}-blocks-increment`}\n >\n <Plus size={14} aria-hidden=\"true\" />\n </Button>\n </div>\n ) : null\n\n return (\n <div className=\"project-purchase\" data-testid=\"project-purchase-options\">\n <section className=\"project-purchase-inclusions-panel\" aria-label=\"Plan allowances\">\n <dl className=\"project-purchase-inclusions\" aria-live=\"polite\">\n <div>\n <dt className=\"text-xs text-muted-foreground\">AI credits / month</dt>\n <dd\n className=\"project-purchase-allowance-value text-xl font-semibold tabular-nums\"\n data-testid=\"purchase-ai-allowance\"\n >\n <Sparkles aria-hidden=\"true\" className=\"project-purchase-icon\" />\n {money(ai * 100)}\n </dd>\n {currentAi != null && (\n <dd\n className=\"project-purchase-current\"\n data-increased={ai > currentAi}\n title={`Compared with ${money(currentAi * 100)}/month on your current plan`}\n >\n {multiplier(ai, currentAi, `+${money((ai - currentAi) * 100)}`)}\n </dd>\n )}\n </div>\n <div>\n <dt className=\"text-xs text-muted-foreground\">Storage</dt>\n <dd\n className=\"project-purchase-allowance-value text-xl font-semibold tabular-nums\"\n data-testid=\"purchase-storage-allowance\"\n >\n <HardDrive aria-hidden=\"true\" className=\"project-purchase-icon\" />\n {storage} GB\n </dd>\n {currentStorage != null && (\n <dd\n className=\"project-purchase-current\"\n data-increased={storage > currentStorage}\n title={`Compared with ${currentStorage} GB on your current plan`}\n >\n {multiplier(storage, currentStorage, `+${storage - currentStorage} GB`)}\n </dd>\n )}\n </div>\n <div>\n <dt className=\"text-xs text-muted-foreground\">\n {collaborators === 1 ? 'Collaborator' : 'Collaborators'} + you\n </dt>\n <dd\n className=\"project-purchase-allowance-value text-xl font-semibold tabular-nums\"\n data-testid=\"purchase-collaborator-allowance\"\n >\n <Users aria-hidden=\"true\" className=\"project-purchase-icon\" />\n {collaborators}\n </dd>\n {currentCollaborators != null && (\n <dd\n className=\"project-purchase-current\"\n data-increased={collaborators > currentCollaborators}\n title={`Compared with ${currentCollaborators} collaborators on your current plan`}\n >\n {collaborators === currentCollaborators\n ? 'Same as now'\n : `${collaborators > currentCollaborators ? '+' : '\u2212'}${Math.abs(collaborators - currentCollaborators)} collaborator${Math.abs(collaborators - currentCollaborators) === 1 ? '' : 's'}`}\n </dd>\n )}\n </div>\n </dl>\n <section className=\"project-purchase-settings\" aria-label=\"Allowance settings\">\n <div className=\"project-purchase-settings-row\">\n <h3 className=\"project-purchase-settings-heading\">Extra usage upgrades:</h3>\n <ToggleGroup\n type=\"single\"\n value={adjustment}\n onValueChange={(value) => {\n if (value === 'min' || value === 'max') setAdjustment(value)\n }}\n disabled={busy}\n className=\"project-purchase-mode\"\n aria-label=\"Allowance adjustment\"\n >\n <ToggleGroupItem value=\"min\">Manual</ToggleGroupItem>\n <ToggleGroupItem value=\"max\">Automatic</ToggleGroupItem>\n </ToggleGroup>\n </div>\n {!manualOpen && (\n <div data-testid=\"auto-upgrade-section\">\n <MonthlySpendCap\n value={cap}\n minimum={0}\n basePence={monthlyNet ?? 0}\n annualMaximumPence={annualCeiling}\n control=\"purchase\"\n stepPence={stepPence}\n maximum={maximumCap}\n onChange={changeSpendCap}\n disabled={busy}\n compact\n />\n </div>\n )}\n {manualOpen && (\n <div className=\"project-purchase-adjustments\">\n <p className=\"project-purchase-manual-intro\">\n Purchase only what you need\n {(monthlyIncrement || annualIncrement) && (\n <>\n {' '}\n (increments of {monthlyIncrement && `${monthlyIncrement}/monthly`}\n {monthlyIncrement && annualIncrement && ' \u00B7 '}\n {annualIncrement && `${annualIncrement}/annual`})\n </>\n )}\n </p>\n {controls(\n 'ai',\n aiBlocks,\n (count) => changeMinimum('ai', count),\n 'AI credits',\n !!addonPrice(prices.monthly, 'ai_usage')\n )}\n {controls(\n 'storage',\n storageBlocks,\n (count) => changeMinimum('storage', count),\n 'storage',\n !!addonPrice(prices.monthly, 'storage')\n )}\n {controls(\n 'collaborator',\n collaboratorBlocks,\n (count) => changeMinimum('collaborator', count),\n 'collaborator places',\n !!prices.monthly?.addon_prices?.find((p) => p.kind === 'collaborators')\n )}\n </div>\n )}\n </section>\n </section>\n\n {onDailyCapChange && (\n <section className=\"project-purchase-daily-foldout\">\n <button\n type=\"button\"\n className=\"project-purchase-setting-toggle\"\n aria-expanded={dailyCapVisible}\n aria-controls={dailyCapId}\n onClick={() => setDailyCapOpen(!dailyCapVisible)}\n disabled={busy}\n >\n <Users aria-hidden=\"true\" className=\"h-4 w-4\" />\n Set collaborator spend limit\n <ChevronDown\n aria-hidden=\"true\"\n className={`h-4 w-4 transition-transform ${dailyCapVisible ? 'rotate-180' : ''}`}\n />\n </button>\n {dailyCapVisible && (\n <div\n id={dailyCapId}\n className=\"project-purchase-daily-cap\"\n role=\"region\"\n aria-label=\"Collaborator daily AI limit\"\n >\n <p className=\"text-sm text-muted-foreground\">\n Collaborators share your project's quota.\n </p>\n <DailyCapField\n value={dailyCapValue ?? ''}\n onChange={onDailyCapChange}\n onSave={onSaveDailyCap}\n canSave={canSaveDailyCap}\n isSaving={busy}\n labels={{ unit: '\u00A3 / day each' }}\n />\n {dailyCapError && (\n <p role=\"alert\" className=\"text-sm text-destructive\">\n {dailyCapError}\n </p>\n )}\n </div>\n )}\n </section>\n )}\n\n {onPromoCodeChange && (\n <div className=\"project-purchase-promo project-purchase-daily-foldout\">\n <button\n type=\"button\"\n className=\"project-purchase-setting-toggle\"\n aria-expanded={promoOpen}\n aria-controls={`${promoId}-panel`}\n onClick={() => setPromoOpen((value) => !value)}\n disabled={busy}\n >\n <Tag aria-hidden=\"true\" className=\"h-4 w-4\" />\n Have a promo code?\n <ChevronDown\n aria-hidden=\"true\"\n className={`h-4 w-4 transition-transform ${promoOpen ? 'rotate-180' : ''}`}\n />\n </button>\n {promoOpen && (\n <div id={`${promoId}-panel`} className=\"space-y-1.5 pb-3\">\n <Label htmlFor={promoId}>Promo code (optional)</Label>\n <div className=\"flex items-center gap-2\">\n <Input\n id={promoId}\n value={promoCode}\n onChange={(event) => {\n onPromoCodeChange(event.target.value)\n setActivePromo('')\n }}\n disabled={busy}\n autoComplete=\"off\"\n placeholder=\"Enter promo code\"\n aria-describedby={`${promoId}-status`}\n />\n <Button\n type=\"button\"\n disabled={busy || promoChecking || !promoCode.trim()}\n onClick={() => {\n if (activePromo === promoCode.trim()) {\n void monthlyQuote.refetch()\n void annualQuote.refetch()\n } else setActivePromo(promoCode.trim())\n }}\n >\n {promoChecking ? 'Checking\u2026' : 'Apply'}\n </Button>\n </div>\n <p\n id={`${promoId}-status`}\n role=\"status\"\n className={`text-sm ${promoError && !promoApplied ? 'text-destructive' : 'text-muted-foreground'}`}\n >\n {promoChecking\n ? 'Checking your code\u2026'\n : promoError && !promoApplied\n ? (quoteError(promoError).message ?? 'This promo code could not be applied.')\n : promoApplied\n ? `${activePromo} applied \u00B7 ${monthlyQuote.data?.discount_label ?? annualQuote.data?.discount_label ?? 'discount included below'}`\n : 'Apply your code to see the updated price.'}\n </p>\n </div>\n )}\n </div>\n )}\n\n <div\n className={`project-purchase-prices ${onChooseFree ? 'project-purchase-prices-with-free' : ''}`}\n >\n {onChooseFree && (\n <button\n type=\"button\"\n className=\"project-purchase-price project-purchase-price-free\"\n data-testid=\"purchase-free\"\n aria-describedby=\"purchase-free-summary\"\n disabled={disabled || busy}\n onClick={onChooseFree}\n >\n <span className=\"project-purchase-price-heading\">\n <span className=\"project-purchase-period\">No Subscription</span>\n </span>\n <span className=\"project-purchase-details\">\n <span\n id=\"purchase-free-summary\"\n data-testid=\"purchase-free-summary\"\n className=\"project-purchase-free-allowances\"\n >\n <span title=\"AI credits per month\">\n <Sparkles aria-hidden=\"true\" />\n <span className=\"sr-only\">AI credits: </span>\n {product.free_ai_gbp != null ? `${money(product.free_ai_gbp * 100)}/mo` : '\u2014'}\n </span>\n <span title=\"Storage\">\n <HardDrive aria-hidden=\"true\" />\n <span className=\"sr-only\">Storage: </span>\n {product.free_storage_gb != null ? `${product.free_storage_gb} GB` : '\u2014'}\n </span>\n <span title=\"Collaborators\">\n <Users aria-hidden=\"true\" />\n <span className=\"sr-only\">Collaborators: </span>\n {product.free_collaborators ?? '\u2014'}\n </span>\n </span>\n </span>\n <span className=\"project-purchase-total\">\n <span className=\"project-purchase-due\" aria-hidden=\"true\" />\n <span className=\"project-purchase-amount\">Free</span>\n </span>\n </button>\n )}\n {(['month', 'year'] as const).map((interval) => {\n const net = interval === 'month' ? monthlyNet : annualNet\n const quote = quoteFor(interval)\n const quoteState = interval === 'month' ? monthlyQuote : annualQuote\n const discounted =\n !!activePromo && quote?.promo_code?.toLowerCase() === activePromo.toLowerCase()\n const promoBlocked = !!promoCode.trim() && (!discounted || !!quoteState.isFetching)\n const recurring = quote?.renewal_total_pence ?? quote?.total_pence ?? net\n const today = quote?.total_pence ?? net\n const credit = today != null ? applyReferralReward(today, reward, currency) : null\n const amount = promoBlocked ? null : (credit?.youPay ?? today)\n return (\n <button\n type=\"button\"\n key={interval}\n disabled={disabled || busy || amount == null}\n onClick={() => onChoose(interval, cap, quote)}\n data-testid={`purchase-${interval}`}\n className={`project-purchase-price ${interval === 'year' ? 'project-purchase-price-annual' : ''}`}\n >\n {interval === 'year' && saving > 0 && (\n <span className=\"project-purchase-saving\">Save {saving}%</span>\n )}\n <span className=\"project-purchase-price-heading project-purchase-select\">\n <span className=\"project-purchase-period\">\n {interval === 'month' ? 'Select monthly' : 'Select annual'}\n </span>\n <ArrowRight aria-hidden=\"true\" size={16} />\n </span>\n <span className=\"project-purchase-details\">\n {(discounted || (credit && credit.bonus > 0)) && recurring != null && (\n <span\n className=\"project-purchase-credit\"\n data-testid={`purchase-${interval}-credit`}\n >\n <span>\n <span>\n Subscription\n {!discounted && quote && quote.tax_pence > 0 ? ' incl. tax' : ''}\n </span>\n <span>\n {money(\n discounted\n ? quote!.subtotal_pence + (quote!.discount_pence ?? 0)\n : recurring\n )}\n </span>\n </span>\n {discounted && (\n <span>\n <span>Promo {quote!.promo_code}</span>\n <span>\u2212{money(quote!.discount_pence ?? 0)}</span>\n </span>\n )}\n {discounted && quote!.tax_pence > 0 && (\n <span>\n <span>{quote!.tax_label ?? 'Tax'}</span>\n <span>{money(quote!.tax_pence)}</span>\n </span>\n )}\n {credit && credit.bonus > 0 && (\n <span>\n <span>Account credit</span>\n <span>\u2212{money(credit.bonus)}</span>\n </span>\n )}\n </span>\n )}\n </span>\n <span className=\"project-purchase-total\">\n <span className=\"project-purchase-due text-xs\">\n {quote && quote.tax_calculated !== false\n ? quote.tax_pence > 0\n ? 'Due now (incl. tax)'\n : 'Due now'\n : 'Due now (ex VAT)'}\n </span>\n <span className=\"project-purchase-amount\">\n {amount != null ? money(amount) : '\u2014'}\n </span>\n {recurring != null && (\n <span className=\"project-purchase-renewal text-xs\">\n Then {money(recurring)}/{interval === 'year' ? 'year' : 'month'}\n {quote?.renewal_note ? ` \u00B7 ${quote.renewal_note.toLowerCase()}` : ''}\n </span>\n )}\n </span>\n </button>\n )\n })}\n </div>\n\n {busy && (\n <p role=\"status\" className=\"text-sm text-muted-foreground\">\n {busyLabel}\n </p>\n )}\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAuIW,SAiNO,UAjNP,KA+EL,YA/EK;AAvIX,SAAS,OAAO,gBAAgB;AAChC,SAAS,YAAY,aAAa,WAAW,OAAO,MAAM,UAAU,KAAK,aAAa;AACtF,SAAS,uBAAuB;AAChC,SAAS,oBAAoB;AAE7B,SAAS,QAAQ,OAAO,OAAO,aAAa,uBAAuB;AACnE;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,aAAa,wBAAwB;AAC9C,SAAS,2BAA2B;AACpC,SAAS,kBAAiC;AAC1C,SAAS,qBAAqB;AAKvB,SAAS,YACd,OACA,IACA,SACA,eACe;AACf,QAAM,OAAO,UAAU,KAAK,GAAG,iBAAiB,OAAO;AACvD,MAAI,QAAQ,KAAM,QAAO;AACzB,MAAI,QAAQ;AACZ,aAAW,CAAC,MAAM,KAAK,KAAK;AAA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AA,2BACjC;AAAA,wBAED,UAAU,OAAO,QAAQ,KACxB,qBAAC,UACC;AAAA,8CAAC,UAAK,4BAAc;AAAA,0BACpB,qBAAC,UAAK;AAAA;AAAA,4BAAE,MAAM,OAAO,KAAK;AAAA,6BAAE;AAAA,2BAC9B;AAAA;AAAA;AAAA,kBAEJ,GAEJ;AAAA,kBACA,qBAAC,UAAK,WAAU,0BACd;AAAA,wCAAC,UAAK,WAAU,gCACb,mBAAS,MAAM,mBAAmB,QAC/B,MAAM,YAAY,IAChB,wBACA,YACF,oBACN;AAAA,oBACA,oBAAC,UAAK,WAAU,2BACb,oBAAU,OAAO,MAAM,MAAM,IAAI,UACpC;AAAA,oBACC,aAAa,QACZ,qBAAC,UAAK,WAAU,oCAAmC;AAAA;AAAA,sBAC3C,MAAM,SAAS;AAAA,sBAAE;AAAA,sBAAE,aAAa,SAAS,SAAS;AAAA,sBACvD,OAAO,eAAe,SAAM,MAAM,aAAa,YAAY,CAAC,KAAK;AAAA,uBACpE;AAAA,qBAEJ;AAAA;AAAA;AAAA,cAxEK;AAAA,YAyEP;AAAA,UAEJ,CAAC;AAAA;AAAA;AAAA,IACH;AAAA,IAEC,QACC,oBAAC,OAAE,MAAK,UAAS,WAAU,iCACxB,qBACH;AAAA,KAEJ;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -15,7 +15,7 @@ import { requestProjectBillingFocus, useProjectBillingFocus } from "./billing-fo
|
|
|
15
15
|
import { BillingCard, PendingChange } from "./BillingCard.js";
|
|
16
16
|
import { AddAddonDialog } from "./AddAddonDialog.js";
|
|
17
17
|
import { ReduceAddonDialog } from "./ReduceAddonDialog.js";
|
|
18
|
-
import {
|
|
18
|
+
import { MIN_AUTO_TOPUP_THRESHOLD_GBP } from "./plan-constants.js";
|
|
19
19
|
import { aiUsageResetTimestamp } from "./quota-items.js";
|
|
20
20
|
import {
|
|
21
21
|
addStepCaption,
|
|
@@ -248,9 +248,9 @@ function UsageCapEditor({ project, addons }) {
|
|
|
248
248
|
const sectionRef = useRef(null);
|
|
249
249
|
const inputRef = useRef(null);
|
|
250
250
|
const minimum = 0;
|
|
251
|
-
const stepPence = addons.spend_cap_step_pence
|
|
252
|
-
const saved = addons.spend_cap_pence ?? addons.default_spend_cap_pence
|
|
253
|
-
const maximum = addons.maximum_spend_cap_pence
|
|
251
|
+
const stepPence = addons.spend_cap_step_pence;
|
|
252
|
+
const saved = addons.spend_cap_pence ?? addons.default_spend_cap_pence;
|
|
253
|
+
const maximum = addons.maximum_spend_cap_pence;
|
|
254
254
|
const normalize = (n) => Math.max(0, Math.min(maximum, Math.floor(n / stepPence) * stepPence));
|
|
255
255
|
const [value, setValue] = useState(normalize(saved));
|
|
256
256
|
useEffect(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/ProjectUsageCard.tsx"],
|
|
4
|
-
"sourcesContent": ["import { MonthlySpendCap } from './MonthlySpendCap'\n/**\n * ProjectUsageCard \u2014 a Pro project's \"Usage and plan\" card: one usage meter per resource (AI credits this month,\n * storage) and the monthly usage cap. Short labels and one-line facts only; how top-ups, proration, the cap and\n * reductions work is behind the card's \"More info\" link.\n *\n * Each meter shows used vs the allowance now, marking the plan's part and shading the top-ups, hatches how much more\n * automatic top-ups may add before the usage cap stops them (\"No limit\" / \u00A30 states), says what renews from the next\n * period when that differs (with Undo), and has + / \u2212 beside it with the price of one step:\n * - \"+\" opens the add confirm (charged now: AI credits the full block, storage prorated for the rest of the period);\n * the usage cap never blocks it.\n * - \"\u2212\" opens a one-click confirm that removes one block from the next renewal; this period's allowance stays.\n * The usage cap limits automatic top-ups only (default \u00A3100; \u00A30 = no automatic top-ups; or no limit).\n */\n\nimport { useEffect, useRef, useState, type ReactNode } from 'react'\nimport { formatGbp } from '@arbidocs/react'\nimport { Button, Input, Label } from '@arbidocs/react/ui'\nimport { Minus, Plus } from 'lucide-react'\nimport { UsageMeter } from '../../components/UsageMeter'\nimport { MoreInfo, MoreInfoList } from '../../settings'\nimport type { components } from '@arbidocs/client'\nimport { useUpdateProjectAddonSettings, useUpdateProjectNextPeriodAddons } from '@arbidocs/react'\nimport { addonErrorMessage, type AddonKind } from './useAddonPurchase'\nimport { formatMoney } from './reward-balance'\nimport { notify } from '@arbidocs/react/shell'\nimport { requestProjectBillingFocus, useProjectBillingFocus } from './billing-focus'\nimport { BillingCard, PendingChange } from './BillingCard'\nimport { AddAddonDialog } from './AddAddonDialog'\nimport { ReduceAddonDialog } from './ReduceAddonDialog'\nimport { DEFAULT_SPEND_CAP_PENCE, MIN_AUTO_TOPUP_THRESHOLD_GBP } from './plan-constants'\nimport { aiUsageResetTimestamp } from './quota-items'\nimport {\n addStepCaption,\n addonSettingsBody,\n ANNUAL_PREMIUM_AI_NOTE,\n autoRoom,\n blocksLabel,\n budgetSavedMessage,\n formatPeriodEnd,\n isAddonBudgetZero,\n nextPeriodBody,\n nextRemovedBlockSize,\n reduceBounds,\n splitBlocks,\n stepLabel,\n USAGE_CAP_HELP,\n} from './addon-pricing'\n\ntype ProjectResponse = components['schemas']['ProjectResponse']\ntype ProjectAddons = components['schemas']['ProjectAddons']\n\nconst gbp = (pence: number) => formatMoney(pence, 'gbp')\nconst gb = (n: number) => `${Math.round(n * 10) / 10} GB`\n\n/** \"3 Nov\" \u2014 short day-month for in-period dates. */\nfunction formatShortDate(unix: number | null | undefined): string | null {\n if (!unix) return null\n return new Date(unix * 1000).toLocaleDateString('en-GB', { day: 'numeric', month: 'short' })\n}\n\n/** \"Auto top-up below \u00A3[1]\" \u2014 the automatic AI top-up's trigger (in \u00A3 of AI credits left). */\nfunction AutoTopupThreshold({\n project,\n addons,\n}: {\n project: ProjectResponse\n addons: ProjectAddons\n}) {\n const updateSettings = useUpdateProjectAddonSettings()\n const min = addons.min_auto_topup_threshold_gbp || MIN_AUTO_TOPUP_THRESHOLD_GBP\n const saved = addons.auto_topup_threshold_gbp\n const [value, setValue] = useState(String(saved))\n useEffect(() => setValue(String(saved)), [saved])\n\n const parsed = Number(value)\n const valid = Number.isFinite(parsed) && parsed >= min\n const dirty = valid && parsed !== saved\n const off = isAddonBudgetZero(addons)\n\n const save = () => {\n if (!dirty) return\n updateSettings.mutate(\n {\n projectExtId: project.external_id,\n body: addonSettingsBody(addons, { auto_topup_threshold_gbp: parsed }),\n },\n {\n onSuccess: () => notify.success(`Auto-add below ${formatGbp(parsed)} of AI credits left`),\n onError: (error) => notify.error(addonErrorMessage(error)),\n }\n )\n }\n\n const id = `auto-topup-threshold-${project.external_id}`\n return (\n <div className=\"space-y-1\" data-testid=\"auto-addons\">\n <div className=\"flex flex-wrap items-center gap-2 text-xs\">\n <Label htmlFor={id} className=\"text-xs font-normal text-muted-foreground\">\n Auto top-up below\n </Label>\n <span className=\"flex items-center gap-1.5\">\n <span className=\"text-muted-foreground\" aria-hidden>\n \u00A3\n </span>\n <Input\n id={id}\n type=\"number\"\n inputMode=\"decimal\"\n min={min}\n step={0.5}\n className=\"h-7 w-16 text-xs\"\n value={value}\n disabled={off}\n onChange={(e) => setValue(e.target.value)}\n onKeyDown={(e) => e.key === 'Enter' && save()}\n aria-invalid={!valid}\n data-testid=\"auto-topup-threshold-input\"\n />\n {dirty && (\n <Button\n size=\"sm\"\n variant=\"outline\"\n className=\"h-7\"\n onClick={save}\n disabled={updateSettings.isPending}\n data-testid=\"save-auto-topup-threshold-button\"\n >\n Save\n </Button>\n )}\n </span>\n </div>\n {!valid && (\n <p className=\"text-xs text-destructive\" role=\"alert\">\n Minimum {formatGbp(min)}.\n </p>\n )}\n </div>\n )\n}\n\n/** One + / \u2212 step button with its one-line price beside it. */\nfunction StepAction({\n icon,\n label,\n caption,\n onClick,\n testId,\n ariaLabel,\n}: {\n icon: ReactNode\n label: string\n caption: string\n onClick: () => void\n testId: string\n ariaLabel: string\n}) {\n return (\n <div className=\"flex min-w-0 items-center gap-2\">\n <Button\n size=\"sm\"\n variant=\"outline\"\n className=\"w-20 shrink-0 justify-center tabular-nums\"\n onClick={onClick}\n aria-label={ariaLabel}\n data-testid={testId}\n >\n {icon}\n {label}\n </Button>\n <span\n className=\"min-w-0 text-xs leading-snug text-muted-foreground\"\n data-testid={`${testId}-caption`}\n >\n {caption}\n </span>\n </div>\n )\n}\n\n/** One resource's meter: allowance bar, automatic room, next period (with Undo) and + / \u2212. */\nfunction ResourceMeter({\n kind,\n project,\n addons,\n onAdd,\n onReduce,\n children,\n}: {\n kind: AddonKind\n project: ProjectResponse\n addons: ProjectAddons\n onAdd: () => void\n onReduce: () => void\n children?: ReactNode\n}) {\n const update = useUpdateProjectNextPeriodAddons()\n const isAi = kind === 'ai_usage'\n const slug = isAi ? 'ai-usage' : 'storage'\n const periodEnd = formatPeriodEnd(addons.period_end ?? project.current_period_end)\n const from = periodEnd ?? 'your next renewal'\n const fromShort = formatShortDate(addons.period_end ?? project.current_period_end) ?? 'renewal'\n const { min, current, next } = reduceBounds(kind, addons)\n const fmt = (n: number) => (isAi ? formatGbp(n) : gb(n))\n\n const used = isAi ? addons.ai_used_gbp : addons.storage_used_gb\n const allowance = isAi ? addons.ai_allowance_gbp : addons.storage_allowance_gb\n const allowanceNext = isAi ? addons.ai_allowance_next_gbp : addons.storage_allowance_next_gb\n const plan = isAi ? addons.plan_ai_gbp : addons.plan_storage_gb\n const topUps = Math.max(0, allowance - plan)\n const blocks = isAi ? addons.ai_blocks : addons.storage_blocks\n const hasLegacy = splitBlocks(kind, blocks, addons).legacy > 0\n const room = autoRoom(kind, addons)\n const capZero = isAddonBudgetZero(addons)\n const resets = isAi ? formatShortDate(aiUsageResetTimestamp(project)) : null\n const removeSize = nextRemovedBlockSize(kind, addons)\n\n const undo = () =>\n update.mutate(\n {\n projectExtId: project.external_id,\n body: nextPeriodBody(kind, current),\n },\n {\n onSuccess: () => notify.success('Kept'),\n onError: (error) => notify.error(addonErrorMessage(error)),\n }\n )\n\n // The normal case is the hatched \"Automatic up to \u2026\" legend entry; only the exceptions get a line.\n const autoLine = capZero\n ? 'Automatic top-ups off (\u00A30 cap)'\n : room == null\n ? 'Automatic top-ups: no limit'\n : room > 0\n ? null\n : 'Automatic top-ups: cap reached'\n\n return (\n <UsageMeter\n label={isAi ? 'AI credits' : 'Storage'}\n hint={resets ? `resets ${resets}` : undefined}\n value={`${fmt(used)} used \u00B7 ${fmt(allowance)} included now`}\n allowance={{ used, plan, topUps, autoRoom: capZero ? 0 : room }}\n legend={{\n plan: `Plan ${fmt(plan)}`,\n topUps:\n topUps > 0\n ? `Top-ups ${fmt(topUps)}${hasLegacy ? ` (${blocksLabel(kind, blocks, addons)})` : ''}`\n : undefined,\n autoRoom: room != null && room > 0 && !capZero ? `Automatic up to ${fmt(room)}` : undefined,\n }}\n testId={`usage-meter-${slug}`}\n details={\n autoLine || allowanceNext !== allowance || children ? (\n <>\n {autoLine && <p data-testid={`usage-meter-${slug}-auto`}>{autoLine}</p>}\n {allowanceNext !== allowance && (\n <PendingChange\n testId={`usage-meter-${slug}-next`}\n onUndo={next < current ? undo : undefined}\n isBusy={update.isPending}\n undoTestId={`undo-reduce-${slug}-button`}\n >\n From {from}: {isAi ? `${formatGbp(allowanceNext)} a month` : gb(allowanceNext)}\n </PendingChange>\n )}\n {children}\n </>\n ) : undefined\n }\n actions={\n <>\n <StepAction\n icon={<Plus className=\"size-3.5\" />}\n label={isAi ? formatGbp(addons.block_ai_gbp) : `${addons.block_storage_gb} GB`}\n caption={addStepCaption(kind, addons)}\n onClick={onAdd}\n ariaLabel={`Add ${stepLabel(kind, isAi ? addons.block_ai_gbp : addons.block_storage_gb)}`}\n testId={isAi ? 'add-ai-block-button' : 'add-storage-block-button'}\n />\n {next > min && (\n <details className=\"text-sm\">\n <summary className=\"cursor-pointer text-muted-foreground\">\n Adjust usage add-ons\n </summary>\n <StepAction\n icon={<Minus className=\"size-3.5\" />}\n label={isAi ? formatGbp(removeSize) : `${removeSize} GB`}\n caption={`from ${fromShort}`}\n onClick={onReduce}\n ariaLabel={`Remove ${stepLabel(kind, removeSize)} from ${from}`}\n testId={`reduce-${slug}-button`}\n />\n </details>\n )}\n </>\n }\n />\n )\n}\n\n/** Inclusive monthly spend cap. Existing allowances stay until explicitly reduced. */\nfunction UsageCapEditor({ project, addons }: { project: ProjectResponse; addons: ProjectAddons }) {\n const updateSettings = useUpdateProjectAddonSettings()\n const sectionRef = useRef<HTMLDivElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const minimum = 0\n const stepPence = addons.spend_cap_step_pence ?? 2000\n const saved = addons.spend_cap_pence ?? addons.default_spend_cap_pence ?? DEFAULT_SPEND_CAP_PENCE\n const maximum = addons.maximum_spend_cap_pence ?? 50000\n const normalize = (n: number) =>\n Math.max(0, Math.min(maximum, Math.floor(n / stepPence) * stepPence))\n const [value, setValue] = useState(normalize(saved))\n useEffect(\n () => setValue(Math.max(0, Math.min(maximum, Math.floor(saved / stepPence) * stepPence))),\n [saved, maximum, stepPence]\n )\n const focus = useProjectBillingFocus()\n useEffect(() => {\n if (focus?.projectExtId !== project.external_id || focus.section !== 'spend-cap') return\n sectionRef.current?.scrollIntoView?.({ behavior: 'smooth', block: 'center' })\n inputRef.current?.focus()\n requestProjectBillingFocus(null)\n }, [focus, project.external_id])\n const save = () =>\n updateSettings.mutate(\n {\n projectExtId: project.external_id,\n body: addonSettingsBody(addons, { spend_cap_pence: value }),\n },\n {\n onSuccess: () => notify.success(budgetSavedMessage(value)),\n onError: (error) => notify.error(addonErrorMessage(error)),\n }\n )\n return (\n <div ref={sectionRef} className=\"space-y-3\" data-testid=\"project-spend-cap\">\n <MonthlySpendCap\n value={value}\n minimum={minimum}\n stepPence={stepPence}\n maximum={maximum}\n onChange={setValue}\n inputRef={inputRef}\n />\n {addons.total_monthly_ex_vat_pence != null && (\n <p className=\"text-sm text-muted-foreground\">\n Your current plan and allowances: {gbp(addons.total_monthly_ex_vat_pence)}/month ex VAT.\n </p>\n )}\n {addons.cap_reached && (\n <p className=\"text-xs text-muted-foreground\" data-testid=\"addon-cap-reached\">\n Your next automatic top-up would exceed the cap. Raise it or adjust usage add-ons.\n </p>\n )}\n <Button\n size=\"sm\"\n onClick={save}\n disabled={value === addons.spend_cap_pence || updateSettings.isPending}\n data-testid=\"save-spend-cap-button\"\n >\n {updateSettings.isPending ? 'Saving\u2026' : 'Save cap'}\n </Button>\n </div>\n )\n}\n\n/** The card's \"More info\": what the meters show and how top-ups, the cap and reductions work. */\nfunction UsageInfo({ addons, isAnnual }: { addons: ProjectAddons; isAnnual: boolean }) {\n const period = isAnnual ? 'year' : 'month'\n const legacy = (addons.legacy_ai_blocks ?? 0) > 0 || (addons.legacy_storage_blocks ?? 0) > 0\n return (\n <MoreInfo title=\"Usage and top-ups\" testId=\"usage-more-info\">\n <MoreInfoList\n items={[\n {\n term: 'Meters',\n text: \"What you used against this month's allowance: the plan (marked) plus top-ups. The hatched part is what automatic top-ups may still add.\",\n },\n {\n term: 'Adding',\n text: `+ adds ${formatGbp(addons.block_ai_gbp)} of AI credits or ${addons.block_storage_gb} GB. AI credits is charged in full today; storage only for the rest of the period. Top-ups renew each ${period} until you reduce them.`,\n },\n {\n term: 'Automatic top-ups',\n text: 'One step is added when AI credits drops below your auto top-up level, or when an upload needs more storage.',\n },\n { term: 'Usage cap', text: USAGE_CAP_HELP },\n {\n term: 'Reducing',\n text: \"\u2212 removes one step from your next renewal. You keep this period's allowance. No refunds.\",\n },\n ...(legacy\n ? [\n {\n term: 'Earlier top-ups',\n text: 'Top-ups bought on an earlier price keep their size and price until removed; they are removed last.',\n },\n ]\n : []),\n ...(isAnnual ? [{ term: 'Annual', text: `${ANNUAL_PREMIUM_AI_NOTE}.` }] : []),\n {\n term: 'Prices',\n text: 'Shown ex VAT. The confirm step shows the total with VAT before you pay.',\n },\n ]}\n />\n </MoreInfo>\n )\n}\n\nexport function ProjectUsageCard({\n project,\n addons,\n}: {\n project: ProjectResponse\n addons: ProjectAddons\n}) {\n const [adding, setAdding] = useState<AddonKind | null>(null)\n const [reducing, setReducing] = useState<AddonKind | null>(null)\n const isAnnual = project.plan_interval === 'year'\n\n return (\n <BillingCard\n title=\"Usage and plan\"\n testId=\"project-usage-card\"\n action={<UsageInfo addons={addons} isAnnual={isAnnual} />}\n >\n {addons.renewal_error && (\n <p role=\"status\" className=\"text-sm text-destructive\">\n {addons.renewal_error}\n </p>\n )}\n <ResourceMeter\n kind=\"ai_usage\"\n project={project}\n addons={addons}\n onAdd={() => setAdding('ai_usage')}\n onReduce={() => setReducing('ai_usage')}\n >\n <AutoTopupThreshold project={project} addons={addons} />\n </ResourceMeter>\n\n <div className=\"border-t border-border pt-4\">\n <ResourceMeter\n kind=\"storage\"\n project={project}\n addons={addons}\n onAdd={() => setAdding('storage')}\n onReduce={() => setReducing('storage')}\n />\n </div>\n\n <div className=\"border-t border-border pt-4\">\n <UsageCapEditor project={project} addons={addons} />\n </div>\n\n {adding && (\n <AddAddonDialog\n kind={adding}\n project={project}\n open\n onOpenChange={(open) => !open && setAdding(null)}\n />\n )}\n {reducing && (\n <ReduceAddonDialog\n kind={reducing}\n project={project}\n open\n onOpenChange={(open) => !open && setReducing(null)}\n />\n )}\n </BillingCard>\n )\n}\n"],
|
|
5
|
-
"mappings": ";AAkGQ,SA8JE,UA9JF,KAGA,YAHA;AAlGR,SAAS,uBAAuB;AAehC,SAAS,WAAW,QAAQ,gBAAgC;AAC5D,SAAS,iBAAiB;AAC1B,SAAS,QAAQ,OAAO,aAAa;AACrC,SAAS,OAAO,YAAY;AAC5B,SAAS,kBAAkB;AAC3B,SAAS,UAAU,oBAAoB;AAEvC,SAAS,+BAA+B,wCAAwC;AAChF,SAAS,yBAAyC;AAClD,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,4BAA4B,8BAA8B;AACnE,SAAS,aAAa,qBAAqB;AAC3C,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAClC,SAAS,
|
|
4
|
+
"sourcesContent": ["import { MonthlySpendCap } from './MonthlySpendCap'\n/**\n * ProjectUsageCard \u2014 a Pro project's \"Usage and plan\" card: one usage meter per resource (AI credits this month,\n * storage) and the monthly usage cap. Short labels and one-line facts only; how top-ups, proration, the cap and\n * reductions work is behind the card's \"More info\" link.\n *\n * Each meter shows used vs the allowance now, marking the plan's part and shading the top-ups, hatches how much more\n * automatic top-ups may add before the usage cap stops them (\"No limit\" / \u00A30 states), says what renews from the next\n * period when that differs (with Undo), and has + / \u2212 beside it with the price of one step:\n * - \"+\" opens the add confirm (charged now: AI credits the full block, storage prorated for the rest of the period);\n * the usage cap never blocks it.\n * - \"\u2212\" opens a one-click confirm that removes one block from the next renewal; this period's allowance stays.\n * The usage cap limits automatic top-ups only (default \u00A3100; \u00A30 = no automatic top-ups; or no limit).\n */\n\nimport { useEffect, useRef, useState, type ReactNode } from 'react'\nimport { formatGbp } from '@arbidocs/react'\nimport { Button, Input, Label } from '@arbidocs/react/ui'\nimport { Minus, Plus } from 'lucide-react'\nimport { UsageMeter } from '../../components/UsageMeter'\nimport { MoreInfo, MoreInfoList } from '../../settings'\nimport type { components } from '@arbidocs/client'\nimport { useUpdateProjectAddonSettings, useUpdateProjectNextPeriodAddons } from '@arbidocs/react'\nimport { addonErrorMessage, type AddonKind } from './useAddonPurchase'\nimport { formatMoney } from './reward-balance'\nimport { notify } from '@arbidocs/react/shell'\nimport { requestProjectBillingFocus, useProjectBillingFocus } from './billing-focus'\nimport { BillingCard, PendingChange } from './BillingCard'\nimport { AddAddonDialog } from './AddAddonDialog'\nimport { ReduceAddonDialog } from './ReduceAddonDialog'\nimport { MIN_AUTO_TOPUP_THRESHOLD_GBP } from './plan-constants'\nimport { aiUsageResetTimestamp } from './quota-items'\nimport {\n addStepCaption,\n addonSettingsBody,\n ANNUAL_PREMIUM_AI_NOTE,\n autoRoom,\n blocksLabel,\n budgetSavedMessage,\n formatPeriodEnd,\n isAddonBudgetZero,\n nextPeriodBody,\n nextRemovedBlockSize,\n reduceBounds,\n splitBlocks,\n stepLabel,\n USAGE_CAP_HELP,\n} from './addon-pricing'\n\ntype ProjectResponse = components['schemas']['ProjectResponse']\ntype ProjectAddons = components['schemas']['ProjectAddons']\n\nconst gbp = (pence: number) => formatMoney(pence, 'gbp')\nconst gb = (n: number) => `${Math.round(n * 10) / 10} GB`\n\n/** \"3 Nov\" \u2014 short day-month for in-period dates. */\nfunction formatShortDate(unix: number | null | undefined): string | null {\n if (!unix) return null\n return new Date(unix * 1000).toLocaleDateString('en-GB', { day: 'numeric', month: 'short' })\n}\n\n/** \"Auto top-up below \u00A3[1]\" \u2014 the automatic AI top-up's trigger (in \u00A3 of AI credits left). */\nfunction AutoTopupThreshold({\n project,\n addons,\n}: {\n project: ProjectResponse\n addons: ProjectAddons\n}) {\n const updateSettings = useUpdateProjectAddonSettings()\n const min = addons.min_auto_topup_threshold_gbp || MIN_AUTO_TOPUP_THRESHOLD_GBP\n const saved = addons.auto_topup_threshold_gbp\n const [value, setValue] = useState(String(saved))\n useEffect(() => setValue(String(saved)), [saved])\n\n const parsed = Number(value)\n const valid = Number.isFinite(parsed) && parsed >= min\n const dirty = valid && parsed !== saved\n const off = isAddonBudgetZero(addons)\n\n const save = () => {\n if (!dirty) return\n updateSettings.mutate(\n {\n projectExtId: project.external_id,\n body: addonSettingsBody(addons, { auto_topup_threshold_gbp: parsed }),\n },\n {\n onSuccess: () => notify.success(`Auto-add below ${formatGbp(parsed)} of AI credits left`),\n onError: (error) => notify.error(addonErrorMessage(error)),\n }\n )\n }\n\n const id = `auto-topup-threshold-${project.external_id}`\n return (\n <div className=\"space-y-1\" data-testid=\"auto-addons\">\n <div className=\"flex flex-wrap items-center gap-2 text-xs\">\n <Label htmlFor={id} className=\"text-xs font-normal text-muted-foreground\">\n Auto top-up below\n </Label>\n <span className=\"flex items-center gap-1.5\">\n <span className=\"text-muted-foreground\" aria-hidden>\n \u00A3\n </span>\n <Input\n id={id}\n type=\"number\"\n inputMode=\"decimal\"\n min={min}\n step={0.5}\n className=\"h-7 w-16 text-xs\"\n value={value}\n disabled={off}\n onChange={(e) => setValue(e.target.value)}\n onKeyDown={(e) => e.key === 'Enter' && save()}\n aria-invalid={!valid}\n data-testid=\"auto-topup-threshold-input\"\n />\n {dirty && (\n <Button\n size=\"sm\"\n variant=\"outline\"\n className=\"h-7\"\n onClick={save}\n disabled={updateSettings.isPending}\n data-testid=\"save-auto-topup-threshold-button\"\n >\n Save\n </Button>\n )}\n </span>\n </div>\n {!valid && (\n <p className=\"text-xs text-destructive\" role=\"alert\">\n Minimum {formatGbp(min)}.\n </p>\n )}\n </div>\n )\n}\n\n/** One + / \u2212 step button with its one-line price beside it. */\nfunction StepAction({\n icon,\n label,\n caption,\n onClick,\n testId,\n ariaLabel,\n}: {\n icon: ReactNode\n label: string\n caption: string\n onClick: () => void\n testId: string\n ariaLabel: string\n}) {\n return (\n <div className=\"flex min-w-0 items-center gap-2\">\n <Button\n size=\"sm\"\n variant=\"outline\"\n className=\"w-20 shrink-0 justify-center tabular-nums\"\n onClick={onClick}\n aria-label={ariaLabel}\n data-testid={testId}\n >\n {icon}\n {label}\n </Button>\n <span\n className=\"min-w-0 text-xs leading-snug text-muted-foreground\"\n data-testid={`${testId}-caption`}\n >\n {caption}\n </span>\n </div>\n )\n}\n\n/** One resource's meter: allowance bar, automatic room, next period (with Undo) and + / \u2212. */\nfunction ResourceMeter({\n kind,\n project,\n addons,\n onAdd,\n onReduce,\n children,\n}: {\n kind: AddonKind\n project: ProjectResponse\n addons: ProjectAddons\n onAdd: () => void\n onReduce: () => void\n children?: ReactNode\n}) {\n const update = useUpdateProjectNextPeriodAddons()\n const isAi = kind === 'ai_usage'\n const slug = isAi ? 'ai-usage' : 'storage'\n const periodEnd = formatPeriodEnd(addons.period_end ?? project.current_period_end)\n const from = periodEnd ?? 'your next renewal'\n const fromShort = formatShortDate(addons.period_end ?? project.current_period_end) ?? 'renewal'\n const { min, current, next } = reduceBounds(kind, addons)\n const fmt = (n: number) => (isAi ? formatGbp(n) : gb(n))\n\n const used = isAi ? addons.ai_used_gbp : addons.storage_used_gb\n const allowance = isAi ? addons.ai_allowance_gbp : addons.storage_allowance_gb\n const allowanceNext = isAi ? addons.ai_allowance_next_gbp : addons.storage_allowance_next_gb\n const plan = isAi ? addons.plan_ai_gbp : addons.plan_storage_gb\n const topUps = Math.max(0, allowance - plan)\n const blocks = isAi ? addons.ai_blocks : addons.storage_blocks\n const hasLegacy = splitBlocks(kind, blocks, addons).legacy > 0\n const room = autoRoom(kind, addons)\n const capZero = isAddonBudgetZero(addons)\n const resets = isAi ? formatShortDate(aiUsageResetTimestamp(project)) : null\n const removeSize = nextRemovedBlockSize(kind, addons)\n\n const undo = () =>\n update.mutate(\n {\n projectExtId: project.external_id,\n body: nextPeriodBody(kind, current),\n },\n {\n onSuccess: () => notify.success('Kept'),\n onError: (error) => notify.error(addonErrorMessage(error)),\n }\n )\n\n // The normal case is the hatched \"Automatic up to \u2026\" legend entry; only the exceptions get a line.\n const autoLine = capZero\n ? 'Automatic top-ups off (\u00A30 cap)'\n : room == null\n ? 'Automatic top-ups: no limit'\n : room > 0\n ? null\n : 'Automatic top-ups: cap reached'\n\n return (\n <UsageMeter\n label={isAi ? 'AI credits' : 'Storage'}\n hint={resets ? `resets ${resets}` : undefined}\n value={`${fmt(used)} used \u00B7 ${fmt(allowance)} included now`}\n allowance={{ used, plan, topUps, autoRoom: capZero ? 0 : room }}\n legend={{\n plan: `Plan ${fmt(plan)}`,\n topUps:\n topUps > 0\n ? `Top-ups ${fmt(topUps)}${hasLegacy ? ` (${blocksLabel(kind, blocks, addons)})` : ''}`\n : undefined,\n autoRoom: room != null && room > 0 && !capZero ? `Automatic up to ${fmt(room)}` : undefined,\n }}\n testId={`usage-meter-${slug}`}\n details={\n autoLine || allowanceNext !== allowance || children ? (\n <>\n {autoLine && <p data-testid={`usage-meter-${slug}-auto`}>{autoLine}</p>}\n {allowanceNext !== allowance && (\n <PendingChange\n testId={`usage-meter-${slug}-next`}\n onUndo={next < current ? undo : undefined}\n isBusy={update.isPending}\n undoTestId={`undo-reduce-${slug}-button`}\n >\n From {from}: {isAi ? `${formatGbp(allowanceNext)} a month` : gb(allowanceNext)}\n </PendingChange>\n )}\n {children}\n </>\n ) : undefined\n }\n actions={\n <>\n <StepAction\n icon={<Plus className=\"size-3.5\" />}\n label={isAi ? formatGbp(addons.block_ai_gbp) : `${addons.block_storage_gb} GB`}\n caption={addStepCaption(kind, addons)}\n onClick={onAdd}\n ariaLabel={`Add ${stepLabel(kind, isAi ? addons.block_ai_gbp : addons.block_storage_gb)}`}\n testId={isAi ? 'add-ai-block-button' : 'add-storage-block-button'}\n />\n {next > min && (\n <details className=\"text-sm\">\n <summary className=\"cursor-pointer text-muted-foreground\">\n Adjust usage add-ons\n </summary>\n <StepAction\n icon={<Minus className=\"size-3.5\" />}\n label={isAi ? formatGbp(removeSize) : `${removeSize} GB`}\n caption={`from ${fromShort}`}\n onClick={onReduce}\n ariaLabel={`Remove ${stepLabel(kind, removeSize)} from ${from}`}\n testId={`reduce-${slug}-button`}\n />\n </details>\n )}\n </>\n }\n />\n )\n}\n\n/** Inclusive monthly spend cap. Existing allowances stay until explicitly reduced. */\nfunction UsageCapEditor({ project, addons }: { project: ProjectResponse; addons: ProjectAddons }) {\n const updateSettings = useUpdateProjectAddonSettings()\n const sectionRef = useRef<HTMLDivElement>(null)\n const inputRef = useRef<HTMLInputElement>(null)\n const minimum = 0\n const stepPence = addons.spend_cap_step_pence\n const saved = addons.spend_cap_pence ?? addons.default_spend_cap_pence\n const maximum = addons.maximum_spend_cap_pence\n const normalize = (n: number) =>\n Math.max(0, Math.min(maximum, Math.floor(n / stepPence) * stepPence))\n const [value, setValue] = useState(normalize(saved))\n useEffect(\n () => setValue(Math.max(0, Math.min(maximum, Math.floor(saved / stepPence) * stepPence))),\n [saved, maximum, stepPence]\n )\n const focus = useProjectBillingFocus()\n useEffect(() => {\n if (focus?.projectExtId !== project.external_id || focus.section !== 'spend-cap') return\n sectionRef.current?.scrollIntoView?.({ behavior: 'smooth', block: 'center' })\n inputRef.current?.focus()\n requestProjectBillingFocus(null)\n }, [focus, project.external_id])\n const save = () =>\n updateSettings.mutate(\n {\n projectExtId: project.external_id,\n body: addonSettingsBody(addons, { spend_cap_pence: value }),\n },\n {\n onSuccess: () => notify.success(budgetSavedMessage(value)),\n onError: (error) => notify.error(addonErrorMessage(error)),\n }\n )\n return (\n <div ref={sectionRef} className=\"space-y-3\" data-testid=\"project-spend-cap\">\n <MonthlySpendCap\n value={value}\n minimum={minimum}\n stepPence={stepPence}\n maximum={maximum}\n onChange={setValue}\n inputRef={inputRef}\n />\n {addons.total_monthly_ex_vat_pence != null && (\n <p className=\"text-sm text-muted-foreground\">\n Your current plan and allowances: {gbp(addons.total_monthly_ex_vat_pence)}/month ex VAT.\n </p>\n )}\n {addons.cap_reached && (\n <p className=\"text-xs text-muted-foreground\" data-testid=\"addon-cap-reached\">\n Your next automatic top-up would exceed the cap. Raise it or adjust usage add-ons.\n </p>\n )}\n <Button\n size=\"sm\"\n onClick={save}\n disabled={value === addons.spend_cap_pence || updateSettings.isPending}\n data-testid=\"save-spend-cap-button\"\n >\n {updateSettings.isPending ? 'Saving\u2026' : 'Save cap'}\n </Button>\n </div>\n )\n}\n\n/** The card's \"More info\": what the meters show and how top-ups, the cap and reductions work. */\nfunction UsageInfo({ addons, isAnnual }: { addons: ProjectAddons; isAnnual: boolean }) {\n const period = isAnnual ? 'year' : 'month'\n const legacy = (addons.legacy_ai_blocks ?? 0) > 0 || (addons.legacy_storage_blocks ?? 0) > 0\n return (\n <MoreInfo title=\"Usage and top-ups\" testId=\"usage-more-info\">\n <MoreInfoList\n items={[\n {\n term: 'Meters',\n text: \"What you used against this month's allowance: the plan (marked) plus top-ups. The hatched part is what automatic top-ups may still add.\",\n },\n {\n term: 'Adding',\n text: `+ adds ${formatGbp(addons.block_ai_gbp)} of AI credits or ${addons.block_storage_gb} GB. AI credits is charged in full today; storage only for the rest of the period. Top-ups renew each ${period} until you reduce them.`,\n },\n {\n term: 'Automatic top-ups',\n text: 'One step is added when AI credits drops below your auto top-up level, or when an upload needs more storage.',\n },\n { term: 'Usage cap', text: USAGE_CAP_HELP },\n {\n term: 'Reducing',\n text: \"\u2212 removes one step from your next renewal. You keep this period's allowance. No refunds.\",\n },\n ...(legacy\n ? [\n {\n term: 'Earlier top-ups',\n text: 'Top-ups bought on an earlier price keep their size and price until removed; they are removed last.',\n },\n ]\n : []),\n ...(isAnnual ? [{ term: 'Annual', text: `${ANNUAL_PREMIUM_AI_NOTE}.` }] : []),\n {\n term: 'Prices',\n text: 'Shown ex VAT. The confirm step shows the total with VAT before you pay.',\n },\n ]}\n />\n </MoreInfo>\n )\n}\n\nexport function ProjectUsageCard({\n project,\n addons,\n}: {\n project: ProjectResponse\n addons: ProjectAddons\n}) {\n const [adding, setAdding] = useState<AddonKind | null>(null)\n const [reducing, setReducing] = useState<AddonKind | null>(null)\n const isAnnual = project.plan_interval === 'year'\n\n return (\n <BillingCard\n title=\"Usage and plan\"\n testId=\"project-usage-card\"\n action={<UsageInfo addons={addons} isAnnual={isAnnual} />}\n >\n {addons.renewal_error && (\n <p role=\"status\" className=\"text-sm text-destructive\">\n {addons.renewal_error}\n </p>\n )}\n <ResourceMeter\n kind=\"ai_usage\"\n project={project}\n addons={addons}\n onAdd={() => setAdding('ai_usage')}\n onReduce={() => setReducing('ai_usage')}\n >\n <AutoTopupThreshold project={project} addons={addons} />\n </ResourceMeter>\n\n <div className=\"border-t border-border pt-4\">\n <ResourceMeter\n kind=\"storage\"\n project={project}\n addons={addons}\n onAdd={() => setAdding('storage')}\n onReduce={() => setReducing('storage')}\n />\n </div>\n\n <div className=\"border-t border-border pt-4\">\n <UsageCapEditor project={project} addons={addons} />\n </div>\n\n {adding && (\n <AddAddonDialog\n kind={adding}\n project={project}\n open\n onOpenChange={(open) => !open && setAdding(null)}\n />\n )}\n {reducing && (\n <ReduceAddonDialog\n kind={reducing}\n project={project}\n open\n onOpenChange={(open) => !open && setReducing(null)}\n />\n )}\n </BillingCard>\n )\n}\n"],
|
|
5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|
-
notify.success(
|
|
50
|
+
notify.success(`Downgrade scheduled for your next billing cycle (${from})`);
|
|
51
51
|
onOpenChange(false);
|
|
52
52
|
},
|
|
53
53
|
onError: (error) => notify.error(addonErrorMessage(error))
|
|
@@ -67,7 +67,7 @@ function ReduceAddonDialog({
|
|
|
67
67
|
] }),
|
|
68
68
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-x-3 gap-y-1", children: [
|
|
69
69
|
/* @__PURE__ */ jsxs(DialogDescription, { "data-testid": "reduce-addon-applies", children: [
|
|
70
|
-
"
|
|
70
|
+
"Takes effect next billing cycle \xB7 ",
|
|
71
71
|
fromShort,
|
|
72
72
|
" \xB7 no refund"
|
|
73
73
|
] }),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/ReduceAddonDialog.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * ReduceAddonDialog \u2014 confirm removing one AI credits / storage block (\u2212\u00A320 / \u221220 GB) from the next period.\n *\n * One click on \"\u2212\" opens it; one click confirms. The reduction applies from the next renewal (`period_end`): this\n * period's allowance stays until then and nothing is refunded, so an automatic top-up can be turned back down to\n * cover only the current period. Each confirm removes one more block from what renews (today's blocks go first;\n * legacy blocks keep their old size). Storage is checked against the requested allowance at renewal.\n */\n\nimport { formatGbp } from '@arbidocs/react'\nimport {\n Button,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '@arbidocs/react/ui'\nimport { ModalSection, MoreInfo } from '../../settings'\nimport type { components } from '@arbidocs/client'\nimport { useUpdateProjectNextPeriodAddons } from '@arbidocs/react'\nimport { addonErrorMessage, type AddonKind } from './useAddonPurchase'\nimport { notify } from '@arbidocs/react/shell'\nimport {\n formatPeriodEnd,\n nextPeriodBody,\n nextRemovedBlockSize,\n reduceBounds,\n stepLabel,\n} from './addon-pricing'\n\ntype ProjectResponse = components['schemas']['ProjectResponse']\n\nconst gb = (n: number) => `${Math.round(n * 10) / 10} GB`\n\nexport function ReduceAddonDialog({\n kind,\n project,\n open,\n onOpenChange,\n}: {\n kind: AddonKind\n project: ProjectResponse\n open: boolean\n onOpenChange: (open: boolean) => void\n}) {\n const update = useUpdateProjectNextPeriodAddons()\n const addons = project.addons\n if (!addons) return null\n\n const { min, next } = reduceBounds(kind, addons)\n const keep = Math.max(min, next - 1)\n const size = nextRemovedBlockSize(kind, addons)\n const what = stepLabel(kind, size)\n const from =\n formatPeriodEnd(addons.period_end ?? project.current_period_end) ?? 'your next renewal'\n const fromShort = from.replace(/ \\d{4}$/, '')\n const allowanceNext =\n kind === 'ai_usage'\n ? addons.ai_allowance_next_gbp - size\n : addons.storage_allowance_next_gb - size\n const allowanceNow = kind === 'ai_usage' ? addons.ai_allowance_gbp : addons.storage_allowance_gb\n const unit = (n: number) => (kind === 'ai_usage' ? `${formatGbp(n)} a month` : gb(n))\n\n const save = () =>\n update.mutate(\n {\n projectExtId: project.external_id,\n body: nextPeriodBody(kind, keep),\n },\n {\n onSuccess: () => {\n notify.success(
|
|
5
|
-
"mappings": ";AAuFU,SAUI,KAVJ;AA9EV,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,gBAAgB;AAEvC,SAAS,wCAAwC;AACjD,SAAS,yBAAyC;AAClD,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,MAAM,KAAK,CAAC,MAAc,GAAG,KAAK,MAAM,IAAI,EAAE,IAAI,EAAE;AAE7C,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKG;AACD,QAAM,SAAS,iCAAiC;AAChD,QAAM,SAAS,QAAQ;AACvB,MAAI,CAAC,OAAQ,QAAO;AAEpB,QAAM,EAAE,KAAK,KAAK,IAAI,aAAa,MAAM,MAAM;AAC/C,QAAM,OAAO,KAAK,IAAI,KAAK,OAAO,CAAC;AACnC,QAAM,OAAO,qBAAqB,MAAM,MAAM;AAC9C,QAAM,OAAO,UAAU,MAAM,IAAI;AACjC,QAAM,OACJ,gBAAgB,OAAO,cAAc,QAAQ,kBAAkB,KAAK;AACtE,QAAM,YAAY,KAAK,QAAQ,WAAW,EAAE;AAC5C,QAAM,gBACJ,SAAS,aACL,OAAO,wBAAwB,OAC/B,OAAO,4BAA4B;AACzC,QAAM,eAAe,SAAS,aAAa,OAAO,mBAAmB,OAAO;AAC5E,QAAM,OAAO,CAAC,MAAe,SAAS,aAAa,GAAG,UAAU,CAAC,CAAC,aAAa,GAAG,CAAC;AAEnF,QAAM,OAAO,MACX,OAAO;AAAA,IACL;AAAA,MACE,cAAc,QAAQ;AAAA,MACtB,MAAM,eAAe,MAAM,IAAI;AAAA,IACjC;AAAA,IACA;AAAA,MACE,WAAW,MAAM;AACf,eAAO,QAAQ,
|
|
4
|
+
"sourcesContent": ["/**\n * ReduceAddonDialog \u2014 confirm removing one AI credits / storage block (\u2212\u00A320 / \u221220 GB) from the next period.\n *\n * One click on \"\u2212\" opens it; one click confirms. The reduction applies from the next renewal (`period_end`): this\n * period's allowance stays until then and nothing is refunded, so an automatic top-up can be turned back down to\n * cover only the current period. Each confirm removes one more block from what renews (today's blocks go first;\n * legacy blocks keep their old size). Storage is checked against the requested allowance at renewal.\n */\n\nimport { formatGbp } from '@arbidocs/react'\nimport {\n Button,\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n} from '@arbidocs/react/ui'\nimport { ModalSection, MoreInfo } from '../../settings'\nimport type { components } from '@arbidocs/client'\nimport { useUpdateProjectNextPeriodAddons } from '@arbidocs/react'\nimport { addonErrorMessage, type AddonKind } from './useAddonPurchase'\nimport { notify } from '@arbidocs/react/shell'\nimport {\n formatPeriodEnd,\n nextPeriodBody,\n nextRemovedBlockSize,\n reduceBounds,\n stepLabel,\n} from './addon-pricing'\n\ntype ProjectResponse = components['schemas']['ProjectResponse']\n\nconst gb = (n: number) => `${Math.round(n * 10) / 10} GB`\n\nexport function ReduceAddonDialog({\n kind,\n project,\n open,\n onOpenChange,\n}: {\n kind: AddonKind\n project: ProjectResponse\n open: boolean\n onOpenChange: (open: boolean) => void\n}) {\n const update = useUpdateProjectNextPeriodAddons()\n const addons = project.addons\n if (!addons) return null\n\n const { min, next } = reduceBounds(kind, addons)\n const keep = Math.max(min, next - 1)\n const size = nextRemovedBlockSize(kind, addons)\n const what = stepLabel(kind, size)\n const from =\n formatPeriodEnd(addons.period_end ?? project.current_period_end) ?? 'your next renewal'\n const fromShort = from.replace(/ \\d{4}$/, '')\n const allowanceNext =\n kind === 'ai_usage'\n ? addons.ai_allowance_next_gbp - size\n : addons.storage_allowance_next_gb - size\n const allowanceNow = kind === 'ai_usage' ? addons.ai_allowance_gbp : addons.storage_allowance_gb\n const unit = (n: number) => (kind === 'ai_usage' ? `${formatGbp(n)} a month` : gb(n))\n\n const save = () =>\n update.mutate(\n {\n projectExtId: project.external_id,\n body: nextPeriodBody(kind, keep),\n },\n {\n onSuccess: () => {\n notify.success(`Downgrade scheduled for your next billing cycle (${from})`)\n onOpenChange(false)\n },\n onError: (error) => notify.error(addonErrorMessage(error)),\n }\n )\n\n return (\n <Dialog open={open} onOpenChange={onOpenChange}>\n <DialogContent\n className=\"max-w-md\"\n data-testid={kind === 'ai_usage' ? 'reduce-ai-usage-dialog' : 'reduce-storage-dialog'}\n >\n <DialogHeader>\n <DialogTitle>Remove {what}?</DialogTitle>\n <div className=\"flex flex-wrap items-center gap-x-3 gap-y-1\">\n <DialogDescription data-testid=\"reduce-addon-applies\">\n Takes effect next billing cycle \u00B7 {fromShort} \u00B7 no refund\n </DialogDescription>\n <MoreInfo title=\"Reducing a top-up\" testId=\"reduce-addon-more-info\">\n <p>\n The reduction applies from your next renewal ({from}). You keep this period's\n allowance until then, and nothing is refunded.\n </p>\n <p>\n Use this to turn an automatic top-up back down so it covers only the current period.\n Undo any time before the renewal.\n </p>\n </MoreInfo>\n </div>\n </DialogHeader>\n <ModalSection className=\"space-y-1.5 text-sm\">\n <dl className=\"space-y-1.5\" data-testid=\"reduce-addon-summary\">\n <div className=\"flex items-baseline justify-between gap-4\">\n <dt className=\"text-muted-foreground\">Now</dt>\n <dd className=\"tabular-nums text-foreground\">{unit(allowanceNow)}</dd>\n </div>\n <div className=\"flex items-baseline justify-between gap-4\">\n <dt className=\"text-muted-foreground\">From {from}</dt>\n <dd className=\"tabular-nums text-foreground\" data-testid=\"reduce-addon-next\">\n {unit(Math.max(0, allowanceNext))}\n </dd>\n </div>\n </dl>\n </ModalSection>\n {kind === 'storage' && addons.storage_used_gb > allowanceNext && (\n <p\n role=\"alert\"\n className=\"text-sm text-amber-700 dark:text-amber-400\"\n data-testid=\"storage-reduction-warning\"\n >\n You currently use {gb(addons.storage_used_gb)}. Reduce your storage to{' '}\n {gb(allowanceNext)} or less before {from}. If your files still exceed this allowance at\n renewal, the downgrade will fail and your existing allowance will stay.\n </p>\n )}\n <DialogFooter>\n <Button variant=\"outline\" onClick={() => onOpenChange(false)}>\n Cancel\n </Button>\n <Button\n onClick={save}\n disabled={keep >= next || update.isPending}\n data-testid=\"confirm-reduce-addon-button\"\n >\n {update.isPending ? 'Saving\u2026' : `Remove ${what}`}\n </Button>\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AAuFU,SAUI,KAVJ;AA9EV,SAAS,iBAAiB;AAC1B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,gBAAgB;AAEvC,SAAS,wCAAwC;AACjD,SAAS,yBAAyC;AAClD,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AA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EX,iBAAO,YAAY,iBAAY,UAAU,IAAI;AAAA;AAAA,UAChD;AAAA,WACF;AAAA;AAAA;AAAA,EACF,GACF;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -78,7 +78,8 @@ function StripeCheckoutModal({
|
|
|
78
78
|
},
|
|
79
79
|
onError: (error) => {
|
|
80
80
|
console.error("Failed to create checkout session:", error);
|
|
81
|
-
const
|
|
81
|
+
const detail = apiErrorDetail(error);
|
|
82
|
+
const reason = typeof detail === "string" ? detail : detail?.message;
|
|
82
83
|
notify.error(
|
|
83
84
|
reason ? `Checkout didn't start: ${reason}` : "Checkout didn't start. Try again."
|
|
84
85
|
);
|
|
@@ -112,7 +113,7 @@ function StripeCheckoutModal({
|
|
|
112
113
|
}
|
|
113
114
|
}, [open]);
|
|
114
115
|
const isStripeConfigured = stripeEnabled;
|
|
115
|
-
const vatNote = quote ? `${checkoutItemsLabel(aiBlocks, storageBlocks, collaboratorBlocks, price)} \xB7 ${quoteTotalLine(quote)}` : null;
|
|
116
|
+
const vatNote = quote ? `${checkoutItemsLabel(aiBlocks, storageBlocks, collaboratorBlocks, price)} \xB7 ${promoCode && !quote.promo_code ? "Before promo code: " : ""}${quoteTotalLine(quote)}` : null;
|
|
116
117
|
return /* @__PURE__ */ jsx(
|
|
117
118
|
CheckoutDialogFrame,
|
|
118
119
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/connection/billing/StripeCheckoutModal.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * StripeCheckoutModal Component\n *\n * Modal with embedded Stripe checkout for a Pro subscription.\n * Uses Stripe Elements for secure payment processing.\n * Checkout is scoped to a specific project.\n */\n\nimport { useEffect, useState } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { CheckoutDialogFrame, MoreInfo } from '../../settings'\nimport { useBillingSupport } from './support'\nimport { apiErrorDetail } from './api-error'\nimport {\n useCreateProjectCheckout,\n useInvalidateEntitlements,\n useInvalidateProjects,\n useRefreshProject,\n} from '@arbidocs/react'\nimport { notify } from '@arbidocs/react/shell'\nimport { checkoutItemsLabel, PRO_PACKS } from './plan-pricing'\nimport { quoteTotalLine, type TaxQuote } from './tax-quote'\n\ninterface StripeCheckoutModalProps {\n projectExtId: string\n price?: components['schemas']['ProductPrice']\n /** Pro billing interval: monthly or annual. */\n interval: 'month' | 'year'\n /** Monthly usage cap chosen at checkout (pence); null/omitted keeps the default. */\n addonBudgetPence?: number | null\n /** Add-on blocks bought with the plan (+\u00A320 of AI credits a month / +20 GB each): on the first invoice. */\n aiBlocks?: number\n collaboratorBlocks?: number\n storageBlocks?: number\n promoCode?: string\n /** ISO-2 billing country picked before checkout; prefills the Stripe customer's address. */\n billingCountry?: string\n /** ZIP / postcode, where the tax depends on it (e.g. the US). */\n postalCode?: string\n /** The total quoted before checkout, repeated above Stripe's summary. */\n quote?: TaxQuote\n open: boolean\n onOpenChange: (open: boolean) => void\n /** Called when Stripe reports the payment completed (before the dialog closes),\n * so callers can distinguish a successful checkout from a cancel/close. */\n onCompleted?: () => void\n}\n\nexport function StripeCheckoutModal({\n projectExtId,\n price,\n interval,\n addonBudgetPence = null,\n aiBlocks = 0,\n storageBlocks = 0,\n collaboratorBlocks = 0,\n promoCode,\n billingCountry,\n postalCode,\n quote,\n open,\n onOpenChange,\n onCompleted,\n}: StripeCheckoutModalProps) {\n const [clientSecret, setClientSecret] = useState<string | null>(null)\n const [isCreating, setIsCreating] = useState(false)\n const [stripe, setStripe] = useState<unknown>(null)\n const { stripeEnabled, checkout } = useBillingSupport()\n const createCheckout = useCreateProjectCheckout()\n const refreshProject = useRefreshProject()\n const invalidateProjects = useInvalidateProjects()\n // Pro brings the paid features (Mail, Calendar): read them again rather than wait out a copy.\n const invalidateEntitlements = useInvalidateEntitlements()\n\n // Fired by Stripe when payment completes (redirect_on_completion=\"never\").\n // Refresh the project \u2014 this links the subscription, grants the Pro allowance and any\n // referral reward \u2014 then close the dialog. useRefreshProject invalidates the project\n // list and user settings once the refresh returns, so the UI (and referral reward) update.\n const handleComplete = () => {\n // Signal success BEFORE closing so the parent's onOpenChange handler doesn't\n // treat this close as a cancellation (and delete the now-paid project).\n onCompleted?.()\n // The project already exists (created pending before checkout), so list it now rather than\n // waiting for the refresh round trip to Stripe; the refresh invalidates again when it lands.\n void invalidateProjects()\n void invalidateEntitlements()\n // The refresh is what grants Pro on the server: read the entitlements again once it lands.\n refreshProject.mutate(projectExtId, { onSettled: () => void invalidateEntitlements() })\n notify.success(\"You're on Pro\")\n onOpenChange(false)\n }\n\n // Lazy load Stripe only when modal opens\n useEffect(() => {\n if (open) {\n const stripePromise = checkout?.load()\n if (stripePromise) {\n void stripePromise.then(setStripe)\n }\n }\n }, [open, checkout])\n\n useEffect(() => {\n // Only create session once when modal opens\n if (open && projectExtId && !clientSecret && !isCreating && !createCheckout.isPending) {\n setIsCreating(true)\n createCheckout.mutate(\n {\n projectExtId,\n body: {\n interval,\n packs: PRO_PACKS,\n ai_blocks: aiBlocks,\n storage_blocks: storageBlocks,\n collaborator_blocks: collaboratorBlocks,\n addon_budget_pence: addonBudgetPence,\n ...(promoCode ? { promo_code: promoCode } : {}),\n ...(billingCountry ? { billing_country: billingCountry } : {}),\n ...(billingCountry && postalCode ? { postal_code: postalCode } : {}),\n },\n },\n {\n onSuccess: (data) => {\n setClientSecret(data.client_secret)\n setIsCreating(false)\n },\n onError: (error) => {\n console.error('Failed to create checkout session:', error)\n // The API returns {detail: {code, message}} with Stripe's own reason when it has one.\n const
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * StripeCheckoutModal Component\n *\n * Modal with embedded Stripe checkout for a Pro subscription.\n * Uses Stripe Elements for secure payment processing.\n * Checkout is scoped to a specific project.\n */\n\nimport { useEffect, useState } from 'react'\nimport type { components } from '@arbidocs/client'\nimport { CheckoutDialogFrame, MoreInfo } from '../../settings'\nimport { useBillingSupport } from './support'\nimport { apiErrorDetail } from './api-error'\nimport {\n useCreateProjectCheckout,\n useInvalidateEntitlements,\n useInvalidateProjects,\n useRefreshProject,\n} from '@arbidocs/react'\nimport { notify } from '@arbidocs/react/shell'\nimport { checkoutItemsLabel, PRO_PACKS } from './plan-pricing'\nimport { quoteTotalLine, type TaxQuote } from './tax-quote'\n\ninterface StripeCheckoutModalProps {\n projectExtId: string\n price?: components['schemas']['ProductPrice']\n /** Pro billing interval: monthly or annual. */\n interval: 'month' | 'year'\n /** Monthly usage cap chosen at checkout (pence); null/omitted keeps the default. */\n addonBudgetPence?: number | null\n /** Add-on blocks bought with the plan (+\u00A320 of AI credits a month / +20 GB each): on the first invoice. */\n aiBlocks?: number\n collaboratorBlocks?: number\n storageBlocks?: number\n promoCode?: string\n /** ISO-2 billing country picked before checkout; prefills the Stripe customer's address. */\n billingCountry?: string\n /** ZIP / postcode, where the tax depends on it (e.g. the US). */\n postalCode?: string\n /** The total quoted before checkout, repeated above Stripe's summary. */\n quote?: TaxQuote\n open: boolean\n onOpenChange: (open: boolean) => void\n /** Called when Stripe reports the payment completed (before the dialog closes),\n * so callers can distinguish a successful checkout from a cancel/close. */\n onCompleted?: () => void\n}\n\nexport function StripeCheckoutModal({\n projectExtId,\n price,\n interval,\n addonBudgetPence = null,\n aiBlocks = 0,\n storageBlocks = 0,\n collaboratorBlocks = 0,\n promoCode,\n billingCountry,\n postalCode,\n quote,\n open,\n onOpenChange,\n onCompleted,\n}: StripeCheckoutModalProps) {\n const [clientSecret, setClientSecret] = useState<string | null>(null)\n const [isCreating, setIsCreating] = useState(false)\n const [stripe, setStripe] = useState<unknown>(null)\n const { stripeEnabled, checkout } = useBillingSupport()\n const createCheckout = useCreateProjectCheckout()\n const refreshProject = useRefreshProject()\n const invalidateProjects = useInvalidateProjects()\n // Pro brings the paid features (Mail, Calendar): read them again rather than wait out a copy.\n const invalidateEntitlements = useInvalidateEntitlements()\n\n // Fired by Stripe when payment completes (redirect_on_completion=\"never\").\n // Refresh the project \u2014 this links the subscription, grants the Pro allowance and any\n // referral reward \u2014 then close the dialog. useRefreshProject invalidates the project\n // list and user settings once the refresh returns, so the UI (and referral reward) update.\n const handleComplete = () => {\n // Signal success BEFORE closing so the parent's onOpenChange handler doesn't\n // treat this close as a cancellation (and delete the now-paid project).\n onCompleted?.()\n // The project already exists (created pending before checkout), so list it now rather than\n // waiting for the refresh round trip to Stripe; the refresh invalidates again when it lands.\n void invalidateProjects()\n void invalidateEntitlements()\n // The refresh is what grants Pro on the server: read the entitlements again once it lands.\n refreshProject.mutate(projectExtId, { onSettled: () => void invalidateEntitlements() })\n notify.success(\"You're on Pro\")\n onOpenChange(false)\n }\n\n // Lazy load Stripe only when modal opens\n useEffect(() => {\n if (open) {\n const stripePromise = checkout?.load()\n if (stripePromise) {\n void stripePromise.then(setStripe)\n }\n }\n }, [open, checkout])\n\n useEffect(() => {\n // Only create session once when modal opens\n if (open && projectExtId && !clientSecret && !isCreating && !createCheckout.isPending) {\n setIsCreating(true)\n createCheckout.mutate(\n {\n projectExtId,\n body: {\n interval,\n packs: PRO_PACKS,\n ai_blocks: aiBlocks,\n storage_blocks: storageBlocks,\n collaborator_blocks: collaboratorBlocks,\n addon_budget_pence: addonBudgetPence,\n ...(promoCode ? { promo_code: promoCode } : {}),\n ...(billingCountry ? { billing_country: billingCountry } : {}),\n ...(billingCountry && postalCode ? { postal_code: postalCode } : {}),\n },\n },\n {\n onSuccess: (data) => {\n setClientSecret(data.client_secret)\n setIsCreating(false)\n },\n onError: (error) => {\n console.error('Failed to create checkout session:', error)\n // The API returns {detail: {code, message}} with Stripe's own reason when it has one.\n const detail = apiErrorDetail(error)\n const reason =\n typeof detail === 'string'\n ? detail\n : (detail as { message?: string } | undefined)?.message\n notify.error(\n reason ? `Checkout didn't start: ${reason}` : \"Checkout didn't start. Try again.\"\n )\n setIsCreating(false)\n onOpenChange(false)\n },\n }\n )\n }\n }, [\n open,\n interval,\n addonBudgetPence,\n aiBlocks,\n storageBlocks,\n collaboratorBlocks,\n projectExtId,\n promoCode,\n billingCountry,\n postalCode,\n clientSecret,\n isCreating,\n createCheckout,\n onOpenChange,\n ])\n\n // Reset state when modal closes\n useEffect(() => {\n if (!open) {\n setClientSecret(null)\n setIsCreating(false)\n setStripe(null)\n }\n }, [open])\n\n // Check if Stripe is configured (key present) \u2014 must not load Stripe.js itself\n const isStripeConfigured = stripeEnabled\n\n // Repeat the quoted total above Stripe's summary. The billing country (and postcode) is saved on\n // the Stripe customer first, so Stripe taxes the same address from its first frame.\n const vatNote = quote\n ? `${checkoutItemsLabel(aiBlocks, storageBlocks, collaboratorBlocks, price)} \u00B7 ${promoCode && !quote.promo_code ? 'Before promo code: ' : ''}${quoteTotalLine(quote)}`\n : null\n\n return (\n <CheckoutDialogFrame\n open={open}\n onOpenChange={onOpenChange}\n isUnavailable={!isStripeConfigured}\n isLoading={isCreating || createCheckout.isPending}\n hasError={createCheckout.isError}\n >\n {clientSecret && !!stripe && (\n <>\n {vatNote && (\n <p data-testid=\"checkout-vat-note\" className=\"mb-4 text-sm text-muted-foreground\">\n {vatNote}\n </p>\n )}\n {checkout?.render(stripe, { clientSecret, onComplete: handleComplete })}\n <div className=\"mt-3\">\n <MoreInfo title=\"Paying\" label=\"Payment help\" testId=\"checkout-payment-help\">\n {/* Stripe's inline decline message doesn't say what happened to the money. */}\n <p data-testid=\"checkout-decline-note\">\n Card declined? Nothing was charged. Try again or use another card.\n </p>\n <p data-testid=\"checkout-vat-id-note\">\n No VAT number? Leave ‘purchasing as a business’ unticked.\n </p>\n <p>\n Add-ons chosen here are on the first invoice with the plan and renew with it until\n you reduce them.\n </p>\n </MoreInfo>\n </div>\n </>\n )}\n </CheckoutDialogFrame>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA2LQ,mBAEI,KAMA,YARJ;AAnLR,SAAS,WAAW,gBAAgB;AAEpC,SAAS,qBAAqB,gBAAgB;AAC9C,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B;AAAA,EACE;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AAA,MAChB,WAAW,cAAc,eAAe;AAAA,MACxC,UAAU,eAAe;AAAA,MAExB,0BAAgB,CAAC,CAAC,UACjB,iCACG;AAAA,mBACC,oBAAC,OAAE,eAAY,qBAAoB,WAAU,sCAC1C,mBACH;AAAA,QAED,UAAU,OAAO,QAAQ,EAAE,cAAc,YAAY,eAAe,CAAC;AAAA,QACtE,oBAAC,SAAI,WAAU,QACb,+BAAC,YAAS,OAAM,UAAS,OAAM,gBAAe,QAAO,yBAEnD;AAAA,8BAAC,OAAE,eAAY,yBAAwB,gFAEvC;AAAA,UACA,oBAAC,OAAE,eAAY,wBAAuB,iFAEtC;AAAA,UACA,oBAAC,OAAE,iHAGH;AAAA,WACF,GACF;AAAA,SACF;AAAA;AAAA,EAEJ;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import type { components } from '@arbidocs/client';
|
|
1
2
|
interface SubscriptionPlansProps {
|
|
2
3
|
projectExtId: string;
|
|
4
|
+
projectName?: string;
|
|
3
5
|
isPersonal?: boolean;
|
|
6
|
+
dailyCapPerUser?: number | null;
|
|
7
|
+
currentQuotas?: components['schemas']['ProjectQuotas'];
|
|
4
8
|
onDismiss?: () => void;
|
|
5
9
|
}
|
|
6
|
-
export declare function SubscriptionPlans({ projectExtId, onDismiss }: SubscriptionPlansProps): import("react").JSX.Element;
|
|
10
|
+
export declare function SubscriptionPlans({ projectExtId, projectName, onDismiss, dailyCapPerUser, currentQuotas, }: SubscriptionPlansProps): import("react").JSX.Element;
|
|
7
11
|
export {};
|
|
@@ -1,14 +1,63 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState } from "react";
|
|
4
|
-
import { Button } from "@arbidocs/react/ui";
|
|
4
|
+
import { Button, Input, Label } from "@arbidocs/react/ui";
|
|
5
5
|
import { PlanNotice, PlanStack } from "../../settings/index.js";
|
|
6
|
-
import { useProducts } from "@arbidocs/react";
|
|
6
|
+
import { useProducts, useUpdateProjectFields } from "@arbidocs/react";
|
|
7
7
|
import { StripeCheckoutModal } from "./StripeCheckoutModal.js";
|
|
8
8
|
import { ProjectPurchaseOptions } from "./ProjectPurchaseOptions.js";
|
|
9
9
|
import { findProPrices } from "./plan-pricing.js";
|
|
10
|
-
function SubscriptionPlans({
|
|
10
|
+
function SubscriptionPlans({
|
|
11
|
+
projectExtId,
|
|
12
|
+
projectName,
|
|
13
|
+
onDismiss,
|
|
14
|
+
dailyCapPerUser = null,
|
|
15
|
+
currentQuotas
|
|
16
|
+
}) {
|
|
11
17
|
const { data: products, isLoading, error } = useProducts();
|
|
18
|
+
const rename = useUpdateProjectFields();
|
|
19
|
+
const [name, setName] = useState(projectName ?? "");
|
|
20
|
+
const [nameError, setNameError] = useState(null);
|
|
21
|
+
const validName = projectName === void 0 || name.trim().length > 0;
|
|
22
|
+
const [dailyCapValue, setDailyCapValue] = useState(
|
|
23
|
+
dailyCapPerUser == null ? "" : String(dailyCapPerUser)
|
|
24
|
+
);
|
|
25
|
+
const [savedDailyCap, setSavedDailyCap] = useState(dailyCapPerUser);
|
|
26
|
+
const [dailyCapError, setDailyCapError] = useState(null);
|
|
27
|
+
const parsedDailyCap = dailyCapValue.trim() === "" ? null : Number(dailyCapValue);
|
|
28
|
+
const validDailyCap = parsedDailyCap === null || Number.isFinite(parsedDailyCap) && parsedDailyCap >= 0;
|
|
29
|
+
const dailyCap = parsedDailyCap === null ? null : Math.round(parsedDailyCap * 100) / 100;
|
|
30
|
+
const dirtyDailyCap = dailyCap !== savedDailyCap;
|
|
31
|
+
const choose = (next, capOnly = false) => {
|
|
32
|
+
if (!capOnly && !validName || !validDailyCap || rename.isPending) return;
|
|
33
|
+
const nameChanged = !capOnly && projectName !== void 0 && name.trim() !== projectName;
|
|
34
|
+
if (!nameChanged && !dirtyDailyCap) {
|
|
35
|
+
next();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
setNameError(null);
|
|
39
|
+
setDailyCapError(null);
|
|
40
|
+
rename.mutate(
|
|
41
|
+
{
|
|
42
|
+
projectExtId,
|
|
43
|
+
patch: {
|
|
44
|
+
...nameChanged ? { name: name.trim() } : {},
|
|
45
|
+
...dirtyDailyCap ? { daily_cap_per_user: dailyCap } : {}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
onSuccess: () => {
|
|
50
|
+
setSavedDailyCap(dailyCap);
|
|
51
|
+
next();
|
|
52
|
+
},
|
|
53
|
+
onError: () => {
|
|
54
|
+
if (dirtyDailyCap) setDailyCapError("Couldn't save the daily limit. Try again.");
|
|
55
|
+
else setNameError("Couldn't save the project name. Try again.");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
const [promoCode, setPromoCode] = useState("");
|
|
12
61
|
const [aiBlocks, setAiBlocks] = useState(0);
|
|
13
62
|
const [storageBlocks, setStorageBlocks] = useState(0);
|
|
14
63
|
const [collaboratorBlocks, setCollaboratorBlocks] = useState(0);
|
|
@@ -19,21 +68,54 @@ function SubscriptionPlans({ projectExtId, onDismiss }) {
|
|
|
19
68
|
if (!products?.length) return /* @__PURE__ */ jsx(PlanNotice, { children: "No plans available." });
|
|
20
69
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
21
70
|
/* @__PURE__ */ jsxs(PlanStack, { children: [
|
|
71
|
+
projectName !== void 0 && /* @__PURE__ */ jsxs("div", { className: "space-y-2", "data-testid": "change-plan-project", children: [
|
|
72
|
+
/* @__PURE__ */ jsx(Label, { htmlFor: "upgrade-project-name", children: "Project name" }),
|
|
73
|
+
/* @__PURE__ */ jsx(
|
|
74
|
+
Input,
|
|
75
|
+
{
|
|
76
|
+
id: "upgrade-project-name",
|
|
77
|
+
value: name,
|
|
78
|
+
onChange: (event) => {
|
|
79
|
+
setName(event.target.value);
|
|
80
|
+
setNameError(null);
|
|
81
|
+
},
|
|
82
|
+
disabled: rename.isPending,
|
|
83
|
+
"aria-invalid": !validName || !!nameError,
|
|
84
|
+
"aria-describedby": nameError ? "upgrade-project-name-error" : void 0
|
|
85
|
+
}
|
|
86
|
+
),
|
|
87
|
+
nameError && /* @__PURE__ */ jsx("p", { id: "upgrade-project-name-error", role: "alert", className: "text-sm text-destructive", children: nameError })
|
|
88
|
+
] }),
|
|
22
89
|
/* @__PURE__ */ jsx(
|
|
23
90
|
ProjectPurchaseOptions,
|
|
24
91
|
{
|
|
25
92
|
products,
|
|
93
|
+
promoCode,
|
|
94
|
+
onPromoCodeChange: setPromoCode,
|
|
26
95
|
projectExtId,
|
|
96
|
+
currentQuotas,
|
|
27
97
|
aiBlocks,
|
|
28
98
|
storageBlocks,
|
|
29
99
|
collaboratorBlocks,
|
|
30
100
|
onAiBlocksChange: setAiBlocks,
|
|
31
101
|
onStorageBlocksChange: setStorageBlocks,
|
|
32
102
|
onCollaboratorBlocksChange: setCollaboratorBlocks,
|
|
33
|
-
|
|
34
|
-
|
|
103
|
+
dailyCapValue,
|
|
104
|
+
onDailyCapChange: (value) => {
|
|
105
|
+
setDailyCapValue(value);
|
|
106
|
+
setDailyCapError(null);
|
|
107
|
+
},
|
|
108
|
+
onSaveDailyCap: () => choose(() => {
|
|
109
|
+
}, true),
|
|
110
|
+
canSaveDailyCap: dirtyDailyCap && validDailyCap,
|
|
111
|
+
dailyCapError: !validDailyCap ? "Enter a positive amount, zero, or leave blank for no limit." : dailyCapError,
|
|
112
|
+
disabled: !validName || !validDailyCap,
|
|
113
|
+
busy: rename.isPending,
|
|
114
|
+
busyLabel: "Saving project settings\u2026",
|
|
115
|
+
onChoose: (interval, capPence, quote) => choose(() => {
|
|
116
|
+
setCheckout({ interval, capPence, quote, promoCode: promoCode.trim() || void 0 });
|
|
35
117
|
setCheckoutOpen(true);
|
|
36
|
-
}
|
|
118
|
+
})
|
|
37
119
|
}
|
|
38
120
|
),
|
|
39
121
|
onDismiss && /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Button, { variant: "ghost", onClick: onDismiss, children: "Cancel" }) })
|
|
@@ -41,6 +123,7 @@ function SubscriptionPlans({ projectExtId, onDismiss }) {
|
|
|
41
123
|
checkout && /* @__PURE__ */ jsx(
|
|
42
124
|
StripeCheckoutModal,
|
|
43
125
|
{
|
|
126
|
+
promoCode: checkout.promoCode,
|
|
44
127
|
price: findProPrices(products)[checkout.interval === "year" ? "annual" : "monthly"],
|
|
45
128
|
projectExtId,
|
|
46
129
|
interval: checkout.interval,
|