@openrails/billing-ui 0.268.2 → 0.269.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.
Files changed (142) hide show
  1. package/dist/admin/context.d.ts +164 -62
  2. package/dist/admin/lib/api/endpoints.d.ts +3 -7
  3. package/dist/admin/lib/api/import-endpoints.d.ts +44 -0
  4. package/dist/admin/lib/api/index.d.ts +17 -7
  5. package/dist/admin/lib/api/types.d.ts +0 -29
  6. package/dist/admin/lib/import-queries.d.ts +66 -0
  7. package/dist/admin/lib/mutations.d.ts +1 -5
  8. package/dist/admin/lib/queries.d.ts +6 -20
  9. package/dist/admin/messages.d.ts +176 -6
  10. package/dist/admin/pages/catalog/index.d.ts +0 -1
  11. package/dist/admin/pages/imports/detail.d.ts +2 -0
  12. package/dist/admin/pages/imports/index.d.ts +2 -0
  13. package/dist/admin/pages/imports/mapping-csv.d.ts +10 -0
  14. package/dist/admin/pages/imports/progress.d.ts +21 -0
  15. package/dist/admin/pages/imports/records.d.ts +2 -0
  16. package/dist/admin/pages/imports/shared.d.ts +22 -0
  17. package/dist/admin/pages/parked/index.d.ts +2 -0
  18. package/dist/admin/pages/proposals/grouping.d.ts +13 -0
  19. package/dist/admin/pages/proposals/index.d.ts +2 -0
  20. package/dist/admin/pages/provider-prices/index.d.ts +2 -0
  21. package/dist/admin/pages/provider-prices/map-dialog.d.ts +11 -0
  22. package/dist/admin/routes.d.ts +1 -1
  23. package/dist/{admin-attempts-BLeeKABa.js → admin-attempts-DQTg0UzZ.js} +82 -82
  24. package/dist/{admin-attempts-BLeeKABa.js.map → admin-attempts-DQTg0UzZ.js.map} +1 -1
  25. package/dist/{admin-auth-DWVWxDup.js → admin-auth-1aZIgXiS.js} +2 -2
  26. package/dist/{admin-auth-DWVWxDup.js.map → admin-auth-1aZIgXiS.js.map} +1 -1
  27. package/dist/{admin-badge-CrEqD9Ew.js → admin-badge-pgG6D9-a.js} +2 -2
  28. package/dist/{admin-badge-CrEqD9Ew.js.map → admin-badge-pgG6D9-a.js.map} +1 -1
  29. package/dist/{admin-button-a7bDFgp0.js → admin-button-CrcYk5r0.js} +2 -2
  30. package/dist/{admin-button-a7bDFgp0.js.map → admin-button-CrcYk5r0.js.map} +1 -1
  31. package/dist/{admin-capabilities-QYUuJXvG.js → admin-capabilities-BDcZeHL_.js} +2 -2
  32. package/dist/{admin-capabilities-QYUuJXvG.js.map → admin-capabilities-BDcZeHL_.js.map} +1 -1
  33. package/dist/{admin-card-D1tz8Lbh.js → admin-card-DvTMc5Se.js} +2 -2
  34. package/dist/{admin-card-D1tz8Lbh.js.map → admin-card-DvTMc5Se.js.map} +1 -1
  35. package/dist/{admin-catalog-ggiDgWsR.js → admin-catalog-BlF5mnu4.js} +285 -382
  36. package/dist/admin-catalog-BlF5mnu4.js.map +1 -0
  37. package/dist/{admin-dom-VkcwevWr.js → admin-cursor-pager-CIb3Jw2F.js} +20 -25
  38. package/dist/admin-cursor-pager-CIb3Jw2F.js.map +1 -0
  39. package/dist/{admin-customers-BVMg-gUv.js → admin-customers-EpfoWDh-.js} +13 -13
  40. package/dist/{admin-customers-BVMg-gUv.js.map → admin-customers-EpfoWDh-.js.map} +1 -1
  41. package/dist/{admin-dashboard-Cc13i8i9.js → admin-dashboard-CJE63yz4.js} +46 -46
  42. package/dist/{admin-dashboard-Cc13i8i9.js.map → admin-dashboard-CJE63yz4.js.map} +1 -1
  43. package/dist/{admin-data-table-BL84xKKF.js → admin-data-table-hvFcJepL.js} +16 -16
  44. package/dist/{admin-data-table-BL84xKKF.js.map → admin-data-table-hvFcJepL.js.map} +1 -1
  45. package/dist/{admin-detail-CaEwBdX9.js → admin-detail-BRP6pL7t.js} +51 -51
  46. package/dist/{admin-detail-CaEwBdX9.js.map → admin-detail-BRP6pL7t.js.map} +1 -1
  47. package/dist/{admin-detail-9YAep3ts.js → admin-detail-CRzFb_pa.js} +232 -232
  48. package/dist/{admin-detail-9YAep3ts.js.map → admin-detail-CRzFb_pa.js.map} +1 -1
  49. package/dist/admin-detail-Ceod8AXy.js +299 -0
  50. package/dist/admin-detail-Ceod8AXy.js.map +1 -0
  51. package/dist/{admin-detail-C8t5jBps.js → admin-detail-QLxU8r-5.js} +62 -62
  52. package/dist/{admin-detail-C8t5jBps.js.map → admin-detail-QLxU8r-5.js.map} +1 -1
  53. package/dist/admin-detail-pPC8Q9l-.js +710 -0
  54. package/dist/{admin-detail-D2zcz_Xm.js.map → admin-detail-pPC8Q9l-.js.map} +1 -1
  55. package/dist/{admin-dialog-CiAw5vx-.js → admin-dialog-BSRf9Zre.js} +24 -24
  56. package/dist/{admin-dialog-CiAw5vx-.js.map → admin-dialog-BSRf9Zre.js.map} +1 -1
  57. package/dist/admin-dom-C7Y7A6Wa.js +8 -0
  58. package/dist/admin-dom-C7Y7A6Wa.js.map +1 -0
  59. package/dist/{admin-dropdown-menu-CYJbmqK2.js → admin-dropdown-menu-D0E5rwmn.js} +2 -2
  60. package/dist/{admin-dropdown-menu-CYJbmqK2.js.map → admin-dropdown-menu-D0E5rwmn.js.map} +1 -1
  61. package/dist/{admin-fact-card-BHTpDlaX.js → admin-fact-card-BPSVhS15.js} +2 -2
  62. package/dist/{admin-fact-card-BHTpDlaX.js.map → admin-fact-card-BPSVhS15.js.map} +1 -1
  63. package/dist/{admin-health-BUnjbvYR.js → admin-health-D0L5Kig7.js} +84 -84
  64. package/dist/{admin-health-BUnjbvYR.js.map → admin-health-D0L5Kig7.js.map} +1 -1
  65. package/dist/admin-imports-TCOljTgw.js +269 -0
  66. package/dist/admin-imports-TCOljTgw.js.map +1 -0
  67. package/dist/{admin-input-C-S_RGGo.js → admin-input-DJAK9nmk.js} +2 -2
  68. package/dist/{admin-input-C-S_RGGo.js.map → admin-input-DJAK9nmk.js.map} +1 -1
  69. package/dist/{admin-label-DPVYDdSO.js → admin-label-aviN9Gng.js} +2 -2
  70. package/dist/{admin-label-DPVYDdSO.js.map → admin-label-aviN9Gng.js.map} +1 -1
  71. package/dist/{admin-linked-table-row-D-gbTT7a.js → admin-linked-table-row-BGr7JXeM.js} +6 -6
  72. package/dist/{admin-linked-table-row-D-gbTT7a.js.map → admin-linked-table-row-BGr7JXeM.js.map} +1 -1
  73. package/dist/admin-map-dialog-DpGaIq52.js +135 -0
  74. package/dist/admin-map-dialog-DpGaIq52.js.map +1 -0
  75. package/dist/admin-mapping-csv-FtkyTBmk.js +56 -0
  76. package/dist/admin-mapping-csv-FtkyTBmk.js.map +1 -0
  77. package/dist/{admin-metering-BjbL0jjT.js → admin-metering-D-e-37Jn.js} +285 -285
  78. package/dist/{admin-metering-BjbL0jjT.js.map → admin-metering-D-e-37Jn.js.map} +1 -1
  79. package/dist/admin-ops-CQP4TzWM.js +235 -0
  80. package/dist/admin-ops-CQP4TzWM.js.map +1 -0
  81. package/dist/{admin-orders-BVW9-Fs9.js → admin-orders-BJ7W5S8P.js} +32 -32
  82. package/dist/{admin-orders-BVW9-Fs9.js.map → admin-orders-BJ7W5S8P.js.map} +1 -1
  83. package/dist/admin-parked-7HL8mOjw.js +193 -0
  84. package/dist/admin-parked-7HL8mOjw.js.map +1 -0
  85. package/dist/{admin-payments-C5MsFFmm.js → admin-payments-CzkzqYA1.js} +17 -17
  86. package/dist/{admin-payments-C5MsFFmm.js.map → admin-payments-CzkzqYA1.js.map} +1 -1
  87. package/dist/{admin-price-detail-D517JYHB.js → admin-price-detail-CSI5oKdb.js} +74 -74
  88. package/dist/{admin-price-detail-D517JYHB.js.map → admin-price-detail-CSI5oKdb.js.map} +1 -1
  89. package/dist/{admin-price-wizard-bj36o3ux.js → admin-price-wizard-CBEcNGvP.js} +38 -38
  90. package/dist/{admin-price-wizard-bj36o3ux.js.map → admin-price-wizard-CBEcNGvP.js.map} +1 -1
  91. package/dist/admin-proposals-dtgijWKz.js +375 -0
  92. package/dist/admin-proposals-dtgijWKz.js.map +1 -0
  93. package/dist/admin-provider-prices-ChuponcZ.js +246 -0
  94. package/dist/admin-provider-prices-ChuponcZ.js.map +1 -0
  95. package/dist/{admin-range-picker-D2aFF8IV.js → admin-range-picker-De36L-AP.js} +12 -12
  96. package/dist/{admin-range-picker-D2aFF8IV.js.map → admin-range-picker-De36L-AP.js.map} +1 -1
  97. package/dist/admin-records-CUHUOXAU.js +391 -0
  98. package/dist/admin-records-CUHUOXAU.js.map +1 -0
  99. package/dist/{admin-reports-D-ob04d4.js → admin-reports-BFGS_PWf.js} +45 -45
  100. package/dist/{admin-reports-D-ob04d4.js.map → admin-reports-BFGS_PWf.js.map} +1 -1
  101. package/dist/{admin-select-C8O7nx72.js → admin-select-BUcEU5Rg.js} +2 -2
  102. package/dist/{admin-select-C8O7nx72.js.map → admin-select-BUcEU5Rg.js.map} +1 -1
  103. package/dist/{admin-settings-Bs6cLcqi.js → admin-settings-DYC-c7mJ.js} +296 -296
  104. package/dist/{admin-settings-Bs6cLcqi.js.map → admin-settings-DYC-c7mJ.js.map} +1 -1
  105. package/dist/admin-shared-CzG8Pan3.js +222 -0
  106. package/dist/admin-shared-CzG8Pan3.js.map +1 -0
  107. package/dist/{admin-skeleton-wfocg2PJ.js → admin-skeleton-B0yzYY_X.js} +2 -2
  108. package/dist/{admin-skeleton-wfocg2PJ.js.map → admin-skeleton-B0yzYY_X.js.map} +1 -1
  109. package/dist/{admin-status-badge-D_gDMrht.js → admin-status-badge-0-K37EfN.js} +7 -2
  110. package/dist/admin-status-badge-0-K37EfN.js.map +1 -0
  111. package/dist/{admin-subscriptions-DYR1RGMO.js → admin-subscriptions-CvW-YFs0.js} +74 -74
  112. package/dist/{admin-subscriptions-DYR1RGMO.js.map → admin-subscriptions-CvW-YFs0.js.map} +1 -1
  113. package/dist/{admin-switch-F5D0AYjT.js → admin-switch-DDorugaw.js} +2 -2
  114. package/dist/{admin-switch-F5D0AYjT.js.map → admin-switch-DDorugaw.js.map} +1 -1
  115. package/dist/{admin-table-nUij5fLc.js → admin-table-BU6Tie69.js} +2 -2
  116. package/dist/{admin-table-nUij5fLc.js.map → admin-table-BU6Tie69.js.map} +1 -1
  117. package/dist/{admin-tabs-C3myjKdr.js → admin-tabs-D5lqdVcC.js} +2 -2
  118. package/dist/{admin-tabs-C3myjKdr.js.map → admin-tabs-D5lqdVcC.js.map} +1 -1
  119. package/dist/{admin-textarea-v-L-PXIc.js → admin-textarea-Dc6lnEub.js} +2 -2
  120. package/dist/{admin-textarea-v-L-PXIc.js.map → admin-textarea-Dc6lnEub.js.map} +1 -1
  121. package/dist/{admin-typed-confirm-dialog-BLgpuikW.js → admin-typed-confirm-dialog-Bk6XxmPb.js} +6 -6
  122. package/dist/{admin-typed-confirm-dialog-BLgpuikW.js.map → admin-typed-confirm-dialog-Bk6XxmPb.js.map} +1 -1
  123. package/dist/{admin-utils-6yE4YIVI.js → admin-utils-B9eEBNsR.js} +398 -146
  124. package/dist/admin-utils-B9eEBNsR.js.map +1 -0
  125. package/dist/{admin-widget-viz-BiEfckd4.js → admin-widget-viz-8aukE3v_.js} +34 -34
  126. package/dist/{admin-widget-viz-BiEfckd4.js.map → admin-widget-viz-8aukE3v_.js.map} +1 -1
  127. package/dist/admin.css +1 -1
  128. package/dist/admin.js +489 -264
  129. package/dist/admin.js.map +1 -1
  130. package/dist/client/generated/error-codes.d.ts +1 -1
  131. package/dist/client/generated/routes.d.ts +94 -22
  132. package/dist/client/generated/wire.d.ts +89 -14
  133. package/dist/index.js +1 -1
  134. package/dist/styles.css +1 -1
  135. package/package.json +2 -2
  136. package/dist/admin-catalog-ggiDgWsR.js.map +0 -1
  137. package/dist/admin-detail-D2zcz_Xm.js +0 -710
  138. package/dist/admin-dom-VkcwevWr.js.map +0 -1
  139. package/dist/admin-ops-DT8epiXg.js +0 -217
  140. package/dist/admin-ops-DT8epiXg.js.map +0 -1
  141. package/dist/admin-status-badge-D_gDMrht.js.map +0 -1
  142. package/dist/admin-utils-6yE4YIVI.js.map +0 -1
