@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
|
@@ -3,18 +3,18 @@ import { i as usePayApi } from "./api-context-3GmfqvIB.mjs";
|
|
|
3
3
|
import { n as useCountriesApi } from "./countries-api-context-CMh13cfX.mjs";
|
|
4
4
|
import { C as subscriptions_reactivate, D as subscriptions_update, E as subscriptions_skip, S as subscriptions_pause, T as subscriptions_show, b as subscriptions_cancel, w as subscriptions_resume, x as subscriptions_list } from "./portal_tenant-Q3x7ALaZ.mjs";
|
|
5
5
|
import { n as usePortalTenantClient } from "./PortalTenantClientProvider-4ZmY6hac.mjs";
|
|
6
|
-
import { A as Select, Bt as warnOrThrowProtectedError, C as Skeleton, Cn as AlertDialogContent, Dn as AlertDialogTitle, En as AlertDialogHeader, Gt as enUS, Ht as getWeek, In as cn$1, It as isAfter, K as Label, L as Input, Lt as format, M as SelectItem,
|
|
6
|
+
import { A as Select, Bt as warnOrThrowProtectedError, C as Skeleton, Cn as AlertDialogContent, Dn as AlertDialogTitle, En as AlertDialogHeader, Gt as enUS, Ht as getWeek, In as cn$1, It as isAfter, K as Label, L as Input, Lt as format, M as SelectItem, Mt as Calendar$1, N as SelectTrigger, On as Button, P as SelectValue, Rt as isProtectedDayOfYearToken, Sn as AlertDialogCancel, Tn as AlertDialogFooter, Ut as getWeekYear, Vt as longFormatters, Wt as getISOWeek, Xt as addWeeks, Yt as addYears, a as ToggleGroup, an as addDays, b as fluidToast, bn as AlertDialog, cn as millisecondsInHour, ct as DialogFooter, d as Table$1, dn as Breadcrumb, en as getTimezoneOffsetInMilliseconds, f as TableBody, fn as BreadcrumbItem, ft as DialogTitle, g as TableRow, gn as BreadcrumbSeparator, h as TableHeader, hn as BreadcrumbPage, ht as PopoverTrigger, in as addMonths, it as Dialog, j as SelectContent, ln as millisecondsInMinute, lt as DialogHeader, mn as BreadcrumbList, mt as PopoverContent, nn as startOfWeek, o as ToggleGroupItem, on as toDate, ot as DialogContent, p as TableCell, pn as BreadcrumbLink, pt as Popover, rn as getDefaultOptions$1, sn as constructFrom, tn as startOfISOWeek, un as millisecondsInSecond, wn as AlertDialogDescription, zt as isProtectedWeekYearToken } from "./src-C2-FdDaD.mjs";
|
|
7
7
|
import { r as useScreenHeaderBreadcrumbs } from "./ScreenHeaderContext-kG_zh0zW.mjs";
|
|
8
8
|
import { n as payKeys, r as storeKeys } from "./query-keys-xJy_fapN.mjs";
|
|
9
9
|
import { t as useAccount } from "./use-account-CBMPhhs7.mjs";
|
|
10
10
|
import { n as useAppNavigation } from "./AppNavigationContext-Dvc0yoZF.mjs";
|
|
11
|
-
import { f as
|
|
11
|
+
import { _ as EllipsesDropdown, a as AddressFormDialog, f as EditPaymentMethodDialog, g as ConfirmActionDialog, h as getCardExpiry, i as CreditCardFormDialog, m as getCardDisplayName, n as createFluidPayApiAdapter, p as PaymentIcon, r as mapToFluidPayPaymentMethod, t as AddressAutocompleteInput, v as FluidPayCoreProvider, y as ProfileUIProvider } from "./AddressAutocompleteInput-Dg-75n-K.mjs";
|
|
12
12
|
import { i as InfiniteScrollSentinel, r as TableColumn } from "./order-status-badge-z-_tAqHq.mjs";
|
|
13
13
|
import { t as SearchSort } from "./SearchSort-RMqZCtu4.mjs";
|
|
14
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
14
|
+
import { createContext, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
15
15
|
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
16
16
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
-
import { CalendarDays, CalendarIcon, ChevronLeft, ChevronRight, Pause, Play, RotateCcw, SkipForward, XCircle } from "lucide-react";
|
|
17
|
+
import { CalendarDays, CalendarIcon, ChevronDown, ChevronLeft, ChevronRight, Pause, Play, RotateCcw, SkipForward, XCircle } from "lucide-react";
|
|
18
18
|
import { clsx } from "clsx";
|
|
19
19
|
import { twMerge } from "tailwind-merge";
|
|
20
20
|
//#region ../../../node_modules/.pnpm/date-fns@4.1.0/node_modules/date-fns/getDefaultOptions.js
|
|
@@ -2645,6 +2645,7 @@ function createPortalSubscriptionsAdapter(client) {
|
|
|
2645
2645
|
const subscription = {};
|
|
2646
2646
|
if (body.payment_method_id != null) subscription.payment_method_id = body.payment_method_id;
|
|
2647
2647
|
if (body.quantity != null) subscription.quantity = body.quantity;
|
|
2648
|
+
if (body.address_id != null) subscription.address_id = body.address_id;
|
|
2648
2649
|
if (body.next_bill_date != null) subscription.next_bill_date = body.next_bill_date;
|
|
2649
2650
|
return mapSubscriptionDetail(await subscriptions_update(client, subscriptionToken, { subscription }));
|
|
2650
2651
|
}
|
|
@@ -4003,7 +4004,7 @@ function SubscriptionManagementSection({ subscription, isActive, isPaused, isCan
|
|
|
4003
4004
|
/* @__PURE__ */ jsxs("div", {
|
|
4004
4005
|
className: "pt-2",
|
|
4005
4006
|
children: [/* @__PURE__ */ jsx("h3", {
|
|
4006
|
-
className: "text-foreground text-sm/6 font-semibold",
|
|
4007
|
+
className: "text-foreground mb-4 text-sm/6 font-semibold",
|
|
4007
4008
|
children: "Payment & Shipping"
|
|
4008
4009
|
}), /* @__PURE__ */ jsxs("div", {
|
|
4009
4010
|
className: "flex flex-col",
|
|
@@ -4403,136 +4404,119 @@ function SubscriptionDetailScreen$1({ token, onNavigateToList, onNavigateToSubsc
|
|
|
4403
4404
|
* (accordion, collapsed summary, list, add button), with rows that
|
|
4404
4405
|
* commit a selection through onSelectPaymentMethod when clicked.
|
|
4405
4406
|
*/
|
|
4406
|
-
function SelectablePaymentMethodDropdown({ title, displayPaymentMethod, paymentMethodList, selectedPaymentMethodId, onSelectPaymentMethod, onAddPaymentMethodClick, addPaymentMethodLabel = "+ Add a payment method", showAddButton = true, isLoading = false, isPending = false, className = "" }) {
|
|
4407
|
-
const [
|
|
4408
|
-
const
|
|
4409
|
-
|
|
4410
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
4411
|
-
className: "flex flex-row items-center space-x-2",
|
|
4412
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
4413
|
-
className: "flex h-6 w-10 flex-shrink-0 items-center justify-center",
|
|
4414
|
-
children: /* @__PURE__ */ jsx(PaymentIcon, {
|
|
4415
|
-
logoUrl: paymentMethod.details.logo_url,
|
|
4416
|
-
brand: paymentMethod.details.card_type,
|
|
4417
|
-
alt: paymentMethod.details.card_type ?? "Payment Method"
|
|
4418
|
-
})
|
|
4419
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
4420
|
-
className: "flex flex-col",
|
|
4421
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
4422
|
-
className: "text-foreground flex items-center text-sm font-medium capitalize",
|
|
4423
|
-
children: getCardDisplayName(paymentMethod)
|
|
4424
|
-
}), expiry && /* @__PURE__ */ jsx("div", {
|
|
4425
|
-
className: "text-muted-foreground text-sm",
|
|
4426
|
-
children: expiry
|
|
4427
|
-
})]
|
|
4428
|
-
})]
|
|
4429
|
-
});
|
|
4430
|
-
};
|
|
4407
|
+
function SelectablePaymentMethodDropdown({ title, displayPaymentMethod, paymentMethodList, selectedPaymentMethodId, onSelectPaymentMethod, onAddPaymentMethodClick, onEditPaymentMethod, onDeletePaymentMethod, onMakeDefaultPaymentMethod, addPaymentMethodLabel = "+ Add a payment method", showAddButton = true, isLoading = false, isPending = false, className = "" }) {
|
|
4408
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
4409
|
+
const sectionId = useId();
|
|
4410
|
+
const collapsedExpiry = displayPaymentMethod ? getCardExpiry(displayPaymentMethod) : null;
|
|
4431
4411
|
return /* @__PURE__ */ jsxs("div", {
|
|
4432
4412
|
className: cn$1("border-border mb-6 border-b pb-4", className),
|
|
4433
|
-
children: [
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
})]
|
|
4456
|
-
}) : !paymentsValue && displayPaymentMethod && /* @__PURE__ */ jsx("div", {
|
|
4457
|
-
className: "mb-2 flex w-full cursor-pointer flex-col",
|
|
4458
|
-
onClick: () => setPaymentsValue("payment_methods"),
|
|
4459
|
-
children: renderPaymentMethod(displayPaymentMethod)
|
|
4460
|
-
}),
|
|
4461
|
-
/* @__PURE__ */ jsx(AccordionContent, {
|
|
4462
|
-
className: "max-h-[400px] overflow-y-auto px-0.5 pt-2 pb-1",
|
|
4463
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
4464
|
-
className: "mt-2 flex flex-col justify-between space-y-4",
|
|
4465
|
-
children: isLoading ? /* @__PURE__ */ jsx(Fragment$1, { children: [1, 2].map((i) => /* @__PURE__ */ jsx("div", {
|
|
4466
|
-
className: "bg-muted items-center rounded p-3",
|
|
4467
|
-
children: /* @__PURE__ */ jsxs("div", {
|
|
4468
|
-
className: "flex flex-row items-center space-x-2",
|
|
4469
|
-
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-10" }), /* @__PURE__ */ jsxs("div", {
|
|
4470
|
-
className: "flex flex-col space-y-1",
|
|
4471
|
-
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-32" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" })]
|
|
4472
|
-
})]
|
|
4473
|
-
})
|
|
4474
|
-
}, `skeleton-${i}`)) }) : paymentMethodList.map((paymentMethod) => {
|
|
4475
|
-
const isSelected = selectedPaymentMethodId === paymentMethod.id;
|
|
4476
|
-
const expiry = getCardExpiry(paymentMethod);
|
|
4477
|
-
return /* @__PURE__ */ jsxs("button", {
|
|
4478
|
-
type: "button",
|
|
4479
|
-
"aria-pressed": isSelected,
|
|
4480
|
-
disabled: isPending,
|
|
4481
|
-
onClick: () => onSelectPaymentMethod(paymentMethod),
|
|
4482
|
-
className: cn$1("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", {
|
|
4483
|
-
"opacity-60 hover:opacity-100": !isSelected,
|
|
4484
|
-
"ring-primary z-10 opacity-100": isSelected
|
|
4485
|
-
}),
|
|
4486
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
4487
|
-
className: "flex flex-row items-center space-x-3",
|
|
4488
|
-
children: [
|
|
4489
|
-
/* @__PURE__ */ jsx("span", {
|
|
4490
|
-
"aria-hidden": true,
|
|
4491
|
-
className: cn$1("flex h-4 w-4 shrink-0 items-center justify-center rounded-full border", isSelected ? "border-primary" : "border-input"),
|
|
4492
|
-
children: isSelected && /* @__PURE__ */ jsx("span", { className: "bg-primary h-2 w-2 rounded-full" })
|
|
4493
|
-
}),
|
|
4494
|
-
/* @__PURE__ */ jsx("div", {
|
|
4495
|
-
className: "flex h-6 w-10 flex-shrink-0 items-center justify-center",
|
|
4496
|
-
children: /* @__PURE__ */ jsx(PaymentIcon, {
|
|
4497
|
-
logoUrl: paymentMethod.details.logo_url,
|
|
4498
|
-
brand: paymentMethod.details.card_type,
|
|
4499
|
-
alt: paymentMethod.details.card_type ?? "Payment Method"
|
|
4500
|
-
})
|
|
4501
|
-
}),
|
|
4502
|
-
/* @__PURE__ */ jsxs("div", {
|
|
4503
|
-
className: "flex flex-col",
|
|
4504
|
-
children: [/* @__PURE__ */ jsx("div", {
|
|
4505
|
-
className: "text-card-foreground flex items-center text-sm font-medium capitalize",
|
|
4506
|
-
children: getCardDisplayName(paymentMethod)
|
|
4507
|
-
}), expiry && /* @__PURE__ */ jsx("div", {
|
|
4508
|
-
className: "text-muted-foreground text-sm",
|
|
4509
|
-
children: expiry
|
|
4510
|
-
})]
|
|
4511
|
-
})
|
|
4512
|
-
]
|
|
4513
|
-
}), paymentMethod.default && /* @__PURE__ */ jsx("p", {
|
|
4514
|
-
className: "bg-secondary text-secondary-foreground rounded px-2 py-0.5 text-xs font-medium",
|
|
4515
|
-
children: "Default"
|
|
4516
|
-
})]
|
|
4517
|
-
}, paymentMethod.id);
|
|
4518
|
-
})
|
|
4519
|
-
})
|
|
4413
|
+
children: [
|
|
4414
|
+
/* @__PURE__ */ jsxs("button", {
|
|
4415
|
+
type: "button",
|
|
4416
|
+
"aria-expanded": isOpen,
|
|
4417
|
+
"aria-controls": sectionId,
|
|
4418
|
+
onClick: () => setIsOpen((prev) => !prev),
|
|
4419
|
+
className: "flex w-full flex-row items-center justify-between",
|
|
4420
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4421
|
+
className: "text-muted-foreground text-sm",
|
|
4422
|
+
children: title
|
|
4423
|
+
}), /* @__PURE__ */ jsx(ChevronDown, { className: cn$1("text-muted-foreground h-4 w-4 transition-transform duration-200", isOpen && "rotate-180") })]
|
|
4424
|
+
}),
|
|
4425
|
+
!isOpen && displayPaymentMethod && /* @__PURE__ */ jsxs("button", {
|
|
4426
|
+
type: "button",
|
|
4427
|
+
onClick: () => setIsOpen(true),
|
|
4428
|
+
className: "mt-1 mb-2 flex w-full cursor-pointer flex-row items-center gap-3 text-left",
|
|
4429
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
4430
|
+
className: "flex h-6 w-10 flex-shrink-0 items-center justify-center",
|
|
4431
|
+
children: /* @__PURE__ */ jsx(PaymentIcon, {
|
|
4432
|
+
logoUrl: displayPaymentMethod.details.logo_url,
|
|
4433
|
+
brand: displayPaymentMethod.details.card_type,
|
|
4434
|
+
alt: displayPaymentMethod.details.card_type ?? "Payment Method"
|
|
4520
4435
|
})
|
|
4521
|
-
|
|
4436
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
4437
|
+
className: "flex min-w-0 flex-col",
|
|
4438
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4439
|
+
className: "text-foreground text-sm font-medium capitalize",
|
|
4440
|
+
children: getCardDisplayName(displayPaymentMethod)
|
|
4441
|
+
}), collapsedExpiry && /* @__PURE__ */ jsx("span", {
|
|
4442
|
+
className: "text-muted-foreground text-sm",
|
|
4443
|
+
children: collapsedExpiry
|
|
4444
|
+
})]
|
|
4445
|
+
})]
|
|
4446
|
+
}),
|
|
4447
|
+
isOpen && /* @__PURE__ */ jsx("div", {
|
|
4448
|
+
id: sectionId,
|
|
4449
|
+
className: "mt-5 flex max-h-[400px] flex-col space-y-4 overflow-y-auto pr-0.5",
|
|
4450
|
+
children: isLoading ? /* @__PURE__ */ jsx(Fragment$1, { children: [1, 2].map((i) => /* @__PURE__ */ jsxs("div", {
|
|
4451
|
+
className: "bg-muted flex flex-row items-center space-x-2 rounded-sm p-3",
|
|
4452
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-10" }), /* @__PURE__ */ jsxs("div", {
|
|
4453
|
+
className: "flex flex-col space-y-1",
|
|
4454
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-32" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-24" })]
|
|
4455
|
+
})]
|
|
4456
|
+
}, `skeleton-${i}`)) }) : paymentMethodList.map((paymentMethod) => {
|
|
4457
|
+
const isSelected = selectedPaymentMethodId === paymentMethod.id;
|
|
4458
|
+
const expiry = getCardExpiry(paymentMethod);
|
|
4459
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
4460
|
+
type: "button",
|
|
4461
|
+
"aria-pressed": isSelected,
|
|
4462
|
+
disabled: isPending,
|
|
4463
|
+
onClick: () => onSelectPaymentMethod(paymentMethod),
|
|
4464
|
+
className: cn$1("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"),
|
|
4465
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
4466
|
+
className: "flex min-w-0 flex-row items-center gap-3",
|
|
4467
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
4468
|
+
className: "flex h-6 w-10 flex-shrink-0 items-center justify-center",
|
|
4469
|
+
children: /* @__PURE__ */ jsx(PaymentIcon, {
|
|
4470
|
+
logoUrl: paymentMethod.details.logo_url,
|
|
4471
|
+
brand: paymentMethod.details.card_type,
|
|
4472
|
+
alt: paymentMethod.details.card_type ?? "Payment Method"
|
|
4473
|
+
})
|
|
4474
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
4475
|
+
className: "flex min-w-0 flex-col",
|
|
4476
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4477
|
+
className: "text-foreground text-sm font-medium capitalize",
|
|
4478
|
+
children: getCardDisplayName(paymentMethod)
|
|
4479
|
+
}), expiry && /* @__PURE__ */ jsx("span", {
|
|
4480
|
+
className: "text-muted-foreground text-sm",
|
|
4481
|
+
children: expiry
|
|
4482
|
+
})]
|
|
4483
|
+
})]
|
|
4484
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
4485
|
+
className: "flex shrink-0 flex-row items-center gap-2",
|
|
4486
|
+
children: [paymentMethod.default && /* @__PURE__ */ jsx("span", {
|
|
4487
|
+
className: "bg-primary text-primary-foreground rounded px-2 py-0.5 text-xs font-medium",
|
|
4488
|
+
children: "Default"
|
|
4489
|
+
}), (onEditPaymentMethod || onDeletePaymentMethod || onMakeDefaultPaymentMethod) && /* @__PURE__ */ jsx("span", {
|
|
4490
|
+
onClick: (e) => e.stopPropagation(),
|
|
4491
|
+
onKeyDown: (e) => e.stopPropagation(),
|
|
4492
|
+
children: /* @__PURE__ */ jsx(EllipsesDropdown, {
|
|
4493
|
+
onEdit: onEditPaymentMethod ? () => onEditPaymentMethod(paymentMethod) : void 0,
|
|
4494
|
+
onDelete: onDeletePaymentMethod ? () => onDeletePaymentMethod(paymentMethod) : void 0,
|
|
4495
|
+
onMakeDefault: !paymentMethod.default && onMakeDefaultPaymentMethod ? () => onMakeDefaultPaymentMethod(paymentMethod) : void 0
|
|
4496
|
+
})
|
|
4497
|
+
})]
|
|
4498
|
+
})]
|
|
4499
|
+
}, paymentMethod.id);
|
|
4500
|
+
})
|
|
4501
|
+
}),
|
|
4502
|
+
showAddButton && /* @__PURE__ */ jsx("button", {
|
|
4503
|
+
type: "button",
|
|
4504
|
+
disabled: isPending,
|
|
4505
|
+
className: "text-foreground mt-3 text-left text-sm disabled:cursor-not-allowed disabled:opacity-60",
|
|
4506
|
+
onClick: onAddPaymentMethodClick,
|
|
4507
|
+
children: addPaymentMethodLabel
|
|
4522
4508
|
})
|
|
4523
|
-
|
|
4524
|
-
type: "button",
|
|
4525
|
-
disabled: isPending,
|
|
4526
|
-
className: cn$1("text-foreground text-left text-sm disabled:cursor-not-allowed disabled:opacity-60", paymentsValue ? "mt-4" : "mt-3"),
|
|
4527
|
-
onClick: onAddPaymentMethodClick,
|
|
4528
|
-
children: addPaymentMethodLabel
|
|
4529
|
-
})]
|
|
4509
|
+
]
|
|
4530
4510
|
});
|
|
4531
4511
|
}
|
|
4532
4512
|
//#endregion
|
|
4533
4513
|
//#region src/subscriptions/PortalSubscriptionPaymentMethodSection.tsx
|
|
4534
|
-
const t = (key) => ({
|
|
4514
|
+
const t$1 = (key) => ({
|
|
4535
4515
|
add_credit_card: "Add Credit Card",
|
|
4516
|
+
edit_card: "Card Details",
|
|
4517
|
+
delete_credit_card: "Delete Credit Card",
|
|
4518
|
+
delete_credit_card_message: "Are you sure you want to delete this payment method? This action cannot be undone.",
|
|
4519
|
+
delete: "Delete",
|
|
4536
4520
|
save_card: "Save Card",
|
|
4537
4521
|
securing: "Loading secure form...",
|
|
4538
4522
|
cancel: "Cancel",
|
|
@@ -4580,6 +4564,9 @@ function PortalSubscriptionPaymentMethodSection({ paymentMethod: currentPaymentM
|
|
|
4580
4564
|
const queryClient = useQueryClient();
|
|
4581
4565
|
const fluidPayShim = useMemo(() => createFluidPayApiAdapter(payApi), [payApi]);
|
|
4582
4566
|
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false);
|
|
4567
|
+
const [editingPaymentMethod, setEditingPaymentMethod] = useState(null);
|
|
4568
|
+
const [deletingPaymentMethod, setDeletingPaymentMethod] = useState(null);
|
|
4569
|
+
const [deleteError, setDeleteError] = useState(void 0);
|
|
4583
4570
|
const { data: paymentMethods = [], isLoading: isLoadingMethods } = useQuery({
|
|
4584
4571
|
queryKey: payKeys.paymentMethods.list(),
|
|
4585
4572
|
queryFn: async () => {
|
|
@@ -4590,7 +4577,7 @@ function PortalSubscriptionPaymentMethodSection({ paymentMethod: currentPaymentM
|
|
|
4590
4577
|
const { data: countriesData } = useQuery({
|
|
4591
4578
|
queryKey: storeKeys.countries(),
|
|
4592
4579
|
queryFn: () => countriesApi.listCountries(),
|
|
4593
|
-
enabled: isAddDialogOpen
|
|
4580
|
+
enabled: isAddDialogOpen || editingPaymentMethod !== null
|
|
4594
4581
|
});
|
|
4595
4582
|
const countryOptions = useMemo(() => [...countriesData?.countries ?? []].map((c) => ({
|
|
4596
4583
|
iso: c.code,
|
|
@@ -4615,49 +4602,513 @@ function PortalSubscriptionPaymentMethodSection({ paymentMethod: currentPaymentM
|
|
|
4615
4602
|
},
|
|
4616
4603
|
onError: (err) => onError?.("Failed to add payment method", err)
|
|
4617
4604
|
});
|
|
4618
|
-
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
selectedPaymentMethodId: currentPaymentMethod.id,
|
|
4630
|
-
onSelectPaymentMethod: (pm) => {
|
|
4631
|
-
if (pm.id === currentPaymentMethod.id) return;
|
|
4632
|
-
updateSubscription.mutate({
|
|
4633
|
-
subscriptionToken,
|
|
4634
|
-
body: { payment_method_id: pm.id }
|
|
4635
|
-
});
|
|
4605
|
+
const updatePaymentMethodMutation = useMutation({
|
|
4606
|
+
mutationFn: ({ paymentMethodId, data }) => payApi.updatePaymentMethod(paymentMethodId, { payment_method: {
|
|
4607
|
+
default: data.set_as_default,
|
|
4608
|
+
billing_address: {
|
|
4609
|
+
name: data.billing_address.name,
|
|
4610
|
+
street1: data.billing_address.address1,
|
|
4611
|
+
street2: data.billing_address.address2 ?? null,
|
|
4612
|
+
city: data.billing_address.city,
|
|
4613
|
+
state: data.billing_address.state,
|
|
4614
|
+
zip: data.billing_address.zip,
|
|
4615
|
+
country: data.billing_address.country_code
|
|
4636
4616
|
}
|
|
4637
|
-
}),
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4617
|
+
} }),
|
|
4618
|
+
onSuccess: async () => {
|
|
4619
|
+
await queryClient.invalidateQueries({ queryKey: payKeys.paymentMethods.all });
|
|
4620
|
+
onSuccess?.("Payment method updated");
|
|
4621
|
+
},
|
|
4622
|
+
onError: (err) => onError?.("Failed to update payment method", err)
|
|
4623
|
+
});
|
|
4624
|
+
const deletePaymentMethodMutation = useMutation({
|
|
4625
|
+
mutationFn: (paymentMethodId) => payApi.deletePaymentMethod(paymentMethodId),
|
|
4626
|
+
onSuccess: async () => {
|
|
4627
|
+
await queryClient.invalidateQueries({ queryKey: payKeys.paymentMethods.all });
|
|
4628
|
+
onSuccess?.("Payment method deleted");
|
|
4629
|
+
}
|
|
4630
|
+
});
|
|
4631
|
+
const makeDefaultPaymentMethodMutation = useMutation({
|
|
4632
|
+
mutationFn: (pm) => {
|
|
4633
|
+
const body = { payment_method: { default: true } };
|
|
4634
|
+
if (pm.billing_address) body.payment_method.billing_address = {
|
|
4635
|
+
name: pm.billing_address.name,
|
|
4636
|
+
street1: pm.billing_address.address1 ?? "",
|
|
4637
|
+
street2: pm.billing_address.address2 ?? null,
|
|
4638
|
+
city: pm.billing_address.city ?? "",
|
|
4639
|
+
state: pm.billing_address.state ?? "",
|
|
4640
|
+
zip: pm.billing_address.zip ?? "",
|
|
4641
|
+
country: pm.billing_address.country_code ?? ""
|
|
4642
|
+
};
|
|
4643
|
+
return payApi.updatePaymentMethod(pm.id, body);
|
|
4644
|
+
},
|
|
4645
|
+
onSuccess: async () => {
|
|
4646
|
+
await queryClient.invalidateQueries({ queryKey: payKeys.paymentMethods.all });
|
|
4647
|
+
onSuccess?.("Default payment method updated");
|
|
4648
|
+
},
|
|
4649
|
+
onError: (err) => onError?.("Failed to update default payment method", err)
|
|
4650
|
+
});
|
|
4651
|
+
const displayed = paymentMethods.find((pm) => pm.id === currentPaymentMethod.id) ?? subscriptionPaymentMethodToFluidPay(currentPaymentMethod);
|
|
4652
|
+
const handleConfirmDelete = async () => {
|
|
4653
|
+
if (!deletingPaymentMethod) return;
|
|
4654
|
+
setDeleteError(void 0);
|
|
4655
|
+
try {
|
|
4656
|
+
await deletePaymentMethodMutation.mutateAsync(deletingPaymentMethod.id);
|
|
4657
|
+
setDeletingPaymentMethod(null);
|
|
4658
|
+
} catch (err) {
|
|
4659
|
+
setDeleteError(err instanceof Error ? err.message : "We were unable to delete this payment method. Please try again.");
|
|
4660
|
+
}
|
|
4661
|
+
};
|
|
4662
|
+
return /* @__PURE__ */ jsx(FluidPayCoreProvider, {
|
|
4663
|
+
api: fluidPayShim,
|
|
4664
|
+
children: /* @__PURE__ */ jsxs(ProfileUIProvider, {
|
|
4665
|
+
t: t$1,
|
|
4666
|
+
children: [
|
|
4667
|
+
/* @__PURE__ */ jsx(SelectablePaymentMethodDropdown, {
|
|
4668
|
+
title: "Payment Method",
|
|
4669
|
+
displayPaymentMethod: displayed,
|
|
4670
|
+
paymentMethodList: paymentMethods,
|
|
4671
|
+
onAddPaymentMethodClick: () => setIsAddDialogOpen(true),
|
|
4672
|
+
addPaymentMethodLabel: "+ Add Payment Method",
|
|
4673
|
+
showAddButton: true,
|
|
4674
|
+
isLoading: isLoadingMethods,
|
|
4675
|
+
isPending: updateSubscription.isPending || addCardMutation.isPending || updatePaymentMethodMutation.isPending || makeDefaultPaymentMethodMutation.isPending,
|
|
4676
|
+
selectedPaymentMethodId: currentPaymentMethod.id,
|
|
4677
|
+
onSelectPaymentMethod: (pm) => {
|
|
4678
|
+
if (pm.id === currentPaymentMethod.id) return;
|
|
4679
|
+
updateSubscription.mutate({
|
|
4680
|
+
subscriptionToken,
|
|
4681
|
+
body: { payment_method_id: pm.id }
|
|
4682
|
+
});
|
|
4683
|
+
},
|
|
4684
|
+
onEditPaymentMethod: (pm) => setEditingPaymentMethod(pm),
|
|
4685
|
+
onDeletePaymentMethod: (pm) => {
|
|
4686
|
+
setDeleteError(void 0);
|
|
4687
|
+
setDeletingPaymentMethod(pm);
|
|
4688
|
+
},
|
|
4689
|
+
onMakeDefaultPaymentMethod: (pm) => makeDefaultPaymentMethodMutation.mutate(pm)
|
|
4690
|
+
}),
|
|
4691
|
+
/* @__PURE__ */ jsx(CreditCardFormDialog, {
|
|
4692
|
+
isOpen: isAddDialogOpen,
|
|
4693
|
+
onClose: () => setIsAddDialogOpen(false),
|
|
4694
|
+
t: t$1,
|
|
4695
|
+
onSubmit: async (data) => {
|
|
4696
|
+
try {
|
|
4697
|
+
await addCardMutation.mutateAsync(data);
|
|
4698
|
+
setIsAddDialogOpen(false);
|
|
4699
|
+
} catch {}
|
|
4700
|
+
},
|
|
4701
|
+
isSubmitting: addCardMutation.isPending,
|
|
4702
|
+
countries: countryOptions,
|
|
4703
|
+
jwt: "",
|
|
4704
|
+
renderAddressAutocomplete: ({ control, setValue, countryCode }) => /* @__PURE__ */ jsx(AddressAutocompleteInput, {
|
|
4705
|
+
control,
|
|
4706
|
+
setValue,
|
|
4707
|
+
countryIso: countryCode,
|
|
4708
|
+
addressLineField: "address1",
|
|
4709
|
+
cityField: "city",
|
|
4710
|
+
stateField: "state",
|
|
4711
|
+
postalCodeField: "zip",
|
|
4712
|
+
placeholder: t$1("address_line_1")
|
|
4713
|
+
})
|
|
4714
|
+
}),
|
|
4715
|
+
/* @__PURE__ */ jsx(EditPaymentMethodDialog, {
|
|
4716
|
+
isOpen: editingPaymentMethod !== null,
|
|
4717
|
+
paymentMethod: editingPaymentMethod,
|
|
4718
|
+
billingAddress: editingPaymentMethod?.billing_address ?? null,
|
|
4719
|
+
onClose: () => setEditingPaymentMethod(null),
|
|
4720
|
+
onSubmit: async (data) => {
|
|
4721
|
+
if (!editingPaymentMethod) return;
|
|
4722
|
+
try {
|
|
4723
|
+
await updatePaymentMethodMutation.mutateAsync({
|
|
4724
|
+
paymentMethodId: editingPaymentMethod.id,
|
|
4725
|
+
data
|
|
4726
|
+
});
|
|
4727
|
+
setEditingPaymentMethod(null);
|
|
4728
|
+
} catch {}
|
|
4729
|
+
},
|
|
4730
|
+
isSubmitting: updatePaymentMethodMutation.isPending,
|
|
4731
|
+
countries: countryOptions
|
|
4732
|
+
}),
|
|
4733
|
+
/* @__PURE__ */ jsx(ConfirmActionDialog, {
|
|
4734
|
+
title: t$1("delete_credit_card"),
|
|
4735
|
+
description: t$1("delete_credit_card_message"),
|
|
4736
|
+
actionText: t$1("delete"),
|
|
4737
|
+
openDialog: deletingPaymentMethod !== null,
|
|
4738
|
+
setOpenDialog: (open) => {
|
|
4739
|
+
if (!open) {
|
|
4740
|
+
setDeletingPaymentMethod(null);
|
|
4741
|
+
setDeleteError(void 0);
|
|
4742
|
+
}
|
|
4743
|
+
},
|
|
4744
|
+
onAction: handleConfirmDelete,
|
|
4745
|
+
errorMsg: deleteError,
|
|
4746
|
+
isLoading: deletePaymentMethodMutation.isPending
|
|
4747
|
+
})
|
|
4748
|
+
]
|
|
4749
|
+
})
|
|
4750
|
+
});
|
|
4751
|
+
}
|
|
4752
|
+
//#endregion
|
|
4753
|
+
//#region src/subscriptions/SelectableAddressDropdown.tsx
|
|
4754
|
+
function formatLine1(address) {
|
|
4755
|
+
return [address.address1, address.address2].filter(Boolean).join(", ");
|
|
4756
|
+
}
|
|
4757
|
+
function formatCityStateZip(address) {
|
|
4758
|
+
return [[address.city, address.state].filter(Boolean).join(", "), address.postal_code].filter(Boolean).join(" ");
|
|
4759
|
+
}
|
|
4760
|
+
/**
|
|
4761
|
+
* Selectable variant of profile-ui's AddressDropdown, mirroring
|
|
4762
|
+
* SelectablePaymentMethodDropdown. Flat layout (no Card wrapper) so it
|
|
4763
|
+
* sits inline next to the payment method dropdown in the subscription
|
|
4764
|
+
* detail's Payment & Shipping section.
|
|
4765
|
+
*/
|
|
4766
|
+
function SelectableAddressDropdown({ title, displayAddress, addressList, selectedAddressId, onSelectAddress, onAddAddressClick, onEditAddress, onDeleteAddress, onMakeDefaultAddress, addAddressLabel = "+ Add an Address", showAddButton = true, isLoading = false, isPending = false, className = "" }) {
|
|
4767
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
4768
|
+
const sectionId = useId();
|
|
4769
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4770
|
+
className: cn$1("border-border mb-6 border-b pb-4", className),
|
|
4771
|
+
children: [
|
|
4772
|
+
/* @__PURE__ */ jsxs("button", {
|
|
4773
|
+
type: "button",
|
|
4774
|
+
"aria-expanded": isOpen,
|
|
4775
|
+
"aria-controls": sectionId,
|
|
4776
|
+
onClick: () => setIsOpen((prev) => !prev),
|
|
4777
|
+
className: "flex w-full flex-row items-center justify-between",
|
|
4778
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4779
|
+
className: "text-muted-foreground text-sm",
|
|
4780
|
+
children: title
|
|
4781
|
+
}), /* @__PURE__ */ jsx(ChevronDown, { className: cn$1("text-muted-foreground h-4 w-4 transition-transform duration-200", isOpen && "rotate-180") })]
|
|
4782
|
+
}),
|
|
4783
|
+
!isOpen && displayAddress && /* @__PURE__ */ jsxs("button", {
|
|
4784
|
+
type: "button",
|
|
4785
|
+
onClick: () => setIsOpen(true),
|
|
4786
|
+
className: "mt-1 mb-2 flex w-full cursor-pointer flex-col text-left",
|
|
4787
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
4788
|
+
className: "text-foreground text-sm font-medium",
|
|
4789
|
+
children: [
|
|
4790
|
+
displayAddress.name,
|
|
4791
|
+
displayAddress.name && displayAddress.address1 ? ", " : "",
|
|
4792
|
+
displayAddress.address1
|
|
4793
|
+
]
|
|
4794
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4795
|
+
className: "text-muted-foreground text-sm",
|
|
4796
|
+
children: formatCityStateZip(displayAddress)
|
|
4797
|
+
})]
|
|
4798
|
+
}),
|
|
4799
|
+
isOpen && /* @__PURE__ */ jsx("div", {
|
|
4800
|
+
id: sectionId,
|
|
4801
|
+
className: "mt-5 flex max-h-[400px] flex-col space-y-4 overflow-y-auto pr-0.5",
|
|
4802
|
+
children: isLoading ? /* @__PURE__ */ jsx(Fragment$1, { children: [1, 2].map((i) => /* @__PURE__ */ jsxs("div", {
|
|
4803
|
+
className: "bg-muted rounded-sm p-3",
|
|
4804
|
+
children: [
|
|
4805
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "mb-1 h-4 w-32" }),
|
|
4806
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "mb-1 h-4 w-48" }),
|
|
4807
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-40" })
|
|
4808
|
+
]
|
|
4809
|
+
}, `skeleton-${i}`)) }) : addressList.map((address) => {
|
|
4810
|
+
const isSelected = selectedAddressId === address.id;
|
|
4811
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
4812
|
+
type: "button",
|
|
4813
|
+
"aria-pressed": isSelected,
|
|
4814
|
+
disabled: isPending,
|
|
4815
|
+
onClick: () => onSelectAddress(address),
|
|
4816
|
+
className: cn$1("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"),
|
|
4817
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
4818
|
+
className: "flex min-w-0 flex-col",
|
|
4819
|
+
children: [
|
|
4820
|
+
/* @__PURE__ */ jsx("span", {
|
|
4821
|
+
className: "text-foreground text-sm font-medium",
|
|
4822
|
+
children: address.name
|
|
4823
|
+
}),
|
|
4824
|
+
/* @__PURE__ */ jsx("span", {
|
|
4825
|
+
className: "text-muted-foreground text-sm",
|
|
4826
|
+
children: formatLine1(address)
|
|
4827
|
+
}),
|
|
4828
|
+
/* @__PURE__ */ jsx("span", {
|
|
4829
|
+
className: "text-muted-foreground text-sm",
|
|
4830
|
+
children: formatCityStateZip(address)
|
|
4831
|
+
})
|
|
4832
|
+
]
|
|
4833
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
4834
|
+
className: "flex shrink-0 flex-row items-center gap-2",
|
|
4835
|
+
children: [address.default && /* @__PURE__ */ jsx("span", {
|
|
4836
|
+
className: "bg-primary text-primary-foreground rounded px-2 py-0.5 text-xs font-medium",
|
|
4837
|
+
children: "Default"
|
|
4838
|
+
}), (onEditAddress || onDeleteAddress || onMakeDefaultAddress) && /* @__PURE__ */ jsx("span", {
|
|
4839
|
+
onClick: (e) => e.stopPropagation(),
|
|
4840
|
+
onKeyDown: (e) => e.stopPropagation(),
|
|
4841
|
+
children: /* @__PURE__ */ jsx(EllipsesDropdown, {
|
|
4842
|
+
onEdit: onEditAddress ? () => onEditAddress(address) : void 0,
|
|
4843
|
+
onDelete: onDeleteAddress ? () => onDeleteAddress(address) : void 0,
|
|
4844
|
+
onMakeDefault: !address.default && onMakeDefaultAddress ? () => onMakeDefaultAddress(address) : void 0
|
|
4845
|
+
})
|
|
4846
|
+
})]
|
|
4847
|
+
})]
|
|
4848
|
+
}, address.id);
|
|
4849
|
+
})
|
|
4850
|
+
}),
|
|
4851
|
+
showAddButton && /* @__PURE__ */ jsx("button", {
|
|
4852
|
+
type: "button",
|
|
4853
|
+
disabled: isPending,
|
|
4854
|
+
className: "text-foreground mt-3 text-left text-sm disabled:cursor-not-allowed disabled:opacity-60",
|
|
4855
|
+
onClick: onAddAddressClick,
|
|
4856
|
+
children: addAddressLabel
|
|
4659
4857
|
})
|
|
4660
|
-
|
|
4858
|
+
]
|
|
4859
|
+
});
|
|
4860
|
+
}
|
|
4861
|
+
//#endregion
|
|
4862
|
+
//#region src/subscriptions/PortalSubscriptionShippingAddressSection.tsx
|
|
4863
|
+
const t = (key) => ({
|
|
4864
|
+
add_an_address: "Add an Address",
|
|
4865
|
+
add_address: "Add Address",
|
|
4866
|
+
edit_address: "Edit Address",
|
|
4867
|
+
delete_address: "Delete Address",
|
|
4868
|
+
delete_address_message: "Are you sure you want to delete this address? This action cannot be undone.",
|
|
4869
|
+
delete: "Delete",
|
|
4870
|
+
cancel: "Cancel",
|
|
4871
|
+
country: "Country",
|
|
4872
|
+
name: "Name",
|
|
4873
|
+
address_line_1: "Address Line 1",
|
|
4874
|
+
address_line_2: "Address Line 2",
|
|
4875
|
+
city: "City",
|
|
4876
|
+
state: "State",
|
|
4877
|
+
province: "Province",
|
|
4878
|
+
zip_code: "Zip Code",
|
|
4879
|
+
postal_code: "Postal Code",
|
|
4880
|
+
select_state: "Select state",
|
|
4881
|
+
select_an_option: "Select an option",
|
|
4882
|
+
set_as_default_address: "Set as default address",
|
|
4883
|
+
save_address: "Save Address"
|
|
4884
|
+
})[key] ?? key.split("_").map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join(" ");
|
|
4885
|
+
function composeAddressName(firstName, lastName) {
|
|
4886
|
+
const combined = `${firstName} ${lastName}`.trim();
|
|
4887
|
+
return combined.length > 0 ? combined : null;
|
|
4888
|
+
}
|
|
4889
|
+
function mapToFluidPayAddress(raw) {
|
|
4890
|
+
return {
|
|
4891
|
+
id: raw.id,
|
|
4892
|
+
address1: raw.street1,
|
|
4893
|
+
address2: raw.street2,
|
|
4894
|
+
city: raw.city,
|
|
4895
|
+
country_code: raw.country,
|
|
4896
|
+
default: raw.default,
|
|
4897
|
+
name: raw.name,
|
|
4898
|
+
postal_code: raw.zip,
|
|
4899
|
+
state: raw.state,
|
|
4900
|
+
subdivision_code: null
|
|
4901
|
+
};
|
|
4902
|
+
}
|
|
4903
|
+
function subscriptionAddressToFluidPay(raw) {
|
|
4904
|
+
if (!raw) return null;
|
|
4905
|
+
return {
|
|
4906
|
+
id: raw.id,
|
|
4907
|
+
address1: raw.address1,
|
|
4908
|
+
address2: raw.address2,
|
|
4909
|
+
city: raw.city,
|
|
4910
|
+
country_code: raw.country_code,
|
|
4911
|
+
default: raw.default,
|
|
4912
|
+
name: raw.name,
|
|
4913
|
+
postal_code: raw.postal_code,
|
|
4914
|
+
state: raw.state,
|
|
4915
|
+
subdivision_code: raw.subdivision_code
|
|
4916
|
+
};
|
|
4917
|
+
}
|
|
4918
|
+
function PortalSubscriptionShippingAddressSection({ address: currentAddress, subscriptionToken, onSuccess, onError }) {
|
|
4919
|
+
const payApi = usePayApi();
|
|
4920
|
+
const queryClient = useQueryClient();
|
|
4921
|
+
const fluidPayShim = useMemo(() => createFluidPayApiAdapter(payApi), [payApi]);
|
|
4922
|
+
const [isFormDialogOpen, setIsFormDialogOpen] = useState(false);
|
|
4923
|
+
const [editingAddress, setEditingAddress] = useState(null);
|
|
4924
|
+
const [deletingAddress, setDeletingAddress] = useState(null);
|
|
4925
|
+
const [deleteError, setDeleteError] = useState(void 0);
|
|
4926
|
+
const { data: addresses = [], isLoading } = useQuery({
|
|
4927
|
+
queryKey: payKeys.addresses.list(),
|
|
4928
|
+
queryFn: async () => {
|
|
4929
|
+
return (await payApi.fetchAddresses()).addresses.map(mapToFluidPayAddress);
|
|
4930
|
+
}
|
|
4931
|
+
});
|
|
4932
|
+
const countriesApi = useCountriesApi();
|
|
4933
|
+
const { data: countriesData } = useQuery({
|
|
4934
|
+
queryKey: storeKeys.countries(),
|
|
4935
|
+
queryFn: () => countriesApi.listCountries(),
|
|
4936
|
+
enabled: isFormDialogOpen
|
|
4937
|
+
});
|
|
4938
|
+
const countryOptions = useMemo(() => [...countriesData?.countries ?? []].map((c) => ({
|
|
4939
|
+
iso: c.code,
|
|
4940
|
+
name: c.name
|
|
4941
|
+
})).sort((a, b) => a.name.localeCompare(b.name)), [countriesData]);
|
|
4942
|
+
const statesByCountry = useMemo(() => {
|
|
4943
|
+
const map = /* @__PURE__ */ new Map();
|
|
4944
|
+
for (const c of countriesData?.countries ?? []) map.set(c.code, c.states.map((s) => ({
|
|
4945
|
+
name: s.name,
|
|
4946
|
+
isoCode: s.code
|
|
4947
|
+
})));
|
|
4948
|
+
return map;
|
|
4949
|
+
}, [countriesData]);
|
|
4950
|
+
const fetchStatesFromCountries = useCallback((countryCode) => Promise.resolve(statesByCountry.get(countryCode) ?? []), [statesByCountry]);
|
|
4951
|
+
const updateSubscription = useUpdateSubscriptionInfo({
|
|
4952
|
+
onSuccess: () => {
|
|
4953
|
+
onSuccess?.("Shipping address updated");
|
|
4954
|
+
queryClient.invalidateQueries({ queryKey: subscriptionsKeys.detail(subscriptionToken) });
|
|
4955
|
+
},
|
|
4956
|
+
onError: (err) => onError?.("Failed to update shipping address", err)
|
|
4957
|
+
});
|
|
4958
|
+
const createAddressMutation = useMutation({
|
|
4959
|
+
mutationFn: (body) => payApi.createAddress({ address: {
|
|
4960
|
+
name: composeAddressName(body.address.first_name, body.address.last_name),
|
|
4961
|
+
street1: body.address.address1,
|
|
4962
|
+
street2: body.address.address2,
|
|
4963
|
+
city: body.address.city,
|
|
4964
|
+
state: body.address.state,
|
|
4965
|
+
zip: body.address.postal_code,
|
|
4966
|
+
country: body.address.country_code,
|
|
4967
|
+
default: body.address.default
|
|
4968
|
+
} }),
|
|
4969
|
+
onSuccess: () => {
|
|
4970
|
+
queryClient.invalidateQueries({ queryKey: payKeys.addresses.all });
|
|
4971
|
+
onSuccess?.("Address added");
|
|
4972
|
+
},
|
|
4973
|
+
onError: (err) => onError?.("Failed to add address", err)
|
|
4974
|
+
});
|
|
4975
|
+
const updateAddressMutation = useMutation({
|
|
4976
|
+
mutationFn: ({ addressId, body }) => payApi.updateAddress(addressId, { address: {
|
|
4977
|
+
name: composeAddressName(body.address.first_name, body.address.last_name),
|
|
4978
|
+
street1: body.address.address1,
|
|
4979
|
+
street2: body.address.address2,
|
|
4980
|
+
city: body.address.city,
|
|
4981
|
+
state: body.address.state,
|
|
4982
|
+
zip: body.address.postal_code,
|
|
4983
|
+
country: body.address.country_code,
|
|
4984
|
+
default: body.address.default
|
|
4985
|
+
} }),
|
|
4986
|
+
onSuccess: () => {
|
|
4987
|
+
queryClient.invalidateQueries({ queryKey: payKeys.addresses.all });
|
|
4988
|
+
onSuccess?.("Address updated");
|
|
4989
|
+
},
|
|
4990
|
+
onError: (err) => onError?.("Failed to update address", err)
|
|
4991
|
+
});
|
|
4992
|
+
const deleteAddressMutation = useMutation({
|
|
4993
|
+
mutationFn: (addressId) => payApi.deleteAddress(addressId),
|
|
4994
|
+
onSuccess: () => {
|
|
4995
|
+
queryClient.invalidateQueries({ queryKey: payKeys.addresses.all });
|
|
4996
|
+
onSuccess?.("Address deleted");
|
|
4997
|
+
}
|
|
4998
|
+
});
|
|
4999
|
+
const makeDefaultAddressMutation = useMutation({
|
|
5000
|
+
mutationFn: (address) => payApi.updateAddress(address.id, { address: {
|
|
5001
|
+
name: address.name ?? null,
|
|
5002
|
+
street1: address.address1 ?? "",
|
|
5003
|
+
street2: address.address2,
|
|
5004
|
+
city: address.city ?? "",
|
|
5005
|
+
state: address.state ?? "",
|
|
5006
|
+
zip: address.postal_code ?? "",
|
|
5007
|
+
country: address.country_code ?? "",
|
|
5008
|
+
default: true
|
|
5009
|
+
} }),
|
|
5010
|
+
onSuccess: () => {
|
|
5011
|
+
queryClient.invalidateQueries({ queryKey: payKeys.addresses.all });
|
|
5012
|
+
onSuccess?.("Default address updated");
|
|
5013
|
+
},
|
|
5014
|
+
onError: (err) => onError?.("Failed to update default address", err)
|
|
5015
|
+
});
|
|
5016
|
+
const displayed = addresses.find((a) => a.id === currentAddress?.id) ?? subscriptionAddressToFluidPay(currentAddress);
|
|
5017
|
+
const handleCloseFormDialog = () => {
|
|
5018
|
+
setIsFormDialogOpen(false);
|
|
5019
|
+
setEditingAddress(null);
|
|
5020
|
+
};
|
|
5021
|
+
const handleConfirmDelete = async () => {
|
|
5022
|
+
if (!deletingAddress) return;
|
|
5023
|
+
setDeleteError(void 0);
|
|
5024
|
+
try {
|
|
5025
|
+
await deleteAddressMutation.mutateAsync(deletingAddress.id);
|
|
5026
|
+
setDeletingAddress(null);
|
|
5027
|
+
} catch (err) {
|
|
5028
|
+
setDeleteError(err instanceof Error ? err.message : "We were unable to delete this address. Please try again.");
|
|
5029
|
+
}
|
|
5030
|
+
};
|
|
5031
|
+
return /* @__PURE__ */ jsx(FluidPayCoreProvider, {
|
|
5032
|
+
api: fluidPayShim,
|
|
5033
|
+
children: /* @__PURE__ */ jsxs(ProfileUIProvider, {
|
|
5034
|
+
t,
|
|
5035
|
+
children: [
|
|
5036
|
+
/* @__PURE__ */ jsx(SelectableAddressDropdown, {
|
|
5037
|
+
title: "Shipping Address",
|
|
5038
|
+
displayAddress: displayed,
|
|
5039
|
+
addressList: addresses,
|
|
5040
|
+
selectedAddressId: currentAddress?.id ?? 0,
|
|
5041
|
+
onSelectAddress: (addr) => {
|
|
5042
|
+
if (addr.id === currentAddress?.id) return;
|
|
5043
|
+
updateSubscription.mutate({
|
|
5044
|
+
subscriptionToken,
|
|
5045
|
+
body: { address_id: addr.id }
|
|
5046
|
+
});
|
|
5047
|
+
},
|
|
5048
|
+
onAddAddressClick: () => {
|
|
5049
|
+
setEditingAddress(null);
|
|
5050
|
+
setIsFormDialogOpen(true);
|
|
5051
|
+
},
|
|
5052
|
+
onEditAddress: (addr) => {
|
|
5053
|
+
setEditingAddress(addr);
|
|
5054
|
+
setIsFormDialogOpen(true);
|
|
5055
|
+
},
|
|
5056
|
+
onDeleteAddress: (addr) => {
|
|
5057
|
+
setDeleteError(void 0);
|
|
5058
|
+
setDeletingAddress(addr);
|
|
5059
|
+
},
|
|
5060
|
+
onMakeDefaultAddress: (addr) => makeDefaultAddressMutation.mutate(addr),
|
|
5061
|
+
addAddressLabel: "+ Add an address",
|
|
5062
|
+
showAddButton: true,
|
|
5063
|
+
isLoading,
|
|
5064
|
+
isPending: updateSubscription.isPending || createAddressMutation.isPending || updateAddressMutation.isPending || makeDefaultAddressMutation.isPending
|
|
5065
|
+
}),
|
|
5066
|
+
/* @__PURE__ */ jsx(AddressFormDialog, {
|
|
5067
|
+
isOpen: isFormDialogOpen,
|
|
5068
|
+
onClose: handleCloseFormDialog,
|
|
5069
|
+
selectedAddress: editingAddress,
|
|
5070
|
+
t,
|
|
5071
|
+
onSubmit: async (data) => {
|
|
5072
|
+
try {
|
|
5073
|
+
if (editingAddress) await updateAddressMutation.mutateAsync({
|
|
5074
|
+
addressId: editingAddress.id,
|
|
5075
|
+
body: data
|
|
5076
|
+
});
|
|
5077
|
+
else await createAddressMutation.mutateAsync(data);
|
|
5078
|
+
handleCloseFormDialog();
|
|
5079
|
+
} catch {}
|
|
5080
|
+
},
|
|
5081
|
+
isSubmitting: createAddressMutation.isPending || updateAddressMutation.isPending,
|
|
5082
|
+
countries: countryOptions,
|
|
5083
|
+
fetchStates: fetchStatesFromCountries,
|
|
5084
|
+
renderAddressAutocomplete: ({ control, setValue, countryCode }) => /* @__PURE__ */ jsx(AddressAutocompleteInput, {
|
|
5085
|
+
control,
|
|
5086
|
+
setValue,
|
|
5087
|
+
countryIso: countryCode,
|
|
5088
|
+
addressLineField: "address1",
|
|
5089
|
+
cityField: "city",
|
|
5090
|
+
stateField: "state",
|
|
5091
|
+
postalCodeField: "postal_code",
|
|
5092
|
+
placeholder: t("address_line_1")
|
|
5093
|
+
})
|
|
5094
|
+
}),
|
|
5095
|
+
/* @__PURE__ */ jsx(ConfirmActionDialog, {
|
|
5096
|
+
title: t("delete_address"),
|
|
5097
|
+
description: t("delete_address_message"),
|
|
5098
|
+
actionText: t("delete"),
|
|
5099
|
+
openDialog: deletingAddress !== null,
|
|
5100
|
+
setOpenDialog: (open) => {
|
|
5101
|
+
if (!open) {
|
|
5102
|
+
setDeletingAddress(null);
|
|
5103
|
+
setDeleteError(void 0);
|
|
5104
|
+
}
|
|
5105
|
+
},
|
|
5106
|
+
onAction: handleConfirmDelete,
|
|
5107
|
+
errorMsg: deleteError,
|
|
5108
|
+
isLoading: deleteAddressMutation.isPending
|
|
5109
|
+
})
|
|
5110
|
+
]
|
|
5111
|
+
})
|
|
4661
5112
|
});
|
|
4662
5113
|
}
|
|
4663
5114
|
//#endregion
|
|
@@ -4687,6 +5138,13 @@ function SubscriptionDetailScreen({ token, onToast }) {
|
|
|
4687
5138
|
onError: (message, err) => {
|
|
4688
5139
|
onToast(`${message}: ${err instanceof Error ? err.message : "An error occurred"}`, "error");
|
|
4689
5140
|
}
|
|
5141
|
+
}),
|
|
5142
|
+
renderShippingAddress: (ctx) => /* @__PURE__ */ jsx(PortalSubscriptionShippingAddressSection, {
|
|
5143
|
+
...ctx,
|
|
5144
|
+
onSuccess: (message) => onToast(message, "success"),
|
|
5145
|
+
onError: (message, err) => {
|
|
5146
|
+
onToast(`${message}: ${err instanceof Error ? err.message : "An error occurred"}`, "error");
|
|
5147
|
+
}
|
|
4690
5148
|
})
|
|
4691
5149
|
});
|
|
4692
5150
|
}
|
|
@@ -4737,4 +5195,4 @@ const subscriptionsScreenPropertySchema = {
|
|
|
4737
5195
|
//#endregion
|
|
4738
5196
|
export { SubscriptionsScreen_exports as n, subscriptionsScreenPropertySchema as r, SubscriptionsScreen as t };
|
|
4739
5197
|
|
|
4740
|
-
//# sourceMappingURL=SubscriptionsScreen-
|
|
5198
|
+
//# sourceMappingURL=SubscriptionsScreen-CsNE6gik.mjs.map
|