@fluid-app/portal-sdk 0.1.803 → 0.1.805

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 (37) hide show
  1. package/dist/{FluidProvider-CbezJu7k.cjs → FluidProvider-BMoMyErE.cjs} +43 -1
  2. package/dist/{FluidProvider-CbezJu7k.cjs.map → FluidProvider-BMoMyErE.cjs.map} +1 -1
  3. package/dist/{FluidProvider-BUgLvMU0.mjs → FluidProvider-Dq5eM99i.mjs} +43 -1
  4. package/dist/{FluidProvider-BUgLvMU0.mjs.map → FluidProvider-Dq5eM99i.mjs.map} +1 -1
  5. package/dist/{MessagingScreen-CaR23V-j.mjs → MessagingScreen-BNfYvLRt.mjs} +2 -2
  6. package/dist/{MessagingScreen-CaR23V-j.mjs.map → MessagingScreen-BNfYvLRt.mjs.map} +1 -1
  7. package/dist/{MessagingScreen-D2xdPEC1.cjs → MessagingScreen-B_WZonYP.cjs} +2 -2
  8. package/dist/{MessagingScreen-D2xdPEC1.cjs.map → MessagingScreen-B_WZonYP.cjs.map} +1 -1
  9. package/dist/{MessagingScreen-BY_DfqH_.mjs → MessagingScreen-C8M7VgKE.mjs} +2 -2
  10. package/dist/{MessagingScreen-cBMjM-MN.cjs → MessagingScreen-DaqZenAk.cjs} +2 -2
  11. package/dist/{OrdersScreen-DZSH0C_x.mjs → OrdersScreen-BKSwZdTS.mjs} +2 -2
  12. package/dist/{OrdersScreen-Luerich7.cjs → OrdersScreen-BM6064zb.cjs} +2 -2
  13. package/dist/{OrdersScreen-DQyPk86D.cjs → OrdersScreen-Dh6cKvoD.cjs} +2 -2
  14. package/dist/{OrdersScreen-DQyPk86D.cjs.map → OrdersScreen-Dh6cKvoD.cjs.map} +1 -1
  15. package/dist/{OrdersScreen-d4iYw6dH.mjs → OrdersScreen-K1aCPtYb.mjs} +2 -2
  16. package/dist/{OrdersScreen-d4iYw6dH.mjs.map → OrdersScreen-K1aCPtYb.mjs.map} +1 -1
  17. package/dist/{ProfileScreen-C1OTbsAH.cjs → ProfileScreen-CkCm1BTd.cjs} +3 -3
  18. package/dist/{ProfileScreen-UiYKJI4W.cjs → ProfileScreen-Cp6uetRK.cjs} +2 -2
  19. package/dist/{ProfileScreen-UiYKJI4W.cjs.map → ProfileScreen-Cp6uetRK.cjs.map} +1 -1
  20. package/dist/{ProfileScreen-BoAweM-N.mjs → ProfileScreen-DNlnG12U.mjs} +2 -2
  21. package/dist/{ProfileScreen-BoAweM-N.mjs.map → ProfileScreen-DNlnG12U.mjs.map} +1 -1
  22. package/dist/{ProfileScreen-fDEfMhHF.mjs → ProfileScreen-PW4MqHpr.mjs} +3 -3
  23. package/dist/{SubscriptionsScreen-Bq9rz8_l.cjs → SubscriptionsScreen-0YpZDxbJ.cjs} +459 -101
  24. package/dist/SubscriptionsScreen-0YpZDxbJ.cjs.map +1 -0
  25. package/dist/{SubscriptionsScreen-BVNRW8Mc.cjs → SubscriptionsScreen-BvfbO0Ph.cjs} +3 -3
  26. package/dist/{SubscriptionsScreen-DTNR_sKF.mjs → SubscriptionsScreen-ChH6JtYD.mjs} +3 -3
  27. package/dist/{SubscriptionsScreen-DrW_5UWh.mjs → SubscriptionsScreen-Dzfs1Tj4.mjs} +460 -102
  28. package/dist/SubscriptionsScreen-Dzfs1Tj4.mjs.map +1 -0
  29. package/dist/index.cjs +14 -14
  30. package/dist/index.mjs +14 -14
  31. package/dist/{use-portal-card-add-3ds-flow-7sMchA1Y.mjs → use-portal-card-add-3ds-flow-BfVoevu3.mjs} +2 -2
  32. package/dist/{use-portal-card-add-3ds-flow-7sMchA1Y.mjs.map → use-portal-card-add-3ds-flow-BfVoevu3.mjs.map} +1 -1
  33. package/dist/{use-portal-card-add-3ds-flow-CKQr5F5Q.cjs → use-portal-card-add-3ds-flow-oy_eyeQA.cjs} +2 -2
  34. package/dist/{use-portal-card-add-3ds-flow-CKQr5F5Q.cjs.map → use-portal-card-add-3ds-flow-oy_eyeQA.cjs.map} +1 -1
  35. package/package.json +2 -2
  36. package/dist/SubscriptionsScreen-Bq9rz8_l.cjs.map +0 -1
  37. package/dist/SubscriptionsScreen-DrW_5UWh.mjs.map +0 -1