@@ -1,710 +0,0 @@
1
- import { E as e, S as t, c as n, p as r, r as i, s as a, w as o } from "./admin-utils-6yE4YIVI.js";
2
- import { t as s } from "./admin-button-a7bDFgp0.js";
3
- import { t as c } from "./admin-input-C-S_RGGo.js";
4
- import { a as l } from "./admin-capabilities-QYUuJXvG.js";
5
- import { i as u, o as d, s as f, u as p } from "./admin-format-DoohJ7Fg.js";
6
- import { t as m } from "./admin-form-field-errors-hbUMIriS.js";
7
- import { a as h, i as g, n as ee, r as _, t as v } from "./admin-select-C8O7nx72.js";
8
- import { a as y, n as b, o as te, r as x, s as S, t as C } from "./admin-table-nUij5fLc.js";
9
- import { t as w } from "./admin-badge-CrEqD9Ew.js";
10
- import { t as T } from "./admin-status-badge-D_gDMrht.js";
11
- import { a as E, i as ne, n as re, o as ie, r as ae, s as oe, t as se } from "./admin-dialog-CiAw5vx-.js";
12
- import { t as D } from "./admin-label-DPVYDdSO.js";
13
- import { t as O } from "./admin-switch-F5D0AYjT.js";
14
- import { n as ce, r as le } from "./admin-dialog-width-BPrgdYlj.js";
15
- import { n as k } from "./admin-price-format-BVUpDoSC.js";
16
- import { a as ue, o as de, r as fe, t as pe } from "./admin-card-D1tz8Lbh.js";
17
- import { t as A } from "./admin-fact-card-BHTpDlaX.js";
18
- import { t as j } from "./admin-dunning-B2zgtrOo.js";
19
- import { t as M } from "./admin-typed-confirm-dialog-BLgpuikW.js";
20
- import * as N from "react";
21
- import { useMutation as P, useQuery as F, useQueryClient as I } from "@tanstack/react-query";
22
- import { Fragment as me, jsx as L, jsxs as R } from "react/jsx-runtime";
23
- import { HugeiconsIcon as z } from "@hugeicons/react";
24
- import { ArrowLeft01Icon as B } from "@hugeicons/core-free-icons";
25
- import { useForm as V } from "@tanstack/react-form";
26
- //#region src/admin/pages/subscriptions/subscription-change-options.ts
27
- function he(e) {
28
- let t = e.price, n = `${f(t.unit_amount, t.currency)}${t.quantity ? " per seat" : ""}`;
29
- return [
30
- e.product.display_name,
31
- e.direction,
32
- `${n} ${k(t)}`,
33
- t.key
34
- ].join(" · ");
35
- }
36
- function ge(e, t) {
37
- let n = e.quantity;
38
- return n ? t !== null && t >= n.min && t <= n.max ? t : n.min : null;
39
- }
40
- function _e({ rail: e, status: t, collectionPolicy: n, scheduledChange: r }) {
41
- if (t !== "active" && t !== "past_due") return "Only active or past-due subscriptions can change";
42
- if (r && n !== "engine") return "Its provider already bills a scheduled change";
43
- if (e === "ccbill") return "CCBill changes require customer self-service";
44
- if (e === "solana") return "Solana changes require the customer's wallet signature";
45
- }
46
- function ve({ currentProduct: e, currentPrice: t, currentCurrency: n, products: r, prices: i, scheduledChange: a }) {
47
- let o = e && t && (t.quantity || a) ? [{
48
- direction: "current",
49
- price: t,
50
- product: e
51
- }] : [], s = e?.tier_group?.trim(), c = n?.trim().toLowerCase();
52
- if (!e || !s || !c || a?.source === "migration") return o;
53
- let l = new Map(r.filter((t) => !t.archived && t.id !== e.id && t.tier_group?.trim() === s).map((e) => [e.id, e]));
54
- return o.concat(i.flatMap((t) => {
55
- let n = l.get(t.product_id);
56
- return !n || t.archived || !t.billing_interval_hours || t.currency.trim().toLowerCase() !== c ? [] : [{
57
- direction: n.tier_rank < e.tier_rank ? "downgrade" : "upgrade",
58
- price: t,
59
- product: n
60
- }];
61
- }).sort((e, t) => e.product.tier_rank - t.product.tier_rank || e.product.display_name.localeCompare(t.product.display_name) || e.price.id.localeCompare(t.price.id)));
62
- }
63
- //#endregion
64
- //#region src/admin/pages/subscriptions/change-subscription-dialog.tsx
65
- function ye(e) {
66
- let { selectedMerchant: t } = r();
67
- return /* @__PURE__ */ L(H, { ...e }, `${t() ?? ""}:${e.subscriptionId}`);
68
- }
69
- function H({ subscriptionId: n, customerId: i, productId: a, priceId: l, quantity: u, currency: p, collectionPolicy: m, scheduledChange: y, rail: b, status: te }) {
70
- let { toast: x, toastApiError: S, adminMutations: C, adminQueries: T } = r(), { id: O, text: ce } = e(), [k, ue] = N.useState(!1), [de, fe] = N.useState(""), [pe, A] = N.useState(""), [j, M] = N.useState(""), [me, z] = N.useState(""), B = N.useRef(/* @__PURE__ */ new Map()), V = N.useRef(0);
71
- N.useEffect(() => () => {
72
- V.current++;
73
- }, []);
74
- let ye = I(), H = P(C.previewSubscriptionChange(n)), U = P(C.changeSubscription(ye, n, i)), W = F({
75
- ...T.allProducts({ errorAction: "Load subscription plans" }),
76
- enabled: k
77
- }), G = F({
78
- ...T.allPrices({ errorAction: "Load subscription prices" }),
79
- enabled: k
80
- }), K = W.data?.data ?? [], be = G.data?.data ?? [], xe = K.find((e) => e.id === a), Se = be.find((e) => e.id === l), q = ve({
81
- currentProduct: xe,
82
- currentPrice: Se,
83
- currentCurrency: p ?? Se?.currency,
84
- products: K,
85
- prices: be,
86
- scheduledChange: y
87
- }), J = q.find((e) => e.price.id === de), Y = J?.price.quantity, X = Number(pe), Ce = !Y || Number.isInteger(X) && X >= Y.min && X <= Y.max, Z = J && Ce ? {
88
- price_id: J.price.id,
89
- ...Y ? { quantity: X } : {}
90
- } : void 0, we = J?.direction === "current" && !y && (!Y || X === u), Q = Z ? JSON.stringify(Z) : "", $ = Q && me === Q ? H.data : void 0, Te = _e({
91
- rail: b,
92
- status: te,
93
- collectionPolicy: m,
94
- scheduledChange: y
95
- }), Ee = (e) => {
96
- V.current++, ue(e);
97
- }, De = (e) => {
98
- V.current++;
99
- let t = q.find((t) => t.price.id === e)?.price;
100
- fe(e ?? ""), A(String(t ? ge(t, u) ?? "" : "")), z(""), H.reset(), U.reset();
101
- }, Oe = (e) => {
102
- V.current++, A(e), z(""), H.reset(), U.reset();
103
- }, ke = H.error instanceof Error ? H.error.message : "", Ae = U.error instanceof Error ? U.error.message : "", je = U.data?.message, Me = U.data?.next_action?.url ?? void 0;
104
- return /* @__PURE__ */ R(se, {
105
- open: k,
106
- onOpenChange: Ee,
107
- children: [/* @__PURE__ */ L(oe, { render: /* @__PURE__ */ L(s, {
108
- variant: "outline",
109
- size: "sm",
110
- disabled: !!Te && !U.variables,
111
- title: Te,
112
- children: /* @__PURE__ */ L(o, { id: "Change subscription" })
113
- }) }), /* @__PURE__ */ R(re, {
114
- className: le,
115
- children: [
116
- /* @__PURE__ */ R(E, { children: [/* @__PURE__ */ L(ie, { children: /* @__PURE__ */ L(o, { id: "Change subscription" }) }), /* @__PURE__ */ L(ae, { children: /* @__PURE__ */ L(o, { 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." }) })] }),
117
- /* @__PURE__ */ R("div", {
118
- className: "grid gap-5",
119
- children: [
120
- /* @__PURE__ */ R("div", {
121
- className: "grid gap-1.5",
122
- children: [
123
- /* @__PURE__ */ L(D, {
124
- htmlFor: O("subscription-tier"),
125
- children: /* @__PURE__ */ L(o, { id: "New plan" })
126
- }),
127
- /* @__PURE__ */ R(v, {
128
- value: de,
129
- onValueChange: De,
130
- children: [/* @__PURE__ */ L(g, {
131
- id: O("subscription-tier"),
132
- className: "w-full",
133
- disabled: W.isPending || G.isPending,
134
- children: /* @__PURE__ */ L(h, { placeholder: W.isPending || G.isPending ? "Loading plans…" : "Choose a plan" })
135
- }), /* @__PURE__ */ L(ee, { children: q.map((e) => /* @__PURE__ */ L(_, {
136
- value: e.price.id,
137
- children: he(e)
138
- }, e.price.id)) })]
139
- }),
140
- !W.isPending && !G.isPending && !W.isError && !G.isError && q.length === 0 && /* @__PURE__ */ L("p", {
141
- className: "text-xs text-muted-foreground",
142
- children: /* @__PURE__ */ L(o, { id: "No eligible recurring plans share this tier group and currency." })
143
- }),
144
- (W.isError || G.isError) && /* @__PURE__ */ L("p", {
145
- className: "text-xs text-destructive",
146
- role: "alert",
147
- children: /* @__PURE__ */ L(o, { id: "Could not load the available plans." })
148
- })
149
- ]
150
- }),
151
- Y && /* @__PURE__ */ R("div", {
152
- className: "grid gap-1.5",
153
- children: [
154
- /* @__PURE__ */ L(D, {
155
- htmlFor: O("subscription-seats"),
156
- children: /* @__PURE__ */ L(o, { id: "Seats" })
157
- }),
158
- /* @__PURE__ */ L(c, {
159
- id: O("subscription-seats"),
160
- type: "number",
161
- inputMode: "numeric",
162
- min: Y.min,
163
- max: Y.max,
164
- value: pe,
165
- onChange: (e) => Oe(e.target.value)
166
- }),
167
- /* @__PURE__ */ R("p", {
168
- className: "text-xs text-muted-foreground",
169
- children: [
170
- Y.min,
171
- /* @__PURE__ */ L(o, { id: " to " }),
172
- Y.max,
173
- /* @__PURE__ */ L(o, { id: " seats." })
174
- ]
175
- })
176
- ]
177
- }),
178
- /* @__PURE__ */ R("div", {
179
- className: "grid gap-1.5",
180
- children: [
181
- /* @__PURE__ */ L(D, {
182
- htmlFor: O("subscription-change-reason"),
183
- children: /* @__PURE__ */ L(o, { id: "Reason" })
184
- }),
185
- /* @__PURE__ */ L(c, {
186
- id: O("subscription-change-reason"),
187
- value: j,
188
- maxLength: 500,
189
- placeholder: ce("What the customer asked for"),
190
- onChange: (e) => M(e.target.value)
191
- }),
192
- /* @__PURE__ */ L("p", {
193
- className: "text-xs text-muted-foreground",
194
- children: /* @__PURE__ */ L(o, { id: "Kept with the scheduled change." })
195
- })
196
- ]
197
- }),
198
- $ && J && /* @__PURE__ */ R("div", {
199
- className: "grid gap-3",
200
- "aria-live": "polite",
201
- children: [
202
- /* @__PURE__ */ R("div", {
203
- className: "flex items-center justify-between gap-4",
204
- children: [/* @__PURE__ */ L("span", {
205
- className: "text-sm font-medium",
206
- children: /* @__PURE__ */ L(o, { id: "Review" })
207
- }), /* @__PURE__ */ L(w, {
208
- variant: "secondary",
209
- children: $.effective === "now" ? "Immediate" : "At renewal"
210
- })]
211
- }),
212
- /* @__PURE__ */ R("dl", {
213
- className: "grid grid-cols-2 gap-x-8 gap-y-3 border-y py-4 text-sm",
214
- children: [
215
- $.quantity !== null && /* @__PURE__ */ R("div", {
216
- className: "grid gap-1",
217
- children: [/* @__PURE__ */ L("dt", {
218
- className: "text-xs text-muted-foreground",
219
- children: /* @__PURE__ */ L(o, { id: "Seats" })
220
- }), /* @__PURE__ */ L("dd", {
221
- className: "font-medium tabular-nums",
222
- children: $.quantity
223
- })]
224
- }),
225
- /* @__PURE__ */ R("div", {
226
- className: "grid gap-1",
227
- children: [/* @__PURE__ */ L("dt", {
228
- className: "text-xs text-muted-foreground",
229
- children: /* @__PURE__ */ L(o, { id: "Due now" })
230
- }), /* @__PURE__ */ L("dd", {
231
- className: "font-medium tabular-nums",
232
- children: f($.amount_due_now, $.currency)
233
- })]
234
- }),
235
- /* @__PURE__ */ R("div", {
236
- className: "grid gap-1",
237
- children: [/* @__PURE__ */ L("dt", {
238
- className: "text-xs text-muted-foreground",
239
- children: /* @__PURE__ */ L(o, { id: "Next charge" })
240
- }), /* @__PURE__ */ L("dd", {
241
- className: "font-medium tabular-nums",
242
- children: f($.next_charge_amount, $.currency)
243
- })]
244
- }),
245
- /* @__PURE__ */ R("div", {
246
- className: "grid gap-1",
247
- children: [/* @__PURE__ */ L("dt", {
248
- className: "text-xs text-muted-foreground",
249
- children: /* @__PURE__ */ L(o, { id: "Effective" })
250
- }), /* @__PURE__ */ L("dd", {
251
- className: "font-medium",
252
- children: $.effective === "now" ? "Immediately" : d($.next_charge_date)
253
- })]
254
- }),
255
- /* @__PURE__ */ R("div", {
256
- className: "grid gap-1",
257
- children: [/* @__PURE__ */ L("dt", {
258
- className: "text-xs text-muted-foreground",
259
- children: /* @__PURE__ */ L(o, { id: "Next billing date" })
260
- }), /* @__PURE__ */ L("dd", {
261
- className: "font-medium tabular-nums",
262
- children: d($.next_charge_date)
263
- })]
264
- })
265
- ]
266
- }),
267
- $.is_estimate && /* @__PURE__ */ L("p", {
268
- className: "text-xs text-muted-foreground",
269
- children: /* @__PURE__ */ L(o, { id: "The payment provider calculates the final prorated amount." })
270
- })
271
- ]
272
- }),
273
- (ke || Ae) && /* @__PURE__ */ L("p", {
274
- className: "text-sm text-destructive",
275
- role: "alert",
276
- children: Ae || ke
277
- }),
278
- U.data && U.data.status !== "succeeded" && /* @__PURE__ */ R("div", {
279
- className: "grid gap-2 rounded-lg bg-muted px-3 py-2.5 text-sm",
280
- "aria-live": "polite",
281
- children: [/* @__PURE__ */ L("p", { children: je ?? "This change needs another step." }), Me && /* @__PURE__ */ L("a", {
282
- href: Me,
283
- target: "_blank",
284
- rel: "noreferrer",
285
- className: "w-fit font-medium text-primary underline underline-offset-4",
286
- children: /* @__PURE__ */ L(o, { id: "Continue with payment provider" })
287
- })]
288
- })
289
- ]
290
- }),
291
- /* @__PURE__ */ R(ne, { children: [/* @__PURE__ */ L(s, {
292
- type: "button",
293
- variant: "outline",
294
- onClick: () => Ee(!1),
295
- children: /* @__PURE__ */ L(o, { id: "Cancel" })
296
- }), $ ? /* @__PURE__ */ L(s, {
297
- type: "button",
298
- disabled: U.isPending || !j.trim() || !!U.data && U.data?.status !== "processing",
299
- onClick: async () => {
300
- if (!Z) return;
301
- let e = V.current, n = B.current.get(Q) ?? crypto.randomUUID();
302
- B.current.set(Q, n);
303
- let r = () => {
304
- B.current.get(Q) === n && B.current.delete(Q);
305
- };
306
- try {
307
- let t = await U.mutateAsync({
308
- change: {
309
- ...Z,
310
- reason: j.trim()
311
- },
312
- idempotencyKey: n
313
- });
314
- if ((t.status === "succeeded" || t.status === "blocked") && r(), V.current !== e) return;
315
- t.status === "succeeded" && (x.success(t.effective === "now" ? "Subscription changed" : "Change scheduled for the next renewal"), Ee(!1), fe(""), A(""), M(""), z(""), H.reset(), U.reset()), t.status === "processing" && x.info("The provider is still confirming this change. Check again to read the result.");
316
- } catch (n) {
317
- n instanceof t && (n.status === 402 || n.status === 409 && (n.code === "subscription_change_refused" || n.code === "subscription_change_idempotency_conflict")) && r(), V.current === e && S(n, "Change subscription");
318
- }
319
- },
320
- children: U.isPending ? "Applying…" : U.data ? U.data.status === "processing" ? "Check result" : U.data.status === "blocked" ? "Change blocked" : "Action required" : "Confirm change"
321
- }) : /* @__PURE__ */ L(s, {
322
- type: "button",
323
- disabled: !Z || we || H.isPending,
324
- onClick: async () => {
325
- if (!Z) return;
326
- let e = V.current;
327
- try {
328
- if (await H.mutateAsync(Z), V.current !== e) return;
329
- z(Q);
330
- } catch (t) {
331
- V.current === e && S(t, "Preview subscription change");
332
- }
333
- },
334
- children: H.isPending ? "Reviewing…" : "Review change"
335
- })] })
336
- ]
337
- })]
338
- });
339
- }
340
- //#endregion
341
- //#region src/admin/pages/subscriptions/detail.tsx
342
- function U() {
343
- let { text: t } = e(), { adminQueries: c } = r(), u = l(), { id: m = "" } = n(), h = a(), { data: g, isPending: ee } = F(c.subscription(m)), { data: _ } = F(c.payments({ subscription_id: m }, 20)), v = _?.data ?? [];
344
- if (ee) return /* @__PURE__ */ L("p", {
345
- className: "text-sm text-muted-foreground",
346
- children: /* @__PURE__ */ L(o, { id: "Loading…" })
347
- });
348
- if (!g) return /* @__PURE__ */ L("p", {
349
- className: "text-sm text-muted-foreground",
350
- children: /* @__PURE__ */ L(o, { id: "Subscription not found." })
351
- });
352
- let E = g.status === "active" || g.status === "past_due" || g.status === "awaiting_method" || g.status === "unverified", ne = g.status === "canceled" || g.status === "past_due";
353
- return /* @__PURE__ */ R("div", {
354
- className: "flex flex-col gap-4",
355
- children: [
356
- /* @__PURE__ */ R("div", {
357
- className: "flex items-center gap-3",
358
- children: [
359
- /* @__PURE__ */ L(s, {
360
- variant: "ghost",
361
- size: "icon",
362
- onClick: () => h(-1),
363
- "aria-label": t("Back"),
364
- children: /* @__PURE__ */ L(z, {
365
- icon: B,
366
- className: "size-4"
367
- })
368
- }),
369
- /* @__PURE__ */ R("div", { children: [/* @__PURE__ */ R("h2", {
370
- className: "flex items-center gap-2 text-sm",
371
- children: [
372
- g.id,
373
- " ",
374
- /* @__PURE__ */ L(T, { status: g.status })
375
- ]
376
- }), /* @__PURE__ */ R("p", {
377
- className: "text-xs text-muted-foreground",
378
- children: [
379
- g.rail,
380
- " · ",
381
- g.rail_subscription_id || "no rail id"
382
- ]
383
- })] }),
384
- /* @__PURE__ */ R("div", {
385
- className: "ml-auto flex gap-2",
386
- children: [
387
- u && ne && /* @__PURE__ */ L(G, {
388
- id: g.id,
389
- customerId: g.customer_id
390
- }),
391
- u && /* @__PURE__ */ L(ye, {
392
- subscriptionId: g.id,
393
- customerId: g.customer_id,
394
- productId: g.product_id,
395
- priceId: g.price_id,
396
- quantity: g.quantity,
397
- currency: g.price?.currency,
398
- collectionPolicy: g.collection_policy,
399
- scheduledChange: g.scheduled_change,
400
- rail: g.rail,
401
- status: g.status
402
- }),
403
- u && /* @__PURE__ */ L(be, {
404
- subscriptionId: g.id,
405
- customerId: g.customer_id,
406
- rail: g.rail,
407
- collectionPolicy: g.collection_policy
408
- }),
409
- u && E && /* @__PURE__ */ L(W, {
410
- id: g.id,
411
- customerId: g.customer_id
412
- })
413
- ]
414
- })
415
- ]
416
- }),
417
- /* @__PURE__ */ R("div", {
418
- className: "grid gap-3 sm:grid-cols-2 lg:grid-cols-4",
419
- children: [
420
- /* @__PURE__ */ L(A, {
421
- label: t("Customer"),
422
- children: g.customer_id ? /* @__PURE__ */ L(i, {
423
- className: "text-xs underline-offset-2 hover:underline",
424
- to: `/customers/${g.customer_id}`,
425
- children: p(g.customer_id, 13)
426
- }) : "—"
427
- }),
428
- /* @__PURE__ */ L(A, {
429
- label: t("Started"),
430
- children: d(g.started_at)
431
- }),
432
- /* @__PURE__ */ R(A, {
433
- label: t("Current period"),
434
- children: [
435
- d(g.current_period_starts_at),
436
- " →",
437
- " ",
438
- d(g.current_period_ends_at)
439
- ]
440
- }),
441
- /* @__PURE__ */ L(A, {
442
- label: t("Price"),
443
- children: /* @__PURE__ */ R("div", {
444
- className: "flex flex-col gap-1",
445
- children: [
446
- /* @__PURE__ */ R("span", {
447
- className: "flex items-center gap-2",
448
- children: [g.price?.unit_amount !== void 0 && g.price?.currency ? /* @__PURE__ */ L(i, {
449
- className: "underline-offset-2 hover:underline",
450
- to: `/catalog/prices/${encodeURIComponent(g.price_id)}`,
451
- children: f(g.price.unit_amount, g.price.currency)
452
- }) : /* @__PURE__ */ L(i, {
453
- className: "text-xs underline-offset-2 hover:underline",
454
- to: `/catalog/prices/${encodeURIComponent(g.price_id)}`,
455
- children: p(g.price_id ?? "—", 13)
456
- }), g.price?.archived && /* @__PURE__ */ L(w, {
457
- variant: "secondary",
458
- title: t("Pinned to an archived (prior) version"),
459
- children: /* @__PURE__ */ L(o, { id: "prior version" })
460
- })]
461
- }),
462
- g.price?.key && /* @__PURE__ */ L("span", {
463
- className: "text-xs text-muted-foreground",
464
- children: g.price.key
465
- }),
466
- g.scheduled_change && /* @__PURE__ */ L(xe, { change: g.scheduled_change })
467
- ]
468
- })
469
- }),
470
- g.quantity !== null && /* @__PURE__ */ R(A, {
471
- label: t("Seats"),
472
- children: [g.quantity, g.scheduled_change?.quantity != null && ` → ${g.scheduled_change.quantity} at renewal`]
473
- }),
474
- /* @__PURE__ */ L(A, {
475
- label: t("Dunning"),
476
- children: g.dunning ? j(g.dunning) : "—"
477
- }),
478
- /* @__PURE__ */ L(A, {
479
- label: g.dunning?.waiting_for_new_card ? "Card deadline" : "Final retry",
480
- children: d(g.dunning?.final_retry_at)
481
- }),
482
- /* @__PURE__ */ L(A, {
483
- label: t("Last decline"),
484
- children: g.dunning?.last_failure_reason ?? "—"
485
- }),
486
- /* @__PURE__ */ L(A, {
487
- label: t("Canceled"),
488
- children: g.canceled_at ? `${d(g.canceled_at)} (${g.cancel_type ?? "?"})` : "—"
489
- })
490
- ]
491
- }),
492
- /* @__PURE__ */ R(pe, { children: [/* @__PURE__ */ L(ue, { children: /* @__PURE__ */ L(de, {
493
- className: "text-sm",
494
- children: /* @__PURE__ */ L(o, { id: "Payments" })
495
- }) }), /* @__PURE__ */ L(fe, { children: v.length ? /* @__PURE__ */ R(C, { children: [/* @__PURE__ */ L(te, { children: /* @__PURE__ */ R(S, {
496
- className: "hover:bg-transparent",
497
- children: [
498
- /* @__PURE__ */ L(y, {
499
- className: "text-muted-foreground",
500
- children: /* @__PURE__ */ L(o, { id: "Payment" })
501
- }),
502
- /* @__PURE__ */ L(y, {
503
- className: "text-muted-foreground",
504
- children: /* @__PURE__ */ L(o, { id: "Status" })
505
- }),
506
- /* @__PURE__ */ L(y, {
507
- className: "text-muted-foreground",
508
- children: /* @__PURE__ */ L(o, { id: "Kind" })
509
- }),
510
- /* @__PURE__ */ L(y, {
511
- className: "text-muted-foreground",
512
- children: /* @__PURE__ */ L(o, { id: "Amount" })
513
- }),
514
- /* @__PURE__ */ L(y, {
515
- className: "text-muted-foreground",
516
- children: /* @__PURE__ */ L(o, { id: "Created" })
517
- })
518
- ]
519
- }) }), /* @__PURE__ */ L(b, { children: v.map((e) => /* @__PURE__ */ R(S, { children: [
520
- /* @__PURE__ */ L(x, { children: /* @__PURE__ */ L(i, {
521
- className: "text-xs underline-offset-2 hover:underline",
522
- to: `/payments/${e.id}`,
523
- children: p(e.id, 13)
524
- }) }),
525
- /* @__PURE__ */ L(x, { children: /* @__PURE__ */ L(T, { status: e.status }) }),
526
- /* @__PURE__ */ L(x, { children: e.kind }),
527
- /* @__PURE__ */ L(x, { children: f(e.amount, e.currency) }),
528
- /* @__PURE__ */ L(x, { children: d(e.created_at) })
529
- ] }, e.id)) })] }) : /* @__PURE__ */ L("p", {
530
- className: "text-sm text-muted-foreground",
531
- children: /* @__PURE__ */ L(o, { id: "No payments recorded." })
532
- }) })] })
533
- ]
534
- });
535
- }
536
- function W({ id: t, customerId: n }) {
537
- let { toast: i, toastApiError: a, adminMutations: l } = r(), { text: u, id: d } = e(), [f, p] = N.useState(!1), m = I(), h = P(l.cancelSubscription(m, t, n)), g = V({ defaultValues: {
538
- reason: "",
539
- revokeAccess: !1
540
- } });
541
- return /* @__PURE__ */ R(me, { children: [/* @__PURE__ */ L(s, {
542
- variant: "destructive",
543
- size: "sm",
544
- onClick: () => p(!0),
545
- children: /* @__PURE__ */ L(o, { id: "Cancel subscription" })
546
- }), /* @__PURE__ */ L(M, {
547
- open: f,
548
- onOpenChange: (e) => {
549
- p(e), e || (g.reset(), h.reset());
550
- },
551
- title: u("Cancel subscription"),
552
- description: u("Terminal cancellation at the payment rail. This is a last resort. Dunning parks subscriptions as past_due without losing entitlements."),
553
- confirmationWord: "CANCEL",
554
- actionLabel: "Cancel subscription",
555
- onConfirm: async () => {
556
- try {
557
- await h.mutateAsync(g.state.values), i.success("Subscription canceled");
558
- } catch (e) {
559
- throw a(e, "Cancel subscription"), e;
560
- }
561
- },
562
- children: /* @__PURE__ */ R("div", {
563
- className: "grid gap-3",
564
- children: [/* @__PURE__ */ L(g.Field, {
565
- name: "reason",
566
- children: (e) => /* @__PURE__ */ R("div", {
567
- className: "grid gap-1.5",
568
- children: [/* @__PURE__ */ L(D, {
569
- htmlFor: d("cancel-reason"),
570
- children: /* @__PURE__ */ L(o, { id: "Reason" })
571
- }), /* @__PURE__ */ L(c, {
572
- id: d("cancel-reason"),
573
- value: e.state.value,
574
- onBlur: e.handleBlur,
575
- onChange: (t) => e.handleChange(t.target.value),
576
- placeholder: u("why is this being canceled?")
577
- })]
578
- })
579
- }), /* @__PURE__ */ L(g.Field, {
580
- name: "revokeAccess",
581
- children: (e) => /* @__PURE__ */ R("div", {
582
- className: "flex items-center gap-2",
583
- children: [/* @__PURE__ */ L(O, {
584
- id: d("cancel-revoke"),
585
- checked: e.state.value,
586
- onCheckedChange: e.handleChange
587
- }), /* @__PURE__ */ L(D, {
588
- htmlFor: d("cancel-revoke"),
589
- children: /* @__PURE__ */ L(o, { id: "Also revoke access immediately" })
590
- })]
591
- })
592
- })]
593
- })
594
- })] });
595
- }
596
- function G({ id: e, customerId: t }) {
597
- let { toast: n, toastApiError: i, adminMutations: a } = r(), o = I(), c = P(a.resumeSubscription(o, e, t));
598
- return /* @__PURE__ */ L(s, {
599
- variant: "outline",
600
- size: "sm",
601
- disabled: c.isPending,
602
- onClick: async () => {
603
- try {
604
- await c.mutateAsync(), n.success("Resume queued");
605
- } catch (e) {
606
- i(e, "Resume subscription");
607
- }
608
- },
609
- children: c.isPending ? "Queuing…" : "Resume"
610
- });
611
- }
612
- var K = "default";
613
- function be({ subscriptionId: t, customerId: n, rail: i, collectionPolicy: a }) {
614
- let { toast: c, toastApiError: l, adminMutations: d, adminQueries: f } = r(), { id: p, text: y } = e(), [b, te] = N.useState(!1), x = I(), S = P(d.changeSubscriptionPaymentMethod(x, t, n)), { data: C } = F(f.customerPaymentMethods(b ? n : void 0)), w = V({
615
- defaultValues: { paymentMethodId: "" },
616
- onSubmit: async ({ value: e }) => {
617
- try {
618
- await S.mutateAsync(e.paymentMethodId === K ? null : e.paymentMethodId), c.success("Payment method updated"), T(!1);
619
- } catch (e) {
620
- l(e, "Change payment method");
621
- }
622
- }
623
- }), T = (e) => {
624
- te(e), e || (w.reset(), S.reset());
625
- }, O = i !== "solana" && (a === "engine" || a === "nmi_schedule");
626
- return /* @__PURE__ */ R(se, {
627
- open: b,
628
- onOpenChange: T,
629
- children: [/* @__PURE__ */ L(oe, { render: /* @__PURE__ */ L(s, {
630
- variant: "outline",
631
- size: "sm",
632
- disabled: !O,
633
- title: O ? void 0 : `Payment-method change is not supported on ${i}`,
634
- children: /* @__PURE__ */ L(o, { id: "Change payment method" })
635
- }) }), /* @__PURE__ */ R(re, {
636
- className: ce,
637
- children: [/* @__PURE__ */ R(E, { children: [/* @__PURE__ */ L(ie, { children: /* @__PURE__ */ L(o, { id: "Change payment method" }) }), /* @__PURE__ */ L(ae, { children: /* @__PURE__ */ L(o, { id: "Points future renewals of this subscription at another of the customer&apos;s stored cards (same rail), or back at their default card for its currency." }) })] }), /* @__PURE__ */ R("form", {
638
- onSubmit: (e) => {
639
- e.preventDefault(), e.stopPropagation(), w.handleSubmit();
640
- },
641
- className: "grid gap-4",
642
- children: [/* @__PURE__ */ L(w.Field, {
643
- name: "paymentMethodId",
644
- validators: { onChange: ({ value: e }) => e ? void 0 : "Pick a stored payment method" },
645
- children: (e) => /* @__PURE__ */ R("div", {
646
- className: "grid gap-1.5",
647
- children: [
648
- /* @__PURE__ */ L(D, {
649
- htmlFor: p("subscription-payment-method"),
650
- children: /* @__PURE__ */ L(o, { id: "Payment method" })
651
- }),
652
- /* @__PURE__ */ R(v, {
653
- value: e.state.value,
654
- onValueChange: (t) => e.handleChange(t ?? ""),
655
- children: [/* @__PURE__ */ L(g, {
656
- className: "w-full",
657
- id: p("subscription-payment-method"),
658
- "aria-invalid": e.state.meta.errors.length > 0,
659
- children: /* @__PURE__ */ L(h, { placeholder: y("Pick a stored payment method") })
660
- }), /* @__PURE__ */ R(ee, { children: [/* @__PURE__ */ L(_, {
661
- value: K,
662
- children: /* @__PURE__ */ L(o, { id: "The customer&apos;s default card" })
663
- }), (C ?? []).filter((e) => e.rail === i).map((e) => /* @__PURE__ */ R(_, {
664
- value: e.id,
665
- children: [
666
- u(e.card),
667
- " (",
668
- e.rail,
669
- ")"
670
- ]
671
- }, e.id))] })]
672
- }),
673
- /* @__PURE__ */ L(m, { errors: e.state.meta.errors })
674
- ]
675
- })
676
- }), /* @__PURE__ */ L(ne, { children: /* @__PURE__ */ L(w.Subscribe, {
677
- selector: (e) => [
678
- e.values.paymentMethodId,
679
- e.canSubmit,
680
- e.isSubmitting
681
- ],
682
- children: ([e, t, n]) => /* @__PURE__ */ L(s, {
683
- type: "submit",
684
- disabled: !e || !t || n,
685
- children: n ? "Updating…" : "Update"
686
- })
687
- }) })]
688
- })]
689
- })]
690
- });
691
- }
692
- function xe({ change: e }) {
693
- let { adminQueries: t } = r(), { data: n } = F(t.price(e.price_id));
694
- return /* @__PURE__ */ R(w, {
695
- className: "bg-held-surface text-held",
696
- children: [
697
- e.source === "migration" ? "migrates" : "changes",
698
- /* @__PURE__ */ L(o, { id: " to" }),
699
- " ",
700
- n ? f(n.unit_amount, n.currency) : p(e.price_id, 9),
701
- " ",
702
- /* @__PURE__ */ L(o, { id: "at the first renewal from " }),
703
- d(e.effective_at)
704
- ]
705
- });
706
- }
707
- //#endregion
708
- export { U as SubscriptionDetailPage };
709
-
710
- //# sourceMappingURL=admin-detail-D2zcz_Xm.js.map