@openrails/billing-ui 0.254.0 → 0.256.0
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/README.md +6 -5
- package/dist/account/cancel-dialog.d.ts +2 -2
- package/dist/account/subscriptions-panel.d.ts +1 -2
- package/dist/admin/lib/api/types.d.ts +1 -1
- package/dist/admin/messages.d.ts +8 -5
- package/dist/admin/pages/catalog/price-format.d.ts +3 -1
- package/dist/admin/pages/catalog/psp-links.d.ts +1 -1
- package/dist/{admin-catalog-rrFZd5N8.js → admin-catalog-C0QRANp7.js} +8 -11
- package/dist/{admin-catalog-rrFZd5N8.js.map → admin-catalog-C0QRANp7.js.map} +1 -1
- package/dist/{admin-detail-Cq59e14B.js → admin-detail-qetSqVDt.js} +2 -2
- package/dist/{admin-detail-Cq59e14B.js.map → admin-detail-qetSqVDt.js.map} +1 -1
- package/dist/{admin-price-detail-Bwk9PXHP.js → admin-price-detail-C9CJwLeM.js} +101 -128
- package/dist/admin-price-detail-C9CJwLeM.js.map +1 -0
- package/dist/{admin-price-format-DM1qORWI.js → admin-price-format-BVUpDoSC.js} +5 -1
- package/dist/admin-price-format-BVUpDoSC.js.map +1 -0
- package/dist/{admin-price-wizard-ByD7j8mB.js → admin-price-wizard-DAkDGWkH.js} +123 -124
- package/dist/admin-price-wizard-DAkDGWkH.js.map +1 -0
- package/dist/admin.css +1 -1
- package/dist/admin.js +13 -10
- package/dist/admin.js.map +1 -1
- package/dist/client/client.d.ts +4 -4
- package/dist/client/generated/error-codes.d.ts +1 -1
- package/dist/client/generated/routes.d.ts +29 -12
- package/dist/client/generated/wire.d.ts +62 -21
- package/dist/client/types.d.ts +119 -20
- package/dist/{client-B301IAQD.js → client-Bs2YY-PV.js} +19 -3
- package/dist/client-Bs2YY-PV.js.map +1 -0
- package/dist/client.js +1 -1
- package/dist/{hooks-DARbMTwv.js → hooks-CCA-6uEa.js} +134 -123
- package/dist/{hooks-DARbMTwv.js.map → hooks-CCA-6uEa.js.map} +1 -1
- package/dist/index.js +729 -716
- package/dist/index.js.map +1 -1
- package/dist/locales/de.js +1 -0
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.d.ts +1 -0
- package/dist/locales/en.js +1 -0
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es.js +1 -0
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/ja.js +1 -0
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/ko.js +1 -0
- package/dist/locales/ko.js.map +1 -1
- package/dist/locales/zh.js +1 -0
- package/dist/locales/zh.js.map +1 -1
- package/dist/react/hooks.d.ts +3 -4
- package/dist/react.js +1 -1
- package/package.json +1 -1
- package/dist/admin-price-detail-Bwk9PXHP.js.map +0 -1
- package/dist/admin-price-format-DM1qORWI.js.map +0 -1
- package/dist/admin-price-wizard-ByD7j8mB.js.map +0 -1
- package/dist/client-B301IAQD.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"admin-detail-Cq59e14B.js","names":[],"sources":["../src/admin/pages/subscriptions/subscription-change-options.ts","../src/admin/pages/subscriptions/change-subscription-dialog.tsx","../src/admin/pages/subscriptions/detail.tsx"],"sourcesContent":["import type { Rail, SubscriptionStatus } from \"#orck/admin/lib/api/types\"\nimport type {\n Price,\n Product,\n ScheduledChange,\n} from \"#orck/client/generated/wire\"\nimport { formatNativeAmount } from \"#orck/admin/lib/format\"\nimport { priceIntervalLabel } from \"#orck/admin/pages/catalog/price-format\"\n\nexport interface SubscriptionChangeOption {\n direction: \"current\" | \"upgrade\" | \"downgrade\"\n price: Price\n product: Product\n}\n\nexport function subscriptionChangeOptionLabel(\n option: SubscriptionChangeOption\n): string {\n const price = option.price\n const amount = `${formatNativeAmount(price.unit_amount, price.currency)}${price.quantity ? \" per seat\" : \"\"}`\n return [\n option.product.display_name,\n option.direction,\n `${amount} ${priceIntervalLabel(price)}`,\n price.key,\n ].join(\" · \")\n}\n\n// The seats a change starts from: the subscription's when the price allows\n// them, otherwise the price's minimum.\nexport function initialSeats(\n price: Price,\n current: number | null\n): number | null {\n const bounds = price.quantity\n if (!bounds) return null\n if (current !== null && current >= bounds.min && current <= bounds.max) {\n return current\n }\n return bounds.min\n}\n\nexport function adminSubscriptionChangeBlockReason({\n rail,\n status,\n collectionPolicy,\n scheduledChange,\n}: {\n rail: Rail\n status: SubscriptionStatus\n collectionPolicy?: string\n scheduledChange?: Pick<ScheduledChange, \"source\"> | null\n}): string | undefined {\n if (status !== \"active\" && status !== \"past_due\") {\n return \"Only active or past-due subscriptions can change\"\n }\n // OpenRails changes back only the scheduled change it bills itself.\n if (scheduledChange && collectionPolicy !== \"engine\") {\n return \"Its provider already bills a scheduled change\"\n }\n if (rail === \"ccbill\") return \"CCBill changes require customer self-service\"\n if (rail === \"solana\") {\n return \"Solana changes require the customer's wallet signature\"\n }\n return undefined\n}\n\n// The changes the console offers: the current price, for its seats or to\n// change back from a scheduled change, then, unless a price migration is\n// pending, live recurring prices of the tier group in the same currency.\nexport function subscriptionChangeOptions({\n currentProduct,\n currentPrice,\n currentCurrency,\n products,\n prices,\n scheduledChange,\n}: {\n currentProduct?: Product\n currentPrice?: Price\n currentCurrency?: string\n products: Product[]\n prices: Price[]\n scheduledChange?: Pick<ScheduledChange, \"source\"> | null\n}): SubscriptionChangeOption[] {\n const current: SubscriptionChangeOption[] =\n currentProduct && currentPrice && (currentPrice.quantity || scheduledChange)\n ? [{ direction: \"current\", price: currentPrice, product: currentProduct }]\n : []\n const tierGroup = currentProduct?.tier_group?.trim()\n const currency = currentCurrency?.trim().toLowerCase()\n if (\n !currentProduct ||\n !tierGroup ||\n !currency ||\n scheduledChange?.source === \"migration\"\n ) {\n return current\n }\n\n const productsByID = new Map(\n products\n .filter(\n (product) =>\n !product.archived &&\n product.id !== currentProduct.id &&\n product.tier_group?.trim() === tierGroup\n )\n .map((product) => [product.id, product])\n )\n\n return current.concat(\n prices\n .flatMap((price): SubscriptionChangeOption[] => {\n const product = productsByID.get(price.product_id)\n if (\n !product ||\n price.archived ||\n !price.billing_interval_hours ||\n price.currency.trim().toLowerCase() !== currency\n ) {\n return []\n }\n return [\n {\n direction:\n product.tier_rank < currentProduct.tier_rank\n ? \"downgrade\"\n : \"upgrade\",\n price,\n product,\n },\n ]\n })\n .sort(\n (left, right) =>\n left.product.tier_rank - right.product.tier_rank ||\n left.product.display_name.localeCompare(right.product.display_name) ||\n left.price.id.localeCompare(right.price.id)\n )\n )\n}\n","import { AdminMessage, useAdminUI } from \"#orck/admin/ui-context\"\nimport { useAdminServices } from \"#orck/admin/context\"\nimport * as React from \"react\"\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\"\n\nimport { Badge } from \"#orck/admin/components/ui/badge\"\nimport { Button } from \"#orck/admin/components/ui/button\"\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n DialogTrigger,\n} from \"#orck/admin/components/ui/dialog\"\nimport { Input } from \"#orck/admin/components/ui/input\"\nimport { Label } from \"#orck/admin/components/ui/label\"\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"#orck/admin/components/ui/select\"\nimport type {\n ChangeSubscriptionParams,\n Rail,\n ScheduledChange,\n SubscriptionStatus,\n} from \"#orck/admin/lib/api/types\"\nimport { ApiError } from \"#orck/admin/lib/api/client\"\nimport { DIALOG_WIDE } from \"#orck/admin/lib/dialog-width\"\nimport { formatDate, formatNativeAmount } from \"#orck/admin/lib/format\"\n\nimport {\n adminSubscriptionChangeBlockReason,\n initialSeats,\n subscriptionChangeOptionLabel,\n subscriptionChangeOptions,\n} from \"#orck/admin/pages/subscriptions/subscription-change-options\"\n\ninterface ChangeSubscriptionDialogProps {\n subscriptionId: string\n customerId?: string\n productId: string\n priceId: string\n quantity: number | null\n currency?: string\n collectionPolicy?: string\n scheduledChange?: ScheduledChange | null\n rail: Rail\n status: SubscriptionStatus\n}\n\nexport function ChangeSubscriptionDialog(props: ChangeSubscriptionDialogProps) {\n const { selectedMerchant } = useAdminServices()\n\n return (\n <ChangeSubscriptionForm\n key={`${selectedMerchant() ?? \"\"}:${props.subscriptionId}`}\n {...props}\n />\n )\n}\n\nfunction ChangeSubscriptionForm({\n subscriptionId,\n customerId,\n productId,\n priceId,\n quantity,\n currency,\n collectionPolicy,\n scheduledChange,\n rail,\n status,\n}: ChangeSubscriptionDialogProps) {\n const { toast, toastApiError, adminMutations, adminQueries } =\n useAdminServices()\n\n const { id: adminId, text: adminText } = useAdminUI()\n\n const [open, setOpen] = React.useState(false)\n const [selectedPriceId, setSelectedPriceId] = React.useState(\"\")\n const [seats, setSeats] = React.useState(\"\")\n const [reason, setReason] = React.useState(\"\")\n const [reviewedKey, setReviewedKey] = React.useState(\"\")\n // A dismissed dialog or another preview cannot establish non-execution.\n // Retain each submitted request's key until its outcome is definitive.\n const attempts = React.useRef(new Map<string, string>())\n const view = React.useRef(0)\n React.useEffect(\n () => () => {\n view.current++\n },\n []\n )\n const queryClient = useQueryClient()\n const preview = useMutation(\n adminMutations.previewSubscriptionChange(subscriptionId)\n )\n const change = useMutation(\n adminMutations.changeSubscription(queryClient, subscriptionId, customerId)\n )\n const productsQuery = useQuery({\n ...adminQueries.allProducts({ errorAction: \"Load subscription plans\" }),\n enabled: open,\n })\n const pricesQuery = useQuery({\n ...adminQueries.allPrices({ errorAction: \"Load subscription prices\" }),\n enabled: open,\n })\n\n const products = productsQuery.data?.data ?? []\n const prices = pricesQuery.data?.data ?? []\n const currentProduct = products.find((product) => product.id === productId)\n const currentPrice = prices.find((price) => price.id === priceId)\n const options = subscriptionChangeOptions({\n currentProduct,\n currentPrice,\n currentCurrency: currency ?? currentPrice?.currency,\n products,\n prices,\n scheduledChange,\n })\n const selected = options.find((option) => option.price.id === selectedPriceId)\n const bounds = selected?.price.quantity\n const seatCount = Number(seats)\n const seatsValid =\n !bounds ||\n (Number.isInteger(seatCount) &&\n seatCount >= bounds.min &&\n seatCount <= bounds.max)\n // The current price with its seats changes back from a scheduled change.\n const request: ChangeSubscriptionParams | undefined =\n selected && seatsValid\n ? {\n price_id: selected.price.id,\n ...(bounds ? { quantity: seatCount } : {}),\n }\n : undefined\n const unchanged =\n selected?.direction === \"current\" &&\n !scheduledChange &&\n (!bounds || seatCount === quantity)\n const requestKey = request ? JSON.stringify(request) : \"\"\n const reviewed =\n requestKey && reviewedKey === requestKey ? preview.data : undefined\n const blockReason = adminSubscriptionChangeBlockReason({\n rail,\n status,\n collectionPolicy,\n scheduledChange,\n })\n\n const handleOpenChange = (next: boolean) => {\n view.current++\n setOpen(next)\n }\n\n const handleSelect = (value: string | null) => {\n view.current++\n const price = options.find((option) => option.price.id === value)?.price\n setSelectedPriceId(value ?? \"\")\n setSeats(String(price ? (initialSeats(price, quantity) ?? \"\") : \"\"))\n setReviewedKey(\"\")\n preview.reset()\n change.reset()\n }\n\n const handleSeats = (value: string) => {\n view.current++\n setSeats(value)\n setReviewedKey(\"\")\n preview.reset()\n change.reset()\n }\n\n const previewError =\n preview.error instanceof Error ? preview.error.message : \"\"\n const changeError = change.error instanceof Error ? change.error.message : \"\"\n const responseMessage = change.data?.message\n const responseURL = change.data?.next_action?.url ?? undefined\n\n return (\n <Dialog open={open} onOpenChange={handleOpenChange}>\n <DialogTrigger\n render={\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={Boolean(blockReason) && !change.variables}\n title={blockReason}\n >\n <AdminMessage id={\"Change subscription\"} />\n </Button>\n }\n />\n <DialogContent className={DIALOG_WIDE}>\n <DialogHeader>\n <DialogTitle>\n <AdminMessage id={\"Change subscription\"} />\n </DialogTitle>\n <DialogDescription>\n <AdminMessage\n id={\"Schedule the customer's plan or seats for the next renewal. No card is charged now. Choosing the current plan and seats clears a pending change. The customer is told.\"}\n />\n </DialogDescription>\n </DialogHeader>\n\n <div className=\"grid gap-5\">\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"subscription-tier\")}>\n <AdminMessage id={\"New plan\"} />\n </Label>\n <Select value={selectedPriceId} onValueChange={handleSelect}>\n <SelectTrigger\n id={adminId(\"subscription-tier\")}\n className=\"w-full\"\n disabled={productsQuery.isPending || pricesQuery.isPending}\n >\n <SelectValue\n placeholder={\n productsQuery.isPending || pricesQuery.isPending\n ? \"Loading plans…\"\n : \"Choose a plan\"\n }\n />\n </SelectTrigger>\n <SelectContent>\n {options.map((option) => (\n <SelectItem key={option.price.id} value={option.price.id}>\n {subscriptionChangeOptionLabel(option)}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n {!productsQuery.isPending &&\n !pricesQuery.isPending &&\n !productsQuery.isError &&\n !pricesQuery.isError &&\n options.length === 0 && (\n <p className=\"text-xs text-muted-foreground\">\n <AdminMessage\n id={\n \"No eligible recurring plans share this tier group and currency.\"\n }\n />\n </p>\n )}\n {(productsQuery.isError || pricesQuery.isError) && (\n <p className=\"text-xs text-destructive\" role=\"alert\">\n <AdminMessage id={\"Could not load the available plans.\"} />\n </p>\n )}\n </div>\n\n {bounds && (\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"subscription-seats\")}>\n <AdminMessage id={\"Seats\"} />\n </Label>\n <Input\n id={adminId(\"subscription-seats\")}\n type=\"number\"\n inputMode=\"numeric\"\n min={bounds.min}\n max={bounds.max}\n value={seats}\n onChange={(event) => handleSeats(event.target.value)}\n />\n <p className=\"text-xs text-muted-foreground\">\n {bounds.min}\n <AdminMessage id={\" to \"} />\n {bounds.max}\n <AdminMessage id={\" seats.\"} />\n </p>\n </div>\n )}\n\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"subscription-change-reason\")}>\n <AdminMessage id={\"Reason\"} />\n </Label>\n <Input\n id={adminId(\"subscription-change-reason\")}\n value={reason}\n maxLength={500}\n placeholder={adminText(\"What the customer asked for\")}\n onChange={(event) => setReason(event.target.value)}\n />\n <p className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Kept with the scheduled change.\"} />\n </p>\n </div>\n\n {reviewed && selected && (\n <div className=\"grid gap-3\" aria-live=\"polite\">\n <div className=\"flex items-center justify-between gap-4\">\n <span className=\"text-sm font-medium\">\n <AdminMessage id={\"Review\"} />\n </span>\n <Badge variant=\"secondary\">\n {reviewed.effective === \"now\" ? \"Immediate\" : \"At renewal\"}\n </Badge>\n </div>\n <dl className=\"grid grid-cols-2 gap-x-8 gap-y-3 border-y py-4 text-sm\">\n {reviewed.quantity !== null && (\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Seats\"} />\n </dt>\n <dd className=\"font-medium tabular-nums\">\n {reviewed.quantity}\n </dd>\n </div>\n )}\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Due now\"} />\n </dt>\n <dd className=\"font-medium tabular-nums\">\n {formatNativeAmount(\n reviewed.amount_due_now,\n reviewed.currency\n )}\n </dd>\n </div>\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Next charge\"} />\n </dt>\n <dd className=\"font-medium tabular-nums\">\n {formatNativeAmount(\n reviewed.next_charge_amount,\n reviewed.currency\n )}\n </dd>\n </div>\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Effective\"} />\n </dt>\n <dd className=\"font-medium\">\n {reviewed.effective === \"now\"\n ? \"Immediately\"\n : formatDate(reviewed.next_charge_date)}\n </dd>\n </div>\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Next billing date\"} />\n </dt>\n <dd className=\"font-medium tabular-nums\">\n {formatDate(reviewed.next_charge_date)}\n </dd>\n </div>\n </dl>\n {reviewed.is_estimate && (\n <p className=\"text-xs text-muted-foreground\">\n <AdminMessage\n id={\n \"The payment provider calculates the final prorated amount.\"\n }\n />\n </p>\n )}\n </div>\n )}\n\n {(previewError || changeError) && (\n <p className=\"text-sm text-destructive\" role=\"alert\">\n {changeError || previewError}\n </p>\n )}\n\n {change.data && change.data.status !== \"succeeded\" && (\n <div\n className=\"grid gap-2 rounded-lg bg-muted px-3 py-2.5 text-sm\"\n aria-live=\"polite\"\n >\n <p>{responseMessage ?? \"This change needs another step.\"}</p>\n {responseURL && (\n <a\n href={responseURL}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"w-fit font-medium text-primary underline underline-offset-4\"\n >\n <AdminMessage id={\"Continue with payment provider\"} />\n </a>\n )}\n </div>\n )}\n </div>\n\n <DialogFooter>\n <Button\n type=\"button\"\n variant=\"outline\"\n onClick={() => handleOpenChange(false)}\n >\n <AdminMessage id={\"Cancel\"} />\n </Button>\n {!reviewed ? (\n <Button\n type=\"button\"\n disabled={!request || unchanged || preview.isPending}\n onClick={async () => {\n if (!request) return\n const currentView = view.current\n try {\n await preview.mutateAsync(request)\n if (view.current !== currentView) return\n setReviewedKey(requestKey)\n } catch (error) {\n if (view.current === currentView) {\n toastApiError(error, \"Preview subscription change\")\n }\n }\n }}\n >\n {preview.isPending ? \"Reviewing…\" : \"Review change\"}\n </Button>\n ) : (\n <Button\n type=\"button\"\n disabled={\n change.isPending ||\n !reason.trim() ||\n (Boolean(change.data) && change.data?.status !== \"processing\")\n }\n onClick={async () => {\n if (!request) return\n const currentView = view.current\n const changeKey =\n attempts.current.get(requestKey) ?? crypto.randomUUID()\n attempts.current.set(requestKey, changeKey)\n const completeAttempt = () => {\n if (attempts.current.get(requestKey) === changeKey) {\n attempts.current.delete(requestKey)\n }\n }\n try {\n const result = await change.mutateAsync({\n change: { ...request, reason: reason.trim() },\n idempotencyKey: changeKey,\n })\n if (\n result.status === \"succeeded\" ||\n result.status === \"blocked\"\n ) {\n completeAttempt()\n }\n if (view.current !== currentView) return\n if (result.status === \"succeeded\") {\n toast.success(\n result.effective === \"now\"\n ? \"Subscription changed\"\n : \"Change scheduled for the next renewal\"\n )\n handleOpenChange(false)\n setSelectedPriceId(\"\")\n setSeats(\"\")\n setReason(\"\")\n setReviewedKey(\"\")\n preview.reset()\n change.reset()\n }\n if (result.status === \"processing\") {\n toast.info(\n \"The provider is still confirming this change. Check again to read the result.\"\n )\n }\n } catch (error) {\n // 402 is a final provider refusal regardless of its code.\n // Other refusals can reject a readback of an already accepted\n // operation, so retire only explicitly terminal outcomes.\n if (\n error instanceof ApiError &&\n (error.status === 402 ||\n (error.status === 409 &&\n (error.code === \"subscription_change_refused\" ||\n error.code ===\n \"subscription_change_idempotency_conflict\")))\n ) {\n completeAttempt()\n }\n if (view.current === currentView) {\n toastApiError(error, \"Change subscription\")\n }\n }\n }}\n >\n {change.isPending\n ? \"Applying…\"\n : change.data\n ? change.data.status === \"processing\"\n ? \"Check result\"\n : change.data.status === \"blocked\"\n ? \"Change blocked\"\n : \"Action required\"\n : \"Confirm change\"}\n </Button>\n )}\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n","import { AdminMessage, useAdminUI } from \"#orck/admin/ui-context\"\nimport { useAdminServices } from \"#orck/admin/context\"\nimport { HugeiconsIcon } from \"@hugeicons/react\"\nimport { ArrowLeft01Icon } from \"@hugeicons/core-free-icons\"\nimport * as React from \"react\"\nimport { Link, useNavigate, useParams } from \"#orck/admin/router\"\n\nimport { useForm } from \"@tanstack/react-form\"\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\"\n\nimport { Fact } from \"#orck/admin/components/fact-card\"\nimport { FormFieldErrors } from \"#orck/admin/components/form-field-errors\"\nimport { StatusBadge } from \"#orck/admin/components/status-badge\"\nimport { TypedConfirmDialog } from \"#orck/admin/components/typed-confirm-dialog\"\nimport { Badge } from \"#orck/admin/components/ui/badge\"\nimport { Button } from \"#orck/admin/components/ui/button\"\nimport {\n Card,\n CardContent,\n CardHeader,\n CardTitle,\n} from \"#orck/admin/components/ui/card\"\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n DialogTrigger,\n} from \"#orck/admin/components/ui/dialog\"\nimport { Input } from \"#orck/admin/components/ui/input\"\nimport { Label } from \"#orck/admin/components/ui/label\"\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"#orck/admin/components/ui/select\"\nimport { Switch } from \"#orck/admin/components/ui/switch\"\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n} from \"#orck/admin/components/ui/table\"\nimport type { ScheduledChange } from \"#orck/admin/lib/api/types\"\nimport { DIALOG_FORM } from \"#orck/admin/lib/dialog-width\"\nimport {\n formatCard,\n formatDate,\n formatNativeAmount,\n shortId,\n} from \"#orck/admin/lib/format\"\n\nimport { ChangeSubscriptionDialog } from \"#orck/admin/pages/subscriptions/change-subscription-dialog\"\nimport { dunningSummary } from \"#orck/admin/pages/subscriptions/dunning\"\nimport { useAdminUpdates } from \"#orck/admin/lib/capabilities\"\n\nexport function SubscriptionDetailPage() {\n const { text: adminText } = useAdminUI()\n\n const { adminQueries } = useAdminServices()\n\n const canUpdate = useAdminUpdates()\n const { id = \"\" } = useParams()\n const navigate = useNavigate()\n const { data: sub, isPending: loading } = useQuery(\n adminQueries.subscription(id)\n )\n const { data: paymentPage } = useQuery(\n adminQueries.payments({ subscription_id: id }, 20)\n )\n const payments = paymentPage?.data ?? []\n if (loading)\n return (\n <p className=\"text-sm text-muted-foreground\">\n <AdminMessage id={\"Loading…\"} />\n </p>\n )\n if (!sub)\n return (\n <p className=\"text-sm text-muted-foreground\">\n <AdminMessage id={\"Subscription not found.\"} />\n </p>\n )\n\n const cancellable =\n sub.status === \"active\" ||\n sub.status === \"past_due\" ||\n sub.status === \"awaiting_method\" ||\n sub.status === \"unverified\"\n const resumable = sub.status === \"canceled\" || sub.status === \"past_due\"\n\n return (\n <div className=\"flex flex-col gap-4\">\n <div className=\"flex items-center gap-3\">\n <Button\n variant=\"ghost\"\n size=\"icon\"\n onClick={() => navigate(-1)}\n aria-label={adminText(\"Back\")}\n >\n <HugeiconsIcon icon={ArrowLeft01Icon} className=\"size-4\" />\n </Button>\n <div>\n <h2 className=\"flex items-center gap-2 text-sm\">\n {sub.id} <StatusBadge status={sub.status} />\n </h2>\n <p className=\"text-xs text-muted-foreground\">\n {sub.rail} · {sub.rail_subscription_id || \"no rail id\"}\n </p>\n </div>\n <div className=\"ml-auto flex gap-2\">\n {canUpdate && resumable && (\n <ResumeButton id={sub.id} customerId={sub.customer_id} />\n )}\n {canUpdate && (\n <ChangeSubscriptionDialog\n subscriptionId={sub.id}\n customerId={sub.customer_id}\n productId={sub.product_id}\n priceId={sub.price_id}\n quantity={sub.quantity}\n currency={sub.price?.currency}\n collectionPolicy={sub.collection_policy}\n scheduledChange={sub.scheduled_change}\n rail={sub.rail}\n status={sub.status}\n />\n )}\n {canUpdate && (\n <ChangePaymentMethodDialog\n subscriptionId={sub.id}\n customerId={sub.customer_id}\n rail={sub.rail}\n collectionPolicy={sub.collection_policy}\n />\n )}\n {canUpdate && cancellable && (\n <CancelDialog id={sub.id} customerId={sub.customer_id} />\n )}\n </div>\n </div>\n\n <div className=\"grid gap-3 sm:grid-cols-2 lg:grid-cols-4\">\n <Fact label={adminText(\"Customer\")}>\n {sub.customer_id ? (\n <Link\n className=\"text-xs underline-offset-2 hover:underline\"\n to={`/customers/${sub.customer_id}`}\n >\n {shortId(sub.customer_id, 13)}\n </Link>\n ) : (\n \"—\"\n )}\n </Fact>\n <Fact label={adminText(\"Started\")}>{formatDate(sub.started_at)}</Fact>\n <Fact label={adminText(\"Current period\")}>\n {formatDate(sub.current_period_starts_at)} →{\" \"}\n {formatDate(sub.current_period_ends_at)}\n </Fact>\n <Fact label={adminText(\"Price\")}>\n <div className=\"flex flex-col gap-1\">\n <span className=\"flex items-center gap-2\">\n {sub.price?.unit_amount !== undefined && sub.price?.currency ? (\n <Link\n className=\"underline-offset-2 hover:underline\"\n to={`/catalog/prices/${encodeURIComponent(sub.price_id)}`}\n >\n {formatNativeAmount(\n sub.price.unit_amount,\n sub.price.currency\n )}\n </Link>\n ) : (\n <Link\n className=\"text-xs underline-offset-2 hover:underline\"\n to={`/catalog/prices/${encodeURIComponent(sub.price_id)}`}\n >\n {shortId(sub.price_id ?? \"—\", 13)}\n </Link>\n )}\n {sub.price?.archived && (\n <Badge\n variant=\"secondary\"\n title={adminText(\"Pinned to an archived (prior) version\")}\n >\n <AdminMessage id={\"prior version\"} />\n </Badge>\n )}\n </span>\n {sub.price?.key && (\n <span className=\"text-xs text-muted-foreground\">\n {sub.price.key}\n </span>\n )}\n {sub.scheduled_change && (\n <ScheduledChangeBadge change={sub.scheduled_change} />\n )}\n </div>\n </Fact>\n {sub.quantity !== null && (\n <Fact label={adminText(\"Seats\")}>\n {sub.quantity}\n {sub.scheduled_change?.quantity != null &&\n ` → ${sub.scheduled_change.quantity} at renewal`}\n </Fact>\n )}\n <Fact label={adminText(\"Dunning\")}>\n {sub.dunning ? dunningSummary(sub.dunning) : \"—\"}\n </Fact>\n <Fact\n label={\n sub.dunning?.waiting_for_new_card ? \"Card deadline\" : \"Final retry\"\n }\n >\n {formatDate(sub.dunning?.final_retry_at)}\n </Fact>\n <Fact label={adminText(\"Last decline\")}>\n {sub.dunning?.last_failure_reason ?? \"—\"}\n </Fact>\n <Fact label={adminText(\"Canceled\")}>\n {sub.canceled_at\n ? `${formatDate(sub.canceled_at)} (${sub.cancel_type ?? \"?\"})`\n : \"—\"}\n </Fact>\n </div>\n\n <Card>\n <CardHeader>\n <CardTitle className=\"text-sm\">\n <AdminMessage id={\"Payments\"} />\n </CardTitle>\n </CardHeader>\n <CardContent>\n {!payments.length ? (\n <p className=\"text-sm text-muted-foreground\">\n <AdminMessage id={\"No payments recorded.\"} />\n </p>\n ) : (\n <Table>\n <TableHeader>\n <TableRow className=\"hover:bg-transparent\">\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Payment\"} />\n </TableHead>\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Status\"} />\n </TableHead>\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Kind\"} />\n </TableHead>\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Amount\"} />\n </TableHead>\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Created\"} />\n </TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {payments.map((p) => (\n <TableRow key={p.id}>\n <TableCell>\n <Link\n className=\"text-xs underline-offset-2 hover:underline\"\n to={`/payments/${p.id}`}\n >\n {shortId(p.id, 13)}\n </Link>\n </TableCell>\n <TableCell>\n <StatusBadge status={p.status} />\n </TableCell>\n <TableCell>{p.kind}</TableCell>\n <TableCell>\n {formatNativeAmount(p.amount, p.currency)}\n </TableCell>\n <TableCell>{formatDate(p.created_at)}</TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n )}\n </CardContent>\n </Card>\n </div>\n )\n}\n\nfunction CancelDialog({ id, customerId }: { id: string; customerId?: string }) {\n const { toast, toastApiError, adminMutations } = useAdminServices()\n\n const { text: adminText, id: adminId } = useAdminUI()\n\n const [open, setOpen] = React.useState(false)\n const queryClient = useQueryClient()\n const cancel = useMutation(\n adminMutations.cancelSubscription(queryClient, id, customerId)\n )\n const form = useForm({\n defaultValues: { reason: \"\", revokeAccess: false },\n })\n\n const handleOpenChange = (next: boolean) => {\n setOpen(next)\n if (!next) {\n form.reset()\n cancel.reset()\n }\n }\n\n return (\n <>\n <Button variant=\"destructive\" size=\"sm\" onClick={() => setOpen(true)}>\n <AdminMessage id={\"Cancel subscription\"} />\n </Button>\n <TypedConfirmDialog\n open={open}\n onOpenChange={handleOpenChange}\n title={adminText(\"Cancel subscription\")}\n description={adminText(\n \"Terminal cancellation at the payment rail. This is a last resort. Dunning parks subscriptions as past_due without losing entitlements.\"\n )}\n confirmationWord=\"CANCEL\"\n actionLabel=\"Cancel subscription\"\n onConfirm={async () => {\n try {\n await cancel.mutateAsync(form.state.values)\n toast.success(\"Subscription canceled\")\n } catch (err) {\n toastApiError(err, \"Cancel subscription\")\n throw err\n }\n }}\n >\n <div className=\"grid gap-3\">\n <form.Field name=\"reason\">\n {(field) => (\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"cancel-reason\")}>\n <AdminMessage id={\"Reason\"} />\n </Label>\n <Input\n id={adminId(\"cancel-reason\")}\n value={field.state.value}\n onBlur={field.handleBlur}\n onChange={(event) => field.handleChange(event.target.value)}\n placeholder={adminText(\"why is this being canceled?\")}\n />\n </div>\n )}\n </form.Field>\n <form.Field name=\"revokeAccess\">\n {(field) => (\n <div className=\"flex items-center gap-2\">\n <Switch\n id={adminId(\"cancel-revoke\")}\n checked={field.state.value}\n onCheckedChange={field.handleChange}\n />\n <Label htmlFor={adminId(\"cancel-revoke\")}>\n <AdminMessage id={\"Also revoke access immediately\"} />\n </Label>\n </div>\n )}\n </form.Field>\n </div>\n </TypedConfirmDialog>\n </>\n )\n}\n\nfunction ResumeButton({ id, customerId }: { id: string; customerId?: string }) {\n const { toast, toastApiError, adminMutations } = useAdminServices()\n\n const queryClient = useQueryClient()\n const resume = useMutation(\n adminMutations.resumeSubscription(queryClient, id, customerId)\n )\n return (\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={resume.isPending}\n onClick={async () => {\n try {\n await resume.mutateAsync()\n toast.success(\"Resume queued\")\n } catch (err) {\n toastApiError(err, \"Resume subscription\")\n }\n }}\n >\n {resume.isPending ? \"Queuing…\" : \"Resume\"}\n </Button>\n )\n}\n\n// The choice that makes the subscription follow the customer's default card.\nconst FOLLOW_DEFAULT = \"default\"\n\nfunction ChangePaymentMethodDialog({\n subscriptionId,\n customerId,\n rail,\n collectionPolicy,\n}: {\n subscriptionId: string\n customerId?: string\n rail: string\n collectionPolicy?: string\n}) {\n const { toast, toastApiError, adminMutations, adminQueries } =\n useAdminServices()\n\n const { id: adminId, text: adminText } = useAdminUI()\n\n const [open, setOpen] = React.useState(false)\n const queryClient = useQueryClient()\n const changePaymentMethod = useMutation(\n adminMutations.changeSubscriptionPaymentMethod(\n queryClient,\n subscriptionId,\n customerId\n )\n )\n const { data: pms } = useQuery(\n adminQueries.customerPaymentMethods(open ? customerId : undefined)\n )\n const form = useForm({\n defaultValues: { paymentMethodId: \"\" },\n onSubmit: async ({ value }) => {\n try {\n await changePaymentMethod.mutateAsync(\n value.paymentMethodId === FOLLOW_DEFAULT\n ? null\n : value.paymentMethodId\n )\n toast.success(\"Payment method updated\")\n handleOpenChange(false)\n } catch (err) {\n toastApiError(err, \"Change payment method\")\n }\n },\n })\n\n const handleOpenChange = (next: boolean) => {\n setOpen(next)\n if (!next) {\n form.reset()\n changePaymentMethod.reset()\n }\n }\n\n // A card subscription OpenRails collects, or an NMI schedule; a provider\n // that keeps the card (Stripe-owned, CCBill) or a wallet has none to change.\n const supported =\n rail !== \"solana\" &&\n (collectionPolicy === \"engine\" || collectionPolicy === \"nmi_schedule\")\n return (\n <Dialog open={open} onOpenChange={handleOpenChange}>\n <DialogTrigger\n render={\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={!supported}\n title={\n supported\n ? undefined\n : `Payment-method change is not supported on ${rail}`\n }\n >\n <AdminMessage id={\"Change payment method\"} />\n </Button>\n }\n />\n <DialogContent className={DIALOG_FORM}>\n <DialogHeader>\n <DialogTitle>\n <AdminMessage id={\"Change payment method\"} />\n </DialogTitle>\n <DialogDescription>\n <AdminMessage\n id={\n \"Points future renewals of this subscription at another of the customer's stored cards (same rail), or back at their default card for its currency.\"\n }\n />\n </DialogDescription>\n </DialogHeader>\n <form\n onSubmit={(event) => {\n event.preventDefault()\n event.stopPropagation()\n void form.handleSubmit()\n }}\n className=\"grid gap-4\"\n >\n <form.Field\n name=\"paymentMethodId\"\n validators={{\n onChange: ({ value }) =>\n value ? undefined : \"Pick a stored payment method\",\n }}\n >\n {(field) => (\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"subscription-payment-method\")}>\n <AdminMessage id={\"Payment method\"} />\n </Label>\n <Select\n value={field.state.value}\n onValueChange={(value) => field.handleChange(value ?? \"\")}\n >\n <SelectTrigger\n className=\"w-full\"\n id={adminId(\"subscription-payment-method\")}\n aria-invalid={field.state.meta.errors.length > 0}\n >\n <SelectValue\n placeholder={adminText(\"Pick a stored payment method\")}\n />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value={FOLLOW_DEFAULT}>\n <AdminMessage id={\"The customer's default card\"} />\n </SelectItem>\n {(pms ?? [])\n .filter((pm) => pm.rail === rail)\n .map((pm) => (\n <SelectItem key={pm.id} value={pm.id}>\n {formatCard(pm.card)} ({pm.rail})\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n <FormFieldErrors errors={field.state.meta.errors} />\n </div>\n )}\n </form.Field>\n <DialogFooter>\n <form.Subscribe\n selector={(state) =>\n [\n state.values.paymentMethodId,\n state.canSubmit,\n state.isSubmitting,\n ] as const\n }\n >\n {([paymentMethodId, canSubmit, isSubmitting]) => (\n <Button\n type=\"submit\"\n disabled={!paymentMethodId || !canSubmit || isSubmitting}\n >\n {isSubmitting ? \"Updating…\" : \"Update\"}\n </Button>\n )}\n </form.Subscribe>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n )\n}\n\n// ScheduledChangeBadge shows the change waiting for the next renewal: a price\n// migration's move or a scheduled downgrade. A change back to the current\n// price clears it.\nfunction ScheduledChangeBadge({ change }: { change: ScheduledChange }) {\n const { adminQueries } = useAdminServices()\n\n const { data: toPrice } = useQuery(adminQueries.price(change.price_id))\n return (\n <Badge className=\"bg-held-surface text-held\">\n {change.source === \"migration\" ? \"migrates\" : \"changes\"}\n <AdminMessage id={\" to\"} />{\" \"}\n {toPrice\n ? formatNativeAmount(toPrice.unit_amount, toPrice.currency)\n : shortId(change.price_id, 9)}{\" \"}\n <AdminMessage id={\"at the first renewal from \"} />\n {formatDate(change.effective_at)}\n </Badge>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,SAAgB,GACd,GACQ;CACR,IAAM,IAAQ,EAAO,OACf,IAAS,GAAG,EAAmB,EAAM,aAAa,EAAM,QAAQ,IAAI,EAAM,WAAW,cAAc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ACG,EAAmB,EAAQ,aAAa,EAAQ,QAAQ,IACxD,EAAQ,EAAO,UAAU,CAAC;GAAG;GACjC,kBAAC,GAAD,EAAc,IAAI,6BAA+B,CAAA;GAChD,EAAW,EAAO,YAAY;EAC1B;;AAEX"}
|
|
1
|
+
{"version":3,"file":"admin-detail-qetSqVDt.js","names":[],"sources":["../src/admin/pages/subscriptions/subscription-change-options.ts","../src/admin/pages/subscriptions/change-subscription-dialog.tsx","../src/admin/pages/subscriptions/detail.tsx"],"sourcesContent":["import type { Rail, SubscriptionStatus } from \"#orck/admin/lib/api/types\"\nimport type {\n Price,\n Product,\n ScheduledChange,\n} from \"#orck/client/generated/wire\"\nimport { formatNativeAmount } from \"#orck/admin/lib/format\"\nimport { priceIntervalLabel } from \"#orck/admin/pages/catalog/price-format\"\n\nexport interface SubscriptionChangeOption {\n direction: \"current\" | \"upgrade\" | \"downgrade\"\n price: Price\n product: Product\n}\n\nexport function subscriptionChangeOptionLabel(\n option: SubscriptionChangeOption\n): string {\n const price = option.price\n const amount = `${formatNativeAmount(price.unit_amount, price.currency)}${price.quantity ? \" per seat\" : \"\"}`\n return [\n option.product.display_name,\n option.direction,\n `${amount} ${priceIntervalLabel(price)}`,\n price.key,\n ].join(\" · \")\n}\n\n// The seats a change starts from: the subscription's when the price allows\n// them, otherwise the price's minimum.\nexport function initialSeats(\n price: Price,\n current: number | null\n): number | null {\n const bounds = price.quantity\n if (!bounds) return null\n if (current !== null && current >= bounds.min && current <= bounds.max) {\n return current\n }\n return bounds.min\n}\n\nexport function adminSubscriptionChangeBlockReason({\n rail,\n status,\n collectionPolicy,\n scheduledChange,\n}: {\n rail: Rail\n status: SubscriptionStatus\n collectionPolicy?: string\n scheduledChange?: Pick<ScheduledChange, \"source\"> | null\n}): string | undefined {\n if (status !== \"active\" && status !== \"past_due\") {\n return \"Only active or past-due subscriptions can change\"\n }\n // OpenRails changes back only the scheduled change it bills itself.\n if (scheduledChange && collectionPolicy !== \"engine\") {\n return \"Its provider already bills a scheduled change\"\n }\n if (rail === \"ccbill\") return \"CCBill changes require customer self-service\"\n if (rail === \"solana\") {\n return \"Solana changes require the customer's wallet signature\"\n }\n return undefined\n}\n\n// The changes the console offers: the current price, for its seats or to\n// change back from a scheduled change, then, unless a price migration is\n// pending, live recurring prices of the tier group in the same currency.\nexport function subscriptionChangeOptions({\n currentProduct,\n currentPrice,\n currentCurrency,\n products,\n prices,\n scheduledChange,\n}: {\n currentProduct?: Product\n currentPrice?: Price\n currentCurrency?: string\n products: Product[]\n prices: Price[]\n scheduledChange?: Pick<ScheduledChange, \"source\"> | null\n}): SubscriptionChangeOption[] {\n const current: SubscriptionChangeOption[] =\n currentProduct && currentPrice && (currentPrice.quantity || scheduledChange)\n ? [{ direction: \"current\", price: currentPrice, product: currentProduct }]\n : []\n const tierGroup = currentProduct?.tier_group?.trim()\n const currency = currentCurrency?.trim().toLowerCase()\n if (\n !currentProduct ||\n !tierGroup ||\n !currency ||\n scheduledChange?.source === \"migration\"\n ) {\n return current\n }\n\n const productsByID = new Map(\n products\n .filter(\n (product) =>\n !product.archived &&\n product.id !== currentProduct.id &&\n product.tier_group?.trim() === tierGroup\n )\n .map((product) => [product.id, product])\n )\n\n return current.concat(\n prices\n .flatMap((price): SubscriptionChangeOption[] => {\n const product = productsByID.get(price.product_id)\n if (\n !product ||\n price.archived ||\n !price.billing_interval_hours ||\n price.currency.trim().toLowerCase() !== currency\n ) {\n return []\n }\n return [\n {\n direction:\n product.tier_rank < currentProduct.tier_rank\n ? \"downgrade\"\n : \"upgrade\",\n price,\n product,\n },\n ]\n })\n .sort(\n (left, right) =>\n left.product.tier_rank - right.product.tier_rank ||\n left.product.display_name.localeCompare(right.product.display_name) ||\n left.price.id.localeCompare(right.price.id)\n )\n )\n}\n","import { AdminMessage, useAdminUI } from \"#orck/admin/ui-context\"\nimport { useAdminServices } from \"#orck/admin/context\"\nimport * as React from \"react\"\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\"\n\nimport { Badge } from \"#orck/admin/components/ui/badge\"\nimport { Button } from \"#orck/admin/components/ui/button\"\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n DialogTrigger,\n} from \"#orck/admin/components/ui/dialog\"\nimport { Input } from \"#orck/admin/components/ui/input\"\nimport { Label } from \"#orck/admin/components/ui/label\"\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"#orck/admin/components/ui/select\"\nimport type {\n ChangeSubscriptionParams,\n Rail,\n ScheduledChange,\n SubscriptionStatus,\n} from \"#orck/admin/lib/api/types\"\nimport { ApiError } from \"#orck/admin/lib/api/client\"\nimport { DIALOG_WIDE } from \"#orck/admin/lib/dialog-width\"\nimport { formatDate, formatNativeAmount } from \"#orck/admin/lib/format\"\n\nimport {\n adminSubscriptionChangeBlockReason,\n initialSeats,\n subscriptionChangeOptionLabel,\n subscriptionChangeOptions,\n} from \"#orck/admin/pages/subscriptions/subscription-change-options\"\n\ninterface ChangeSubscriptionDialogProps {\n subscriptionId: string\n customerId?: string\n productId: string\n priceId: string\n quantity: number | null\n currency?: string\n collectionPolicy?: string\n scheduledChange?: ScheduledChange | null\n rail: Rail\n status: SubscriptionStatus\n}\n\nexport function ChangeSubscriptionDialog(props: ChangeSubscriptionDialogProps) {\n const { selectedMerchant } = useAdminServices()\n\n return (\n <ChangeSubscriptionForm\n key={`${selectedMerchant() ?? \"\"}:${props.subscriptionId}`}\n {...props}\n />\n )\n}\n\nfunction ChangeSubscriptionForm({\n subscriptionId,\n customerId,\n productId,\n priceId,\n quantity,\n currency,\n collectionPolicy,\n scheduledChange,\n rail,\n status,\n}: ChangeSubscriptionDialogProps) {\n const { toast, toastApiError, adminMutations, adminQueries } =\n useAdminServices()\n\n const { id: adminId, text: adminText } = useAdminUI()\n\n const [open, setOpen] = React.useState(false)\n const [selectedPriceId, setSelectedPriceId] = React.useState(\"\")\n const [seats, setSeats] = React.useState(\"\")\n const [reason, setReason] = React.useState(\"\")\n const [reviewedKey, setReviewedKey] = React.useState(\"\")\n // A dismissed dialog or another preview cannot establish non-execution.\n // Retain each submitted request's key until its outcome is definitive.\n const attempts = React.useRef(new Map<string, string>())\n const view = React.useRef(0)\n React.useEffect(\n () => () => {\n view.current++\n },\n []\n )\n const queryClient = useQueryClient()\n const preview = useMutation(\n adminMutations.previewSubscriptionChange(subscriptionId)\n )\n const change = useMutation(\n adminMutations.changeSubscription(queryClient, subscriptionId, customerId)\n )\n const productsQuery = useQuery({\n ...adminQueries.allProducts({ errorAction: \"Load subscription plans\" }),\n enabled: open,\n })\n const pricesQuery = useQuery({\n ...adminQueries.allPrices({ errorAction: \"Load subscription prices\" }),\n enabled: open,\n })\n\n const products = productsQuery.data?.data ?? []\n const prices = pricesQuery.data?.data ?? []\n const currentProduct = products.find((product) => product.id === productId)\n const currentPrice = prices.find((price) => price.id === priceId)\n const options = subscriptionChangeOptions({\n currentProduct,\n currentPrice,\n currentCurrency: currency ?? currentPrice?.currency,\n products,\n prices,\n scheduledChange,\n })\n const selected = options.find((option) => option.price.id === selectedPriceId)\n const bounds = selected?.price.quantity\n const seatCount = Number(seats)\n const seatsValid =\n !bounds ||\n (Number.isInteger(seatCount) &&\n seatCount >= bounds.min &&\n seatCount <= bounds.max)\n // The current price with its seats changes back from a scheduled change.\n const request: ChangeSubscriptionParams | undefined =\n selected && seatsValid\n ? {\n price_id: selected.price.id,\n ...(bounds ? { quantity: seatCount } : {}),\n }\n : undefined\n const unchanged =\n selected?.direction === \"current\" &&\n !scheduledChange &&\n (!bounds || seatCount === quantity)\n const requestKey = request ? JSON.stringify(request) : \"\"\n const reviewed =\n requestKey && reviewedKey === requestKey ? preview.data : undefined\n const blockReason = adminSubscriptionChangeBlockReason({\n rail,\n status,\n collectionPolicy,\n scheduledChange,\n })\n\n const handleOpenChange = (next: boolean) => {\n view.current++\n setOpen(next)\n }\n\n const handleSelect = (value: string | null) => {\n view.current++\n const price = options.find((option) => option.price.id === value)?.price\n setSelectedPriceId(value ?? \"\")\n setSeats(String(price ? (initialSeats(price, quantity) ?? \"\") : \"\"))\n setReviewedKey(\"\")\n preview.reset()\n change.reset()\n }\n\n const handleSeats = (value: string) => {\n view.current++\n setSeats(value)\n setReviewedKey(\"\")\n preview.reset()\n change.reset()\n }\n\n const previewError =\n preview.error instanceof Error ? preview.error.message : \"\"\n const changeError = change.error instanceof Error ? change.error.message : \"\"\n const responseMessage = change.data?.message\n const responseURL = change.data?.next_action?.url ?? undefined\n\n return (\n <Dialog open={open} onOpenChange={handleOpenChange}>\n <DialogTrigger\n render={\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={Boolean(blockReason) && !change.variables}\n title={blockReason}\n >\n <AdminMessage id={\"Change subscription\"} />\n </Button>\n }\n />\n <DialogContent className={DIALOG_WIDE}>\n <DialogHeader>\n <DialogTitle>\n <AdminMessage id={\"Change subscription\"} />\n </DialogTitle>\n <DialogDescription>\n <AdminMessage\n id={\"Schedule the customer's plan or seats for the next renewal. No card is charged now. Choosing the current plan and seats clears a pending change. The customer is told.\"}\n />\n </DialogDescription>\n </DialogHeader>\n\n <div className=\"grid gap-5\">\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"subscription-tier\")}>\n <AdminMessage id={\"New plan\"} />\n </Label>\n <Select value={selectedPriceId} onValueChange={handleSelect}>\n <SelectTrigger\n id={adminId(\"subscription-tier\")}\n className=\"w-full\"\n disabled={productsQuery.isPending || pricesQuery.isPending}\n >\n <SelectValue\n placeholder={\n productsQuery.isPending || pricesQuery.isPending\n ? \"Loading plans…\"\n : \"Choose a plan\"\n }\n />\n </SelectTrigger>\n <SelectContent>\n {options.map((option) => (\n <SelectItem key={option.price.id} value={option.price.id}>\n {subscriptionChangeOptionLabel(option)}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n {!productsQuery.isPending &&\n !pricesQuery.isPending &&\n !productsQuery.isError &&\n !pricesQuery.isError &&\n options.length === 0 && (\n <p className=\"text-xs text-muted-foreground\">\n <AdminMessage\n id={\n \"No eligible recurring plans share this tier group and currency.\"\n }\n />\n </p>\n )}\n {(productsQuery.isError || pricesQuery.isError) && (\n <p className=\"text-xs text-destructive\" role=\"alert\">\n <AdminMessage id={\"Could not load the available plans.\"} />\n </p>\n )}\n </div>\n\n {bounds && (\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"subscription-seats\")}>\n <AdminMessage id={\"Seats\"} />\n </Label>\n <Input\n id={adminId(\"subscription-seats\")}\n type=\"number\"\n inputMode=\"numeric\"\n min={bounds.min}\n max={bounds.max}\n value={seats}\n onChange={(event) => handleSeats(event.target.value)}\n />\n <p className=\"text-xs text-muted-foreground\">\n {bounds.min}\n <AdminMessage id={\" to \"} />\n {bounds.max}\n <AdminMessage id={\" seats.\"} />\n </p>\n </div>\n )}\n\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"subscription-change-reason\")}>\n <AdminMessage id={\"Reason\"} />\n </Label>\n <Input\n id={adminId(\"subscription-change-reason\")}\n value={reason}\n maxLength={500}\n placeholder={adminText(\"What the customer asked for\")}\n onChange={(event) => setReason(event.target.value)}\n />\n <p className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Kept with the scheduled change.\"} />\n </p>\n </div>\n\n {reviewed && selected && (\n <div className=\"grid gap-3\" aria-live=\"polite\">\n <div className=\"flex items-center justify-between gap-4\">\n <span className=\"text-sm font-medium\">\n <AdminMessage id={\"Review\"} />\n </span>\n <Badge variant=\"secondary\">\n {reviewed.effective === \"now\" ? \"Immediate\" : \"At renewal\"}\n </Badge>\n </div>\n <dl className=\"grid grid-cols-2 gap-x-8 gap-y-3 border-y py-4 text-sm\">\n {reviewed.quantity !== null && (\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Seats\"} />\n </dt>\n <dd className=\"font-medium tabular-nums\">\n {reviewed.quantity}\n </dd>\n </div>\n )}\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Due now\"} />\n </dt>\n <dd className=\"font-medium tabular-nums\">\n {formatNativeAmount(\n reviewed.amount_due_now,\n reviewed.currency\n )}\n </dd>\n </div>\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Next charge\"} />\n </dt>\n <dd className=\"font-medium tabular-nums\">\n {formatNativeAmount(\n reviewed.next_charge_amount,\n reviewed.currency\n )}\n </dd>\n </div>\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Effective\"} />\n </dt>\n <dd className=\"font-medium\">\n {reviewed.effective === \"now\"\n ? \"Immediately\"\n : formatDate(reviewed.next_charge_date)}\n </dd>\n </div>\n <div className=\"grid gap-1\">\n <dt className=\"text-xs text-muted-foreground\">\n <AdminMessage id={\"Next billing date\"} />\n </dt>\n <dd className=\"font-medium tabular-nums\">\n {formatDate(reviewed.next_charge_date)}\n </dd>\n </div>\n </dl>\n {reviewed.is_estimate && (\n <p className=\"text-xs text-muted-foreground\">\n <AdminMessage\n id={\n \"The payment provider calculates the final prorated amount.\"\n }\n />\n </p>\n )}\n </div>\n )}\n\n {(previewError || changeError) && (\n <p className=\"text-sm text-destructive\" role=\"alert\">\n {changeError || previewError}\n </p>\n )}\n\n {change.data && change.data.status !== \"succeeded\" && (\n <div\n className=\"grid gap-2 rounded-lg bg-muted px-3 py-2.5 text-sm\"\n aria-live=\"polite\"\n >\n <p>{responseMessage ?? \"This change needs another step.\"}</p>\n {responseURL && (\n <a\n href={responseURL}\n target=\"_blank\"\n rel=\"noreferrer\"\n className=\"w-fit font-medium text-primary underline underline-offset-4\"\n >\n <AdminMessage id={\"Continue with payment provider\"} />\n </a>\n )}\n </div>\n )}\n </div>\n\n <DialogFooter>\n <Button\n type=\"button\"\n variant=\"outline\"\n onClick={() => handleOpenChange(false)}\n >\n <AdminMessage id={\"Cancel\"} />\n </Button>\n {!reviewed ? (\n <Button\n type=\"button\"\n disabled={!request || unchanged || preview.isPending}\n onClick={async () => {\n if (!request) return\n const currentView = view.current\n try {\n await preview.mutateAsync(request)\n if (view.current !== currentView) return\n setReviewedKey(requestKey)\n } catch (error) {\n if (view.current === currentView) {\n toastApiError(error, \"Preview subscription change\")\n }\n }\n }}\n >\n {preview.isPending ? \"Reviewing…\" : \"Review change\"}\n </Button>\n ) : (\n <Button\n type=\"button\"\n disabled={\n change.isPending ||\n !reason.trim() ||\n (Boolean(change.data) && change.data?.status !== \"processing\")\n }\n onClick={async () => {\n if (!request) return\n const currentView = view.current\n const changeKey =\n attempts.current.get(requestKey) ?? crypto.randomUUID()\n attempts.current.set(requestKey, changeKey)\n const completeAttempt = () => {\n if (attempts.current.get(requestKey) === changeKey) {\n attempts.current.delete(requestKey)\n }\n }\n try {\n const result = await change.mutateAsync({\n change: { ...request, reason: reason.trim() },\n idempotencyKey: changeKey,\n })\n if (\n result.status === \"succeeded\" ||\n result.status === \"blocked\"\n ) {\n completeAttempt()\n }\n if (view.current !== currentView) return\n if (result.status === \"succeeded\") {\n toast.success(\n result.effective === \"now\"\n ? \"Subscription changed\"\n : \"Change scheduled for the next renewal\"\n )\n handleOpenChange(false)\n setSelectedPriceId(\"\")\n setSeats(\"\")\n setReason(\"\")\n setReviewedKey(\"\")\n preview.reset()\n change.reset()\n }\n if (result.status === \"processing\") {\n toast.info(\n \"The provider is still confirming this change. Check again to read the result.\"\n )\n }\n } catch (error) {\n // 402 is a final provider refusal regardless of its code.\n // Other refusals can reject a readback of an already accepted\n // operation, so retire only explicitly terminal outcomes.\n if (\n error instanceof ApiError &&\n (error.status === 402 ||\n (error.status === 409 &&\n (error.code === \"subscription_change_refused\" ||\n error.code ===\n \"subscription_change_idempotency_conflict\")))\n ) {\n completeAttempt()\n }\n if (view.current === currentView) {\n toastApiError(error, \"Change subscription\")\n }\n }\n }}\n >\n {change.isPending\n ? \"Applying…\"\n : change.data\n ? change.data.status === \"processing\"\n ? \"Check result\"\n : change.data.status === \"blocked\"\n ? \"Change blocked\"\n : \"Action required\"\n : \"Confirm change\"}\n </Button>\n )}\n </DialogFooter>\n </DialogContent>\n </Dialog>\n )\n}\n","import { AdminMessage, useAdminUI } from \"#orck/admin/ui-context\"\nimport { useAdminServices } from \"#orck/admin/context\"\nimport { HugeiconsIcon } from \"@hugeicons/react\"\nimport { ArrowLeft01Icon } from \"@hugeicons/core-free-icons\"\nimport * as React from \"react\"\nimport { Link, useNavigate, useParams } from \"#orck/admin/router\"\n\nimport { useForm } from \"@tanstack/react-form\"\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\"\n\nimport { Fact } from \"#orck/admin/components/fact-card\"\nimport { FormFieldErrors } from \"#orck/admin/components/form-field-errors\"\nimport { StatusBadge } from \"#orck/admin/components/status-badge\"\nimport { TypedConfirmDialog } from \"#orck/admin/components/typed-confirm-dialog\"\nimport { Badge } from \"#orck/admin/components/ui/badge\"\nimport { Button } from \"#orck/admin/components/ui/button\"\nimport {\n Card,\n CardContent,\n CardHeader,\n CardTitle,\n} from \"#orck/admin/components/ui/card\"\nimport {\n Dialog,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogTitle,\n DialogTrigger,\n} from \"#orck/admin/components/ui/dialog\"\nimport { Input } from \"#orck/admin/components/ui/input\"\nimport { Label } from \"#orck/admin/components/ui/label\"\nimport {\n Select,\n SelectContent,\n SelectItem,\n SelectTrigger,\n SelectValue,\n} from \"#orck/admin/components/ui/select\"\nimport { Switch } from \"#orck/admin/components/ui/switch\"\nimport {\n Table,\n TableBody,\n TableCell,\n TableHead,\n TableHeader,\n TableRow,\n} from \"#orck/admin/components/ui/table\"\nimport type { ScheduledChange } from \"#orck/admin/lib/api/types\"\nimport { DIALOG_FORM } from \"#orck/admin/lib/dialog-width\"\nimport {\n formatCard,\n formatDate,\n formatNativeAmount,\n shortId,\n} from \"#orck/admin/lib/format\"\n\nimport { ChangeSubscriptionDialog } from \"#orck/admin/pages/subscriptions/change-subscription-dialog\"\nimport { dunningSummary } from \"#orck/admin/pages/subscriptions/dunning\"\nimport { useAdminUpdates } from \"#orck/admin/lib/capabilities\"\n\nexport function SubscriptionDetailPage() {\n const { text: adminText } = useAdminUI()\n\n const { adminQueries } = useAdminServices()\n\n const canUpdate = useAdminUpdates()\n const { id = \"\" } = useParams()\n const navigate = useNavigate()\n const { data: sub, isPending: loading } = useQuery(\n adminQueries.subscription(id)\n )\n const { data: paymentPage } = useQuery(\n adminQueries.payments({ subscription_id: id }, 20)\n )\n const payments = paymentPage?.data ?? []\n if (loading)\n return (\n <p className=\"text-sm text-muted-foreground\">\n <AdminMessage id={\"Loading…\"} />\n </p>\n )\n if (!sub)\n return (\n <p className=\"text-sm text-muted-foreground\">\n <AdminMessage id={\"Subscription not found.\"} />\n </p>\n )\n\n const cancellable =\n sub.status === \"active\" ||\n sub.status === \"past_due\" ||\n sub.status === \"awaiting_method\" ||\n sub.status === \"unverified\"\n const resumable = sub.status === \"canceled\" || sub.status === \"past_due\"\n\n return (\n <div className=\"flex flex-col gap-4\">\n <div className=\"flex items-center gap-3\">\n <Button\n variant=\"ghost\"\n size=\"icon\"\n onClick={() => navigate(-1)}\n aria-label={adminText(\"Back\")}\n >\n <HugeiconsIcon icon={ArrowLeft01Icon} className=\"size-4\" />\n </Button>\n <div>\n <h2 className=\"flex items-center gap-2 text-sm\">\n {sub.id} <StatusBadge status={sub.status} />\n </h2>\n <p className=\"text-xs text-muted-foreground\">\n {sub.rail} · {sub.rail_subscription_id || \"no rail id\"}\n </p>\n </div>\n <div className=\"ml-auto flex gap-2\">\n {canUpdate && resumable && (\n <ResumeButton id={sub.id} customerId={sub.customer_id} />\n )}\n {canUpdate && (\n <ChangeSubscriptionDialog\n subscriptionId={sub.id}\n customerId={sub.customer_id}\n productId={sub.product_id}\n priceId={sub.price_id}\n quantity={sub.quantity}\n currency={sub.price?.currency}\n collectionPolicy={sub.collection_policy}\n scheduledChange={sub.scheduled_change}\n rail={sub.rail}\n status={sub.status}\n />\n )}\n {canUpdate && (\n <ChangePaymentMethodDialog\n subscriptionId={sub.id}\n customerId={sub.customer_id}\n rail={sub.rail}\n collectionPolicy={sub.collection_policy}\n />\n )}\n {canUpdate && cancellable && (\n <CancelDialog id={sub.id} customerId={sub.customer_id} />\n )}\n </div>\n </div>\n\n <div className=\"grid gap-3 sm:grid-cols-2 lg:grid-cols-4\">\n <Fact label={adminText(\"Customer\")}>\n {sub.customer_id ? (\n <Link\n className=\"text-xs underline-offset-2 hover:underline\"\n to={`/customers/${sub.customer_id}`}\n >\n {shortId(sub.customer_id, 13)}\n </Link>\n ) : (\n \"—\"\n )}\n </Fact>\n <Fact label={adminText(\"Started\")}>{formatDate(sub.started_at)}</Fact>\n <Fact label={adminText(\"Current period\")}>\n {formatDate(sub.current_period_starts_at)} →{\" \"}\n {formatDate(sub.current_period_ends_at)}\n </Fact>\n <Fact label={adminText(\"Price\")}>\n <div className=\"flex flex-col gap-1\">\n <span className=\"flex items-center gap-2\">\n {sub.price?.unit_amount !== undefined && sub.price?.currency ? (\n <Link\n className=\"underline-offset-2 hover:underline\"\n to={`/catalog/prices/${encodeURIComponent(sub.price_id)}`}\n >\n {formatNativeAmount(\n sub.price.unit_amount,\n sub.price.currency\n )}\n </Link>\n ) : (\n <Link\n className=\"text-xs underline-offset-2 hover:underline\"\n to={`/catalog/prices/${encodeURIComponent(sub.price_id)}`}\n >\n {shortId(sub.price_id ?? \"—\", 13)}\n </Link>\n )}\n {sub.price?.archived && (\n <Badge\n variant=\"secondary\"\n title={adminText(\"Pinned to an archived (prior) version\")}\n >\n <AdminMessage id={\"prior version\"} />\n </Badge>\n )}\n </span>\n {sub.price?.key && (\n <span className=\"text-xs text-muted-foreground\">\n {sub.price.key}\n </span>\n )}\n {sub.scheduled_change && (\n <ScheduledChangeBadge change={sub.scheduled_change} />\n )}\n </div>\n </Fact>\n {sub.quantity !== null && (\n <Fact label={adminText(\"Seats\")}>\n {sub.quantity}\n {sub.scheduled_change?.quantity != null &&\n ` → ${sub.scheduled_change.quantity} at renewal`}\n </Fact>\n )}\n <Fact label={adminText(\"Dunning\")}>\n {sub.dunning ? dunningSummary(sub.dunning) : \"—\"}\n </Fact>\n <Fact\n label={\n sub.dunning?.waiting_for_new_card ? \"Card deadline\" : \"Final retry\"\n }\n >\n {formatDate(sub.dunning?.final_retry_at)}\n </Fact>\n <Fact label={adminText(\"Last decline\")}>\n {sub.dunning?.last_failure_reason ?? \"—\"}\n </Fact>\n <Fact label={adminText(\"Canceled\")}>\n {sub.canceled_at\n ? `${formatDate(sub.canceled_at)} (${sub.cancel_type ?? \"?\"})`\n : \"—\"}\n </Fact>\n </div>\n\n <Card>\n <CardHeader>\n <CardTitle className=\"text-sm\">\n <AdminMessage id={\"Payments\"} />\n </CardTitle>\n </CardHeader>\n <CardContent>\n {!payments.length ? (\n <p className=\"text-sm text-muted-foreground\">\n <AdminMessage id={\"No payments recorded.\"} />\n </p>\n ) : (\n <Table>\n <TableHeader>\n <TableRow className=\"hover:bg-transparent\">\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Payment\"} />\n </TableHead>\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Status\"} />\n </TableHead>\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Kind\"} />\n </TableHead>\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Amount\"} />\n </TableHead>\n <TableHead className=\"text-muted-foreground\">\n <AdminMessage id={\"Created\"} />\n </TableHead>\n </TableRow>\n </TableHeader>\n <TableBody>\n {payments.map((p) => (\n <TableRow key={p.id}>\n <TableCell>\n <Link\n className=\"text-xs underline-offset-2 hover:underline\"\n to={`/payments/${p.id}`}\n >\n {shortId(p.id, 13)}\n </Link>\n </TableCell>\n <TableCell>\n <StatusBadge status={p.status} />\n </TableCell>\n <TableCell>{p.kind}</TableCell>\n <TableCell>\n {formatNativeAmount(p.amount, p.currency)}\n </TableCell>\n <TableCell>{formatDate(p.created_at)}</TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n )}\n </CardContent>\n </Card>\n </div>\n )\n}\n\nfunction CancelDialog({ id, customerId }: { id: string; customerId?: string }) {\n const { toast, toastApiError, adminMutations } = useAdminServices()\n\n const { text: adminText, id: adminId } = useAdminUI()\n\n const [open, setOpen] = React.useState(false)\n const queryClient = useQueryClient()\n const cancel = useMutation(\n adminMutations.cancelSubscription(queryClient, id, customerId)\n )\n const form = useForm({\n defaultValues: { reason: \"\", revokeAccess: false },\n })\n\n const handleOpenChange = (next: boolean) => {\n setOpen(next)\n if (!next) {\n form.reset()\n cancel.reset()\n }\n }\n\n return (\n <>\n <Button variant=\"destructive\" size=\"sm\" onClick={() => setOpen(true)}>\n <AdminMessage id={\"Cancel subscription\"} />\n </Button>\n <TypedConfirmDialog\n open={open}\n onOpenChange={handleOpenChange}\n title={adminText(\"Cancel subscription\")}\n description={adminText(\n \"Terminal cancellation at the payment rail. This is a last resort. Dunning parks subscriptions as past_due without losing entitlements.\"\n )}\n confirmationWord=\"CANCEL\"\n actionLabel=\"Cancel subscription\"\n onConfirm={async () => {\n try {\n await cancel.mutateAsync(form.state.values)\n toast.success(\"Subscription canceled\")\n } catch (err) {\n toastApiError(err, \"Cancel subscription\")\n throw err\n }\n }}\n >\n <div className=\"grid gap-3\">\n <form.Field name=\"reason\">\n {(field) => (\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"cancel-reason\")}>\n <AdminMessage id={\"Reason\"} />\n </Label>\n <Input\n id={adminId(\"cancel-reason\")}\n value={field.state.value}\n onBlur={field.handleBlur}\n onChange={(event) => field.handleChange(event.target.value)}\n placeholder={adminText(\"why is this being canceled?\")}\n />\n </div>\n )}\n </form.Field>\n <form.Field name=\"revokeAccess\">\n {(field) => (\n <div className=\"flex items-center gap-2\">\n <Switch\n id={adminId(\"cancel-revoke\")}\n checked={field.state.value}\n onCheckedChange={field.handleChange}\n />\n <Label htmlFor={adminId(\"cancel-revoke\")}>\n <AdminMessage id={\"Also revoke access immediately\"} />\n </Label>\n </div>\n )}\n </form.Field>\n </div>\n </TypedConfirmDialog>\n </>\n )\n}\n\nfunction ResumeButton({ id, customerId }: { id: string; customerId?: string }) {\n const { toast, toastApiError, adminMutations } = useAdminServices()\n\n const queryClient = useQueryClient()\n const resume = useMutation(\n adminMutations.resumeSubscription(queryClient, id, customerId)\n )\n return (\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={resume.isPending}\n onClick={async () => {\n try {\n await resume.mutateAsync()\n toast.success(\"Resume queued\")\n } catch (err) {\n toastApiError(err, \"Resume subscription\")\n }\n }}\n >\n {resume.isPending ? \"Queuing…\" : \"Resume\"}\n </Button>\n )\n}\n\n// The choice that makes the subscription follow the customer's default card.\nconst FOLLOW_DEFAULT = \"default\"\n\nfunction ChangePaymentMethodDialog({\n subscriptionId,\n customerId,\n rail,\n collectionPolicy,\n}: {\n subscriptionId: string\n customerId?: string\n rail: string\n collectionPolicy?: string\n}) {\n const { toast, toastApiError, adminMutations, adminQueries } =\n useAdminServices()\n\n const { id: adminId, text: adminText } = useAdminUI()\n\n const [open, setOpen] = React.useState(false)\n const queryClient = useQueryClient()\n const changePaymentMethod = useMutation(\n adminMutations.changeSubscriptionPaymentMethod(\n queryClient,\n subscriptionId,\n customerId\n )\n )\n const { data: pms } = useQuery(\n adminQueries.customerPaymentMethods(open ? customerId : undefined)\n )\n const form = useForm({\n defaultValues: { paymentMethodId: \"\" },\n onSubmit: async ({ value }) => {\n try {\n await changePaymentMethod.mutateAsync(\n value.paymentMethodId === FOLLOW_DEFAULT\n ? null\n : value.paymentMethodId\n )\n toast.success(\"Payment method updated\")\n handleOpenChange(false)\n } catch (err) {\n toastApiError(err, \"Change payment method\")\n }\n },\n })\n\n const handleOpenChange = (next: boolean) => {\n setOpen(next)\n if (!next) {\n form.reset()\n changePaymentMethod.reset()\n }\n }\n\n // A card subscription OpenRails collects, or an NMI schedule; a provider\n // that keeps the card (Stripe-owned, CCBill) or a wallet has none to change.\n const supported =\n rail !== \"solana\" &&\n (collectionPolicy === \"engine\" || collectionPolicy === \"nmi_schedule\")\n return (\n <Dialog open={open} onOpenChange={handleOpenChange}>\n <DialogTrigger\n render={\n <Button\n variant=\"outline\"\n size=\"sm\"\n disabled={!supported}\n title={\n supported\n ? undefined\n : `Payment-method change is not supported on ${rail}`\n }\n >\n <AdminMessage id={\"Change payment method\"} />\n </Button>\n }\n />\n <DialogContent className={DIALOG_FORM}>\n <DialogHeader>\n <DialogTitle>\n <AdminMessage id={\"Change payment method\"} />\n </DialogTitle>\n <DialogDescription>\n <AdminMessage\n id={\n \"Points future renewals of this subscription at another of the customer's stored cards (same rail), or back at their default card for its currency.\"\n }\n />\n </DialogDescription>\n </DialogHeader>\n <form\n onSubmit={(event) => {\n event.preventDefault()\n event.stopPropagation()\n void form.handleSubmit()\n }}\n className=\"grid gap-4\"\n >\n <form.Field\n name=\"paymentMethodId\"\n validators={{\n onChange: ({ value }) =>\n value ? undefined : \"Pick a stored payment method\",\n }}\n >\n {(field) => (\n <div className=\"grid gap-1.5\">\n <Label htmlFor={adminId(\"subscription-payment-method\")}>\n <AdminMessage id={\"Payment method\"} />\n </Label>\n <Select\n value={field.state.value}\n onValueChange={(value) => field.handleChange(value ?? \"\")}\n >\n <SelectTrigger\n className=\"w-full\"\n id={adminId(\"subscription-payment-method\")}\n aria-invalid={field.state.meta.errors.length > 0}\n >\n <SelectValue\n placeholder={adminText(\"Pick a stored payment method\")}\n />\n </SelectTrigger>\n <SelectContent>\n <SelectItem value={FOLLOW_DEFAULT}>\n <AdminMessage id={\"The customer's default card\"} />\n </SelectItem>\n {(pms ?? [])\n .filter((pm) => pm.rail === rail)\n .map((pm) => (\n <SelectItem key={pm.id} value={pm.id}>\n {formatCard(pm.card)} ({pm.rail})\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n <FormFieldErrors errors={field.state.meta.errors} />\n </div>\n )}\n </form.Field>\n <DialogFooter>\n <form.Subscribe\n selector={(state) =>\n [\n state.values.paymentMethodId,\n state.canSubmit,\n state.isSubmitting,\n ] as const\n }\n >\n {([paymentMethodId, canSubmit, isSubmitting]) => (\n <Button\n type=\"submit\"\n disabled={!paymentMethodId || !canSubmit || isSubmitting}\n >\n {isSubmitting ? \"Updating…\" : \"Update\"}\n </Button>\n )}\n </form.Subscribe>\n </DialogFooter>\n </form>\n </DialogContent>\n </Dialog>\n )\n}\n\n// ScheduledChangeBadge shows the change waiting for the next renewal: a price\n// migration's move or a scheduled downgrade. A change back to the current\n// price clears it.\nfunction ScheduledChangeBadge({ change }: { change: ScheduledChange }) {\n const { adminQueries } = useAdminServices()\n\n const { data: toPrice } = useQuery(adminQueries.price(change.price_id))\n return (\n <Badge className=\"bg-held-surface text-held\">\n {change.source === \"migration\" ? \"migrates\" : \"changes\"}\n <AdminMessage id={\" to\"} />{\" \"}\n {toPrice\n ? formatNativeAmount(toPrice.unit_amount, toPrice.currency)\n : shortId(change.price_id, 9)}{\" \"}\n <AdminMessage id={\"at the first renewal from \"} />\n {formatDate(change.effective_at)}\n </Badge>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,SAAgB,GACd,GACQ;CACR,IAAM,IAAQ,EAAO,OACf,IAAS,GAAG,EAAmB,EAAM,aAAa,EAAM,QAAQ,IAAI,EAAM,WAAW,cAAc;CACzG,OAAO;EACL,EAAO,QAAQ;EACf,EAAO;EACP,GAAG,EAAO,GAAG,EAAmB,CAAK;EACrC,EAAM;CACR,CAAC,CAAC,KAAK,KAAK;AACd;AAIA,SAAgB,GACd,GACA,GACe;CACf,IAAM,IAAS,EAAM;CAKrB,OAJK,IACD,MAAY,QAAQ,KAAW,EAAO,OAAO,KAAW,EAAO,MAC1D,IAEF,EAAO,MAJM;AAKtB;AAEA,SAAgB,GAAmC,EACjD,SACA,WACA,qBACA,sBAMqB;CACrB,IAAI,MAAW,YAAY,MAAW,YACpC,OAAO;CAGT,IAAI,KAAmB,MAAqB,UAC1C,OAAO;CAET,IAAI,MAAS,UAAU,OAAO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