@fluid-app/portal-sdk 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/AccountScreen-B08uxzt6.mjs +2 -0
  2. package/dist/AccountScreen-CQCwpKEC.mjs +741 -0
  3. package/dist/AccountScreen-CQCwpKEC.mjs.map +1 -0
  4. package/dist/AccountScreen-CbhrIAa4.cjs +780 -0
  5. package/dist/AccountScreen-CbhrIAa4.cjs.map +1 -0
  6. package/dist/{ContactsScreen-CB6l0Lf1.mjs → ContactsScreen-CHLFZX_N.mjs} +2 -2
  7. package/dist/{ContactsScreen-CB6l0Lf1.mjs.map → ContactsScreen-CHLFZX_N.mjs.map} +1 -1
  8. package/dist/{ContactsScreen-Dwn5onLu.cjs → ContactsScreen-CjnCemeI.cjs} +4 -4
  9. package/dist/{ContactsScreen-Dwn5onLu.cjs.map → ContactsScreen-CjnCemeI.cjs.map} +1 -1
  10. package/dist/{CoreScreenPlaceholder-Bw8YOPwv.cjs → CoreScreenPlaceholder-C9lBkcyc.cjs} +2 -2
  11. package/dist/{CoreScreenPlaceholder-Bw8YOPwv.cjs.map → CoreScreenPlaceholder-C9lBkcyc.cjs.map} +1 -1
  12. package/dist/{CoreScreenPlaceholder-D93ZYKt2.mjs → CoreScreenPlaceholder-DCJ1hFvJ.mjs} +1 -1
  13. package/dist/{CoreScreenPlaceholder-D93ZYKt2.mjs.map → CoreScreenPlaceholder-DCJ1hFvJ.mjs.map} +1 -1
  14. package/dist/{CustomersScreen-gQb6cWL5.cjs → CustomersScreen-CqwRJogV.cjs} +4 -4
  15. package/dist/{CustomersScreen-gQb6cWL5.cjs.map → CustomersScreen-CqwRJogV.cjs.map} +1 -1
  16. package/dist/{CustomersScreen-BEar6Leg.mjs → CustomersScreen-DBicCB3o.mjs} +2 -2
  17. package/dist/{CustomersScreen-BEar6Leg.mjs.map → CustomersScreen-DBicCB3o.mjs.map} +1 -1
  18. package/dist/{MessagingScreen-YyzXdr95.mjs → FluidProvider-BafZw8PJ.mjs} +6 -503
  19. package/dist/FluidProvider-BafZw8PJ.mjs.map +1 -0
  20. package/dist/{MessagingScreen-Ca22FObh.cjs → FluidProvider-C6SCZDjX.cjs} +3 -542
  21. package/dist/FluidProvider-C6SCZDjX.cjs.map +1 -0
  22. package/dist/MessagingScreen-Bd-1_J9q.cjs +369 -0
  23. package/dist/MessagingScreen-Bd-1_J9q.cjs.map +1 -0
  24. package/dist/MessagingScreen-D8W8V2TW.mjs +2 -0
  25. package/dist/MessagingScreen-DCS0mtbd.mjs +324 -0
  26. package/dist/MessagingScreen-DCS0mtbd.mjs.map +1 -0
  27. package/dist/{OrdersScreen-DB1v051q.mjs → OrdersScreen-B6JCMBY5.mjs} +2 -2
  28. package/dist/{OrdersScreen-DB1v051q.mjs.map → OrdersScreen-B6JCMBY5.mjs.map} +1 -1
  29. package/dist/{OrdersScreen-DbON-kBA.cjs → OrdersScreen-DBxpXgZ9.cjs} +4 -4
  30. package/dist/{OrdersScreen-DbON-kBA.cjs.map → OrdersScreen-DBxpXgZ9.cjs.map} +1 -1
  31. package/dist/{ProductsScreen-CMDGGvE2.cjs → ProductsScreen-BK8cz_MN.cjs} +4 -4
  32. package/dist/{ProductsScreen-CMDGGvE2.cjs.map → ProductsScreen-BK8cz_MN.cjs.map} +1 -1
  33. package/dist/{ProductsScreen-nVDsY6kf.mjs → ProductsScreen-DafsauTY.mjs} +2 -2
  34. package/dist/{ProductsScreen-nVDsY6kf.mjs.map → ProductsScreen-DafsauTY.mjs.map} +1 -1
  35. package/dist/index.cjs +73 -138
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +29 -22
  38. package/dist/index.d.cts.map +1 -1
  39. package/dist/index.d.mts +29 -22
  40. package/dist/index.d.mts.map +1 -1
  41. package/dist/index.mjs +49 -116
  42. package/dist/index.mjs.map +1 -1
  43. package/package.json +19 -13
  44. package/dist/MessagingScreen-Ca22FObh.cjs.map +0 -1
  45. package/dist/MessagingScreen-YyzXdr95.mjs.map +0 -1
