@fluid-app/portal-sdk 0.1.1278 → 0.1.1280

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.
@@ -70,6 +70,6 @@ require("./translation-adapter-B2E8epKq.cjs");
70
70
  require("./sidebar-BTwncyT-.cjs");
71
71
  require("./ScreenHeaderContext-fJKG4BUl.cjs");
72
72
  require("./use-portal-card-add-3ds-flow-CqDD5rFg.cjs");
73
- const require_SubscriptionsScreen = require("./SubscriptionsScreen-Cl4wCwAq.cjs");
73
+ const require_SubscriptionsScreen = require("./SubscriptionsScreen-B5ZjeypU.cjs");
74
74
  exports.SubscriptionsScreen = require_SubscriptionsScreen.SubscriptionsScreen;
75
75
  exports.subscriptionsScreenPropertySchema = require_SubscriptionsScreen.subscriptionsScreenPropertySchema;
@@ -35,7 +35,7 @@ import "./BulletListWidget-Bbn6AV3M.mjs";
35
35
  import "./preview-context-D8_bpnt8.mjs";
36
36
  import "./CalendarWidget-DOBLqQFM.mjs";
37
37
  import "./error-state-D1lbEcUB.mjs";
38
- import { n as subscriptionsScreenPropertySchema, t as SubscriptionsScreen } from "./SubscriptionsScreen-yah2TAvw.mjs";
38
+ import { n as subscriptionsScreenPropertySchema, t as SubscriptionsScreen } from "./SubscriptionsScreen-D0UjahrX.mjs";
39
39
  import "./WidgetLoadingSkeleton-CH2gVgkd.mjs";
40
40
  import "./CardWidget-CEwOwcPG.mjs";
41
41
  import "./purify.es-Ckb34wqr.mjs";