@@ -2,7 +2,7 @@ require("./chunk-9hOWP6kD.cjs");
2
2
  const require_build_widget_registry = require("./build-widget-registry-CR5qbb2G.cjs");
3
3
  const require_fetch_client = require("./fetch-client-BG7NeNDx.cjs");
4
4
  const require_ContactsTranslationBridge = require("./ContactsTranslationBridge-FyqcnCwN.cjs");
5
- const require_FluidProvider = require("./FluidProvider-CbezJu7k.cjs");
5
+ const require_FluidProvider = require("./FluidProvider-BMoMyErE.cjs");
6
6
  const require_use_optional_store = require("./use-optional-store-DiiiefyO.cjs");
7
7
  const require_Combobox = require("./Combobox-DW-UuPXX.cjs");
8
8
  const require_prop_types = require("./prop-types-BcTujKu2.cjs");
@@ -17,7 +17,7 @@ const require_AppNavigationContext = require("./AppNavigationContext-WjLfoRRa.cj
17
17
  const require_use_store = require("./use-store-DFwGIM83.cjs");
18
18
  const require_sidebar = require("./sidebar-BnZL8dM6.cjs");
19
19
  const require_ScreenHeaderContext = require("./ScreenHeaderContext-fJKG4BUl.cjs");
20
- const require_use_portal_card_add_3ds_flow = require("./use-portal-card-add-3ds-flow-CKQr5F5Q.cjs");
20
+ const require_use_portal_card_add_3ds_flow = require("./use-portal-card-add-3ds-flow-oy_eyeQA.cjs");
21
21
  const require_isAfter = require("./isAfter-CUqiCNz0.cjs");
22
22
  let react = require("react");
23
23
  let _tanstack_react_query = require("@tanstack/react-query");
@@ -5582,104 +5582,6 @@ function SubscriptionsListScreen(props) {
5582
5582
  });
5583
5583
  }
5584
5584
  //#endregion