@@ -0,0 +1,780 @@
1
+ const require_FluidProvider = require("./FluidProvider-C6SCZDjX.cjs");
2
+ let react = require("react");
3
+ let _tanstack_react_query = require("@tanstack/react-query");
4
+ let _fluid_app_api_client_core = require("@fluid-app/api-client-core");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ let _fluid_app_fluid_pay_api_client = require("@fluid-app/fluid-pay-api-client");
7
+ let _fluid_app_orders_api_client = require("@fluid-app/orders-api-client");
8
+ let _fluid_app_subscriptions_api_client = require("@fluid-app/subscriptions-api-client");
9
+ let lucide_react = require("lucide-react");
10
+ let react_hook_form = require("react-hook-form");
11
+ let _fluid_app_profile_core = require("@fluid-app/profile-core");
12
+ let _fluid_app_profile_ui = require("@fluid-app/profile-ui");
13
+ let _fluid_app_orders_core = require("@fluid-app/orders-core");
14
+ let _fluid_app_orders_ui = require("@fluid-app/orders-ui");
15
+ let _fluid_app_subscriptions_core = require("@fluid-app/subscriptions-core");
16
+ let _fluid_app_subscriptions_ui = require("@fluid-app/subscriptions-ui");
17
+ //#region src/hooks/use-fluid-auth.ts
18
+ /**
19
+ * useFluidAuth Hook
20
+ *
21
+ * Provides access to authentication state and utilities.
22
+ * This is the primary hook for interacting with auth in components.
23
+ */
24
+ /**
25
+ * Hook to access authentication state and utilities.
26
+ *
27
+ * Must be used within a `FluidAuthProvider`.
28
+ *
29
+ * @returns Authentication context with user info, loading state, and utilities
30
+ * @throws Error if used outside FluidAuthProvider
31
+ *
32
+ * @example
33
+ * ```tsx
34
+ * function UserProfile() {
35
+ * const { isAuthenticated, isLoading, user, clearAuth } = useFluidAuth();
36
+ *
37
+ * if (isLoading) {
38
+ * return <Spinner />;
39
+ * }
40
+ *
41
+ * if (!isAuthenticated) {
42
+ * return <p>Please log in</p>;
43
+ * }
44
+ *
45
+ * return (
46
+ * <div>
47
+ * <p>Welcome, {user.full_name}!</p>
48
+ * <button onClick={clearAuth}>Log out</button>
49
+ * </div>
50
+ * );
51
+ * }
52
+ * ```
53
+ */
54
+ function useFluidAuth() {
55
+ return require_FluidProvider.useFluidAuthContext();
56
+ }
57
+ //#endregion
58
+ //#region src/account/use-account-clients.ts
59
+ /** API version prefix for versioned endpoints (e.g. points ledger) */
60
+ const API_VERSION = "/v202506";
61
+ function useOrdersClient() {
62
+ const { config } = require_FluidProvider.useFluidContext();
63
+ const { token } = useFluidAuth();
64
+ return (0, react.useMemo)(() => (0, _fluid_app_orders_api_client.createFetchClient)({
65
+ baseUrl: config.baseUrl,
66
+ getAuthToken: () => token,
67
+ onAuthError: config.onAuthError
68
+ }), [
69
+ config.baseUrl,
70
+ config.onAuthError,
71
+ token
72
+ ]);
73
+ }
74
+ function useSubscriptionsClient() {
75
+ const { config } = require_FluidProvider.useFluidContext();
76
+ const { token } = useFluidAuth();
77
+ return (0, react.useMemo)(() => (0, _fluid_app_subscriptions_api_client.createFetchClient)({
78
+ baseUrl: config.baseUrl,
79
+ getAuthToken: () => token,
80
+ onAuthError: config.onAuthError
81
+ }), [
82
+ config.baseUrl,
83
+ config.onAuthError,
84
+ token
85
+ ]);
86
+ }
87
+ function useFluidPayClient() {
88
+ const { config } = require_FluidProvider.useFluidContext();
89
+ const { token } = useFluidAuth();
90
+ return (0, react.useMemo)(() => (0, _fluid_app_fluid_pay_api_client.createFetchClient)({
91
+ baseUrl: config.baseUrl,
92
+ getAuthToken: () => token,
93
+ onAuthError: config.onAuthError
94
+ }), [
95
+ config.baseUrl,
96
+ config.onAuthError,
97
+ token
98
+ ]);
99
+ }
100
+ /**
101
+ * Generic SDK fetch client for endpoints not covered by domain-specific clients
102
+ * (e.g. /countries, /v202506/customers/:id/points_ledgers).
103
+ * Uses the same auth/baseUrl/error handling as the domain clients.
104
+ */
105
+ function useSdkClient() {
106
+ const { config } = require_FluidProvider.useFluidContext();
107
+ const { token } = useFluidAuth();
108
+ return (0, react.useMemo)(() => (0, _fluid_app_api_client_core.createFetchClient)({
109
+ baseUrl: config.baseUrl,
110
+ getAuthToken: () => token,
111
+ onAuthError: config.onAuthError
112
+ }), [
113
+ config.baseUrl,
114
+ config.onAuthError,
115
+ token
116
+ ]);
117
+ }
118
+ //#endregion
119
+ //#region src/shell/AppNavigationContext.tsx
120
+ const AppNavigationContext = (0, react.createContext)(null);
121
+ function AppNavigationProvider({ currentSlug, basePath, navigate, children }) {
122
+ const buildHref = (0, react.useMemo)(() => {
123
+ return (slug) => {
124
+ if (basePath === "/") return `/${slug}`;
125
+ return `${basePath}/${slug}`;
126
+ };
127
+ }, [basePath]);
128
+ const value = (0, react.useMemo)(() => ({
129
+ currentSlug,
130
+ basePath,
131
+ navigate,
132
+ buildHref
133
+ }), [
134
+ currentSlug,
135
+ basePath,
136
+ navigate,
137
+ buildHref
138
+ ]);
139
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AppNavigationContext.Provider, {
140
+ value,
141
+ children
142
+ });
143
+ }
144
+ function useAppNavigation() {
145
+ const ctx = (0, react.useContext)(AppNavigationContext);
146
+ if (!ctx) throw new Error("useAppNavigation must be used within an <AppShell> or <AppNavigationProvider>");
147
+ return ctx;
148
+ }
149
+ //#endregion
150
+ //#region src/account/AccountManageLayout.tsx
151
+ const NAV_ITEMS = [
152
+ {
153
+ key: "profile",
154
+ label: "Profile",
155
+ slug: "account/profile",
156
+ icon: lucide_react.User
157
+ },
158
+ {
159
+ key: "orders",
160
+ label: "Orders",
161
+ slug: "account/orders",
162
+ icon: lucide_react.PackageOpen
163
+ },
164
+ {
165
+ key: "subscriptions",
166
+ label: "Subscriptions",
167
+ slug: "account/subscriptions",
168
+ icon: lucide_react.Repeat
169
+ }
170
+ ];
171
+ function getActiveTab(slug) {
172
+ const sub = slug.split("/")[1];
173
+ if (sub === "orders") return "orders";
174
+ if (sub === "subscriptions") return "subscriptions";
175
+ return "profile";
176
+ }
177
+ function AccountManageLayout({ children }) {
178
+ const { currentSlug, navigate } = useAppNavigation();
179
+ const activeTab = getActiveTab(currentSlug);
180
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
181
+ className: "flex flex-col md:flex-row",
182
+ children: [
183
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
184
+ className: "flex gap-1 overflow-x-auto border-b px-4 py-2 md:hidden",
185
+ children: NAV_ITEMS.map(({ key, slug, label, icon: Icon }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
186
+ type: "button",
187
+ onClick: () => navigate(slug),
188
+ className: `flex items-center gap-2 rounded-md px-3 py-2 text-sm font-medium whitespace-nowrap ${activeTab === key ? "bg-sidebar-primary text-sidebar-primary-foreground" : "hover:bg-sidebar-primary hover:text-sidebar-primary-foreground"}`,
189
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { className: "h-4 w-4" }), label]
190
+ }, key))
191
+ }),
192
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("nav", {
193
+ className: "hidden w-48 shrink-0 flex-col gap-1 p-4 md:flex",
194
+ children: NAV_ITEMS.map(({ key, slug, label, icon: Icon }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
195
+ type: "button",
196
+ onClick: () => navigate(slug),
197
+ className: `flex items-center gap-2 rounded-md px-3 py-2 text-left text-sm font-medium ${activeTab === key ? "bg-sidebar-primary text-sidebar-primary-foreground" : "hover:bg-sidebar-primary hover:text-sidebar-primary-foreground"}`,
198
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, { className: "h-4 w-4" }), label]
199
+ }, key))
200
+ }),
201
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
202
+ className: "min-w-0 flex-1",
203
+ children
204
+ })
205
+ ]
206
+ });
207
+ }
208
+ //#endregion
209
+ //#region src/screens/AccountProfileScreen.tsx
210
+ const translations$2 = {
211
+ edit_profile: "Edit Profile",
212
+ first_name: "First Name",
213
+ last_name: "Last Name",
214
+ phone_number: "Phone Number",
215
+ language: "Language",
216
+ first_name_is_required: "First name is required",
217
+ last_name_is_required: "Last name is required",
218
+ language_is_required: "Language is required",
219
+ saving: "Saving...",
220
+ save_changes: "Save Changes",
221
+ select_an_option: "Select an option",
222
+ points_history: "Points History",
223
+ points_available: "Points Available",
224
+ points_awarded: "Points Awarded",
225
+ points_redeemed: "Points Redeemed",
226
+ transaction: "Transaction",
227
+ no_points_history_found: "No points history found",
228
+ shipping_addresses: "Shipping Addresses",
229
+ add_an_address: "Add an Address",
230
+ delete_address: "Delete Address",
231
+ delete_address_message: "Are you sure you want to delete this address? This action cannot be undone.",
232
+ delete: "Delete",
233
+ add_address: "Add Address",
234
+ edit_address: "Edit Address",
235
+ set_as_default_address: "Set as default address",
236
+ save_address: "Save Address",
237
+ card_number: "Card Number",
238
+ expiration_date: "Expiration (MM / YY)",
239
+ cvc: "CVC",
240
+ cardholder_name: "Cardholder Name",
241
+ add_credit_card: "Add Credit Card",
242
+ save_card: "Save Card",
243
+ securing: "Loading secure form...",
244
+ payment_methods: "Payment Methods",
245
+ add_payment_method: "Add Payment Method",
246
+ delete_credit_card: "Delete Credit Card",
247
+ delete_credit_card_message: "Are you sure you want to delete this payment method? This action cannot be undone.",
248
+ edit_card: "Card Details",
249
+ billing_address: "Billing Address",
250
+ country: "Country",
251
+ name: "Name",
252
+ address_line_1: "Address Line 1",
253
+ address_line_2: "Address Line 2",
254
+ city: "City",
255
+ state: "State",
256
+ province: "Province",
257
+ zip_code: "Zip Code",
258
+ postal_code: "Postal Code",
259
+ select_state: "Select state",
260
+ set_as_default_payment_method: "Set as default payment method",
261
+ cancel: "Cancel",
262
+ save: "Save",
263
+ close: "Close",
264
+ edit: "Edit",
265
+ default: "Default",
266
+ card_expires: "Expires",
267
+ no_billing_address: "No billing address on file",
268
+ default_payment_method_updated: "Payment method updated",
269
+ failed_to_set_default_payment_method: "Failed to update payment method"
270
+ };
271
+ function t(key) {
272
+ if (translations$2[key]) return translations$2[key];
273
+ return key.split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
274
+ }
275
+ function adaptPointsLedger(entry) {
276
+ return {
277
+ id: entry.id,
278
+ amount: entry.amount,
279
+ company_id: 0,
280
+ created_at: entry.created_at,
281
+ customer_id: entry.customer_id,
282
+ metadata: {
283
+ transaction_type: entry.metadata?.transaction_type ?? void 0,
284
+ source: entry.metadata?.source ?? void 0
285
+ },
286
+ total_balance: entry.total_balance ?? 0,
287
+ updated_at: entry.created_at
288
+ };
289
+ }
290
+ function AccountProfileScreen({ onToast, countryIso }) {
291
+ const { token, user } = useFluidAuth();
292
+ const client = useFluidPayClient();
293
+ const sdkClient = useSdkClient();
294
+ const queryClient = (0, _tanstack_react_query.useQueryClient)();
295
+ const jwt = token ?? "";
296
+ const userId = user?.id;
297
+ const { data: accountData, isLoading: isLoadingAccount, isError: isAccountError } = (0, _tanstack_react_query.useQuery)({
298
+ queryKey: ["fluidPayAccount", userId],
299
+ queryFn: () => _fluid_app_fluid_pay_api_client.customersApi.fetchCustomerAccount(client, jwt),
300
+ enabled: !!jwt
301
+ });
302
+ const { data: addressesData, isLoading: isLoadingAddresses } = (0, _tanstack_react_query.useQuery)({
303
+ queryKey: ["fluidPayAddresses", userId],
304
+ queryFn: () => _fluid_app_fluid_pay_api_client.addressesApi.fetchCustomerAddresses(client, jwt),
305
+ enabled: !!jwt
306
+ });
307
+ const { data: paymentMethodsData, isLoading: isLoadingPaymentMethods } = (0, _tanstack_react_query.useQuery)({
308
+ queryKey: [
309
+ "fluidPayPaymentMethods",
310
+ userId,
311
+ countryIso
312
+ ],
313
+ queryFn: () => _fluid_app_fluid_pay_api_client.paymentMethodsApi.fetchCustomerPaymentMethods(client, jwt, countryIso),
314
+ enabled: !!jwt
315
+ });
316
+ const { data: countriesData } = (0, _tanstack_react_query.useQuery)({
317
+ queryKey: ["sdk-countries"],
318
+ queryFn: () => sdkClient.get("/countries"),
319
+ initialData: []
320
+ });
321
+ const customerId = accountData?.customer?.id;
322
+ const { data: pointsLedgerData, isLoading: isLoadingPointsLedger } = (0, _tanstack_react_query.useQuery)({
323
+ queryKey: ["customer-points-ledger", customerId],
324
+ queryFn: () => sdkClient.get(`${API_VERSION}/customers/${customerId}/points_ledgers`),
325
+ enabled: !!customerId
326
+ });
327
+ const updateCustomerMutation = (0, _tanstack_react_query.useMutation)({
328
+ mutationFn: (data) => {
329
+ const languageIso = adaptedLanguages?.find((l) => l.name === data.language)?.iso ?? "en";
330
+ return _fluid_app_fluid_pay_api_client.customersApi.updateCustomer(client, jwt, {
331
+ first_name: data.first_name,
332
+ last_name: data.last_name,
333
+ phone: data.phone_number,
334
+ language_iso: languageIso
335
+ });
336
+ },
337
+ onSuccess: () => {
338
+ queryClient.invalidateQueries({ queryKey: ["fluidPayAccount", userId] });
339
+ onToast("Profile updated", "success");
340
+ },
341
+ onError: () => {
342
+ onToast("Failed to update profile", "error");
343
+ }
344
+ });
345
+ const deleteAddressMutation = (0, _tanstack_react_query.useMutation)({
346
+ mutationFn: (addressId) => _fluid_app_fluid_pay_api_client.addressesApi.deleteCustomerAddress(client, jwt, addressId),
347
+ onSuccess: () => {
348
+ queryClient.invalidateQueries({ queryKey: ["fluidPayAddresses", userId] });
349
+ }
350
+ });
351
+ const deletePaymentMethodMutation = (0, _tanstack_react_query.useMutation)({
352
+ mutationFn: (paymentMethodId) => _fluid_app_fluid_pay_api_client.paymentMethodsApi.deleteCustomerPaymentMethod(client, jwt, paymentMethodId),
353
+ onSuccess: () => {
354
+ queryClient.invalidateQueries({ queryKey: [
355
+ "fluidPayPaymentMethods",
356
+ userId,
357
+ countryIso
358
+ ] });
359
+ }
360
+ });
361
+ const updatePaymentMethodMutation = (0, _tanstack_react_query.useMutation)({
362
+ mutationFn: ({ paymentMethodId, data }) => _fluid_app_fluid_pay_api_client.paymentMethodsApi.updatePaymentMethod(client, jwt, paymentMethodId, {
363
+ set_as_default: data.set_as_default,
364
+ billing_address: data.billing_address
365
+ }),
366
+ onSuccess: () => {
367
+ queryClient.invalidateQueries({ queryKey: [
368
+ "fluidPayPaymentMethods",
369
+ userId,
370
+ countryIso
371
+ ] });
372
+ }
373
+ });
374
+ const createAddressMutation = (0, _tanstack_react_query.useMutation)({
375
+ mutationFn: (body) => _fluid_app_fluid_pay_api_client.addressesApi.createCustomerAddress(client, jwt, body),
376
+ onSuccess: () => {
377
+ queryClient.invalidateQueries({ queryKey: ["fluidPayAddresses", userId] });
378
+ onToast("Address created", "success");
379
+ },
380
+ onError: () => {
381
+ onToast("Failed to create address", "error");
382
+ }
383
+ });
384
+ const updateAddressMutation = (0, _tanstack_react_query.useMutation)({
385
+ mutationFn: ({ addressId, body }) => _fluid_app_fluid_pay_api_client.addressesApi.updateCustomerAddress(client, jwt, addressId, body),
386
+ onSuccess: () => {
387
+ queryClient.invalidateQueries({ queryKey: ["fluidPayAddresses", userId] });
388
+ onToast("Address updated", "success");
389
+ },
390
+ onError: () => {
391
+ onToast("Failed to update address", "error");
392
+ }
393
+ });
394
+ const addCreditCardMutation = (0, _tanstack_react_query.useMutation)({
395
+ mutationFn: (data) => _fluid_app_fluid_pay_api_client.paymentMethodsApi.addCreditCardToCustomer(client, jwt, data),
396
+ onSuccess: () => {
397
+ queryClient.invalidateQueries({ queryKey: [
398
+ "fluidPayPaymentMethods",
399
+ userId,
400
+ countryIso
401
+ ] });
402
+ onToast("Payment method added", "success");
403
+ },
404
+ onError: () => {
405
+ onToast("Failed to add payment method", "error");
406
+ }
407
+ });
408
+ const addresses = addressesData?.addresses ?? [];
409
+ const paymentMethods = paymentMethodsData?.payment_methods ?? [];
410
+ const adaptedPointsLedger = pointsLedgerData?.points_ledgers?.map(adaptPointsLedger) ?? [];
411
+ const adaptedLanguages = [{
412
+ id: 0,
413
+ name: "English",
414
+ iso: "en"
415
+ }];
416
+ const countryOptions = (0, react.useMemo)(() => [...countriesData].map((c) => ({
417
+ iso: c.iso,
418
+ name: c.name
419
+ })).sort((a, b) => a.name.localeCompare(b.name)), [countriesData]);
420
+ if (!token) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
421
+ className: "px-4 py-8 sm:px-9",
422
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
423
+ className: "rounded-lg border p-4 text-center",
424
+ children: "Login Required"
425
+ })
426
+ });
427
+ if (isAccountError && !isLoadingAccount) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
428
+ className: "px-4 py-8 sm:px-9",
429
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
430
+ className: "text-muted-foreground text-center text-sm",
431
+ children: "Unable to load account data. Please try again later."
432
+ })
433
+ });
434
+ if (isLoadingAccount || !accountData) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
435
+ className: "px-4 pt-4 sm:px-9 md:pt-8",
436
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
437
+ className: "space-y-4",
438
+ children: [
439
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-16 animate-pulse rounded" }),
440
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-32 animate-pulse rounded" }),
441
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-32 animate-pulse rounded" })
442
+ ]
443
+ })
444
+ });
445
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
446
+ className: "px-4 pt-4 sm:px-9 md:pt-8",
447
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_profile_core.ProfileUIProvider, {
448
+ t,
449
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_profile_ui.Profile, {
450
+ customerAccount: accountData,
451
+ languages: adaptedLanguages,
452
+ onUpdateCustomer: async (data) => {
453
+ await updateCustomerMutation.mutateAsync(data);
454
+ },
455
+ isUpdatingCustomer: updateCustomerMutation.isPending,
456
+ rewardsPointsEnabled: adaptedPointsLedger.length > 0,
457
+ pointsLedger: adaptedPointsLedger,
458
+ isLoadingPointsLedger,
459
+ addresses,
460
+ isLoadingAddresses,
461
+ onDeleteAddress: async (addressId) => {
462
+ await deleteAddressMutation.mutateAsync(addressId);
463
+ },
464
+ isDeletingAddress: deleteAddressMutation.isPending,
465
+ paymentMethods,
466
+ isLoadingPaymentMethods,
467
+ onDeletePaymentMethod: async (paymentMethodId) => {
468
+ await deletePaymentMethodMutation.mutateAsync(paymentMethodId);
469
+ },
470
+ isDeletingPaymentMethod: deletePaymentMethodMutation.isPending,
471
+ onUpdatePaymentMethod: async (paymentMethodId, data) => {
472
+ await updatePaymentMethodMutation.mutateAsync({
473
+ paymentMethodId,
474
+ data
475
+ });
476
+ },
477
+ isUpdatingPaymentMethod: updatePaymentMethodMutation.isPending,
478
+ getBillingAddress: (pm) => pm.billing_address ?? null,
479
+ countries: countryOptions,
480
+ renderAddressDialog: ({ isOpen, onClose, selectedAddress }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_profile_ui.AddressFormDialog, {
481
+ isOpen,
482
+ onClose,
483
+ selectedAddress,
484
+ t,
485
+ onSubmit: async (formData) => {
486
+ if (selectedAddress) await updateAddressMutation.mutateAsync({
487
+ addressId: selectedAddress.id,
488
+ body: formData
489
+ });
490
+ else await createAddressMutation.mutateAsync(formData);
491
+ onClose();
492
+ },
493
+ isSubmitting: createAddressMutation.isPending || updateAddressMutation.isPending,
494
+ countries: countryOptions,
495
+ renderAddressAutocomplete: ({ control, setValue: _setValue }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PlainAddressInput, {
496
+ control,
497
+ name: "address1"
498
+ })
499
+ }),
500
+ renderCreditCardDialog: ({ isOpen, onClose }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_profile_ui.CreditCardFormDialog, {
501
+ isOpen,
502
+ onClose,
503
+ t,
504
+ onSubmit: async (data) => {
505
+ await addCreditCardMutation.mutateAsync(data);
506
+ onClose();
507
+ },
508
+ isSubmitting: addCreditCardMutation.isPending,
509
+ countries: countryOptions,
510
+ jwt,
511
+ client,
512
+ renderAddressAutocomplete: ({ control, setValue: _setValue }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(PlainAddressInput, {
513
+ control,
514
+ name: "address1"
515
+ })
516
+ })
517
+ })
518
+ })
519
+ });
520
+ }
521
+ /**
522
+ * Plain text input fallback for address autocomplete.
523
+ * The SDK doesn't have Google Places integration.
524
+ */
525
+ function PlainAddressInput({ control, name }) {
526
+ const { field } = (0, react_hook_form.useController)({
527
+ control,
528
+ name
529
+ });
530
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
531
+ type: "text",
532
+ value: field.value ?? "",
533
+ placeholder: "Address Line 1",
534
+ className: "border-input bg-background ring-offset-background placeholder:text-muted-foreground focus-visible:ring-ring flex h-10 w-full rounded-md border px-3 py-2 text-sm file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50",
535
+ onChange: field.onChange
536
+ });
537
+ }
538
+ //#endregion
539
+ //#region src/screens/AccountOrdersScreen.tsx
540
+ const translations$1 = {
541
+ search_orders: "Search orders...",
542
+ order_number: "Order #",
543
+ date: "Date",
544
+ status: "Status",
545
+ product: "Product",
546
+ no_orders_found: "No orders found",
547
+ no_matching_orders: "No matching orders",
548
+ no_image_available: "No image available",
549
+ this_product_no_longer_exists: "This product no longer exists",
550
+ subscription: "Subscription",
551
+ view_subscription: "View Subscription",
552
+ total: "Total",
553
+ results: "results",
554
+ previous: "Previous",
555
+ next: "Next",
556
+ pagination: "Pagination"
557
+ };
558
+ function AccountOrdersScreen({ customerId, isLoadingCustomer }) {
559
+ const ordersClient = useOrdersClient();
560
+ const { navigate } = useAppNavigation();
561
+ const handleOrderClick = (order) => {
562
+ navigate(`account/orders/${order.token}`);
563
+ };
564
+ const handleSubscriptionClick = (subscriptionToken) => {
565
+ navigate(`account/subscriptions/${subscriptionToken}`);
566
+ };
567
+ if (isLoadingCustomer) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
568
+ className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
569
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
570
+ className: "space-y-3",
571
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-10 animate-pulse rounded" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-64 animate-pulse rounded" })]
572
+ })
573
+ });
574
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_orders_core.OrdersCoreProvider, {
575
+ client: ordersClient,
576
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
577
+ className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
578
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_orders_ui.OrdersList, {
579
+ customerId,
580
+ onOrderClick: handleOrderClick,
581
+ onSubscriptionClick: handleSubscriptionClick,
582
+ t: (key) => translations$1[key] ?? key
583
+ })
584
+ })
585
+ });
586
+ }
587
+ //#endregion
588
+ //#region src/screens/AccountOrderDetailScreen.tsx
589
+ function AccountOrderDetailScreen({ token, onToast }) {
590
+ const client = useOrdersClient();
591
+ const { navigate } = useAppNavigation();
592
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_orders_core.OrdersCoreProvider, {
593
+ client,
594
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
595
+ className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
596
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_orders_ui.OrderDetail, {
597
+ token,
598
+ onNotFound: () => {
599
+ onToast("Order not found", "warning");
600
+ navigate("account/orders");
601
+ },
602
+ onError: (err) => {
603
+ onToast(`Failed to load order: ${err instanceof Error ? err.message : "An error occurred"}`, "error");
604
+ }
605
+ })
606
+ })
607
+ });
608
+ }
609
+ //#endregion
610
+ //#region src/screens/AccountSubscriptionsScreen.tsx
611
+ const translations = {
612
+ all: "All",
613
+ active: "Active",
614
+ inactive: "Inactive",
615
+ search: "Search",
616
+ subscriptions: "Search subscriptions...",
617
+ product: "Product",
618
+ next_bill_date: "Next Bill Date",
619
+ price: "Price",
620
+ status: "Status",
621
+ no_subscriptions_found: "No subscriptions found",
622
+ unknown_status: "Unknown",
623
+ total: "Total",
624
+ results: "results",
625
+ previous: "Previous",
626
+ next: "Next",
627
+ pagination: "Pagination"
628
+ };
629
+ function AccountSubscriptionsScreen({ customerId, isLoadingCustomer }) {
630
+ const subscriptionsClient = useSubscriptionsClient();
631
+ const { navigate } = useAppNavigation();
632
+ if (isLoadingCustomer) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
633
+ className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
634
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
635
+ className: "space-y-3",
636
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-10 animate-pulse rounded" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "bg-muted h-64 animate-pulse rounded" })]
637
+ })
638
+ });
639
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_subscriptions_core.SubscriptionsCoreProvider, {
640
+ client: subscriptionsClient,
641
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
642
+ className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
643
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_subscriptions_ui.SubscriptionsList, {
644
+ customerId,
645
+ onSubscriptionClick: (subscriptionToken) => navigate(`account/subscriptions/${subscriptionToken}`),
646
+ t: (key) => translations[key] ?? key
647
+ })
648
+ })
649
+ });
650
+ }
651
+ //#endregion
652
+ //#region src/screens/AccountSubscriptionDetailScreen.tsx
653
+ function AccountSubscriptionDetailScreen({ token, onToast }) {
654
+ const client = useSubscriptionsClient();
655
+ const { navigate } = useAppNavigation();
656
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_subscriptions_core.SubscriptionsCoreProvider, {
657
+ client,
658
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
659
+ className: "mx-auto max-w-7xl px-4 py-4 sm:px-6 sm:py-6 lg:px-10 lg:py-8",
660
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_fluid_app_subscriptions_ui.SubscriptionDetail, {
661
+ token,
662
+ onNotFound: () => {
663
+ onToast("Subscription not found", "warning");
664
+ navigate("account/subscriptions");
665
+ },
666
+ onError: (err) => {
667
+ onToast(`Failed to load subscription: ${err instanceof Error ? err.message : "An error occurred"}`, "error");
668
+ },
669
+ onSuccess: (message) => {
670
+ onToast(message, "success");
671
+ },
672
+ onMutationError: (message, err) => {
673
+ onToast(`${message}: ${err instanceof Error ? err.message : "An error occurred"}`, "error");
674
+ }
675
+ })
676
+ })
677
+ });
678
+ }
679
+ //#endregion
680
+ //#region src/screens/AccountScreen.tsx
681
+ var AccountScreen_exports = /* @__PURE__ */ require_FluidProvider.__exportAll({
682
+ AccountScreen: () => AccountScreen,
683
+ accountScreenPropertySchema: () => accountScreenPropertySchema
684
+ });
685
+ function defaultToast(message, type) {
686
+ if (type === "error" || type === "warning") console.warn("[Account]", message);
687
+ else console.info("[Account]", message);
688
+ }
689
+ function AccountScreen({ onToast, background, textColor, accentColor, padding, borderRadius, ...divProps }) {
690
+ const { currentSlug } = useAppNavigation();
691
+ const { config } = require_FluidProvider.useFluidContext();
692
+ const effectiveToast = onToast ?? defaultToast;
693
+ const { token, user } = useFluidAuth();
694
+ const fluidPayClient = useFluidPayClient();
695
+ const jwt = token ?? "";
696
+ const { data: customerData, isLoading: isLoadingCustomer, isError: isCustomerError } = (0, _tanstack_react_query.useQuery)({
697
+ queryKey: ["fluidPayAccount", user?.id],
698
+ queryFn: () => _fluid_app_fluid_pay_api_client.customersApi.fetchCustomerAccount(fluidPayClient, jwt),
699
+ enabled: !!jwt
700
+ });
701
+ const customerId = customerData?.customer?.id;
702
+ const countryIso = config.countryIso ?? "US";
703
+ const parts = currentSlug.split("/");
704
+ const subRoute = parts[1];
705
+ const detailToken = parts[2];
706
+ if ((subRoute === "orders" && !detailToken || subRoute === "subscriptions" && !detailToken) && isCustomerError && !isLoadingCustomer) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
707
+ ...divProps,
708
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountManageLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
709
+ className: "text-muted-foreground px-4 py-8 text-center text-sm",
710
+ children: "Unable to load account data. Please try again later."
711
+ }) })
712
+ });
713
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
714
+ ...divProps,
715
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountManageLayout, { children: subRoute === "orders" && detailToken ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountOrderDetailScreen, {
716
+ token: detailToken,
717
+ onToast: effectiveToast
718
+ }) : subRoute === "orders" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountOrdersScreen, {
719
+ customerId,
720
+ isLoadingCustomer
721
+ }) : subRoute === "subscriptions" && detailToken ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountSubscriptionDetailScreen, {
722
+ token: detailToken,
723
+ onToast: effectiveToast
724
+ }) : subRoute === "subscriptions" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountSubscriptionsScreen, {
725
+ customerId,
726
+ isLoadingCustomer
727
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AccountProfileScreen, {
728
+ onToast: effectiveToast,
729
+ countryIso
730
+ }) })
731
+ });
732
+ }
733
+ const accountScreenPropertySchema = {
734
+ widgetType: "AccountScreen",
735
+ displayName: "Account Screen",
736
+ tabsConfig: [{
737
+ id: "styling",
738
+ label: "Styling"
739
+ }],
740
+ fields: []
741
+ };
742
+ //#endregion
743
+ Object.defineProperty(exports, "AccountScreen", {
744
+ enumerable: true,
745
+ get: function() {
746
+ return AccountScreen;
747
+ }
748
+ });
749
+ Object.defineProperty(exports, "AccountScreen_exports", {
750
+ enumerable: true,
751
+ get: function() {
752
+ return AccountScreen_exports;
753
+ }
754
+ });
755
+ Object.defineProperty(exports, "AppNavigationProvider", {
756
+ enumerable: true,
757
+ get: function() {
758
+ return AppNavigationProvider;
759
+ }
760
+ });
761
+ Object.defineProperty(exports, "accountScreenPropertySchema", {
762
+ enumerable: true,
763
+ get: function() {
764
+ return accountScreenPropertySchema;
765
+ }
766
+ });
767
+ Object.defineProperty(exports, "useAppNavigation", {
768
+ enumerable: true,
769
+ get: function() {
770
+ return useAppNavigation;
771
+ }
772
+ });
773
+ Object.defineProperty(exports, "useFluidAuth", {
774
+ enumerable: true,
775
+ get: function() {
776
+ return useFluidAuth;
777
+ }
778
+ });
779
+
780
+ //# sourceMappingURL=AccountScreen-CbhrIAa4.cjs.map