@openrails/billing-ui 0.274.0 → 0.276.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 (179) hide show
  1. package/README.md +10 -1
  2. package/dist/admin/console.d.ts +33 -0
  3. package/dist/admin/context.d.ts +14 -0
  4. package/dist/admin/index.d.ts +1 -0
  5. package/dist/admin/lib/api/endpoints.d.ts +2 -1
  6. package/dist/admin/lib/api/index.d.ts +1 -0
  7. package/dist/admin/lib/api/order-endpoints.d.ts +1 -0
  8. package/dist/admin/lib/api/types.d.ts +2 -12
  9. package/dist/admin/lib/format.d.ts +5 -1
  10. package/dist/admin/lib/order-queries.d.ts +3 -0
  11. package/dist/admin/lib/queries.d.ts +3 -0
  12. package/dist/admin/messages.d.ts +13 -8
  13. package/dist/admin/pages/dashboard/lib.d.ts +1 -0
  14. package/dist/admin/pages/imports/shared.d.ts +1 -0
  15. package/dist/admin/pages/subscriptions/change-subscription-dialog.d.ts +4 -7
  16. package/dist/admin/pages/subscriptions/subscription-change-options.d.ts +6 -15
  17. package/dist/{admin-attempts-Dzipkstg.js → admin-attempts-CP5CWyNR.js} +28 -28
  18. package/dist/{admin-attempts-Dzipkstg.js.map → admin-attempts-CP5CWyNR.js.map} +1 -1
  19. package/dist/{admin-auth-BCl_Tv3t.js → admin-auth-DlIOmwPo.js} +2 -2
  20. package/dist/{admin-auth-BCl_Tv3t.js.map → admin-auth-DlIOmwPo.js.map} +1 -1
  21. package/dist/{admin-badge-kmYQM9Ge.js → admin-badge-DR_8AhdC.js} +2 -2
  22. package/dist/{admin-badge-kmYQM9Ge.js.map → admin-badge-DR_8AhdC.js.map} +1 -1
  23. package/dist/{admin-button-Cq9ZfX4R.js → admin-button-DBzTD6By.js} +2 -2
  24. package/dist/{admin-button-Cq9ZfX4R.js.map → admin-button-DBzTD6By.js.map} +1 -1
  25. package/dist/{admin-capabilities-k5fQZhN9.js → admin-capabilities-CZdT1Pxe.js} +2 -2
  26. package/dist/{admin-capabilities-k5fQZhN9.js.map → admin-capabilities-CZdT1Pxe.js.map} +1 -1
  27. package/dist/{admin-card-C8k67jJv.js → admin-card-mZl4-s5d.js} +2 -2
  28. package/dist/{admin-card-C8k67jJv.js.map → admin-card-mZl4-s5d.js.map} +1 -1
  29. package/dist/{admin-catalog-CON-GwKL.js → admin-catalog-DpTjS0Yo.js} +38 -38
  30. package/dist/{admin-catalog-CON-GwKL.js.map → admin-catalog-DpTjS0Yo.js.map} +1 -1
  31. package/dist/{admin-cursor-pager-DqFruoNu.js → admin-cursor-pager-C-KjCIy9.js} +4 -4
  32. package/dist/{admin-cursor-pager-DqFruoNu.js.map → admin-cursor-pager-C-KjCIy9.js.map} +1 -1
  33. package/dist/{admin-customers-CWWOrcVR.js → admin-customers-BE3N839X.js} +12 -12
  34. package/dist/{admin-customers-CWWOrcVR.js.map → admin-customers-BE3N839X.js.map} +1 -1
  35. package/dist/{admin-dashboard-BiShWFk2.js → admin-dashboard-BxjkV15J.js} +25 -17
  36. package/dist/admin-dashboard-BxjkV15J.js.map +1 -0
  37. package/dist/{admin-data-table-CdsjYJh5.js → admin-data-table-D89AwWz_.js} +5 -5
  38. package/dist/{admin-data-table-CdsjYJh5.js.map → admin-data-table-D89AwWz_.js.map} +1 -1
  39. package/dist/{admin-detail-BWSC1aCH.js → admin-detail-BKe9xqPd.js} +41 -41
  40. package/dist/{admin-detail-BWSC1aCH.js.map → admin-detail-BKe9xqPd.js.map} +1 -1
  41. package/dist/admin-detail-C8lD7U2t.js +699 -0
  42. package/dist/admin-detail-C8lD7U2t.js.map +1 -0
  43. package/dist/{admin-detail-CMmhZQ2A.js → admin-detail-D6zD085K.js} +45 -37
  44. package/dist/admin-detail-D6zD085K.js.map +1 -0
  45. package/dist/{admin-detail-Cyuf_i9U.js → admin-detail-Ln56otK0.js} +40 -40
  46. package/dist/{admin-detail-Cyuf_i9U.js.map → admin-detail-Ln56otK0.js.map} +1 -1
  47. package/dist/{admin-detail-CiONe1Pt.js → admin-detail-P-UnNvXJ.js} +171 -171
  48. package/dist/admin-detail-P-UnNvXJ.js.map +1 -0
  49. package/dist/{admin-dialog-Ch7rTOCr.js → admin-dialog-Dn2FRJu4.js} +3 -3
  50. package/dist/{admin-dialog-Ch7rTOCr.js.map → admin-dialog-Dn2FRJu4.js.map} +1 -1
  51. package/dist/{admin-dropdown-menu-Bah3f8AZ.js → admin-dropdown-menu-DLUn6Uj3.js} +2 -2
  52. package/dist/{admin-dropdown-menu-Bah3f8AZ.js.map → admin-dropdown-menu-DLUn6Uj3.js.map} +1 -1
  53. package/dist/{admin-dunning-B2zgtrOo.js → admin-dunning-COaHzrmN.js} +2 -2
  54. package/dist/{admin-dunning-B2zgtrOo.js.map → admin-dunning-COaHzrmN.js.map} +1 -1
  55. package/dist/{admin-fact-card-Bt__Cd_U.js → admin-fact-card-DKvBnUXB.js} +2 -2
  56. package/dist/{admin-fact-card-Bt__Cd_U.js.map → admin-fact-card-DKvBnUXB.js.map} +1 -1
  57. package/dist/admin-format-BbiTCqUG.js +171 -0
  58. package/dist/admin-format-BbiTCqUG.js.map +1 -0
  59. package/dist/{admin-health-pzTO6_0v.js → admin-health-DmnI4e8K.js} +10 -10
  60. package/dist/{admin-health-pzTO6_0v.js.map → admin-health-DmnI4e8K.js.map} +1 -1
  61. package/dist/{admin-imports-tT5et8-V.js → admin-imports-C0aMP6sj.js} +18 -18
  62. package/dist/{admin-imports-tT5et8-V.js.map → admin-imports-C0aMP6sj.js.map} +1 -1
  63. package/dist/{admin-input-DvRZy_2a.js → admin-input-JKrQIGfD.js} +2 -2
  64. package/dist/{admin-input-DvRZy_2a.js.map → admin-input-JKrQIGfD.js.map} +1 -1
  65. package/dist/{admin-label-QZtWJGH-.js → admin-label-CHWsVIZC.js} +2 -2
  66. package/dist/{admin-label-QZtWJGH-.js.map → admin-label-CHWsVIZC.js.map} +1 -1
  67. package/dist/{admin-linked-table-row-6jkCKwMn.js → admin-linked-table-row-BMZYYsuk.js} +3 -3
  68. package/dist/{admin-linked-table-row-6jkCKwMn.js.map → admin-linked-table-row-BMZYYsuk.js.map} +1 -1
  69. package/dist/{admin-map-dialog-BV54mvMQ.js → admin-map-dialog-BHUGdCcv.js} +10 -10
  70. package/dist/{admin-map-dialog-BV54mvMQ.js.map → admin-map-dialog-BHUGdCcv.js.map} +1 -1
  71. package/dist/{admin-metering-Bv5EcX6M.js → admin-metering-CDqueHUh.js} +15 -15
  72. package/dist/{admin-metering-Bv5EcX6M.js.map → admin-metering-CDqueHUh.js.map} +1 -1
  73. package/dist/{admin-missing-record-BXqGFDt3.js → admin-missing-record-BPFs3MmO.js} +2 -2
  74. package/dist/{admin-missing-record-BXqGFDt3.js.map → admin-missing-record-BPFs3MmO.js.map} +1 -1
  75. package/dist/{admin-ops-h3RjpcNu.js → admin-ops-CL2kjDwi.js} +18 -15
  76. package/dist/admin-ops-CL2kjDwi.js.map +1 -0
  77. package/dist/admin-orders-C1Sf2qhc.js +192 -0
  78. package/dist/admin-orders-C1Sf2qhc.js.map +1 -0
  79. package/dist/admin-parked-a0tB5bhG.js +193 -0
  80. package/dist/admin-parked-a0tB5bhG.js.map +1 -0
  81. package/dist/admin-payments-DJcjwRA4.js +221 -0
  82. package/dist/admin-payments-DJcjwRA4.js.map +1 -0
  83. package/dist/{admin-price-detail-BjWYU5A-.js → admin-price-detail-BOmeWw15.js} +15 -15
  84. package/dist/{admin-price-detail-BjWYU5A-.js.map → admin-price-detail-BOmeWw15.js.map} +1 -1
  85. package/dist/{admin-price-format-BVUpDoSC.js → admin-price-format-CqOmHrIn.js} +2 -2
  86. package/dist/{admin-price-format-BVUpDoSC.js.map → admin-price-format-CqOmHrIn.js.map} +1 -1
  87. package/dist/{admin-price-wizard-CTbkbmYc.js → admin-price-wizard-B6s5OJeO.js} +9 -9
  88. package/dist/{admin-price-wizard-CTbkbmYc.js.map → admin-price-wizard-B6s5OJeO.js.map} +1 -1
  89. package/dist/{admin-proposals-Ci9Q8j7Y.js → admin-proposals-DVrl-ym4.js} +20 -20
  90. package/dist/{admin-proposals-Ci9Q8j7Y.js.map → admin-proposals-DVrl-ym4.js.map} +1 -1
  91. package/dist/admin-provider-prices-BVVogH7Q.js +241 -0
  92. package/dist/admin-provider-prices-BVVogH7Q.js.map +1 -0
  93. package/dist/{admin-range-picker-nfflPp21.js → admin-range-picker-C6BtSm2B.js} +5 -5
  94. package/dist/{admin-range-picker-nfflPp21.js.map → admin-range-picker-C6BtSm2B.js.map} +1 -1
  95. package/dist/{admin-records-CrTCorWH.js → admin-records-DKtcgN11.js} +19 -19
  96. package/dist/{admin-records-CrTCorWH.js.map → admin-records-DKtcgN11.js.map} +1 -1
  97. package/dist/{admin-reports-BO6wrvtw.js → admin-reports-CtPoiceH.js} +8 -8
  98. package/dist/{admin-reports-BO6wrvtw.js.map → admin-reports-CtPoiceH.js.map} +1 -1
  99. package/dist/{admin-select-DvfJ80Rg.js → admin-select-6Yuh5M1Q.js} +2 -2
  100. package/dist/{admin-select-DvfJ80Rg.js.map → admin-select-6Yuh5M1Q.js.map} +1 -1
  101. package/dist/{admin-settings-BOoTzhyf.js → admin-settings-DscHu4ww.js} +560 -550
  102. package/dist/admin-settings-DscHu4ww.js.map +1 -0
  103. package/dist/{admin-shared-BbGT_qTo.js → admin-shared-BywM-MMp.js} +13 -9
  104. package/dist/{admin-shared-BbGT_qTo.js.map → admin-shared-BywM-MMp.js.map} +1 -1
  105. package/dist/{admin-skeleton-B2a4ScVE.js → admin-skeleton-lndmw89u.js} +2 -2
  106. package/dist/{admin-skeleton-B2a4ScVE.js.map → admin-skeleton-lndmw89u.js.map} +1 -1
  107. package/dist/{admin-status-badge-Bp6cssXY.js → admin-status-badge-IL8ofZ_6.js} +3 -3
  108. package/dist/{admin-status-badge-Bp6cssXY.js.map → admin-status-badge-IL8ofZ_6.js.map} +1 -1
  109. package/dist/{admin-subscriptions-D9JmoicC.js → admin-subscriptions-Cd5CGrue.js} +83 -87
  110. package/dist/admin-subscriptions-Cd5CGrue.js.map +1 -0
  111. package/dist/{admin-switch-DBBxJRZP.js → admin-switch-DpwQSzEm.js} +2 -2
  112. package/dist/{admin-switch-DBBxJRZP.js.map → admin-switch-DpwQSzEm.js.map} +1 -1
  113. package/dist/{admin-table-CPDoVfK4.js → admin-table-D-GdGM1m.js} +2 -2
  114. package/dist/{admin-table-CPDoVfK4.js.map → admin-table-D-GdGM1m.js.map} +1 -1
  115. package/dist/admin-tabs-B--1flzO.js +158 -0
  116. package/dist/admin-tabs-B--1flzO.js.map +1 -0
  117. package/dist/{admin-textarea-d3fu_waS.js → admin-textarea-xsp5V9xM.js} +2 -2
  118. package/dist/{admin-textarea-d3fu_waS.js.map → admin-textarea-xsp5V9xM.js.map} +1 -1
  119. package/dist/{admin-typed-confirm-dialog-BVklYjFo.js → admin-typed-confirm-dialog-NiEDwX_0.js} +6 -6
  120. package/dist/{admin-typed-confirm-dialog-BVklYjFo.js.map → admin-typed-confirm-dialog-NiEDwX_0.js.map} +1 -1
  121. package/dist/{admin-utils-DTT53IpS.js → admin-utils-wuPUD0uh.js} +152 -137
  122. package/dist/admin-utils-wuPUD0uh.js.map +1 -0
  123. package/dist/{admin-widget-viz-Exsqz3Dw.js → admin-widget-viz-kHHVmDEx.js} +215 -187
  124. package/dist/admin-widget-viz-kHHVmDEx.js.map +1 -0
  125. package/dist/admin.css +1 -1
  126. package/dist/admin.js +581 -434
  127. package/dist/admin.js.map +1 -1
  128. package/dist/client/generated/routes.d.ts +17 -0
  129. package/dist/client/generated/wire.d.ts +4 -0
  130. package/dist/client/types.d.ts +6 -0
  131. package/dist/{client-BYgnI6_h.js → client-ctrbivyN.js} +3 -2
  132. package/dist/client-ctrbivyN.js.map +1 -0
  133. package/dist/client.js +1 -1
  134. package/dist/{hooks-t2tSrCpa.js → hooks-KpTetx6F.js} +2 -2
  135. package/dist/{hooks-t2tSrCpa.js.map → hooks-KpTetx6F.js.map} +1 -1
  136. package/dist/index.js +750 -711
  137. package/dist/index.js.map +1 -1
  138. package/dist/lib/card-brands.d.ts +1 -0
  139. package/dist/locales/de.js +3 -0
  140. package/dist/locales/de.js.map +1 -1
  141. package/dist/locales/en.d.ts +3 -0
  142. package/dist/locales/en.js +3 -0
  143. package/dist/locales/en.js.map +1 -1
  144. package/dist/locales/es.js +3 -0
  145. package/dist/locales/es.js.map +1 -1
  146. package/dist/locales/ja.js +3 -0
  147. package/dist/locales/ja.js.map +1 -1
  148. package/dist/locales/ko.js +3 -0
  149. package/dist/locales/ko.js.map +1 -1
  150. package/dist/locales/zh.js +3 -0
  151. package/dist/locales/zh.js.map +1 -1
  152. package/dist/react.js +1 -1
  153. package/dist/styles.css +1 -1
  154. package/package.json +6 -2
  155. package/dist/admin-customer-search-CJHB80rg.js +0 -117
  156. package/dist/admin-customer-search-CJHB80rg.js.map +0 -1
  157. package/dist/admin-dashboard-BiShWFk2.js.map +0 -1
  158. package/dist/admin-detail-CKRtK43V.js +0 -728
  159. package/dist/admin-detail-CKRtK43V.js.map +0 -1
  160. package/dist/admin-detail-CMmhZQ2A.js.map +0 -1
  161. package/dist/admin-detail-CiONe1Pt.js.map +0 -1
  162. package/dist/admin-format-DoohJ7Fg.js +0 -136
  163. package/dist/admin-format-DoohJ7Fg.js.map +0 -1
  164. package/dist/admin-ops-h3RjpcNu.js.map +0 -1
  165. package/dist/admin-orders-DYxPiuTl.js +0 -192
  166. package/dist/admin-orders-DYxPiuTl.js.map +0 -1
  167. package/dist/admin-parked-ClKA60d5.js +0 -193
  168. package/dist/admin-parked-ClKA60d5.js.map +0 -1
  169. package/dist/admin-payments-BlIuy3wL.js +0 -220
  170. package/dist/admin-payments-BlIuy3wL.js.map +0 -1
  171. package/dist/admin-provider-prices-B6Ayq-eN.js +0 -246
  172. package/dist/admin-provider-prices-B6Ayq-eN.js.map +0 -1
  173. package/dist/admin-settings-BOoTzhyf.js.map +0 -1
  174. package/dist/admin-subscriptions-D9JmoicC.js.map +0 -1
  175. package/dist/admin-tabs-DDUv3kiu.js +0 -46
  176. package/dist/admin-tabs-DDUv3kiu.js.map +0 -1
  177. package/dist/admin-utils-DTT53IpS.js.map +0 -1
  178. package/dist/admin-widget-viz-Exsqz3Dw.js.map +0 -1
  179. package/dist/client-BYgnI6_h.js.map +0 -1
