@fluid-app/portal-sdk 0.1.254 → 0.1.255
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AddressAutocompleteInput-Dy5sL54V.mjs → AddressAutocompleteInput-Dg-75n-K.mjs} +9 -12
- package/dist/AddressAutocompleteInput-Dg-75n-K.mjs.map +1 -0
- package/dist/{AddressAutocompleteInput-eO2ZMNvX.cjs → AddressAutocompleteInput-W2jWPYoJ.cjs} +26 -11
- package/dist/AddressAutocompleteInput-W2jWPYoJ.cjs.map +1 -0
- package/dist/{ProfileScreen-CfTHeXRn.mjs → ProfileScreen-D42NNNqT.mjs} +2 -2
- package/dist/{ProfileScreen-DxO1rvGl.mjs → ProfileScreen-Dvq3SfmI.mjs} +2 -2
- package/dist/{ProfileScreen-DxO1rvGl.mjs.map → ProfileScreen-Dvq3SfmI.mjs.map} +1 -1
- package/dist/{ProfileScreen-CFXyi6hi.cjs → ProfileScreen-LL3z9-cx.cjs} +2 -2
- package/dist/{ProfileScreen-CFXyi6hi.cjs.map → ProfileScreen-LL3z9-cx.cjs.map} +1 -1
- package/dist/{ProfileScreen-CS-4fa9g.cjs → ProfileScreen-dU8ZM8eY.cjs} +2 -2
- package/dist/{SubscriptionsScreen-ByoOMsky.cjs → SubscriptionsScreen-Bm8Ncl1e.cjs} +624 -166
- package/dist/SubscriptionsScreen-Bm8Ncl1e.cjs.map +1 -0
- package/dist/{SubscriptionsScreen-Y4UgpC1Y.mjs → SubscriptionsScreen-CsNE6gik.mjs} +627 -169
- package/dist/SubscriptionsScreen-CsNE6gik.mjs.map +1 -0
- package/dist/{SubscriptionsScreen-GCZYPM8-.cjs → SubscriptionsScreen-ztgglvXe.cjs} +2 -2
- package/dist/index.cjs +7 -7
- package/dist/index.mjs +7 -7
- package/package.json +15 -15
- package/dist/AddressAutocompleteInput-Dy5sL54V.mjs.map +0 -1
- package/dist/AddressAutocompleteInput-eO2ZMNvX.cjs.map +0 -1
- package/dist/SubscriptionsScreen-ByoOMsky.cjs.map +0 -1
- package/dist/SubscriptionsScreen-Y4UgpC1Y.mjs.map +0 -1
|
@@ -8,7 +8,7 @@ const require_ScreenHeaderContext = require("./ScreenHeaderContext-JDIUM84f.cjs"
|
|
|
8
8
|
const require_query_keys = require("./query-keys-BpEJqQUB.cjs");
|
|
9
9
|
const require_use_account = require("./use-account-BfU-TydK.cjs");
|
|
10
10
|
const require_AppNavigationContext = require("./AppNavigationContext-CDowN9gd.cjs");
|
|
11
|
-
const require_AddressAutocompleteInput = require("./AddressAutocompleteInput-
|
|
11
|
+
const require_AddressAutocompleteInput = require("./AddressAutocompleteInput-W2jWPYoJ.cjs");
|
|
12
12
|
const require_isAfter = require("./isAfter-DoabulQ5.cjs");
|
|
13
13
|
const require_order_status_badge = require("./order-status-badge-BbY5RoiL.cjs");
|
|
14
14
|
const require_SearchSort = require("./SearchSort-CKdDCwqf.cjs");
|
|
@@ -2706,6 +2706,7 @@ function createPortalSubscriptionsAdapter(client) {
|
|
|
2706
2706
|
const subscription = {};
|
|
2707
2707
|
if (body.payment_method_id != null) subscription.payment_method_id = body.payment_method_id;
|
|
2708
2708
|
if (body.quantity != null) subscription.quantity = body.quantity;
|
|
2709
|
+
if (body.address_id != null) subscription.address_id = body.address_id;
|
|
2709
2710
|
if (body.next_bill_date != null) subscription.next_bill_date = body.next_bill_date;
|
|
2710
2711
|
return mapSubscriptionDetail(await require_portal_tenant.subscriptions_update(client, subscriptionToken, { subscription }));
|
|
2711
2712
|
}
|
|
@@ -4064,7 +4065,7 @@ function SubscriptionManagementSection({ subscription, isActive, isPaused, isCan
|
|
|
4064
4065
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4065
4066
|
className: "pt-2",
|
|
4066
4067
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
|
|
4067
|
-
className: "text-foreground text-sm/6 font-semibold",
|
|
4068
|
+
className: "text-foreground mb-4 text-sm/6 font-semibold",
|
|
4068
4069
|
children: "Payment & Shipping"
|
|
4069
4070
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4070
4071
|
className: "flex flex-col",
|
|
@@ -4464,136 +4465,119 @@ function SubscriptionDetailScreen$1({ token, onNavigateToList, onNavigateToSubsc
|
|
|
4464
4465
|
* (accordion, collapsed summary, list, add button), with rows that
|
|
4465
4466
|
* commit a selection through onSelectPaymentMethod when clicked.
|
|
4466
4467
|
*/
|
|
4467
|
-
function SelectablePaymentMethodDropdown({ title, displayPaymentMethod, paymentMethodList, selectedPaymentMethodId, onSelectPaymentMethod, onAddPaymentMethodClick, addPaymentMethodLabel = "+ Add a payment method", showAddButton = true, isLoading = false, isPending = false, className = "" }) {
|
|
4468
|
-
const [
|
|
4469
|
-
const
|
|
4470
|
-
|
|
4471
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4472
|
-
className: "flex flex-row items-center space-x-2",
|
|
4473
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4474
|
-
className: "flex h-6 w-10 flex-shrink-0 items-center justify-center",
|
|
4475
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.PaymentIcon, {
|
|
4476
|
-
logoUrl: paymentMethod.details.logo_url,
|
|
4477
|
-
brand: paymentMethod.details.card_type,
|
|
4478
|
-
alt: paymentMethod.details.card_type ?? "Payment Method"
|
|
4479
|
-
})
|
|
4480
|
-
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4481
|
-
className: "flex flex-col",
|
|
4482
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4483
|
-
className: "text-foreground flex items-center text-sm font-medium capitalize",
|
|
4484
|
-
children: require_AddressAutocompleteInput.getCardDisplayName(paymentMethod)
|
|
4485
|
-
}), expiry && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4486
|
-
className: "text-muted-foreground text-sm",
|
|
4487
|
-
children: expiry
|
|
4488
|
-
})]
|
|
4489
|
-
})]
|
|
4490
|
-
});
|
|
4491
|
-
};
|
|
4468
|
+
function SelectablePaymentMethodDropdown({ title, displayPaymentMethod, paymentMethodList, selectedPaymentMethodId, onSelectPaymentMethod, onAddPaymentMethodClick, onEditPaymentMethod, onDeletePaymentMethod, onMakeDefaultPaymentMethod, addPaymentMethodLabel = "+ Add a payment method", showAddButton = true, isLoading = false, isPending = false, className = "" }) {
|
|
4469
|
+
const [isOpen, setIsOpen] = (0, react.useState)(false);
|
|
4470
|
+
const sectionId = (0, react.useId)();
|
|
4471
|
+
const collapsedExpiry = displayPaymentMethod ? require_AddressAutocompleteInput.getCardExpiry(displayPaymentMethod) : null;
|
|
4492
4472
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4493
4473
|
className: require_src.cn("border-border mb-6 border-b pb-4", className),
|
|
4494
|
-
children: [
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
})]
|
|
4517
|
-
}) : !paymentsValue && displayPaymentMethod && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4518
|
-
className: "mb-2 flex w-full cursor-pointer flex-col",
|
|
4519
|
-
onClick: () => setPaymentsValue("payment_methods"),
|
|
4520
|
-
children: renderPaymentMethod(displayPaymentMethod)
|
|
4521
|
-
}),
|
|
4522
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.AccordionContent, {
|
|
4523
|
-
className: "max-h-[400px] overflow-y-auto px-0.5 pt-2 pb-1",
|
|
4524
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4525
|
-
className: "mt-2 flex flex-col justify-between space-y-4",
|
|
4526
|
-
children: isLoading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: [1, 2].map((i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4527
|
-
className: "bg-muted items-center rounded p-3",
|
|
4528
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4529
|
-
className: "flex flex-row items-center space-x-2",
|
|
4530
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-6 w-10" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4531
|
-
className: "flex flex-col space-y-1",
|
|
4532
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-4 w-32" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-4 w-24" })]
|
|
4533
|
-
})]
|
|
4534
|
-
})
|
|
4535
|
-
}, `skeleton-${i}`)) }) : paymentMethodList.map((paymentMethod) => {
|
|
4536
|
-
const isSelected = selectedPaymentMethodId === paymentMethod.id;
|
|
4537
|
-
const expiry = require_AddressAutocompleteInput.getCardExpiry(paymentMethod);
|
|
4538
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
4539
|
-
type: "button",
|
|
4540
|
-
"aria-pressed": isSelected,
|
|
4541
|
-
disabled: isPending,
|
|
4542
|
-
onClick: () => onSelectPaymentMethod(paymentMethod),
|
|
4543
|
-
className: require_src.cn("bg-card text-card-foreground ring-border flex min-h-[48px] w-full flex-row items-center justify-between space-x-2 rounded p-3 text-left ring-1 transition-opacity", "not-disabled:cursor-pointer disabled:cursor-not-allowed", {
|
|
4544
|
-
"opacity-60 hover:opacity-100": !isSelected,
|
|
4545
|
-
"ring-primary z-10 opacity-100": isSelected
|
|
4546
|
-
}),
|
|
4547
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4548
|
-
className: "flex flex-row items-center space-x-3",
|
|
4549
|
-
children: [
|
|
4550
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4551
|
-
"aria-hidden": true,
|
|
4552
|
-
className: require_src.cn("flex h-4 w-4 shrink-0 items-center justify-center rounded-full border", isSelected ? "border-primary" : "border-input"),
|
|
4553
|
-
children: isSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "bg-primary h-2 w-2 rounded-full" })
|
|
4554
|
-
}),
|
|
4555
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4556
|
-
className: "flex h-6 w-10 flex-shrink-0 items-center justify-center",
|
|
4557
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.PaymentIcon, {
|
|
4558
|
-
logoUrl: paymentMethod.details.logo_url,
|
|
4559
|
-
brand: paymentMethod.details.card_type,
|
|
4560
|
-
alt: paymentMethod.details.card_type ?? "Payment Method"
|
|
4561
|
-
})
|
|
4562
|
-
}),
|
|
4563
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4564
|
-
className: "flex flex-col",
|
|
4565
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4566
|
-
className: "text-card-foreground flex items-center text-sm font-medium capitalize",
|
|
4567
|
-
children: require_AddressAutocompleteInput.getCardDisplayName(paymentMethod)
|
|
4568
|
-
}), expiry && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4569
|
-
className: "text-muted-foreground text-sm",
|
|
4570
|
-
children: expiry
|
|
4571
|
-
})]
|
|
4572
|
-
})
|
|
4573
|
-
]
|
|
4574
|
-
}), paymentMethod.default && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
4575
|
-
className: "bg-secondary text-secondary-foreground rounded px-2 py-0.5 text-xs font-medium",
|
|
4576
|
-
children: "Default"
|
|
4577
|
-
})]
|
|
4578
|
-
}, paymentMethod.id);
|
|
4579
|
-
})
|
|
4580
|
-
})
|
|
4474
|
+
children: [
|
|
4475
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
4476
|
+
type: "button",
|
|
4477
|
+
"aria-expanded": isOpen,
|
|
4478
|
+
"aria-controls": sectionId,
|
|
4479
|
+
onClick: () => setIsOpen((prev) => !prev),
|
|
4480
|
+
className: "flex w-full flex-row items-center justify-between",
|
|
4481
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4482
|
+
className: "text-muted-foreground text-sm",
|
|
4483
|
+
children: title
|
|
4484
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: require_src.cn("text-muted-foreground h-4 w-4 transition-transform duration-200", isOpen && "rotate-180") })]
|
|
4485
|
+
}),
|
|
4486
|
+
!isOpen && displayPaymentMethod && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
4487
|
+
type: "button",
|
|
4488
|
+
onClick: () => setIsOpen(true),
|
|
4489
|
+
className: "mt-1 mb-2 flex w-full cursor-pointer flex-row items-center gap-3 text-left",
|
|
4490
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4491
|
+
className: "flex h-6 w-10 flex-shrink-0 items-center justify-center",
|
|
4492
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.PaymentIcon, {
|
|
4493
|
+
logoUrl: displayPaymentMethod.details.logo_url,
|
|
4494
|
+
brand: displayPaymentMethod.details.card_type,
|
|
4495
|
+
alt: displayPaymentMethod.details.card_type ?? "Payment Method"
|
|
4581
4496
|
})
|
|
4582
|
-
|
|
4497
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4498
|
+
className: "flex min-w-0 flex-col",
|
|
4499
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4500
|
+
className: "text-foreground text-sm font-medium capitalize",
|
|
4501
|
+
children: require_AddressAutocompleteInput.getCardDisplayName(displayPaymentMethod)
|
|
4502
|
+
}), collapsedExpiry && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4503
|
+
className: "text-muted-foreground text-sm",
|
|
4504
|
+
children: collapsedExpiry
|
|
4505
|
+
})]
|
|
4506
|
+
})]
|
|
4507
|
+
}),
|
|
4508
|
+
isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4509
|
+
id: sectionId,
|
|
4510
|
+
className: "mt-5 flex max-h-[400px] flex-col space-y-4 overflow-y-auto pr-0.5",
|
|
4511
|
+
children: isLoading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: [1, 2].map((i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4512
|
+
className: "bg-muted flex flex-row items-center space-x-2 rounded-sm p-3",
|
|
4513
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-6 w-10" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4514
|
+
className: "flex flex-col space-y-1",
|
|
4515
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-4 w-32" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-4 w-24" })]
|
|
4516
|
+
})]
|
|
4517
|
+
}, `skeleton-${i}`)) }) : paymentMethodList.map((paymentMethod) => {
|
|
4518
|
+
const isSelected = selectedPaymentMethodId === paymentMethod.id;
|
|
4519
|
+
const expiry = require_AddressAutocompleteInput.getCardExpiry(paymentMethod);
|
|
4520
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
4521
|
+
type: "button",
|
|
4522
|
+
"aria-pressed": isSelected,
|
|
4523
|
+
disabled: isPending,
|
|
4524
|
+
onClick: () => onSelectPaymentMethod(paymentMethod),
|
|
4525
|
+
className: require_src.cn("text-foreground flex w-full flex-row items-center justify-between gap-3 rounded-sm p-3 text-left transition-colors", "not-disabled:cursor-pointer disabled:cursor-not-allowed disabled:opacity-60", isSelected ? "bg-background border-border border" : "bg-muted hover:bg-muted/80 border border-transparent"),
|
|
4526
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4527
|
+
className: "flex min-w-0 flex-row items-center gap-3",
|
|
4528
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4529
|
+
className: "flex h-6 w-10 flex-shrink-0 items-center justify-center",
|
|
4530
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.PaymentIcon, {
|
|
4531
|
+
logoUrl: paymentMethod.details.logo_url,
|
|
4532
|
+
brand: paymentMethod.details.card_type,
|
|
4533
|
+
alt: paymentMethod.details.card_type ?? "Payment Method"
|
|
4534
|
+
})
|
|
4535
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4536
|
+
className: "flex min-w-0 flex-col",
|
|
4537
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4538
|
+
className: "text-foreground text-sm font-medium capitalize",
|
|
4539
|
+
children: require_AddressAutocompleteInput.getCardDisplayName(paymentMethod)
|
|
4540
|
+
}), expiry && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4541
|
+
className: "text-muted-foreground text-sm",
|
|
4542
|
+
children: expiry
|
|
4543
|
+
})]
|
|
4544
|
+
})]
|
|
4545
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4546
|
+
className: "flex shrink-0 flex-row items-center gap-2",
|
|
4547
|
+
children: [paymentMethod.default && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4548
|
+
className: "bg-primary text-primary-foreground rounded px-2 py-0.5 text-xs font-medium",
|
|
4549
|
+
children: "Default"
|
|
4550
|
+
}), (onEditPaymentMethod || onDeletePaymentMethod || onMakeDefaultPaymentMethod) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4551
|
+
onClick: (e) => e.stopPropagation(),
|
|
4552
|
+
onKeyDown: (e) => e.stopPropagation(),
|
|
4553
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.EllipsesDropdown, {
|
|
4554
|
+
onEdit: onEditPaymentMethod ? () => onEditPaymentMethod(paymentMethod) : void 0,
|
|
4555
|
+
onDelete: onDeletePaymentMethod ? () => onDeletePaymentMethod(paymentMethod) : void 0,
|
|
4556
|
+
onMakeDefault: !paymentMethod.default && onMakeDefaultPaymentMethod ? () => onMakeDefaultPaymentMethod(paymentMethod) : void 0
|
|
4557
|
+
})
|
|
4558
|
+
})]
|
|
4559
|
+
})]
|
|
4560
|
+
}, paymentMethod.id);
|
|
4561
|
+
})
|
|
4562
|
+
}),
|
|
4563
|
+
showAddButton && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4564
|
+
type: "button",
|
|
4565
|
+
disabled: isPending,
|
|
4566
|
+
className: "text-foreground mt-3 text-left text-sm disabled:cursor-not-allowed disabled:opacity-60",
|
|
4567
|
+
onClick: onAddPaymentMethodClick,
|
|
4568
|
+
children: addPaymentMethodLabel
|
|
4583
4569
|
})
|
|
4584
|
-
|
|
4585
|
-
type: "button",
|
|
4586
|
-
disabled: isPending,
|
|
4587
|
-
className: require_src.cn("text-foreground text-left text-sm disabled:cursor-not-allowed disabled:opacity-60", paymentsValue ? "mt-4" : "mt-3"),
|
|
4588
|
-
onClick: onAddPaymentMethodClick,
|
|
4589
|
-
children: addPaymentMethodLabel
|
|
4590
|
-
})]
|
|
4570
|
+
]
|
|
4591
4571
|
});
|
|
4592
4572
|
}
|
|
4593
4573
|
//#endregion
|
|
4594
4574
|
//#region src/subscriptions/PortalSubscriptionPaymentMethodSection.tsx
|
|
4595
|
-
const t = (key) => ({
|
|
4575
|
+
const t$1 = (key) => ({
|
|
4596
4576
|
add_credit_card: "Add Credit Card",
|
|
4577
|
+
edit_card: "Card Details",
|
|
4578
|
+
delete_credit_card: "Delete Credit Card",
|
|
4579
|
+
delete_credit_card_message: "Are you sure you want to delete this payment method? This action cannot be undone.",
|
|
4580
|
+
delete: "Delete",
|
|
4597
4581
|
save_card: "Save Card",
|
|
4598
4582
|
securing: "Loading secure form...",
|
|
4599
4583
|
cancel: "Cancel",
|
|
@@ -4641,6 +4625,9 @@ function PortalSubscriptionPaymentMethodSection({ paymentMethod: currentPaymentM
|
|
|
4641
4625
|
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
4642
4626
|
const fluidPayShim = (0, react.useMemo)(() => require_AddressAutocompleteInput.createFluidPayApiAdapter(payApi), [payApi]);
|
|
4643
4627
|
const [isAddDialogOpen, setIsAddDialogOpen] = (0, react.useState)(false);
|
|
4628
|
+
const [editingPaymentMethod, setEditingPaymentMethod] = (0, react.useState)(null);
|
|
4629
|
+
const [deletingPaymentMethod, setDeletingPaymentMethod] = (0, react.useState)(null);
|
|
4630
|
+
const [deleteError, setDeleteError] = (0, react.useState)(void 0);
|
|
4644
4631
|
const { data: paymentMethods = [], isLoading: isLoadingMethods } = (0, _tanstack_react_query.useQuery)({
|
|
4645
4632
|
queryKey: require_query_keys.payKeys.paymentMethods.list(),
|
|
4646
4633
|
queryFn: async () => {
|
|
@@ -4651,7 +4638,7 @@ function PortalSubscriptionPaymentMethodSection({ paymentMethod: currentPaymentM
|
|
|
4651
4638
|
const { data: countriesData } = (0, _tanstack_react_query.useQuery)({
|
|
4652
4639
|
queryKey: require_query_keys.storeKeys.countries(),
|
|
4653
4640
|
queryFn: () => countriesApi.listCountries(),
|
|
4654
|
-
enabled: isAddDialogOpen
|
|
4641
|
+
enabled: isAddDialogOpen || editingPaymentMethod !== null
|
|
4655
4642
|
});
|
|
4656
4643
|
const countryOptions = (0, react.useMemo)(() => [...countriesData?.countries ?? []].map((c) => ({
|
|
4657
4644
|
iso: c.code,
|
|
@@ -4676,49 +4663,513 @@ function PortalSubscriptionPaymentMethodSection({ paymentMethod: currentPaymentM
|
|
|
4676
4663
|
},
|
|
4677
4664
|
onError: (err) => onError?.("Failed to add payment method", err)
|
|
4678
4665
|
});
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
selectedPaymentMethodId: currentPaymentMethod.id,
|
|
4691
|
-
onSelectPaymentMethod: (pm) => {
|
|
4692
|
-
if (pm.id === currentPaymentMethod.id) return;
|
|
4693
|
-
updateSubscription.mutate({
|
|
4694
|
-
subscriptionToken,
|
|
4695
|
-
body: { payment_method_id: pm.id }
|
|
4696
|
-
});
|
|
4666
|
+
const updatePaymentMethodMutation = (0, _tanstack_react_query.useMutation)({
|
|
4667
|
+
mutationFn: ({ paymentMethodId, data }) => payApi.updatePaymentMethod(paymentMethodId, { payment_method: {
|
|
4668
|
+
default: data.set_as_default,
|
|
4669
|
+
billing_address: {
|
|
4670
|
+
name: data.billing_address.name,
|
|
4671
|
+
street1: data.billing_address.address1,
|
|
4672
|
+
street2: data.billing_address.address2 ?? null,
|
|
4673
|
+
city: data.billing_address.city,
|
|
4674
|
+
state: data.billing_address.state,
|
|
4675
|
+
zip: data.billing_address.zip,
|
|
4676
|
+
country: data.billing_address.country_code
|
|
4697
4677
|
}
|
|
4698
|
-
}
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4678
|
+
} }),
|
|
4679
|
+
onSuccess: async () => {
|
|
4680
|
+
await queryClient.invalidateQueries({ queryKey: require_query_keys.payKeys.paymentMethods.all });
|
|
4681
|
+
onSuccess?.("Payment method updated");
|
|
4682
|
+
},
|
|
4683
|
+
onError: (err) => onError?.("Failed to update payment method", err)
|
|
4684
|
+
});
|
|
4685
|
+
const deletePaymentMethodMutation = (0, _tanstack_react_query.useMutation)({
|
|
4686
|
+
mutationFn: (paymentMethodId) => payApi.deletePaymentMethod(paymentMethodId),
|
|
4687
|
+
onSuccess: async () => {
|
|
4688
|
+
await queryClient.invalidateQueries({ queryKey: require_query_keys.payKeys.paymentMethods.all });
|
|
4689
|
+
onSuccess?.("Payment method deleted");
|
|
4690
|
+
}
|
|
4691
|
+
});
|
|
4692
|
+
const makeDefaultPaymentMethodMutation = (0, _tanstack_react_query.useMutation)({
|
|
4693
|
+
mutationFn: (pm) => {
|
|
4694
|
+
const body = { payment_method: { default: true } };
|
|
4695
|
+
if (pm.billing_address) body.payment_method.billing_address = {
|
|
4696
|
+
name: pm.billing_address.name,
|
|
4697
|
+
street1: pm.billing_address.address1 ?? "",
|
|
4698
|
+
street2: pm.billing_address.address2 ?? null,
|
|
4699
|
+
city: pm.billing_address.city ?? "",
|
|
4700
|
+
state: pm.billing_address.state ?? "",
|
|
4701
|
+
zip: pm.billing_address.zip ?? "",
|
|
4702
|
+
country: pm.billing_address.country_code ?? ""
|
|
4703
|
+
};
|
|
4704
|
+
return payApi.updatePaymentMethod(pm.id, body);
|
|
4705
|
+
},
|
|
4706
|
+
onSuccess: async () => {
|
|
4707
|
+
await queryClient.invalidateQueries({ queryKey: require_query_keys.payKeys.paymentMethods.all });
|
|
4708
|
+
onSuccess?.("Default payment method updated");
|
|
4709
|
+
},
|
|
4710
|
+
onError: (err) => onError?.("Failed to update default payment method", err)
|
|
4711
|
+
});
|
|
4712
|
+
const displayed = paymentMethods.find((pm) => pm.id === currentPaymentMethod.id) ?? subscriptionPaymentMethodToFluidPay(currentPaymentMethod);
|
|
4713
|
+
const handleConfirmDelete = async () => {
|
|
4714
|
+
if (!deletingPaymentMethod) return;
|
|
4715
|
+
setDeleteError(void 0);
|
|
4716
|
+
try {
|
|
4717
|
+
await deletePaymentMethodMutation.mutateAsync(deletingPaymentMethod.id);
|
|
4718
|
+
setDeletingPaymentMethod(null);
|
|
4719
|
+
} catch (err) {
|
|
4720
|
+
setDeleteError(err instanceof Error ? err.message : "We were unable to delete this payment method. Please try again.");
|
|
4721
|
+
}
|
|
4722
|
+
};
|
|
4723
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.FluidPayCoreProvider, {
|
|
4724
|
+
api: fluidPayShim,
|
|
4725
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_AddressAutocompleteInput.ProfileUIProvider, {
|
|
4726
|
+
t: t$1,
|
|
4727
|
+
children: [
|
|
4728
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectablePaymentMethodDropdown, {
|
|
4729
|
+
title: "Payment Method",
|
|
4730
|
+
displayPaymentMethod: displayed,
|
|
4731
|
+
paymentMethodList: paymentMethods,
|
|
4732
|
+
onAddPaymentMethodClick: () => setIsAddDialogOpen(true),
|
|
4733
|
+
addPaymentMethodLabel: "+ Add Payment Method",
|
|
4734
|
+
showAddButton: true,
|
|
4735
|
+
isLoading: isLoadingMethods,
|
|
4736
|
+
isPending: updateSubscription.isPending || addCardMutation.isPending || updatePaymentMethodMutation.isPending || makeDefaultPaymentMethodMutation.isPending,
|
|
4737
|
+
selectedPaymentMethodId: currentPaymentMethod.id,
|
|
4738
|
+
onSelectPaymentMethod: (pm) => {
|
|
4739
|
+
if (pm.id === currentPaymentMethod.id) return;
|
|
4740
|
+
updateSubscription.mutate({
|
|
4741
|
+
subscriptionToken,
|
|
4742
|
+
body: { payment_method_id: pm.id }
|
|
4743
|
+
});
|
|
4744
|
+
},
|
|
4745
|
+
onEditPaymentMethod: (pm) => setEditingPaymentMethod(pm),
|
|
4746
|
+
onDeletePaymentMethod: (pm) => {
|
|
4747
|
+
setDeleteError(void 0);
|
|
4748
|
+
setDeletingPaymentMethod(pm);
|
|
4749
|
+
},
|
|
4750
|
+
onMakeDefaultPaymentMethod: (pm) => makeDefaultPaymentMethodMutation.mutate(pm)
|
|
4751
|
+
}),
|
|
4752
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.CreditCardFormDialog, {
|
|
4753
|
+
isOpen: isAddDialogOpen,
|
|
4754
|
+
onClose: () => setIsAddDialogOpen(false),
|
|
4755
|
+
t: t$1,
|
|
4756
|
+
onSubmit: async (data) => {
|
|
4757
|
+
try {
|
|
4758
|
+
await addCardMutation.mutateAsync(data);
|
|
4759
|
+
setIsAddDialogOpen(false);
|
|
4760
|
+
} catch {}
|
|
4761
|
+
},
|
|
4762
|
+
isSubmitting: addCardMutation.isPending,
|
|
4763
|
+
countries: countryOptions,
|
|
4764
|
+
jwt: "",
|
|
4765
|
+
renderAddressAutocomplete: ({ control, setValue, countryCode }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.AddressAutocompleteInput, {
|
|
4766
|
+
control,
|
|
4767
|
+
setValue,
|
|
4768
|
+
countryIso: countryCode,
|
|
4769
|
+
addressLineField: "address1",
|
|
4770
|
+
cityField: "city",
|
|
4771
|
+
stateField: "state",
|
|
4772
|
+
postalCodeField: "zip",
|
|
4773
|
+
placeholder: t$1("address_line_1")
|
|
4774
|
+
})
|
|
4775
|
+
}),
|
|
4776
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.EditPaymentMethodDialog, {
|
|
4777
|
+
isOpen: editingPaymentMethod !== null,
|
|
4778
|
+
paymentMethod: editingPaymentMethod,
|
|
4779
|
+
billingAddress: editingPaymentMethod?.billing_address ?? null,
|
|
4780
|
+
onClose: () => setEditingPaymentMethod(null),
|
|
4781
|
+
onSubmit: async (data) => {
|
|
4782
|
+
if (!editingPaymentMethod) return;
|
|
4783
|
+
try {
|
|
4784
|
+
await updatePaymentMethodMutation.mutateAsync({
|
|
4785
|
+
paymentMethodId: editingPaymentMethod.id,
|
|
4786
|
+
data
|
|
4787
|
+
});
|
|
4788
|
+
setEditingPaymentMethod(null);
|
|
4789
|
+
} catch {}
|
|
4790
|
+
},
|
|
4791
|
+
isSubmitting: updatePaymentMethodMutation.isPending,
|
|
4792
|
+
countries: countryOptions
|
|
4793
|
+
}),
|
|
4794
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.ConfirmActionDialog, {
|
|
4795
|
+
title: t$1("delete_credit_card"),
|
|
4796
|
+
description: t$1("delete_credit_card_message"),
|
|
4797
|
+
actionText: t$1("delete"),
|
|
4798
|
+
openDialog: deletingPaymentMethod !== null,
|
|
4799
|
+
setOpenDialog: (open) => {
|
|
4800
|
+
if (!open) {
|
|
4801
|
+
setDeletingPaymentMethod(null);
|
|
4802
|
+
setDeleteError(void 0);
|
|
4803
|
+
}
|
|
4804
|
+
},
|
|
4805
|
+
onAction: handleConfirmDelete,
|
|
4806
|
+
errorMsg: deleteError,
|
|
4807
|
+
isLoading: deletePaymentMethodMutation.isPending
|
|
4808
|
+
})
|
|
4809
|
+
]
|
|
4810
|
+
})
|
|
4811
|
+
});
|
|
4812
|
+
}
|
|
4813
|
+
//#endregion
|
|
4814
|
+
//#region src/subscriptions/SelectableAddressDropdown.tsx
|
|
4815
|
+
function formatLine1(address) {
|
|
4816
|
+
return [address.address1, address.address2].filter(Boolean).join(", ");
|
|
4817
|
+
}
|
|
4818
|
+
function formatCityStateZip(address) {
|
|
4819
|
+
return [[address.city, address.state].filter(Boolean).join(", "), address.postal_code].filter(Boolean).join(" ");
|
|
4820
|
+
}
|
|
4821
|
+
/**
|
|
4822
|
+
* Selectable variant of profile-ui's AddressDropdown, mirroring
|
|
4823
|
+
* SelectablePaymentMethodDropdown. Flat layout (no Card wrapper) so it
|
|
4824
|
+
* sits inline next to the payment method dropdown in the subscription
|
|
4825
|
+
* detail's Payment & Shipping section.
|
|
4826
|
+
*/
|
|
4827
|
+
function SelectableAddressDropdown({ title, displayAddress, addressList, selectedAddressId, onSelectAddress, onAddAddressClick, onEditAddress, onDeleteAddress, onMakeDefaultAddress, addAddressLabel = "+ Add an Address", showAddButton = true, isLoading = false, isPending = false, className = "" }) {
|
|
4828
|
+
const [isOpen, setIsOpen] = (0, react.useState)(false);
|
|
4829
|
+
const sectionId = (0, react.useId)();
|
|
4830
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4831
|
+
className: require_src.cn("border-border mb-6 border-b pb-4", className),
|
|
4832
|
+
children: [
|
|
4833
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
4834
|
+
type: "button",
|
|
4835
|
+
"aria-expanded": isOpen,
|
|
4836
|
+
"aria-controls": sectionId,
|
|
4837
|
+
onClick: () => setIsOpen((prev) => !prev),
|
|
4838
|
+
className: "flex w-full flex-row items-center justify-between",
|
|
4839
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4840
|
+
className: "text-muted-foreground text-sm",
|
|
4841
|
+
children: title
|
|
4842
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: require_src.cn("text-muted-foreground h-4 w-4 transition-transform duration-200", isOpen && "rotate-180") })]
|
|
4843
|
+
}),
|
|
4844
|
+
!isOpen && displayAddress && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
4845
|
+
type: "button",
|
|
4846
|
+
onClick: () => setIsOpen(true),
|
|
4847
|
+
className: "mt-1 mb-2 flex w-full cursor-pointer flex-col text-left",
|
|
4848
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
4849
|
+
className: "text-foreground text-sm font-medium",
|
|
4850
|
+
children: [
|
|
4851
|
+
displayAddress.name,
|
|
4852
|
+
displayAddress.name && displayAddress.address1 ? ", " : "",
|
|
4853
|
+
displayAddress.address1
|
|
4854
|
+
]
|
|
4855
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4856
|
+
className: "text-muted-foreground text-sm",
|
|
4857
|
+
children: formatCityStateZip(displayAddress)
|
|
4858
|
+
})]
|
|
4859
|
+
}),
|
|
4860
|
+
isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
4861
|
+
id: sectionId,
|
|
4862
|
+
className: "mt-5 flex max-h-[400px] flex-col space-y-4 overflow-y-auto pr-0.5",
|
|
4863
|
+
children: isLoading ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: [1, 2].map((i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4864
|
+
className: "bg-muted rounded-sm p-3",
|
|
4865
|
+
children: [
|
|
4866
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "mb-1 h-4 w-32" }),
|
|
4867
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "mb-1 h-4 w-48" }),
|
|
4868
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Skeleton, { className: "h-4 w-40" })
|
|
4869
|
+
]
|
|
4870
|
+
}, `skeleton-${i}`)) }) : addressList.map((address) => {
|
|
4871
|
+
const isSelected = selectedAddressId === address.id;
|
|
4872
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
4873
|
+
type: "button",
|
|
4874
|
+
"aria-pressed": isSelected,
|
|
4875
|
+
disabled: isPending,
|
|
4876
|
+
onClick: () => onSelectAddress(address),
|
|
4877
|
+
className: require_src.cn("text-foreground flex w-full flex-row items-center justify-between gap-3 rounded-sm p-3 text-left transition-colors", "not-disabled:cursor-pointer disabled:cursor-not-allowed disabled:opacity-60", isSelected ? "bg-background border-border border" : "bg-muted hover:bg-muted/80 border border-transparent"),
|
|
4878
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4879
|
+
className: "flex min-w-0 flex-col",
|
|
4880
|
+
children: [
|
|
4881
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4882
|
+
className: "text-foreground text-sm font-medium",
|
|
4883
|
+
children: address.name
|
|
4884
|
+
}),
|
|
4885
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4886
|
+
className: "text-muted-foreground text-sm",
|
|
4887
|
+
children: formatLine1(address)
|
|
4888
|
+
}),
|
|
4889
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4890
|
+
className: "text-muted-foreground text-sm",
|
|
4891
|
+
children: formatCityStateZip(address)
|
|
4892
|
+
})
|
|
4893
|
+
]
|
|
4894
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
4895
|
+
className: "flex shrink-0 flex-row items-center gap-2",
|
|
4896
|
+
children: [address.default && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4897
|
+
className: "bg-primary text-primary-foreground rounded px-2 py-0.5 text-xs font-medium",
|
|
4898
|
+
children: "Default"
|
|
4899
|
+
}), (onEditAddress || onDeleteAddress || onMakeDefaultAddress) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
4900
|
+
onClick: (e) => e.stopPropagation(),
|
|
4901
|
+
onKeyDown: (e) => e.stopPropagation(),
|
|
4902
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.EllipsesDropdown, {
|
|
4903
|
+
onEdit: onEditAddress ? () => onEditAddress(address) : void 0,
|
|
4904
|
+
onDelete: onDeleteAddress ? () => onDeleteAddress(address) : void 0,
|
|
4905
|
+
onMakeDefault: !address.default && onMakeDefaultAddress ? () => onMakeDefaultAddress(address) : void 0
|
|
4906
|
+
})
|
|
4907
|
+
})]
|
|
4908
|
+
})]
|
|
4909
|
+
}, address.id);
|
|
4910
|
+
})
|
|
4911
|
+
}),
|
|
4912
|
+
showAddButton && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
4913
|
+
type: "button",
|
|
4914
|
+
disabled: isPending,
|
|
4915
|
+
className: "text-foreground mt-3 text-left text-sm disabled:cursor-not-allowed disabled:opacity-60",
|
|
4916
|
+
onClick: onAddAddressClick,
|
|
4917
|
+
children: addAddressLabel
|
|
4720
4918
|
})
|
|
4721
|
-
|
|
4919
|
+
]
|
|
4920
|
+
});
|
|
4921
|
+
}
|
|
4922
|
+
//#endregion
|
|
4923
|
+
//#region src/subscriptions/PortalSubscriptionShippingAddressSection.tsx
|
|
4924
|
+
const t = (key) => ({
|
|
4925
|
+
add_an_address: "Add an Address",
|
|
4926
|
+
add_address: "Add Address",
|
|
4927
|
+
edit_address: "Edit Address",
|
|
4928
|
+
delete_address: "Delete Address",
|
|
4929
|
+
delete_address_message: "Are you sure you want to delete this address? This action cannot be undone.",
|
|
4930
|
+
delete: "Delete",
|
|
4931
|
+
cancel: "Cancel",
|
|
4932
|
+
country: "Country",
|
|
4933
|
+
name: "Name",
|
|
4934
|
+
address_line_1: "Address Line 1",
|
|
4935
|
+
address_line_2: "Address Line 2",
|
|
4936
|
+
city: "City",
|
|
4937
|
+
state: "State",
|
|
4938
|
+
province: "Province",
|
|
4939
|
+
zip_code: "Zip Code",
|
|
4940
|
+
postal_code: "Postal Code",
|
|
4941
|
+
select_state: "Select state",
|
|
4942
|
+
select_an_option: "Select an option",
|
|
4943
|
+
set_as_default_address: "Set as default address",
|
|
4944
|
+
save_address: "Save Address"
|
|
4945
|
+
})[key] ?? key.split("_").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
4946
|
+
function composeAddressName(firstName, lastName) {
|
|
4947
|
+
const combined = `${firstName} ${lastName}`.trim();
|
|
4948
|
+
return combined.length > 0 ? combined : null;
|
|
4949
|
+
}
|
|
4950
|
+
function mapToFluidPayAddress(raw) {
|
|
4951
|
+
return {
|
|
4952
|
+
id: raw.id,
|
|
4953
|
+
address1: raw.street1,
|
|
4954
|
+
address2: raw.street2,
|
|
4955
|
+
city: raw.city,
|
|
4956
|
+
country_code: raw.country,
|
|
4957
|
+
default: raw.default,
|
|
4958
|
+
name: raw.name,
|
|
4959
|
+
postal_code: raw.zip,
|
|
4960
|
+
state: raw.state,
|
|
4961
|
+
subdivision_code: null
|
|
4962
|
+
};
|
|
4963
|
+
}
|
|
4964
|
+
function subscriptionAddressToFluidPay(raw) {
|
|
4965
|
+
if (!raw) return null;
|
|
4966
|
+
return {
|
|
4967
|
+
id: raw.id,
|
|
4968
|
+
address1: raw.address1,
|
|
4969
|
+
address2: raw.address2,
|
|
4970
|
+
city: raw.city,
|
|
4971
|
+
country_code: raw.country_code,
|
|
4972
|
+
default: raw.default,
|
|
4973
|
+
name: raw.name,
|
|
4974
|
+
postal_code: raw.postal_code,
|
|
4975
|
+
state: raw.state,
|
|
4976
|
+
subdivision_code: raw.subdivision_code
|
|
4977
|
+
};
|
|
4978
|
+
}
|
|
4979
|
+
function PortalSubscriptionShippingAddressSection({ address: currentAddress, subscriptionToken, onSuccess, onError }) {
|
|
4980
|
+
const payApi = require_api_context.usePayApi();
|
|
4981
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
4982
|
+
const fluidPayShim = (0, react.useMemo)(() => require_AddressAutocompleteInput.createFluidPayApiAdapter(payApi), [payApi]);
|
|
4983
|
+
const [isFormDialogOpen, setIsFormDialogOpen] = (0, react.useState)(false);
|
|
4984
|
+
const [editingAddress, setEditingAddress] = (0, react.useState)(null);
|
|
4985
|
+
const [deletingAddress, setDeletingAddress] = (0, react.useState)(null);
|
|
4986
|
+
const [deleteError, setDeleteError] = (0, react.useState)(void 0);
|
|
4987
|
+
const { data: addresses = [], isLoading } = (0, _tanstack_react_query.useQuery)({
|
|
4988
|
+
queryKey: require_query_keys.payKeys.addresses.list(),
|
|
4989
|
+
queryFn: async () => {
|
|
4990
|
+
return (await payApi.fetchAddresses()).addresses.map(mapToFluidPayAddress);
|
|
4991
|
+
}
|
|
4992
|
+
});
|
|
4993
|
+
const countriesApi = require_countries_api_context.useCountriesApi();
|
|
4994
|
+
const { data: countriesData } = (0, _tanstack_react_query.useQuery)({
|
|
4995
|
+
queryKey: require_query_keys.storeKeys.countries(),
|
|
4996
|
+
queryFn: () => countriesApi.listCountries(),
|
|
4997
|
+
enabled: isFormDialogOpen
|
|
4998
|
+
});
|
|
4999
|
+
const countryOptions = (0, react.useMemo)(() => [...countriesData?.countries ?? []].map((c) => ({
|
|
5000
|
+
iso: c.code,
|
|
5001
|
+
name: c.name
|
|
5002
|
+
})).sort((a, b) => a.name.localeCompare(b.name)), [countriesData]);
|
|
5003
|
+
const statesByCountry = (0, react.useMemo)(() => {
|
|
5004
|
+
const map = /* @__PURE__ */ new Map();
|
|
5005
|
+
for (const c of countriesData?.countries ?? []) map.set(c.code, c.states.map((s) => ({
|
|
5006
|
+
name: s.name,
|
|
5007
|
+
isoCode: s.code
|
|
5008
|
+
})));
|
|
5009
|
+
return map;
|
|
5010
|
+
}, [countriesData]);
|
|
5011
|
+
const fetchStatesFromCountries = (0, react.useCallback)((countryCode) => Promise.resolve(statesByCountry.get(countryCode) ?? []), [statesByCountry]);
|
|
5012
|
+
const updateSubscription = useUpdateSubscriptionInfo({
|
|
5013
|
+
onSuccess: () => {
|
|
5014
|
+
onSuccess?.("Shipping address updated");
|
|
5015
|
+
queryClient.invalidateQueries({ queryKey: subscriptionsKeys.detail(subscriptionToken) });
|
|
5016
|
+
},
|
|
5017
|
+
onError: (err) => onError?.("Failed to update shipping address", err)
|
|
5018
|
+
});
|
|
5019
|
+
const createAddressMutation = (0, _tanstack_react_query.useMutation)({
|
|
5020
|
+
mutationFn: (body) => payApi.createAddress({ address: {
|
|
5021
|
+
name: composeAddressName(body.address.first_name, body.address.last_name),
|
|
5022
|
+
street1: body.address.address1,
|
|
5023
|
+
street2: body.address.address2,
|
|
5024
|
+
city: body.address.city,
|
|
5025
|
+
state: body.address.state,
|
|
5026
|
+
zip: body.address.postal_code,
|
|
5027
|
+
country: body.address.country_code,
|
|
5028
|
+
default: body.address.default
|
|
5029
|
+
} }),
|
|
5030
|
+
onSuccess: () => {
|
|
5031
|
+
queryClient.invalidateQueries({ queryKey: require_query_keys.payKeys.addresses.all });
|
|
5032
|
+
onSuccess?.("Address added");
|
|
5033
|
+
},
|
|
5034
|
+
onError: (err) => onError?.("Failed to add address", err)
|
|
5035
|
+
});
|
|
5036
|
+
const updateAddressMutation = (0, _tanstack_react_query.useMutation)({
|
|
5037
|
+
mutationFn: ({ addressId, body }) => payApi.updateAddress(addressId, { address: {
|
|
5038
|
+
name: composeAddressName(body.address.first_name, body.address.last_name),
|
|
5039
|
+
street1: body.address.address1,
|
|
5040
|
+
street2: body.address.address2,
|
|
5041
|
+
city: body.address.city,
|
|
5042
|
+
state: body.address.state,
|
|
5043
|
+
zip: body.address.postal_code,
|
|
5044
|
+
country: body.address.country_code,
|
|
5045
|
+
default: body.address.default
|
|
5046
|
+
} }),
|
|
5047
|
+
onSuccess: () => {
|
|
5048
|
+
queryClient.invalidateQueries({ queryKey: require_query_keys.payKeys.addresses.all });
|
|
5049
|
+
onSuccess?.("Address updated");
|
|
5050
|
+
},
|
|
5051
|
+
onError: (err) => onError?.("Failed to update address", err)
|
|
5052
|
+
});
|
|
5053
|
+
const deleteAddressMutation = (0, _tanstack_react_query.useMutation)({
|
|
5054
|
+
mutationFn: (addressId) => payApi.deleteAddress(addressId),
|
|
5055
|
+
onSuccess: () => {
|
|
5056
|
+
queryClient.invalidateQueries({ queryKey: require_query_keys.payKeys.addresses.all });
|
|
5057
|
+
onSuccess?.("Address deleted");
|
|
5058
|
+
}
|
|
5059
|
+
});
|
|
5060
|
+
const makeDefaultAddressMutation = (0, _tanstack_react_query.useMutation)({
|
|
5061
|
+
mutationFn: (address) => payApi.updateAddress(address.id, { address: {
|
|
5062
|
+
name: address.name ?? null,
|
|
5063
|
+
street1: address.address1 ?? "",
|
|
5064
|
+
street2: address.address2,
|
|
5065
|
+
city: address.city ?? "",
|
|
5066
|
+
state: address.state ?? "",
|
|
5067
|
+
zip: address.postal_code ?? "",
|
|
5068
|
+
country: address.country_code ?? "",
|
|
5069
|
+
default: true
|
|
5070
|
+
} }),
|
|
5071
|
+
onSuccess: () => {
|
|
5072
|
+
queryClient.invalidateQueries({ queryKey: require_query_keys.payKeys.addresses.all });
|
|
5073
|
+
onSuccess?.("Default address updated");
|
|
5074
|
+
},
|
|
5075
|
+
onError: (err) => onError?.("Failed to update default address", err)
|
|
5076
|
+
});
|
|
5077
|
+
const displayed = addresses.find((a) => a.id === currentAddress?.id) ?? subscriptionAddressToFluidPay(currentAddress);
|
|
5078
|
+
const handleCloseFormDialog = () => {
|
|
5079
|
+
setIsFormDialogOpen(false);
|
|
5080
|
+
setEditingAddress(null);
|
|
5081
|
+
};
|
|
5082
|
+
const handleConfirmDelete = async () => {
|
|
5083
|
+
if (!deletingAddress) return;
|
|
5084
|
+
setDeleteError(void 0);
|
|
5085
|
+
try {
|
|
5086
|
+
await deleteAddressMutation.mutateAsync(deletingAddress.id);
|
|
5087
|
+
setDeletingAddress(null);
|
|
5088
|
+
} catch (err) {
|
|
5089
|
+
setDeleteError(err instanceof Error ? err.message : "We were unable to delete this address. Please try again.");
|
|
5090
|
+
}
|
|
5091
|
+
};
|
|
5092
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.FluidPayCoreProvider, {
|
|
5093
|
+
api: fluidPayShim,
|
|
5094
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_AddressAutocompleteInput.ProfileUIProvider, {
|
|
5095
|
+
t,
|
|
5096
|
+
children: [
|
|
5097
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectableAddressDropdown, {
|
|
5098
|
+
title: "Shipping Address",
|
|
5099
|
+
displayAddress: displayed,
|
|
5100
|
+
addressList: addresses,
|
|
5101
|
+
selectedAddressId: currentAddress?.id ?? 0,
|
|
5102
|
+
onSelectAddress: (addr) => {
|
|
5103
|
+
if (addr.id === currentAddress?.id) return;
|
|
5104
|
+
updateSubscription.mutate({
|
|
5105
|
+
subscriptionToken,
|
|
5106
|
+
body: { address_id: addr.id }
|
|
5107
|
+
});
|
|
5108
|
+
},
|
|
5109
|
+
onAddAddressClick: () => {
|
|
5110
|
+
setEditingAddress(null);
|
|
5111
|
+
setIsFormDialogOpen(true);
|
|
5112
|
+
},
|
|
5113
|
+
onEditAddress: (addr) => {
|
|
5114
|
+
setEditingAddress(addr);
|
|
5115
|
+
setIsFormDialogOpen(true);
|
|
5116
|
+
},
|
|
5117
|
+
onDeleteAddress: (addr) => {
|
|
5118
|
+
setDeleteError(void 0);
|
|
5119
|
+
setDeletingAddress(addr);
|
|
5120
|
+
},
|
|
5121
|
+
onMakeDefaultAddress: (addr) => makeDefaultAddressMutation.mutate(addr),
|
|
5122
|
+
addAddressLabel: "+ Add an address",
|
|
5123
|
+
showAddButton: true,
|
|
5124
|
+
isLoading,
|
|
5125
|
+
isPending: updateSubscription.isPending || createAddressMutation.isPending || updateAddressMutation.isPending || makeDefaultAddressMutation.isPending
|
|
5126
|
+
}),
|
|
5127
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.AddressFormDialog, {
|
|
5128
|
+
isOpen: isFormDialogOpen,
|
|
5129
|
+
onClose: handleCloseFormDialog,
|
|
5130
|
+
selectedAddress: editingAddress,
|
|
5131
|
+
t,
|
|
5132
|
+
onSubmit: async (data) => {
|
|
5133
|
+
try {
|
|
5134
|
+
if (editingAddress) await updateAddressMutation.mutateAsync({
|
|
5135
|
+
addressId: editingAddress.id,
|
|
5136
|
+
body: data
|
|
5137
|
+
});
|
|
5138
|
+
else await createAddressMutation.mutateAsync(data);
|
|
5139
|
+
handleCloseFormDialog();
|
|
5140
|
+
} catch {}
|
|
5141
|
+
},
|
|
5142
|
+
isSubmitting: createAddressMutation.isPending || updateAddressMutation.isPending,
|
|
5143
|
+
countries: countryOptions,
|
|
5144
|
+
fetchStates: fetchStatesFromCountries,
|
|
5145
|
+
renderAddressAutocomplete: ({ control, setValue, countryCode }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.AddressAutocompleteInput, {
|
|
5146
|
+
control,
|
|
5147
|
+
setValue,
|
|
5148
|
+
countryIso: countryCode,
|
|
5149
|
+
addressLineField: "address1",
|
|
5150
|
+
cityField: "city",
|
|
5151
|
+
stateField: "state",
|
|
5152
|
+
postalCodeField: "postal_code",
|
|
5153
|
+
placeholder: t("address_line_1")
|
|
5154
|
+
})
|
|
5155
|
+
}),
|
|
5156
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AddressAutocompleteInput.ConfirmActionDialog, {
|
|
5157
|
+
title: t("delete_address"),
|
|
5158
|
+
description: t("delete_address_message"),
|
|
5159
|
+
actionText: t("delete"),
|
|
5160
|
+
openDialog: deletingAddress !== null,
|
|
5161
|
+
setOpenDialog: (open) => {
|
|
5162
|
+
if (!open) {
|
|
5163
|
+
setDeletingAddress(null);
|
|
5164
|
+
setDeleteError(void 0);
|
|
5165
|
+
}
|
|
5166
|
+
},
|
|
5167
|
+
onAction: handleConfirmDelete,
|
|
5168
|
+
errorMsg: deleteError,
|
|
5169
|
+
isLoading: deleteAddressMutation.isPending
|
|
5170
|
+
})
|
|
5171
|
+
]
|
|
5172
|
+
})
|
|
4722
5173
|
});
|
|
4723
5174
|
}
|
|
4724
5175
|
//#endregion
|
|
@@ -4748,6 +5199,13 @@ function SubscriptionDetailScreen({ token, onToast }) {
|
|
|
4748
5199
|
onError: (message, err) => {
|
|
4749
5200
|
onToast(`${message}: ${err instanceof Error ? err.message : "An error occurred"}`, "error");
|
|
4750
5201
|
}
|
|
5202
|
+
}),
|
|
5203
|
+
renderShippingAddress: (ctx) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PortalSubscriptionShippingAddressSection, {
|
|
5204
|
+
...ctx,
|
|
5205
|
+
onSuccess: (message) => onToast(message, "success"),
|
|
5206
|
+
onError: (message, err) => {
|
|
5207
|
+
onToast(`${message}: ${err instanceof Error ? err.message : "An error occurred"}`, "error");
|
|
5208
|
+
}
|
|
4751
5209
|
})
|
|
4752
5210
|
});
|
|
4753
5211
|
}
|
|
@@ -4805,4 +5263,4 @@ Object.defineProperty(exports, "subscriptionsScreenPropertySchema", {
|
|
|
4805
5263
|
}
|
|
4806
5264
|
});
|
|
4807
5265
|
|
|
4808
|
-
//# sourceMappingURL=SubscriptionsScreen-
|
|
5266
|
+
//# sourceMappingURL=SubscriptionsScreen-Bm8Ncl1e.cjs.map
|