5585
- //#region ../../subscriptions/ui/src/components/cancel-subscription-dialog.tsx
5586
- const PAUSE_MONTH_OPTIONS = [
5587
- 1,
5588
- 2,
5589
- 3
5590
- ];
5591
- function CancelSubscriptionDialog({ open, onOpenChange, onConfirm, onPauseInstead, errorMessage, isPending: isPendingProp = false, presentation = "dialog" }) {
5592
- const { t } = useSubscriptionsTranslation();
5593
- const [isConfirming, setIsConfirming] = (0, react.useState)(false);
5594
- const isPending = isConfirming || isPendingProp;
5595
- const [selectedMonths, setSelectedMonths] = (0, react.useState)(null);
5596
- (0, react.useEffect)(() => {
5597
- if (!open) setSelectedMonths(null);
5598
- }, [open]);
5599
- const handleConfirm = async () => {
5600
- const result = onConfirm();
5601
- if (!(result instanceof Promise)) {
5602
- onOpenChange(false);
5603
- return;
5604
- }
5605
- setIsConfirming(true);
5606
- try {
5607
- await result;
5608
- onOpenChange(false);
5609
- } catch (error) {
5610
- console.error("CancelSubscriptionDialog: action rejected", error);
5611
- } finally {
5612
- setIsConfirming(false);
5613
- }
5614
- };
5615
- const handlePause = () => {
5616
- if (!selectedMonths) return;
5617
- onPauseInstead(selectedMonths);
5618
- };
5619
- return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_ResponsiveDialog.ResponsiveDialog, {
5620
- open,
5621
- onOpenChange: (v) => !isPending && onOpenChange(v),
5622
- title: t("cancel_dialog_title"),
5623
- description: t("cancel_dialog_description"),
5624
- role: "alertdialog",
5625
- presentation,
5626
- children: [
5627
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
5628
- className: "border-border space-y-2 rounded-md border p-3",
5629
- children: [
5630
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
5631
- className: "text-foreground text-sm font-medium",
5632
- children: t("cancel_dialog_pause_question")
5633
- }),
5634
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Label, {
5635
- htmlFor: "cancel-pause-months",
5636
- className: "text-foreground text-sm font-semibold",
5637
- children: t("pause_for")
5638
- }),
5639
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.Select, {
5640
- value: selectedMonths ? String(selectedMonths) : void 0,
5641
- onValueChange: (value) => setSelectedMonths(value ? Number(value) : null),
5642
- disabled: isPending,
5643
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectTrigger, {
5644
- id: "cancel-pause-months",
5645
- className: "w-full",
5646
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectValue, { placeholder: t("select_duration") })
5647
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectContent, { children: PAUSE_MONTH_OPTIONS.map((months) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectItem, {
5648
- value: String(months),
5649
- children: months === 1 ? t("month_singular", { count: String(months) }) : t("month_plural", { count: String(months) })
5650
- }, months)) })]
5651
- }),
5652
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
5653
- variant: "outline",
5654
- onClick: handlePause,
5655
- disabled: isPending || !selectedMonths,
5656
- className: "w-full",
5657
- children: t("cancel_dialog_pause_button")
5658
- })
5659
- ]
5660
- }),
5661
- errorMessage && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
5662
- className: "text-destructive text-left text-sm",
5663
- children: errorMessage
5664
- }),
5665
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.DialogFooter, {
5666
- className: "flex-col gap-2 sm:flex-row sm:justify-end",
5667
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
5668
- variant: "secondary",
5669
- onClick: () => onOpenChange(false),
5670
- disabled: isPending,
5671
- children: t("cancel_dialog_cancel_button")
5672
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
5673
- variant: "destructive",
5674
- onClick: handleConfirm,
5675
- disabled: isPending,
5676
- children: isPending ? t("loading_ellipsis") : t("cancel_dialog_confirm_button")
5677
- })]
5678
- })
5679
- ]
5680
- });
5681
- }
5682
- //#endregion
5683
5585
  //#region ../../subscriptions/ui/src/lib/format.ts
5684
5586
  /** Used when a payload carries no currency, or one Intl does not know. */
5685
5587
  const FALLBACK_CURRENCY = "USD";
@@ -5930,6 +5832,462 @@ function formatMediumDate(date, locale = "en-US") {
5930
5832
  }).format(date);
5931
5833
  }
5932
5834
  }