@@ -1,728 +0,0 @@
1
- import { E as e, O as t, c as n, p as r, r as i, s as a, w as o } from "./admin-utils-DTT53IpS.js";
2
- import { t as s } from "./admin-button-Cq9ZfX4R.js";
3
- import { t as c } from "./admin-input-DvRZy_2a.js";
4
- import { a as l } from "./admin-capabilities-k5fQZhN9.js";
5
- import { i as u, o as d, r as f, s as p, u as m } from "./admin-format-DoohJ7Fg.js";
6
- import { t as h } from "./admin-badge-kmYQM9Ge.js";
7
- import { t as g } from "./admin-status-badge-Bp6cssXY.js";
8
- import { t as _ } from "./admin-form-field-errors-hbUMIriS.js";
9
- import { a as v, i as y, n as b, r as x, t as S } from "./admin-select-DvfJ80Rg.js";
10
- import { a as C, n as w, o as T, r as E, s as D, t as O } from "./admin-table-CPDoVfK4.js";
11
- import { a as k, i as ee, n as te, o as ne, r as re, s as ie, t as ae } from "./admin-dialog-Ch7rTOCr.js";
12
- import { t as A } from "./admin-label-QZtWJGH-.js";
13
- import { i as oe, r as se } from "./admin-dialog-width-CC7QHT1p.js";
14
- import { n as j } from "./admin-price-format-BVUpDoSC.js";
15
- import { a as ce, o as le, r as ue, t as de } from "./admin-card-C8k67jJv.js";
16
- import { t as M } from "./admin-fact-card-Bt__Cd_U.js";
17
- import { t as N } from "./admin-tile-grids-CzGpidd9.js";
18
- import { t as fe } from "./admin-dunning-B2zgtrOo.js";
19
- import { t as pe } from "./admin-missing-record-BXqGFDt3.js";
20
- import { t as P } from "./admin-typed-confirm-dialog-BVklYjFo.js";
21
- import * as F from "react";
22
- import { useMutation as I, useQuery as L, useQueryClient as R } from "@tanstack/react-query";
23
- import { Fragment as z, jsx as B, jsxs as V } from "react/jsx-runtime";
24
- import { HugeiconsIcon as H } from "@hugeicons/react";
25
- import { ArrowLeft01Icon as me } from "@hugeicons/core-free-icons";
26
- import { useForm as U, useStore as W } from "@tanstack/react-form";
27
- //#region src/admin/pages/subscriptions/subscription-change-options.ts
28
- function he(e) {
29
- let t = e.price, n = `${p(t.unit_amount, t.currency)}${t.quantity ? " per seat" : ""}`;
30
- return [
31
- e.product.display_name,
32
- e.direction,
33
- `${n} ${j(t)}`,
34
- t.key
35
- ].join(" · ");
36
- }
37
- function ge(e, t) {
38
- let n = e.quantity;
39
- return n ? t !== null && t >= n.min && t <= n.max ? t : n.min : null;
40
- }
41
- function _e({ rail: e, status: t, collectionPolicy: n, scheduledChange: r }) {
42
- if (t !== "active" && t !== "past_due") return "Only active or past-due subscriptions can change";
43
- if (r && n !== "engine") return "Its provider already bills a scheduled change";
44
- if (e === "ccbill") return "CCBill changes require customer self-service";
45
- if (e === "solana") return "Solana changes require the customer's wallet signature";
46
- }
47
- function ve({ currentProduct: e, currentPrice: t, currentCurrency: n, products: r, prices: i, scheduledChange: a }) {
48
- let o = e && t && (t.quantity || a) ? [{
49
- direction: "current",
50
- price: t,
51
- product: e
52
- }] : [], s = e?.tier_group?.trim(), c = n?.trim().toLowerCase();
53
- if (!e || !s || !c || a?.source === "migration") return o;
54
- let l = new Map(r.filter((t) => !t.archived && t.id !== e.id && t.tier_group?.trim() === s).map((e) => [e.id, e]));
55
- return o.concat(i.flatMap((t) => {
56
- let n = l.get(t.product_id);
57
- return !n || t.archived || !t.billing_interval_hours || t.currency.trim().toLowerCase() !== c ? [] : [{
58
- direction: n.tier_rank < e.tier_rank ? "downgrade" : "upgrade",
59
- price: t,
60
- product: n
61
- }];
62
- }).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)));
63
- }
64
- //#endregion
65
- //#region src/admin/pages/subscriptions/change-subscription-dialog.tsx
66
- function G(e) {
67
- let { selectedMerchant: t } = r();
68
- return /* @__PURE__ */ B(K, { ...e }, `${t() ?? ""}:${e.subscriptionId}`);
69
- }
70
- function K({ subscriptionId: n, customerId: i, productId: a, priceId: l, quantity: u, currency: f, collectionPolicy: m, scheduledChange: g, rail: _, status: C }) {
71
- let { toast: w, toastApiError: T, adminMutations: E, adminQueries: D } = r(), { id: O, text: se } = t(), [j, ce] = F.useState(!1), [le, ue] = F.useState(""), [de, M] = F.useState(""), [N, fe] = F.useState(""), [pe, P] = F.useState(""), z = F.useRef(/* @__PURE__ */ new Map()), H = F.useRef(0);
72
- F.useEffect(() => () => {
73
- H.current++;
74
- }, []);
75
- let me = R(), U = I(E.previewSubscriptionChange(n)), W = I(E.changeSubscription(me, n, i)), G = L({
76
- ...D.allProducts({ errorAction: "Load subscription plans" }),
77
- enabled: j
78
- }), K = L({
79
- ...D.allPrices({ errorAction: "Load subscription prices" }),
80
- enabled: j
81
- }), ye = G.data?.data ?? [], be = K.data?.data ?? [], xe = ye.find((e) => e.id === a), Se = be.find((e) => e.id === l), q = ve({
82
- currentProduct: xe,
83
- currentPrice: Se,
84
- currentCurrency: f ?? Se?.currency,
85
- products: ye,
86
- prices: be,
87
- scheduledChange: g
88
- }), J = q.find((e) => e.price.id === le), Y = J?.price.quantity, X = Number(de), Ce = !Y || Number.isInteger(X) && X >= Y.min && X <= Y.max, Z = J && Ce ? {
89
- price_id: J.price.id,
90
- ...Y ? { quantity: X } : {}
91
- } : void 0, we = J?.direction === "current" && !g && (!Y || X === u), Q = Z ? JSON.stringify(Z) : "", $ = Q && pe === Q ? U.data : void 0, Te = _e({
92
- rail: _,
93
- status: C,
94
- collectionPolicy: m,
95
- scheduledChange: g
96
- }), Ee = (e) => {
97
- H.current++, ce(e);
98
- }, De = (e) => {
99
- H.current++;
100
- let t = q.find((t) => t.price.id === e)?.price;
101
- ue(e ?? ""), M(String(t ? ge(t, u) ?? "" : "")), P(""), U.reset(), W.reset();
102
- }, Oe = (e) => {
103
- H.current++, M(e), P(""), U.reset(), W.reset();
104
- }, ke = U.error instanceof Error ? U.error.message : "", Ae = W.error instanceof Error ? W.error.message : "", je = W.data?.message, Me = W.data?.next_action?.url ?? void 0;
105
- return /* @__PURE__ */ V(ae, {
106
- open: j,
107
- onOpenChange: Ee,
108
- children: [/* @__PURE__ */ B(ie, { render: /* @__PURE__ */ B(s, {
109
- variant: "outline",
110
- size: "sm",
111
- disabled: !!Te && !W.variables,
112
- title: Te,
113
- children: /* @__PURE__ */ B(e, { id: "Change subscription" })
114
- }) }), /* @__PURE__ */ V(te, {
115
- className: oe,
116
- children: [
117
- /* @__PURE__ */ V(k, { children: [/* @__PURE__ */ B(ne, { children: /* @__PURE__ */ B(e, { id: "Change subscription" }) }), /* @__PURE__ */ B(re, { children: /* @__PURE__ */ B(e, { 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." }) })] }),
118
- /* @__PURE__ */ V("div", {
119
- className: "grid gap-5",
120
- children: [
121
- /* @__PURE__ */ V("div", {
122
- className: "grid gap-1.5",
123
- children: [
124
- /* @__PURE__ */ B(A, {
125
- htmlFor: O("subscription-tier"),
126
- children: /* @__PURE__ */ B(e, { id: "New plan" })
127
- }),
128
- /* @__PURE__ */ V(S, {
129
- value: le,
130
- onValueChange: De,
131
- children: [/* @__PURE__ */ B(y, {
132
- id: O("subscription-tier"),
133
- className: "w-full",
134
- disabled: G.isPending || K.isPending,
135
- children: /* @__PURE__ */ B(v, { placeholder: G.isPending || K.isPending ? "Loading plans…" : "Choose a plan" })
136
- }), /* @__PURE__ */ B(b, { children: q.map((e) => /* @__PURE__ */ B(x, {
137
- value: e.price.id,
138
- children: he(e)
139
- }, e.price.id)) })]
140
- }),
141
- !G.isPending && !K.isPending && !G.isError && !K.isError && q.length === 0 && /* @__PURE__ */ B("p", {
142
- className: "text-xs text-muted-foreground",
143
- children: /* @__PURE__ */ B(e, { id: "No eligible recurring plans share this tier group and currency." })
144
- }),
145
- (G.isError || K.isError) && /* @__PURE__ */ B("p", {
146
- className: "text-xs text-destructive",
147
- role: "alert",
148
- children: /* @__PURE__ */ B(e, { id: "Could not load the available plans." })
149
- })
150
- ]
151
- }),
152
- Y && /* @__PURE__ */ V("div", {
153
- className: "grid gap-1.5",
154
- children: [
155
- /* @__PURE__ */ B(A, {
156
- htmlFor: O("subscription-seats"),
157
- children: /* @__PURE__ */ B(e, { id: "Seats" })
158
- }),
159
- /* @__PURE__ */ B(c, {
160
- id: O("subscription-seats"),
161
- type: "number",
162
- inputMode: "numeric",
163
- min: Y.min,
164
- max: Y.max,
165
- value: de,
166
- onChange: (e) => Oe(e.target.value)
167
- }),
168
- /* @__PURE__ */ V("p", {
169
- className: "text-xs text-muted-foreground",
170
- children: [
171
- Y.min,
172
- /* @__PURE__ */ B(e, { id: " to " }),
173
- Y.max,
174
- /* @__PURE__ */ B(e, { id: " seats." })
175
- ]
176
- })
177
- ]
178
- }),
179
- /* @__PURE__ */ V("div", {
180
- className: "grid gap-1.5",
181
- children: [
182
- /* @__PURE__ */ B(A, {
183
- htmlFor: O("subscription-change-reason"),
184
- children: /* @__PURE__ */ B(e, { id: "Reason" })
185
- }),
186
- /* @__PURE__ */ B(c, {
187
- id: O("subscription-change-reason"),
188
- value: N,
189
- maxLength: 500,
190
- placeholder: se("What the customer asked for"),
191
- onChange: (e) => fe(e.target.value)
192
- }),
193
- /* @__PURE__ */ B("p", {
194
- className: "text-xs text-muted-foreground",
195
- children: /* @__PURE__ */ B(e, { id: "Kept with the scheduled change." })
196
- })
197
- ]
198
- }),
199
- $ && J && /* @__PURE__ */ V("div", {
200
- className: "grid gap-3",
201
- "aria-live": "polite",
202
- children: [
203
- /* @__PURE__ */ V("div", {
204
- className: "flex items-center justify-between gap-4",
205
- children: [/* @__PURE__ */ B("span", {
206
- className: "text-sm font-medium",
207
- children: /* @__PURE__ */ B(e, { id: "Review" })
208
- }), /* @__PURE__ */ B(h, {
209
- variant: "secondary",
210
- children: $.effective === "now" ? "Immediate" : "At renewal"
211
- })]
212
- }),
213
- /* @__PURE__ */ V("dl", {
214
- className: "grid grid-cols-2 gap-x-8 gap-y-3 border-y py-4 text-sm",
215
- children: [
216
- $.quantity !== null && /* @__PURE__ */ V("div", {
217
- className: "grid gap-1",
218
- children: [/* @__PURE__ */ B("dt", {
219
- className: "text-xs text-muted-foreground",
220
- children: /* @__PURE__ */ B(e, { id: "Seats" })
221
- }), /* @__PURE__ */ B("dd", {
222
- className: "font-medium tabular-nums",
223
- children: $.quantity
224
- })]
225
- }),
226
- /* @__PURE__ */ V("div", {
227
- className: "grid gap-1",
228
- children: [/* @__PURE__ */ B("dt", {
229
- className: "text-xs text-muted-foreground",
230
- children: /* @__PURE__ */ B(e, { id: "Due now" })
231
- }), /* @__PURE__ */ B("dd", {
232
- className: "font-medium tabular-nums",
233
- children: p($.amount_due_now, $.currency)
234
- })]
235
- }),
236
- /* @__PURE__ */ V("div", {
237
- className: "grid gap-1",
238
- children: [/* @__PURE__ */ B("dt", {
239
- className: "text-xs text-muted-foreground",
240
- children: /* @__PURE__ */ B(e, { id: "Next charge" })
241
- }), /* @__PURE__ */ B("dd", {
242
- className: "font-medium tabular-nums",
243
- children: p($.next_charge_amount, $.currency)
244
- })]
245
- }),
246
- /* @__PURE__ */ V("div", {
247
- className: "grid gap-1",
248
- children: [/* @__PURE__ */ B("dt", {
249
- className: "text-xs text-muted-foreground",
250
- children: /* @__PURE__ */ B(e, { id: "Effective" })
251
- }), /* @__PURE__ */ B("dd", {
252
- className: "font-medium",
253
- children: $.effective === "now" ? "Immediately" : d($.next_charge_date)
254
- })]
255
- }),
256
- /* @__PURE__ */ V("div", {
257
- className: "grid gap-1",
258
- children: [/* @__PURE__ */ B("dt", {
259
- className: "text-xs text-muted-foreground",
260
- children: /* @__PURE__ */ B(e, { id: "Next billing date" })
261
- }), /* @__PURE__ */ B("dd", {
262
- className: "font-medium tabular-nums",
263
- children: d($.next_charge_date)
264
- })]
265
- })
266
- ]
267
- }),
268
- $.is_estimate && /* @__PURE__ */ B("p", {
269
- className: "text-xs text-muted-foreground",
270
- children: /* @__PURE__ */ B(e, { id: "The payment provider calculates the final prorated amount." })
271
- })
272
- ]
273
- }),
274
- (ke || Ae) && /* @__PURE__ */ B("p", {
275
- className: "text-sm text-destructive",
276
- role: "alert",
277
- children: Ae || ke
278
- }),
279
- W.data && W.data.status !== "succeeded" && /* @__PURE__ */ V("div", {
280
- className: "grid gap-2 rounded-lg bg-muted px-3 py-2.5 text-sm",
281
- "aria-live": "polite",
282
- children: [/* @__PURE__ */ B("p", { children: je ?? "This change needs another step." }), Me && /* @__PURE__ */ B("a", {
283
- href: Me,
284
- target: "_blank",
285
- rel: "noreferrer",
286
- className: "w-fit font-medium text-primary underline underline-offset-4",
287
- children: /* @__PURE__ */ B(e, { id: "Continue with payment provider" })
288
- })]
289
- })
290
- ]
291
- }),
292
- /* @__PURE__ */ V(ee, { children: [/* @__PURE__ */ B(s, {
293
- type: "button",
294
- variant: "outline",
295
- onClick: () => Ee(!1),
296
- children: /* @__PURE__ */ B(e, { id: "Cancel" })
297
- }), $ ? /* @__PURE__ */ B(s, {
298
- type: "button",
299
- disabled: W.isPending || !N.trim() || !!W.data && W.data?.status !== "processing",
300
- onClick: async () => {
301
- if (!Z) return;
302
- let e = H.current, t = z.current.get(Q) ?? crypto.randomUUID();
303
- z.current.set(Q, t);
304
- let n = () => {
305
- z.current.get(Q) === t && z.current.delete(Q);
306
- };
307
- try {
308
- let r = await W.mutateAsync({
309
- change: {
310
- ...Z,
311
- reason: N.trim()
312
- },
313
- idempotencyKey: t
314
- });
315
- if ((r.status === "succeeded" || r.status === "blocked") && n(), H.current !== e) return;
316
- r.status === "succeeded" && (w.success(r.effective === "now" ? "Subscription changed" : "Change scheduled for the next renewal"), Ee(!1), ue(""), M(""), fe(""), P(""), U.reset(), W.reset()), r.status === "processing" && w.info("The provider is still confirming this change. Check again to read the result.");
317
- } catch (t) {
318
- t instanceof o && (t.status === 402 || t.status === 409 && (t.code === "subscription_change_refused" || t.code === "subscription_change_idempotency_conflict")) && n(), H.current === e && T(t, "Change subscription");
319
- }
320
- },
321
- children: W.isPending ? "Applying…" : W.data ? W.data.status === "processing" ? "Check result" : W.data.status === "blocked" ? "Change blocked" : "Action required" : "Confirm change"
322
- }) : /* @__PURE__ */ B(s, {
323
- type: "button",
324
- disabled: !Z || we || U.isPending,
325
- onClick: async () => {
326
- if (!Z) return;
327
- let e = H.current;
328
- try {
329
- if (await U.mutateAsync(Z), H.current !== e) return;
330
- P(Q);
331
- } catch (t) {
332
- H.current === e && T(t, "Preview subscription change");
333
- }
334
- },
335
- children: U.isPending ? "Reviewing…" : "Review change"
336
- })] })
337
- ]
338
- })]
339
- });
340
- }
341
- //#endregion
342
- //#region src/admin/pages/subscriptions/detail.tsx
343
- var ye = (e) => new Date(e).toLocaleDateString(void 0, { dateStyle: "medium" });
344
- function be() {
345
- let { text: o } = t(), { adminQueries: c } = r(), u = l(), { id: _ = "" } = n(), v = a(), { data: y, isPending: b, error: x } = L(c.subscription(_)), { data: S } = L(c.payments({ subscription_id: _ }, 20)), k = S?.data ?? [], { data: ee } = L(c.customer(y?.customer_id ?? ""));
346
- if (b) return /* @__PURE__ */ B("p", {
347
- className: "text-sm text-muted-foreground",
348
- children: /* @__PURE__ */ B(e, { id: "Loading…" })
349
- });
350
- if (!y) return /* @__PURE__ */ B(pe, {
351
- title: "Subscription not found",
352
- error: x,
353
- back: "/subscriptions",
354
- backLabel: "Subscriptions"
355
- });
356
- let te = y.status === "active" || y.status === "past_due" || y.status === "awaiting_method" || y.status === "unverified", ne = y.status === "active" || y.status === "past_due", re = ne || y.status === "awaiting_method", ie = y.collection_policy === "engine" ? (y.rail === "nmi" || y.rail === "stripe") && (re || y.resumable) : y.rail === "nmi" && re, ae = ee ? f(ee) : void 0, A = y.product?.display_name;
357
- return /* @__PURE__ */ V("div", {
358
- className: "flex flex-col gap-4",
359
- children: [
360
- /* @__PURE__ */ V("div", {
361
- className: "flex flex-wrap items-center gap-3",
362
- children: [
363
- /* @__PURE__ */ B(s, {
364
- variant: "ghost",
365
- size: "icon",
366
- onClick: () => v(-1),
367
- "aria-label": o("Back"),
368
- children: /* @__PURE__ */ B(H, {
369
- icon: me,
370
- className: "size-4"
371
- })
372
- }),
373
- /* @__PURE__ */ V("div", {
374
- className: "min-w-0",
375
- children: [/* @__PURE__ */ V("h1", {
376
- className: "flex flex-wrap items-center gap-2 text-2xl font-semibold tracking-tight",
377
- children: [A ?? o("Subscription"), /* @__PURE__ */ B(g, { status: y.status })]
378
- }), /* @__PURE__ */ V("p", {
379
- className: "text-xs [overflow-wrap:anywhere] text-muted-foreground",
380
- children: [
381
- y.id,
382
- " · ",
383
- y.rail,
384
- y.rail_subscription_id ? ` · ${y.rail_subscription_id}` : ""
385
- ]
386
- })]
387
- }),
388
- /* @__PURE__ */ V("div", {
389
- className: "flex flex-wrap gap-2 sm:ml-auto",
390
- children: [
391
- u && y.resumable && /* @__PURE__ */ B(q, {
392
- id: y.id,
393
- customerId: y.customer_id
394
- }),
395
- u && ne && /* @__PURE__ */ B(G, {
396
- subscriptionId: y.id,
397
- customerId: y.customer_id,
398
- productId: y.product_id,
399
- priceId: y.price_id,
400
- quantity: y.quantity,
401
- currency: y.price?.currency,
402
- collectionPolicy: y.collection_policy,
403
- scheduledChange: y.scheduled_change,
404
- rail: y.rail,
405
- status: y.status
406
- }),
407
- u && ie && /* @__PURE__ */ B(Y, {
408
- subscriptionId: y.id,
409
- customerId: y.customer_id,
410
- rail: y.rail
411
- }),
412
- u && te && /* @__PURE__ */ B(Se, {
413
- id: y.id,
414
- customerId: y.customer_id,
415
- customer: ae,
416
- plan: A,
417
- periodEnd: y.current_period_ends_at
418
- })
419
- ]
420
- })
421
- ]
422
- }),
423
- /* @__PURE__ */ V("div", {
424
- className: N,
425
- children: [
426
- /* @__PURE__ */ B(M, {
427
- label: o("Customer"),
428
- children: y.customer_id ? /* @__PURE__ */ B(i, {
429
- className: "text-xs underline-offset-2 hover:underline",
430
- to: `/customers/${y.customer_id}`,
431
- children: ae ?? m(y.customer_id, 13)
432
- }) : "—"
433
- }),
434
- /* @__PURE__ */ B(M, {
435
- label: o("Started"),
436
- children: d(y.started_at)
437
- }),
438
- /* @__PURE__ */ V(M, {
439
- label: o("Current period"),
440
- children: [
441
- d(y.current_period_starts_at),
442
- " →",
443
- " ",
444
- d(y.current_period_ends_at)
445
- ]
446
- }),
447
- /* @__PURE__ */ B(M, {
448
- label: o("Price"),
449
- children: /* @__PURE__ */ V("div", {
450
- className: "flex flex-col gap-1",
451
- children: [
452
- /* @__PURE__ */ V("span", {
453
- className: "flex items-center gap-2",
454
- children: [y.price?.unit_amount !== void 0 && y.price?.currency ? /* @__PURE__ */ B(i, {
455
- className: "underline-offset-2 hover:underline",
456
- to: `/catalog/prices/${encodeURIComponent(y.price_id)}`,
457
- children: p(y.price.unit_amount, y.price.currency)
458
- }) : /* @__PURE__ */ B(i, {
459
- className: "text-xs underline-offset-2 hover:underline",
460
- to: `/catalog/prices/${encodeURIComponent(y.price_id)}`,
461
- children: m(y.price_id ?? "—", 13)
462
- }), y.price?.archived && /* @__PURE__ */ B(h, {
463
- variant: "secondary",
464
- title: o("Pinned to an archived (prior) version"),
465
- children: /* @__PURE__ */ B(e, { id: "prior version" })
466
- })]
467
- }),
468
- y.price?.key && /* @__PURE__ */ B("span", {
469
- className: "text-xs text-muted-foreground",
470
- children: y.price.key
471
- }),
472
- y.scheduled_change && /* @__PURE__ */ B(X, { change: y.scheduled_change })
473
- ]
474
- })
475
- }),
476
- y.quantity !== null && /* @__PURE__ */ V(M, {
477
- label: o("Seats"),
478
- children: [y.quantity, y.scheduled_change?.quantity != null && ` → ${y.scheduled_change.quantity} at renewal`]
479
- }),
480
- /* @__PURE__ */ B(M, {
481
- label: o("Dunning"),
482
- children: y.dunning ? fe(y.dunning) : "—"
483
- }),
484
- /* @__PURE__ */ B(M, {
485
- label: y.dunning?.waiting_for_new_card ? "Card deadline" : "Final retry",
486
- children: d(y.dunning?.final_retry_at)
487
- }),
488
- /* @__PURE__ */ B(M, {
489
- label: o("Last decline"),
490
- children: y.dunning?.last_failure_reason ?? "—"
491
- }),
492
- /* @__PURE__ */ B(M, {
493
- label: o("Canceled"),
494
- children: y.canceled_at ? /* @__PURE__ */ V(z, { children: [d(y.canceled_at), y.cancel_type && /* @__PURE__ */ B("span", {
495
- className: "block text-xs text-muted-foreground",
496
- children: o(xe[y.cancel_type] ?? y.cancel_type)
497
- })] }) : "—"
498
- })
499
- ]
500
- }),
501
- /* @__PURE__ */ V(de, { children: [/* @__PURE__ */ B(ce, { children: /* @__PURE__ */ B(le, {
502
- className: "text-sm",
503
- children: /* @__PURE__ */ B(e, { id: "Payments" })
504
- }) }), /* @__PURE__ */ B(ue, { children: k.length ? /* @__PURE__ */ V(O, { children: [/* @__PURE__ */ B(T, { children: /* @__PURE__ */ V(D, {
505
- className: "hover:bg-transparent",
506
- children: [
507
- /* @__PURE__ */ B(C, {
508
- className: "text-muted-foreground",
509
- children: /* @__PURE__ */ B(e, { id: "Payment" })
510
- }),
511
- /* @__PURE__ */ B(C, {
512
- className: "text-muted-foreground",
513
- children: /* @__PURE__ */ B(e, { id: "Status" })
514
- }),
515
- /* @__PURE__ */ B(C, {
516
- className: "text-muted-foreground @max-[36rem]/page:hidden",
517
- children: /* @__PURE__ */ B(e, { id: "Kind" })
518
- }),
519
- /* @__PURE__ */ B(C, {
520
- className: "text-muted-foreground",
521
- children: /* @__PURE__ */ B(e, { id: "Amount" })
522
- }),
523
- /* @__PURE__ */ B(C, {
524
- className: "text-muted-foreground @max-[36rem]/page:hidden",
525
- children: /* @__PURE__ */ B(e, { id: "Created" })
526
- })
527
- ]
528
- }) }), /* @__PURE__ */ B(w, { children: k.map((e) => /* @__PURE__ */ V(D, { children: [
529
- /* @__PURE__ */ B(E, { children: /* @__PURE__ */ B(i, {
530
- className: "text-xs underline-offset-2 hover:underline",
531
- to: `/payments/${e.id}`,
532
- children: m(e.id, 13)
533
- }) }),
534
- /* @__PURE__ */ B(E, { children: /* @__PURE__ */ B(g, { status: e.status }) }),
535
- /* @__PURE__ */ B(E, {
536
- className: "@max-[36rem]/page:hidden",
537
- children: e.kind
538
- }),
539
- /* @__PURE__ */ B(E, { children: p(e.amount, e.currency) }),
540
- /* @__PURE__ */ B(E, {
541
- className: "@max-[36rem]/page:hidden",
542
- children: d(e.created_at)
543
- })
544
- ] }, e.id)) })] }) : /* @__PURE__ */ B("p", {
545
- className: "text-sm text-muted-foreground",
546
- children: /* @__PURE__ */ B(e, { id: "No payments recorded." })
547
- }) })] })
548
- ]
549
- });
550
- }
551
- var xe = {
552
- user: "By the customer",
553
- merchant: "By staff",
554
- expired: "Renewal payment failed",
555
- chargeback: "After a chargeback",
556
- upgrade: "Replaced by an upgrade"
557
- };
558
- function Se({ id: n, customerId: i, customer: a, plan: o, periodEnd: l }) {
559
- let { toast: u, toastApiError: d, adminMutations: f } = r(), { text: p, id: m } = t(), [h, g] = F.useState(!1), _ = R(), v = I(f.cancelSubscription(_, n, i)), y = U({ defaultValues: {
560
- reason: "",
561
- revokeAccess: !1
562
- } }), b = W(y.store, (e) => e.values.revokeAccess), x = a ?? p("The customer"), S = o ?? p("their access");
563
- return /* @__PURE__ */ V(z, { children: [/* @__PURE__ */ B(s, {
564
- variant: "destructive",
565
- size: "sm",
566
- onClick: () => g(!0),
567
- children: /* @__PURE__ */ B(e, { id: "Cancel membership" })
568
- }), /* @__PURE__ */ B(P, {
569
- open: h,
570
- onOpenChange: (e) => {
571
- g(e), e || (y.reset(), v.reset());
572
- },
573
- title: p("Cancel this membership?"),
574
- description: `${p("Renewal stops now and can't be restarted from here.")} ${b ? `${x} ${p("loses")} ${S} ${p("now. No refund is made.")}` : `${x} ${p("keeps")} ${S} ${l ? `${p("until")} ${ye(l)}.` : p("until the current period ends.")}`}`,
575
- confirmationWord: "CANCEL",
576
- actionLabel: p("Cancel membership"),
577
- onConfirm: async () => {
578
- try {
579
- await v.mutateAsync(y.state.values), u.success("Subscription canceled");
580
- } catch (e) {
581
- throw d(e, "Cancel subscription"), e;
582
- }
583
- },
584
- children: /* @__PURE__ */ V("div", {
585
- className: "grid gap-3",
586
- children: [/* @__PURE__ */ B(y.Field, {
587
- name: "reason",
588
- children: (t) => /* @__PURE__ */ V("div", {
589
- className: "grid gap-1.5",
590
- children: [/* @__PURE__ */ B(A, {
591
- htmlFor: m("cancel-reason"),
592
- children: /* @__PURE__ */ B(e, { id: "Reason" })
593
- }), /* @__PURE__ */ B(c, {
594
- id: m("cancel-reason"),
595
- value: t.state.value,
596
- onBlur: t.handleBlur,
597
- onChange: (e) => t.handleChange(e.target.value),
598
- placeholder: p("why is this being canceled?")
599
- })]
600
- })
601
- }), /* @__PURE__ */ B(y.Field, {
602
- name: "revokeAccess",
603
- children: (t) => /* @__PURE__ */ V(A, {
604
- className: "flex min-h-10 items-center gap-2 font-normal",
605
- children: [/* @__PURE__ */ B("input", {
606
- type: "checkbox",
607
- className: "size-4 accent-destructive",
608
- checked: t.state.value,
609
- onChange: (e) => t.handleChange(e.target.checked)
610
- }), /* @__PURE__ */ B(e, { id: "End access now instead (no refund is made)" })]
611
- })
612
- })]
613
- })
614
- })] });
615
- }
616
- function q({ id: e, customerId: t }) {
617
- let { toast: n, toastApiError: i, adminMutations: a } = r(), o = R(), c = I(a.resumeSubscription(o, e, t));
618
- return /* @__PURE__ */ B(s, {
619
- variant: "outline",
620
- size: "sm",
621
- disabled: c.isPending,
622
- onClick: async () => {
623
- try {
624
- await c.mutateAsync(), n.success("Resume queued");
625
- } catch (e) {
626
- i(e, "Resume subscription");
627
- }
628
- },
629
- children: c.isPending ? "Queuing…" : "Resume"
630
- });
631
- }
632
- var J = "default";
633
- function Y({ subscriptionId: n, customerId: i, rail: a }) {
634
- let { toast: o, toastApiError: c, adminMutations: l, adminQueries: d } = r(), { id: f, text: p } = t(), [m, h] = F.useState(!1), g = R(), C = I(l.changeSubscriptionPaymentMethod(g, n, i)), { data: w } = L(d.customerPaymentMethods(m ? i : void 0)), T = U({
635
- defaultValues: { paymentMethodId: "" },
636
- onSubmit: async ({ value: e }) => {
637
- try {
638
- await C.mutateAsync(e.paymentMethodId === J ? null : e.paymentMethodId), o.success("Payment method updated"), E(!1);
639
- } catch (e) {
640
- c(e, "Change payment method");
641
- }
642
- }
643
- }), E = (e) => {
644
- h(e), e || (T.reset(), C.reset());
645
- };
646
- return /* @__PURE__ */ V(ae, {
647
- open: m,
648
- onOpenChange: E,
649
- children: [/* @__PURE__ */ B(ie, { render: /* @__PURE__ */ B(s, {
650
- variant: "outline",
651
- size: "sm",
652
- children: /* @__PURE__ */ B(e, { id: "Change payment method" })
653
- }) }), /* @__PURE__ */ V(te, {
654
- className: se,
655
- children: [/* @__PURE__ */ V(k, { children: [/* @__PURE__ */ B(ne, { children: /* @__PURE__ */ B(e, { id: "Change payment method" }) }), /* @__PURE__ */ B(re, { children: /* @__PURE__ */ B(e, { 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__ */ V("form", {
656
- onSubmit: (e) => {
657
- e.preventDefault(), e.stopPropagation(), T.handleSubmit();
658
- },
659
- className: "grid gap-4",
660
- children: [/* @__PURE__ */ B(T.Field, {
661
- name: "paymentMethodId",
662
- validators: { onChange: ({ value: e }) => e ? void 0 : "Pick a stored payment method" },
663
- children: (t) => /* @__PURE__ */ V("div", {
664
- className: "grid gap-1.5",
665
- children: [
666
- /* @__PURE__ */ B(A, {
667
- htmlFor: f("subscription-payment-method"),
668
- children: /* @__PURE__ */ B(e, { id: "Payment method" })
669
- }),
670
- /* @__PURE__ */ V(S, {
671
- value: t.state.value,
672
- onValueChange: (e) => t.handleChange(e ?? ""),
673
- children: [/* @__PURE__ */ B(y, {
674
- className: "w-full",
675
- id: f("subscription-payment-method"),
676
- "aria-invalid": t.state.meta.errors.length > 0,
677
- children: /* @__PURE__ */ B(v, { placeholder: p("Pick a stored payment method") })
678
- }), /* @__PURE__ */ V(b, { children: [/* @__PURE__ */ B(x, {
679
- value: J,
680
- children: /* @__PURE__ */ B(e, { id: "The customer&apos;s default card" })
681
- }), (w ?? []).filter((e) => e.rail === a).map((e) => /* @__PURE__ */ V(x, {
682
- value: e.id,
683
- children: [
684
- u(e.card),
685
- " (",
686
- e.rail,
687
- ")"
688
- ]
689
- }, e.id))] })]
690
- }),
691
- /* @__PURE__ */ B(_, { errors: t.state.meta.errors })
692
- ]
693
- })
694
- }), /* @__PURE__ */ B(ee, { children: /* @__PURE__ */ B(T.Subscribe, {
695
- selector: (e) => [
696
- e.values.paymentMethodId,
697
- e.canSubmit,
698
- e.isSubmitting
699
- ],
700
- children: ([e, t, n]) => /* @__PURE__ */ B(s, {
701
- type: "submit",
702
- disabled: !e || !t || n,
703
- children: n ? "Updating…" : "Update"
704
- })
705
- }) })]
706
- })]
707
- })]
708
- });
709
- }
710
- function X({ change: t }) {
711
- let { adminQueries: n } = r(), { data: i } = L(n.price(t.price_id));
712
- return /* @__PURE__ */ V(h, {
713
- className: "bg-held-surface text-held",
714
- children: [
715
- t.source === "migration" ? "migrates" : "changes",
716
- /* @__PURE__ */ B(e, { id: " to" }),
717
- " ",
718
- i ? p(i.unit_amount, i.currency) : m(t.price_id, 9),
719
- " ",
720
- /* @__PURE__ */ B(e, { id: "at the first renewal from " }),
721
- d(t.effective_at)
722
- ]
723
- });
724
- }
725
- //#endregion
726
- export { be as SubscriptionDetailPage };
727
-
728
- //# sourceMappingURL=admin-detail-CKRtK43V.js.map