@@ -3441,6 +3441,7 @@ function createPortalSubscriptionsAdapter(client) {
3441
3441
  const body = {};
3442
3442
  if (params.nextBillDate != null) body.next_bill_date = params.nextBillDate;
3443
3443
  if (params.numberOfOrders != null) body.number_of_orders = params.numberOfOrders;
3444
+ if (params.confirmEarlyOrder) body.confirm_early_order = true;
3444
3445
  return mapSubscriptionDetail(await subscriptionsPause({
3445
3446
  client,
3446
3447
  path: { token: subscriptionToken },
@@ -3448,11 +3449,13 @@ function createPortalSubscriptionsAdapter(client) {
3448
3449
  }));
3449
3450
  },
3450
3451
  resumeSubscription: async (subscriptionToken, params) => {
3451
- const body = params.nextBillDate ? { next_bill_date: params.nextBillDate } : void 0;
3452
+ const body = {};
3453
+ if (params.nextBillDate) body.next_bill_date = params.nextBillDate;
3454
+ if (params.confirmEarlyOrder) body.confirm_early_order = true;
3452
3455
  return mapSubscriptionDetail(await subscriptionsResume({
3453
3456
  client,
3454
3457
  path: { token: subscriptionToken },
3455
- body
3458
+ body: Object.keys(body).length > 0 ? body : void 0
3456
3459
  }));
3457
3460
  },
3458
3461
  skipSubscription: async (subscriptionToken, _params) => {
@@ -3983,7 +3986,8 @@ function readEarlyOrderRefusal(error) {
3983
3986
  if (meta?.code !== "early_order_confirmation_required" || typeof meta.scheduled_date !== "string") return null;
3984
3987
  return {
3985
3988
  scheduledDate: meta.scheduled_date,
3986
- lastBillDate: typeof meta.last_bill_date === "string" ? meta.last_bill_date : null
3989
+ lastBillDate: typeof meta.last_bill_date === "string" ? meta.last_bill_date : null,
3990
+ requestedDate: typeof meta.requested_date === "string" ? meta.requested_date : null
3987
3991
  };
3988
3992
  }
3989
3993
  //#endregion
@@ -6638,26 +6642,34 @@ function PauseSubscriptionDialog({ open, onOpenChange, onConfirm, isLoading, err
6638
6642
  const maxSkippableOrders = getMaxSkippableOrders(billingInterval, billingIntervalUnit, currentNextBillDate);
6639
6643
  const orderCountOptions = Array.from({ length: maxSkippableOrders }, (_, i) => i + 1);
6640
6644
  const calculatedResumeDate = selectedOrderCount && currentNextBillDate ? calculateResumeDate(billingInterval, billingIntervalUnit, selectedOrderCount, currentNextBillDate) : null;
6645
+ const [earlyOrderRefusal, setEarlyOrderRefusal] = useState(null);
6641
6646
  useEffect(() => {
6642
6647
  if (!open) return;
6643
6648
  setPauseType("indefinite");
6644
6649
  setSelectedOrderCount(null);
6650
+ setEarlyOrderRefusal(null);
6645
6651
  }, [open]);
6646
- const handleConfirm = () => {
6647
- if (pauseType === "indefinite") {
6648
- onConfirm({ type: "indefinite" });
6649
- return;
6650
- }
6651
- if (pauseType === "order_count" && selectedOrderCount) onConfirm({
6652
+ const handleConfirm = async () => {
6653
+ let selection;
6654
+ if (pauseType === "indefinite") selection = { type: "indefinite" };
6655
+ else if (pauseType === "order_count" && selectedOrderCount) selection = {
6652
6656
  type: "order_count",
6653
6657
  numberOfOrders: selectedOrderCount,
6654
6658
  shownResumeDate: calculatedResumeDate ? format(calculatedResumeDate, "yyyy-MM-dd") : null
6655
- });
6659
+ };
6660
+ else return;
6661
+ try {
6662
+ await onConfirm(selection, earlyOrderRefusal !== null);
6663
+ } catch (error) {
6664
+ const refusal = readEarlyOrderRefusal(error);
6665
+ if (refusal) setEarlyOrderRefusal(refusal);
6666
+ }
6656
6667
  };
6657
6668
  const handleDismiss = (next) => {
6658
6669
  if (!next) {
6659
6670
  setPauseType("indefinite");
6660
6671
  setSelectedOrderCount(null);
6672
+ setEarlyOrderRefusal(null);
6661
6673
  }
6662
6674
  onOpenChange(next);
6663
6675
  };
@@ -6682,6 +6694,7 @@ function PauseSubscriptionDialog({ open, onOpenChange, onConfirm, isLoading, err
6682
6694
  ] });
6683
6695
  })();
6684
6696
  const isActionDisabled = pauseType === "order_count" && !selectedOrderCount;
6697
+ const requestedDayIso = earlyOrderRefusal ? earlyOrderRefusal.requestedDate ?? earlyOrderRefusal.scheduledDate : "";
6685
6698
  return /* @__PURE__ */ jsxs(ResponsiveDialog, {
6686
6699
  open,
6687
6700
  onOpenChange: handleDismiss,
@@ -6691,7 +6704,21 @@ function PauseSubscriptionDialog({ open, onOpenChange, onConfirm, isLoading, err
6691
6704
  children: [
6692
6705
  /* @__PURE__ */ jsx("div", {
6693
6706
  className: "space-y-4",
6694
- children: /* @__PURE__ */ jsxs("div", {
6707
+ children: earlyOrderRefusal ? /* @__PURE__ */ jsxs("div", {
6708
+ className: "space-y-3",
6709
+ role: "alert",
6710
+ children: [/* @__PURE__ */ jsx("p", {
6711
+ className: "text-foreground text-sm font-medium",
6712
+ children: t("bill_date_early_order_confirm_title", { date: formatLongDate$1(parseIsoDate(requestedDayIso), locale) })
6713
+ }), /* @__PURE__ */ jsxs("div", {
6714
+ className: "text-muted-foreground space-y-1 text-sm",
6715
+ children: [
6716
+ earlyOrderRefusal.lastBillDate && /* @__PURE__ */ jsx("p", { children: t("bill_date_early_order_confirm_last_placed", { date: formatLongDate$1(parseIsoDate(earlyOrderRefusal.lastBillDate), locale) }) }),
6717
+ /* @__PURE__ */ jsx("p", { children: t("bill_date_early_order_confirm_next_scheduled", { date: formatLongDate$1(parseIsoDate(earlyOrderRefusal.scheduledDate), locale) }) }),
6718
+ /* @__PURE__ */ jsx("p", { children: t("bill_date_early_order_confirm_consequence", { date: formatLongDate$1(parseIsoDate(requestedDayIso), locale) }) })
6719
+ ]
6720
+ })]
6721
+ }) : /* @__PURE__ */ jsxs("div", {
6695
6722
  className: "space-y-4",
6696
6723
  children: [
6697
6724
  /* @__PURE__ */ jsxs("div", {
@@ -6760,14 +6787,15 @@ function PauseSubscriptionDialog({ open, onOpenChange, onConfirm, isLoading, err
6760
6787
  children: [/* @__PURE__ */ jsx(Button, {
6761
6788
  variant: "outline",
6762
6789
  className: "h-10 min-w-[70px] rounded p-3",
6763
- onClick: () => handleDismiss(false),
6764
- children: t("pause_dialog_cancel")
6790
+ onClick: () => earlyOrderRefusal ? setEarlyOrderRefusal(null) : handleDismiss(false),
6791
+ disabled: earlyOrderRefusal !== null && isLoading,
6792
+ children: earlyOrderRefusal ? t("bill_date_early_order_keep") : t("pause_dialog_cancel")
6765
6793
  }), /* @__PURE__ */ jsx(Button, {
6766
6794
  type: "button",
6767
6795
  className: "h-10 min-w-[70px] rounded p-3",
6768
6796
  onClick: handleConfirm,
6769
6797
  disabled: isActionDisabled || isLoading,
6770
- children: isLoading ? /* @__PURE__ */ jsx("div", { className: "border-primary-foreground size-5 animate-spin rounded-full border-4 border-t-4 border-t-transparent" }) : t("pause_dialog_action")
6798
+ children: isLoading ? /* @__PURE__ */ jsx("div", { className: "border-primary-foreground size-5 animate-spin rounded-full border-4 border-t-4 border-t-transparent" }) : earlyOrderRefusal ? t("bill_date_early_order_place", { date: formatMediumDate(parseIsoDate(requestedDayIso), locale) }) : t("pause_dialog_action")
6771
6799
  })]
6772
6800
  }) })
6773
6801
  ]
@@ -6780,8 +6808,12 @@ function ResumeSubscriptionDialog({ open, onOpenChange, onConfirm, isLoading, er
6780
6808
  const [selectedDate, setSelectedDate] = useState(void 0);
6781
6809
  const [calendarOpen, setCalendarOpen] = useState(false);
6782
6810
  const [confirmingEarlyOrder, setConfirmingEarlyOrder] = useState(false);
6811
+ const [earlyOrderRefusal, setEarlyOrderRefusal] = useState(null);
6783
6812
  useEffect(() => {
6784
- if (!open) setConfirmingEarlyOrder(false);
6813
+ if (!open) {
6814
+ setConfirmingEarlyOrder(false);
6815
+ setEarlyOrderRefusal(null);
6816
+ }
6785
6817
  }, [open]);
6786
6818
  const [popoverContainer, setPopoverContainer] = useState(null);
6787
6819
  const today = /* @__PURE__ */ new Date();
@@ -6794,21 +6826,35 @@ function ResumeSubscriptionDialog({ open, onOpenChange, onConfirm, isLoading, er
6794
6826
  setSelectedDate(isBlackoutDay(clamped, blackoutDays) ? void 0 : clamped);
6795
6827
  }, [open, defaultNextBillDate]);
6796
6828
  const selectedDayIso = selectedDate ? format(selectedDate, "yyyy-MM-dd") : "";
6797
- const scheduledDayIso = currentNextBillDate ? calendarDayIso(currentNextBillDate, timezone) : "";
6798
- const lastOrderDayIso = currentLastBillDate ? calendarDayIso(currentLastBillDate, timezone) : "";
6829
+ const scheduledDate = earlyOrderRefusal?.scheduledDate ?? currentNextBillDate;
6830
+ const lastBillDate = earlyOrderRefusal ? earlyOrderRefusal.lastBillDate : currentLastBillDate;
6831
+ const scheduledDayIso = scheduledDate ? calendarDayIso(scheduledDate, timezone) : "";
6832
+ const lastOrderDayIso = lastBillDate ? calendarDayIso(lastBillDate, timezone) : "";
6799
6833
  const placesEarlyOrder = selectedDayIso !== "" && scheduledDayIso !== "" && selectedDayIso < scheduledDayIso;
6834
+ const submitDate = async () => {
6835
+ try {
6836
+ await onConfirm(selectedDayIso, placesEarlyOrder);
6837
+ } catch (error) {
6838
+ const refusal = readEarlyOrderRefusal(error);
6839
+ if (refusal) {
6840
+ setEarlyOrderRefusal(refusal);
6841
+ setConfirmingEarlyOrder(true);
6842
+ }
6843
+ }
6844
+ };
6800
6845
  const handleConfirm = () => {
6801
6846
  if (!selectedDayIso) return;
6802
6847
  if (placesEarlyOrder && !confirmingEarlyOrder) {
6803
6848
  setConfirmingEarlyOrder(true);
6804
6849
  return;
6805
6850
  }
6806
- onConfirm(selectedDayIso);
6851
+ submitDate();
6807
6852
  };
6808
6853
  const handleDismiss = (next) => {
6809
6854
  if (!next) {
6810
6855
  setSelectedDate(void 0);
6811
6856
  setConfirmingEarlyOrder(false);
6857
+ setEarlyOrderRefusal(null);
6812
6858
  setCalendarOpen(false);
6813
6859
  }
6814
6860
  onOpenChange(next);
@@ -7027,7 +7073,7 @@ function EditBillDateDialog({ open, onOpenChange, onConfirm, isLoading, errorMes
7027
7073
  const scheduledDayIso = scheduledDate ? calendarDayIso(scheduledDate, timezone) : "";
7028
7074
  const lastOrderDayIso = lastBillDate ? calendarDayIso(lastBillDate, timezone) : "";
7029
7075
  const selectedDayIso = selectedDate ? format(selectedDate, "yyyy-MM-dd") : "";
7030
- const placesEarlyOrder = confirmEarlyOrder && selectedDayIso !== "" && scheduledDayIso !== "" && selectedDayIso < scheduledDayIso;
7076
+ const placesEarlyOrder = (confirmEarlyOrder || earlyOrderRefusal !== null) && selectedDayIso !== "" && scheduledDayIso !== "" && selectedDayIso < scheduledDayIso;
7031
7077
  const submitDate = async () => {
7032
7078
  if (!selectedDayIso) return;
7033
7079
  try {
@@ -8386,11 +8432,17 @@ function SubscriptionDetail({ token, onNotFound, onError, onSuccess, onMutationE
8386
8432
  const shownPauseResumeDateRef = useRef(null);
8387
8433
  const pauseMutation = usePauseSubscription({
8388
8434
  onSuccess: (saved, { pauseParams }) => onSuccess?.(billDateMovedNotice(pauseParams.nextBillDate ?? shownPauseResumeDateRef.current, saved.subscription.next_bill_date, t, locale, saved.subscription.timezone) ?? t("subscription_paused")),
8389
- onError: (err) => onMutationError?.(t("failed_to_pause"), err)
8435
+ onError: (err) => {
8436
+ if (readEarlyOrderRefusal(err)) return;
8437
+ onMutationError?.(t("failed_to_pause"), err);
8438
+ }
8390
8439
  });
8391
8440
  const resumeMutation = useResumeSubscription({
8392
8441
  onSuccess: (saved, { resumeParams }) => onSuccess?.(billDateMovedNotice(resumeParams.nextBillDate, saved.subscription.next_bill_date, t, locale, saved.subscription.timezone) ?? t("subscription_resumed")),
8393
- onError: (err) => onMutationError?.(t("failed_to_resume"), err)
8442
+ onError: (err) => {
8443
+ if (readEarlyOrderRefusal(err)) return;
8444
+ onMutationError?.(t("failed_to_resume"), err);
8445
+ }
8394
8446
  });
8395
8447
  const skipMutation = useSkipSubscription({
8396
8448
  onSuccess: () => onSuccess?.(t("next_billing_skipped")),
@@ -8504,24 +8556,26 @@ function SubscriptionDetail({ token, onNotFound, onError, onSuccess, onMutationE
8504
8556
  const aggregateRecoveryDisabled = directParentRecoveryDisabled || childPaymentRecoveryDisabled || waiverMutationPending;
8505
8557
  const paymentMethodDisabled = isSubscriptionCompleted(subscription) || directParentRecoveryDisabled || waiverMutationPending || independentParentMutationDisabled;
8506
8558
  const isMutating = independentParentMutationDisabled || aggregateRecoveryDisabled;
8507
- const handlePauseConfirm = (selection) => {
8559
+ const handlePauseConfirm = (selection, confirmEarlyOrder) => {
8508
8560
  const pauseParams = { customerId };
8509
8561
  shownPauseResumeDateRef.current = null;
8510
8562
  if (selection.type === "order_count") {
8511
8563
  pauseParams.numberOfOrders = selection.numberOfOrders;
8512
8564
  shownPauseResumeDateRef.current = selection.shownResumeDate;
8513
8565
  }
8514
- pauseMutation.mutate({
8566
+ if (confirmEarlyOrder) pauseParams.confirmEarlyOrder = true;
8567
+ return pauseMutation.mutateAsync({
8515
8568
  subscriptionToken: token,
8516
8569
  pauseParams
8517
8570
  }, { onSuccess: () => setShowPauseModal(false) });
8518
8571
  };
8519
- const handleResumeConfirm = (nextBillDate) => {
8520
- resumeMutation.mutate({
8572
+ const handleResumeConfirm = (nextBillDate, placesEarlyOrder) => {
8573
+ return resumeMutation.mutateAsync({
8521
8574
  subscriptionToken: token,
8522
8575
  resumeParams: {
8523
8576
  customerId,
8524
- nextBillDate
8577
+ nextBillDate,
8578
+ ...placesEarlyOrder ? { confirmEarlyOrder: true } : {}
8525
8579
  }
8526
8580
  }, { onSuccess: () => setShowResumeModal(false) });
8527
8581
  };
@@ -8628,7 +8682,10 @@ function SubscriptionDetail({ token, onNotFound, onError, onSuccess, onMutationE
8628
8682
  }
8629
8683
  }, {
8630
8684
  onSuccess: () => setShowCancelModal(false),
8631
- onError: () => setShowCancelModal(false)
8685
+ onError: (err) => {
8686
+ setShowCancelModal(false);
8687
+ if (readEarlyOrderRefusal(err)) onMutationError?.(t("failed_to_pause"), err);
8688
+ }
8632
8689
  });
8633
8690
  },
8634
8691
  isPending: pauseMutation.isPending
@@ -8670,7 +8727,7 @@ function SubscriptionDetail({ token, onNotFound, onError, onSuccess, onMutationE
8670
8727
  },
8671
8728
  onConfirm: handlePauseConfirm,
8672
8729
  isLoading: pauseMutation.isPending,
8673
- errorMessage: pauseMutation.isError ? t("generic_error") : void 0,
8730
+ errorMessage: pauseMutation.isError && !readEarlyOrderRefusal(pauseMutation.error) ? t("generic_error") : void 0,
8674
8731
  currentNextBillDate: subscription.next_bill_date,
8675
8732
  billingInterval: plan.billing_interval,
8676
8733
  billingIntervalUnit: plan.billing_interval_unit
@@ -8684,7 +8741,7 @@ function SubscriptionDetail({ token, onNotFound, onError, onSuccess, onMutationE
8684
8741
  },
8685
8742
  onConfirm: handleResumeConfirm,
8686
8743
  isLoading: resumeMutation.isPending,
8687
- errorMessage: resumeMutation.isError ? t("generic_error") : void 0,
8744
+ errorMessage: resumeMutation.isError && !readEarlyOrderRefusal(resumeMutation.error) ? t("generic_error") : void 0,
8688
8745
  blackoutDays: subscription.blackout_days,
8689
8746
  defaultNextBillDate: calculateNextBillDate(plan.billing_interval, plan.billing_interval_unit),
8690
8747
  currentNextBillDate: subscription.next_bill_date,
@@ -10675,4 +10732,4 @@ const subscriptionsScreenPropertySchema = {
10675
10732
  //#endregion
10676
10733
  export { subscriptionsScreenPropertySchema as n, SubscriptionsScreen as t };
10677
10734
 
10678
- //# sourceMappingURL=SubscriptionsScreen-yah2TAvw.mjs.map
10735
+ //# sourceMappingURL=SubscriptionsScreen-D0UjahrX.mjs.map