5835
+ /** "1 month" or "N months" in the subscriptions dictionary. */
5836
+ function monthsLabel(t, months) {
5837
+ return months === 1 ? t("month_singular", { count: "1" }) : t("month_plural", { count: String(months) });
5838
+ }
5839
+ //#endregion
5840
+ //#region ../../subscriptions/core/src/cancellation-sessions-api.ts
5841
+ var CancellationSessionError = class extends Error {
5842
+ failure;
5843
+ constructor(failure, message) {
5844
+ super(message);
5845
+ this.name = "CancellationSessionError";
5846
+ this.failure = failure;
5847
+ }
5848
+ };
5849
+ //#endregion
5850
+ //#region ../../subscriptions/ui/src/components/cancel-flow.tsx
5851
+ function useCancelFlow(open, binding) {
5852
+ const { t } = useSubscriptionsTranslation();
5853
+ const [step, setStep] = (0, react.useState)({ kind: "plain" });
5854
+ const [error, setError] = (0, react.useState)(null);
5855
+ const [busy, setBusy] = (0, react.useState)(false);
5856
+ const generation = (0, react.useRef)(0);
5857
+ const bindingRef = (0, react.useRef)(binding);
5858
+ bindingRef.current = binding;
5859
+ const openSession = async (current, run) => {
5860
+ try {
5861
+ const session = await current.api.openSession(current.subscriptionToken);
5862
+ if (run === generation.current) setStep({
5863
+ kind: "reason",
5864
+ session
5865
+ });
5866
+ } catch {
5867
+ if (run === generation.current) setStep({ kind: "plain" });
5868
+ }
5869
+ };
5870
+ const enabled = binding !== void 0;
5871
+ const subscriptionToken = binding?.subscriptionToken;
5872
+ const api = binding?.api;
5873
+ (0, react.useEffect)(() => {
5874
+ generation.current += 1;
5875
+ setError(null);
5876
+ setBusy(false);
5877
+ const current = bindingRef.current;
5878
+ if (!open || !current) {
5879
+ setStep({ kind: "plain" });
5880
+ return;
5881
+ }
5882
+ setStep({ kind: "opening" });
5883
+ openSession(current, generation.current);
5884
+ }, [
5885
+ open,
5886
+ enabled,
5887
+ subscriptionToken,
5888
+ api
5889
+ ]);
5890
+ const recover = async (cause) => {
5891
+ const current = bindingRef.current;
5892
+ if (!current) return;
5893
+ if (!(cause instanceof CancellationSessionError)) {
5894
+ setError(t("cancel_flow_error"));
5895
+ return;
5896
+ }
5897
+ if (cause.failure === "unavailable") {
5898
+ setStep({ kind: "plain" });
5899
+ setError(t("cancel_flow_error"));
5900
+ return;
5901
+ }
5902
+ current.onChanged({ kind: "stale" });
5903
+ if (cause.failure === "refused") {
5904
+ setError(t("cancel_flow_refused"));
5905
+ return;
5906
+ }
5907
+ setError(t("cancel_flow_session_restarted"));
5908
+ await openSession(current, generation.current);
5909
+ };
5910
+ const sessionOf = (value) => value.kind === "reason" || value.kind === "offers" ? value.session : null;
5911
+ const withSession = async (fallback, work) => {
5912
+ const current = bindingRef.current;
5913
+ const session = sessionOf(step);
5914
+ if (!current || !session) return fallback;
5915
+ setBusy(true);
5916
+ setError(null);
5917
+ try {
5918
+ return await work(current, session);
5919
+ } catch (cause) {
5920
+ await recover(cause);
5921
+ return fallback;
5922
+ } finally {
5923
+ setBusy(false);
5924
+ }
5925
+ };
5926
+ return {
5927
+ step,
5928
+ error,
5929
+ busy,
5930
+ giveReason: (choice) => withSession(void 0, async (current, session) => {
5931
+ setStep({
5932
+ kind: "offers",
5933
+ session: await current.api.giveReason(current.subscriptionToken, session.id, choice)
5934
+ });
5935
+ }),
5936
+ accept: (offer, variantId) => withSession(false, async (current, session) => {
5937
+ await current.api.acceptOffer(current.subscriptionToken, session.id, {
5938
+ offerId: offer.offerId,
5939
+ variantId
5940
+ });
5941
+ current.onChanged({
5942
+ kind: "saved",
5943
+ notice: t("cancel_flow_saved")
5944
+ });
5945
+ return true;
5946
+ }),
5947
+ cancel: (choice) => withSession("failed", async (current, session) => {
5948
+ const reason = step.kind === "reason" ? choice : void 0;
5949
+ try {
5950
+ await current.api.cancel(current.subscriptionToken, session.id, reason);
5951
+ } catch (cause) {
5952
+ if (reason && cause instanceof CancellationSessionError && cause.failure === "refused") return "plain";
5953
+ throw cause;
5954
+ }
5955
+ current.onChanged({ kind: "cancelled" });
5956
+ return "cancelled";
5957
+ })
5958
+ };
5959
+ }
5960
+ function parseLocalDate(isoDate) {
5961
+ const [year, month, day] = isoDate.slice(0, 10).split("-").map(Number);
5962
+ return new Date(year ?? 0, (month ?? 1) - 1, day ?? 1);
5963
+ }
5964
+ function OfferCard({ offer, disabled, onAccept }) {
5965
+ const { t, locale } = useSubscriptionsTranslation();
5966
+ const [variantId, setVariantId] = (0, react.useState)(null);
5967
+ const terms = offer.terms;
5968
+ const months = Number(terms.months);
5969
+ const title = {
5970
+ skip_next: () => t("cancel_offer_skip_next"),
5971
+ delay: () => t("cancel_offer_delay", { days: String(terms.days) }),
5972
+ change_frequency: () => t("cancel_offer_change_frequency"),
5973
+ swap: () => t("cancel_offer_swap"),
5974
+ pause: () => t("cancel_offer_pause", { duration: monthsLabel(t, months) }),
5975
+ discount: () => terms.duration === "repeating" ? t("cancel_offer_discount_repeating", {
5976
+ percentage: String(terms.percentage),
5977
+ cycles: String(terms.duration_cycles)
5978
+ }) : t("cancel_offer_discount_once", { percentage: String(terms.percentage) }),
5979
+ contact_support: () => t("cancel_offer_contact_support")
5980
+ }[offer.type]();
5981
+ const preview = offer.preview;
5982
+ const date = preview?.nextBillDate ? formatLongDate(parseLocalDate(preview.nextBillDate), locale) : null;
5983
+ const previewText = date && preview?.nextOrderTotal ? t("cancel_offer_preview_total", {
5984
+ date,
5985
+ total: formatCurrency(Number(preview.nextOrderTotal), preview.currency, locale)
5986
+ }) : date ? t("cancel_offer_preview_date", { date }) : null;
5987
+ const supportUrl = typeof terms.url === "string" ? terms.url : null;
5988
+ const needsVariant = offer.type === "swap";
5989
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
5990
+ className: "border-border space-y-2 rounded-md border p-3",
5991
+ children: [
5992
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
5993
+ className: "text-foreground text-sm font-medium",
5994
+ children: title
5995
+ }),
5996
+ previewText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
5997
+ className: "text-muted-foreground text-sm",
5998
+ children: previewText
5999
+ }),
6000
+ needsVariant && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6001
+ className: "space-y-1",
6002
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Label, {
6003
+ htmlFor: `swap-${offer.offerId}`,
6004
+ className: "text-sm",
6005
+ children: t("cancel_offer_swap_label")
6006
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.Select, {
6007
+ value: variantId ? String(variantId) : "",
6008
+ onValueChange: (value) => setVariantId(Number(value)),
6009
+ disabled,
6010
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectTrigger, {
6011
+ id: `swap-${offer.offerId}`,
6012
+ className: "w-full",
6013
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectValue, { placeholder: t("cancel_offer_swap_label") })
6014
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectContent, { children: offer.variantOptions.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectItem, {
6015
+ value: String(option.variantId),
6016
+ children: option.title ?? String(option.variantId)
6017
+ }, option.variantId)) })]
6018
+ })]
6019
+ }),
6020
+ offer.saves ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
6021
+ variant: "outline",
6022
+ className: "w-full",
6023
+ disabled: disabled || needsVariant && variantId === null,
6024
+ onClick: () => onAccept(variantId ?? void 0),
6025
+ children: t("cancel_offer_accept_button")
6026
+ }) : supportUrl && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
6027
+ variant: "outline",
6028
+ className: "w-full",
6029
+ asChild: true,
6030
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
6031
+ href: supportUrl,
6032
+ target: "_blank",
6033
+ rel: "noopener noreferrer",
6034
+ children: t("cancel_offer_contact_button")
6035
+ })
6036
+ })
6037
+ ]
6038
+ });
6039
+ }
6040
+ /** The offer screen. At most one per session; it may hold no offers. */
6041
+ function CancelOffers({ session, disabled, onAccept }) {
6042
+ const { t } = useSubscriptionsTranslation();
6043
+ if (session.offers.length === 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6044
+ className: "text-foreground text-sm",
6045
+ children: t("cancel_flow_no_offers_description")
6046
+ });
6047
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6048
+ className: "space-y-2",
6049
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6050
+ className: "text-foreground text-sm",
6051
+ children: t("cancel_flow_offers_description")
6052
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
6053
+ className: "space-y-2",
6054
+ children: session.offers.map((offer) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OfferCard, {
6055
+ offer,
6056
+ disabled,
6057
+ onAccept: (variantId) => onAccept(offer, variantId)
6058
+ }, offer.offerId))
6059
+ })]
6060
+ });
6061
+ }
6062
+ //#endregion
6063
+ //#region ../../subscriptions/ui/src/components/cancel-reason-picker.tsx
6064
+ const REASON_TEXT_LIMIT = 500;
6065
+ const DICTIONARY_LABELS = {
6066
+ too_expensive: "cancel_reason_too_expensive",
6067
+ too_much_product: "cancel_reason_too_much_product",
6068
+ too_frequent: "cancel_reason_too_frequent",
6069
+ not_seeing_results: "cancel_reason_not_seeing_results",
6070
+ did_not_like_product: "cancel_reason_did_not_like_product",
6071
+ switching_brand: "cancel_reason_switching_brand",
6072
+ shipping_or_delivery_issue: "cancel_reason_shipping_or_delivery_issue",
6073
+ taking_a_break: "cancel_reason_taking_a_break",
6074
+ moving_or_life_change: "cancel_reason_moving_or_life_change",
6075
+ other: "cancel_reason_other"
6076
+ };
6077
+ const emptyCancelReason = {
6078
+ code: null,
6079
+ text: ""
6080
+ };
6081
+ /** The draft as the server takes it, or undefined when no reason is chosen. */
6082
+ function cancelReasonChoice(draft) {
6083
+ if (!draft.code) return void 0;
6084
+ const text = draft.code === "other" ? draft.text.trim() : "";
6085
+ return text ? {
6086
+ reasonCode: draft.code,
6087
+ reasonText: text
6088
+ } : { reasonCode: draft.code };
6089
+ }
6090
+ function CancelReasonPicker({ reasons, value, onChange, disabled }) {
6091
+ const { t, locale } = useSubscriptionsTranslation();
6092
+ const labelFor = (reason) => {
6093
+ const merchantLabel = reason.labels[locale] ?? reason.labels[locale.split(/[-_]/)[0] ?? ""];
6094
+ if (merchantLabel) return merchantLabel;
6095
+ const key = DICTIONARY_LABELS[reason.code];
6096
+ return key ? t(key) : reason.code;
6097
+ };
6098
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6099
+ className: "space-y-2",
6100
+ children: [
6101
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Label, {
6102
+ htmlFor: "cancel-reason",
6103
+ className: "text-foreground text-sm font-semibold",
6104
+ children: t("cancel_dialog_reason_label")
6105
+ }),
6106
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.Select, {
6107
+ value: value.code ?? "",
6108
+ onValueChange: (code) => onChange({
6109
+ ...value,
6110
+ code
6111
+ }),
6112
+ disabled,
6113
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectTrigger, {
6114
+ id: "cancel-reason",
6115
+ className: "w-full",
6116
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectValue, { placeholder: t("cancel_dialog_reason_placeholder") })
6117
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectContent, { children: reasons.map((reason) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectItem, {
6118
+ value: reason.code,
6119
+ children: labelFor(reason)
6120
+ }, reason.code)) })]
6121
+ }),
6122
+ value.code === "other" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Label, {
6123
+ htmlFor: "cancel-reason-text",
6124
+ className: "text-sm",
6125
+ children: t("cancel_dialog_reason_text_label")
6126
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Textarea, {
6127
+ id: "cancel-reason-text",
6128
+ value: value.text,
6129
+ maxLength: REASON_TEXT_LIMIT,
6130
+ onChange: (event) => onChange({
6131
+ ...value,
6132
+ text: event.target.value
6133
+ }),
6134
+ disabled
6135
+ })] })
6136
+ ]
6137
+ });
6138
+ }
6139
+ //#endregion
6140
+ //#region ../../subscriptions/ui/src/components/cancel-subscription-dialog.tsx
6141
+ const PAUSE_MONTH_OPTIONS = [
6142
+ 1,
6143
+ 2,
6144
+ 3
6145
+ ];
6146
+ function CancelSubscriptionDialog({ open, onOpenChange, onConfirm, onPauseInstead, errorMessage, isPending: isPendingProp = false, presentation = "dialog", reasons = [], cancelFlow }) {
6147
+ const { t } = useSubscriptionsTranslation();
6148
+ const flow = useCancelFlow(open, cancelFlow);
6149
+ const [isConfirming, setIsConfirming] = (0, react.useState)(false);
6150
+ const isPending = isConfirming || isPendingProp || flow.busy;
6151
+ const [selectedMonths, setSelectedMonths] = (0, react.useState)(null);
6152
+ const [reason, setReason] = (0, react.useState)(emptyCancelReason);
6153
+ (0, react.useEffect)(() => {
6154
+ if (open) return;
6155
+ setSelectedMonths(null);
6156
+ setReason(emptyCancelReason);
6157
+ }, [open]);
6158
+ const { step } = flow;
6159
+ const inSession = step.kind === "reason" || step.kind === "offers";
6160
+ const confirmPlain = async () => {
6161
+ const result = onConfirm(cancelReasonChoice(reason));
6162
+ if (!(result instanceof Promise)) {
6163
+ onOpenChange(false);
6164
+ return;
6165
+ }
6166
+ setIsConfirming(true);
6167
+ try {
6168
+ await result;
6169
+ onOpenChange(false);
6170
+ } catch (error) {
6171
+ console.error("CancelSubscriptionDialog: action rejected", error);
6172
+ } finally {
6173
+ setIsConfirming(false);
6174
+ }
6175
+ };
6176
+ const handleCancel = async () => {
6177
+ if (!inSession) return confirmPlain();
6178
+ const outcome = await flow.cancel(cancelReasonChoice(reason));
6179
+ if (outcome === "plain") return confirmPlain();
6180
+ if (outcome === "cancelled") onOpenChange(false);
6181
+ };
6182
+ const handleContinue = () => {
6183
+ const choice = cancelReasonChoice(reason);
6184
+ if (choice) flow.giveReason(choice);
6185
+ };
6186
+ const handlePause = () => {
6187
+ if (!selectedMonths) return;
6188
+ onPauseInstead(selectedMonths);
6189
+ };
6190
+ const shownError = flow.error ?? errorMessage;
6191
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_ResponsiveDialog.ResponsiveDialog, {
6192
+ open,
6193
+ onOpenChange: (v) => !isPending && onOpenChange(v),
6194
+ title: t("cancel_dialog_title"),
6195
+ description: step.kind === "reason" ? t("cancel_flow_reason_description") : t("cancel_dialog_description"),
6196
+ role: "alertdialog",
6197
+ presentation,
6198
+ children: [
6199
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6200
+ "data-cancel-step": step.kind,
6201
+ className: "space-y-4",
6202
+ children: [
6203
+ step.kind === "plain" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
6204
+ className: "border-border space-y-2 rounded-md border p-3",
6205
+ children: [
6206
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6207
+ className: "text-foreground text-sm font-medium",
6208
+ children: t("cancel_dialog_pause_question")
6209
+ }),
6210
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Label, {
6211
+ htmlFor: "cancel-pause-months",
6212
+ className: "text-foreground text-sm font-semibold",
6213
+ children: t("pause_for")
6214
+ }),
6215
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.Select, {
6216
+ value: selectedMonths ? String(selectedMonths) : void 0,
6217
+ onValueChange: (value) => setSelectedMonths(value ? Number(value) : null),
6218
+ disabled: isPending,
6219
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectTrigger, {
6220
+ id: "cancel-pause-months",
6221
+ className: "w-full",
6222
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectValue, { placeholder: t("select_duration") })
6223
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectContent, { children: PAUSE_MONTH_OPTIONS.map((months) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.SelectItem, {
6224
+ value: String(months),
6225
+ children: monthsLabel(t, months)
6226
+ }, months)) })]
6227
+ }),
6228
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
6229
+ variant: "outline",
6230
+ onClick: handlePause,
6231
+ disabled: isPending || !selectedMonths,
6232
+ className: "w-full",
6233
+ children: t("cancel_dialog_pause_button")
6234
+ })
6235
+ ]
6236
+ }), reasons.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CancelReasonPicker, {
6237
+ reasons,
6238
+ value: reason,
6239
+ onChange: setReason,
6240
+ disabled: isPending
6241
+ })] }),
6242
+ step.kind === "opening" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6243
+ className: "text-muted-foreground text-sm",
6244
+ children: t("loading_ellipsis")
6245
+ }),
6246
+ step.kind === "reason" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CancelReasonPicker, {
6247
+ reasons: step.session.reasons,
6248
+ value: reason,
6249
+ onChange: setReason,
6250
+ disabled: isPending
6251
+ }),
6252
+ step.kind === "offers" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CancelOffers, {
6253
+ session: step.session,
6254
+ disabled: isPending,
6255
+ onAccept: async (offer, variantId) => {
6256
+ if (await flow.accept(offer, variantId)) onOpenChange(false);
6257
+ }
6258
+ })
6259
+ ]
6260
+ }),
6261
+ shownError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
6262
+ className: "text-destructive text-left text-sm",
6263
+ children: shownError
6264
+ }),
6265
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.DialogFooter, {
6266
+ className: "flex-col gap-2 sm:flex-row sm:justify-end",
6267
+ children: [
6268
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
6269
+ variant: "secondary",
6270
+ onClick: () => onOpenChange(false),
6271
+ disabled: isPending,
6272
+ children: cancelFlow ? t("cancel_flow_keep_button") : t("cancel_dialog_cancel_button")
6273
+ }),
6274
+ step.kind === "reason" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
6275
+ variant: "outline",
6276
+ onClick: handleContinue,
6277
+ disabled: isPending || !reason.code,
6278
+ children: t("cancel_flow_continue_button")
6279
+ }),
6280
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Button, {
6281
+ variant: "destructive",
6282
+ onClick: () => void handleCancel(),
6283
+ disabled: isPending,
6284
+ children: isPending ? t("loading_ellipsis") : t("cancel_dialog_confirm_button")
6285
+ })
6286
+ ]
6287
+ })
6288
+ ]
6289
+ });
6290
+ }
5933
6291
  //#endregion
5934
6292
  //#region ../../subscriptions/ui/src/components/pause-subscription-dialog.tsx
5935
6293
  function PauseSubscriptionDialog({ open, onOpenChange, onConfirm, isLoading, errorMessage, currentNextBillDate, billingInterval = 1, billingIntervalUnit = "month", presentation = "dialog" }) {
@@ -9586,4 +9944,4 @@ Object.defineProperty(exports, "subscriptionsScreenPropertySchema", {
9586
9944
  }
9587
9945
  });
9588
9946
 
9589
- //# sourceMappingURL=SubscriptionsScreen-Bq9rz8_l.cjs.map
9947
+ //# sourceMappingURL=SubscriptionsScreen-0YpZDxbJ.cjs.map