@doswiftly/cli 0.1.17 → 0.1.19
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/README.md +23 -323
- package/dist/commands/check.js +1 -1
- package/dist/commands/check.js.map +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +43 -20
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/doctor.js +3 -3
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/init.js +4 -4
- package/dist/commands/sdk.js +5 -5
- package/dist/commands/sdk.js.map +1 -1
- package/dist/commands/template.js +4 -4
- package/dist/commands/template.js.map +1 -1
- package/dist/commands/types.js +5 -5
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/verify.js +2 -2
- package/dist/commands/verify.js.map +1 -1
- package/dist/lib/package-manager.d.ts +1 -1
- package/dist/lib/package-manager.js +1 -1
- package/package.json +1 -1
- package/templates/storefront-minimal/wrangler.toml +4 -0
- package/templates/storefront-nextjs/README.md +16 -12
- package/templates/storefront-nextjs/app/account/orders/page.tsx +2 -2
- package/templates/storefront-nextjs/app/account/page.tsx +2 -2
- package/templates/storefront-nextjs/app/auth/login/page.tsx +1 -1
- package/templates/storefront-nextjs/app/auth/register/page.tsx +1 -1
- package/templates/storefront-nextjs/app/cart/page.tsx +1 -1
- package/templates/storefront-nextjs/app/categories/[slug]/page.tsx +2 -2
- package/templates/storefront-nextjs/app/categories/page.tsx +1 -1
- package/templates/storefront-nextjs/app/collections/[slug]/page.tsx +1 -1
- package/templates/storefront-nextjs/app/collections/page.tsx +1 -1
- package/templates/storefront-nextjs/app/page.tsx +1 -1
- package/templates/storefront-nextjs/app/products/[slug]/page.tsx +1 -1
- package/templates/storefront-nextjs/app/products/page.tsx +2 -2
- package/templates/storefront-nextjs/app/search/page.tsx +1 -1
- package/templates/storefront-nextjs/components/auth/auth-guard.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/add-to-cart-button.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/cart-icon.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/currency-selector.tsx +2 -2
- package/templates/storefront-nextjs/components/commerce/product-filters.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/product-price.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/search-input.tsx +1 -1
- package/templates/storefront-nextjs/components/commerce/sort-select.tsx +1 -1
- package/templates/storefront-nextjs/components/providers.tsx +1 -1
- package/templates/storefront-nextjs/lib/currency.tsx +3 -3
- package/templates/storefront-nextjs/lib/format.ts +1 -1
- package/templates/storefront-nextjs/lib/graphql-queries.ts +3 -3
- package/templates/storefront-nextjs/package.dev.json +1 -1
- package/templates/storefront-nextjs/package.json +1 -1
- package/templates/storefront-nextjs/package.json.template +1 -1
- package/templates/storefront-nextjs/wrangler.toml +4 -0
- package/templates/storefront-nextjs-shadcn/.github/workflows/deploy.yml +47 -0
- package/templates/storefront-nextjs-shadcn/.github/workflows/preview.yml +47 -0
- package/templates/storefront-nextjs-shadcn/CLAUDE.md +148 -35
- package/templates/storefront-nextjs-shadcn/README.md +29 -162
- package/templates/storefront-nextjs-shadcn/app/account/addresses/page.tsx +98 -91
- package/templates/storefront-nextjs-shadcn/app/account/error.tsx +43 -0
- package/templates/storefront-nextjs-shadcn/app/account/loading.tsx +19 -0
- package/templates/storefront-nextjs-shadcn/app/account/loyalty/page.tsx +53 -162
- package/templates/storefront-nextjs-shadcn/app/account/orders/[id]/loading.tsx +60 -0
- package/templates/storefront-nextjs-shadcn/app/account/orders/[id]/page.tsx +36 -47
- package/templates/storefront-nextjs-shadcn/app/account/orders/page.tsx +46 -29
- package/templates/storefront-nextjs-shadcn/app/account/page.tsx +8 -5
- package/templates/storefront-nextjs-shadcn/app/account/settings/page.tsx +108 -71
- package/templates/storefront-nextjs-shadcn/app/api/auth/clear-token/route.ts +2 -86
- package/templates/storefront-nextjs-shadcn/app/api/auth/set-token/route.ts +2 -124
- package/templates/storefront-nextjs-shadcn/app/auth/forgot-password/page.tsx +10 -5
- package/templates/storefront-nextjs-shadcn/app/blog/[slug]/loading.tsx +17 -0
- package/templates/storefront-nextjs-shadcn/app/blog/[slug]/page.tsx +43 -2
- package/templates/storefront-nextjs-shadcn/app/blog/loading.tsx +19 -0
- package/templates/storefront-nextjs-shadcn/app/brands/page.tsx +2 -1
- package/templates/storefront-nextjs-shadcn/app/cart/loading.tsx +26 -0
- package/templates/storefront-nextjs-shadcn/app/cart/page.tsx +6 -3
- package/templates/storefront-nextjs-shadcn/app/categories/[slug]/category-products-client.tsx +56 -0
- package/templates/storefront-nextjs-shadcn/app/categories/[slug]/loading.tsx +32 -0
- package/templates/storefront-nextjs-shadcn/app/categories/[slug]/page.tsx +76 -59
- package/templates/storefront-nextjs-shadcn/app/categories/page.tsx +8 -4
- package/templates/storefront-nextjs-shadcn/app/checkout/error.tsx +43 -0
- package/templates/storefront-nextjs-shadcn/app/checkout/loading.tsx +31 -0
- package/templates/storefront-nextjs-shadcn/app/checkout/page.tsx +116 -79
- package/templates/storefront-nextjs-shadcn/app/collections/[handle]/loading.tsx +19 -0
- package/templates/storefront-nextjs-shadcn/app/collections/[handle]/page.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/app/collections/loading.tsx +18 -0
- package/templates/storefront-nextjs-shadcn/app/collections/page.tsx +7 -4
- package/templates/storefront-nextjs-shadcn/app/global-error.tsx +117 -0
- package/templates/storefront-nextjs-shadcn/app/globals.css +8 -0
- package/templates/storefront-nextjs-shadcn/app/layout.tsx +46 -11
- package/templates/storefront-nextjs-shadcn/app/products/[slug]/error.tsx +43 -0
- package/templates/storefront-nextjs-shadcn/app/products/[slug]/loading.tsx +29 -0
- package/templates/storefront-nextjs-shadcn/app/products/[slug]/page.tsx +6 -6
- package/templates/storefront-nextjs-shadcn/app/products/[slug]/product-client.tsx +15 -61
- package/templates/storefront-nextjs-shadcn/app/products/loading.tsx +32 -0
- package/templates/storefront-nextjs-shadcn/app/products/products-client.tsx +405 -151
- package/templates/storefront-nextjs-shadcn/app/search/loading.tsx +18 -0
- package/templates/storefront-nextjs-shadcn/app/wishlist/page.tsx +8 -5
- package/templates/storefront-nextjs-shadcn/codegen.ts +48 -31
- package/templates/storefront-nextjs-shadcn/components/account/customer-info.fragment.graphql +36 -0
- package/templates/storefront-nextjs-shadcn/components/account/order-details.tsx +3 -1
- package/templates/storefront-nextjs-shadcn/components/account/order-history.tsx +26 -24
- package/templates/storefront-nextjs-shadcn/components/account/order-summary.fragment.graphql +36 -0
- package/templates/storefront-nextjs-shadcn/components/auth/account-menu.tsx +9 -9
- package/templates/storefront-nextjs-shadcn/components/auth/login-form.tsx +11 -37
- package/templates/storefront-nextjs-shadcn/components/auth/register-form.tsx +37 -23
- package/templates/storefront-nextjs-shadcn/components/cart/cart-drawer.tsx +4 -3
- package/templates/storefront-nextjs-shadcn/components/cart/cart-icon.tsx +8 -5
- package/templates/storefront-nextjs-shadcn/components/cart/cart-item.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/cart/cart-line.fragment.graphql +53 -0
- package/templates/storefront-nextjs-shadcn/components/cart/cart-summary.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/cart/shipping-estimator.tsx +22 -7
- package/templates/storefront-nextjs-shadcn/components/commerce/currency-selector.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/commerce/product-actions.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/commerce/search-input.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/common/price-display.tsx +35 -11
- package/templates/storefront-nextjs-shadcn/components/discount/discount-breakdown.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/discount/discount-code-input.tsx +3 -3
- package/templates/storefront-nextjs-shadcn/components/filters/range-slider-filter.tsx +5 -5
- package/templates/storefront-nextjs-shadcn/components/gift-card/gift-card-input.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/home/category-grid.tsx +2 -1
- package/templates/storefront-nextjs-shadcn/components/home/collection-card.fragment.graphql +21 -0
- package/templates/storefront-nextjs-shadcn/components/home/featured-collections.tsx +2 -12
- package/templates/storefront-nextjs-shadcn/components/home/index.ts +0 -1
- package/templates/storefront-nextjs-shadcn/components/hydrated.tsx +24 -0
- package/templates/storefront-nextjs-shadcn/components/layout/breadcrumbs.tsx +4 -4
- package/templates/storefront-nextjs-shadcn/components/layout/category-node.fragment.graphql +22 -0
- package/templates/storefront-nextjs-shadcn/components/layout/currency-selector.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/layout/header.tsx +33 -23
- package/templates/storefront-nextjs-shadcn/components/loyalty/points-balance.tsx +2 -11
- package/templates/storefront-nextjs-shadcn/components/loyalty/points-history.tsx +8 -25
- package/templates/storefront-nextjs-shadcn/components/loyalty/referral-section.tsx +10 -19
- package/templates/storefront-nextjs-shadcn/components/loyalty/rewards-catalog.tsx +17 -41
- package/templates/storefront-nextjs-shadcn/components/loyalty/tier-progress.tsx +2 -29
- package/templates/storefront-nextjs-shadcn/components/order/index.ts +6 -1
- package/templates/storefront-nextjs-shadcn/components/product/b2b-price-display.tsx +3 -1
- package/templates/storefront-nextjs-shadcn/components/product/filter-active-pills.tsx +69 -0
- package/templates/storefront-nextjs-shadcn/components/product/filter-mobile-sheet.tsx +84 -0
- package/templates/storefront-nextjs-shadcn/components/product/filter-price-range.tsx +138 -0
- package/templates/storefront-nextjs-shadcn/components/product/index.ts +9 -2
- package/templates/storefront-nextjs-shadcn/components/product/product-card.fragment.graphql +49 -0
- package/templates/storefront-nextjs-shadcn/components/product/product-card.tsx +3 -31
- package/templates/storefront-nextjs-shadcn/components/product/product-detail.fragment.graphql +52 -0
- package/templates/storefront-nextjs-shadcn/components/product/product-filters.tsx +176 -123
- package/templates/storefront-nextjs-shadcn/components/product/product-grid.tsx +3 -5
- package/templates/storefront-nextjs-shadcn/components/product/product-image.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/product/product-price.tsx +2 -2
- package/templates/storefront-nextjs-shadcn/components/product/product-reviews.tsx +5 -4
- package/templates/storefront-nextjs-shadcn/components/product/product-sort.tsx +19 -7
- package/templates/storefront-nextjs-shadcn/components/product/product-variant-selector.tsx +8 -23
- package/templates/storefront-nextjs-shadcn/components/product/product-variant.fragment.graphql +51 -0
- package/templates/storefront-nextjs-shadcn/components/product/review-card.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/product/review-form.tsx +1 -7
- package/templates/storefront-nextjs-shadcn/components/product/savings-display.tsx +17 -2
- package/templates/storefront-nextjs-shadcn/components/product/similar-products.tsx +3 -2
- package/templates/storefront-nextjs-shadcn/components/providers/index.ts +1 -1
- package/templates/storefront-nextjs-shadcn/components/providers/stores-provider.tsx +30 -0
- package/templates/storefront-nextjs-shadcn/components/providers/theme-provider.tsx +1 -1
- package/templates/storefront-nextjs-shadcn/components/returns/index.ts +2 -2
- package/templates/storefront-nextjs-shadcn/components/returns/return-request-form.tsx +3 -2
- package/templates/storefront-nextjs-shadcn/components/search/search-results.tsx +3 -2
- package/templates/storefront-nextjs-shadcn/components/ui/form.tsx +174 -0
- package/templates/storefront-nextjs-shadcn/components/ui/index.ts +30 -2
- package/templates/storefront-nextjs-shadcn/components/ui/progress.tsx +40 -0
- package/templates/storefront-nextjs-shadcn/components/ui/sheet.tsx +107 -0
- package/templates/storefront-nextjs-shadcn/components/ui/slider.tsx +33 -0
- package/templates/storefront-nextjs-shadcn/components/ui/textarea.tsx +24 -0
- package/templates/storefront-nextjs-shadcn/components/wishlist/wishlist-icon.tsx +3 -1
- package/templates/storefront-nextjs-shadcn/generated/graphql.ts +12779 -0
- package/templates/storefront-nextjs-shadcn/graphql/custom.example.graphql +159 -0
- package/templates/storefront-nextjs-shadcn/hooks/index.ts +2 -0
- package/templates/storefront-nextjs-shadcn/hooks/use-auth-sync.ts +42 -0
- package/templates/storefront-nextjs-shadcn/hooks/use-auth.ts +17 -295
- package/templates/storefront-nextjs-shadcn/hooks/use-cart-actions.ts +51 -19
- package/templates/storefront-nextjs-shadcn/hooks/use-cart-sync.ts +13 -9
- package/templates/storefront-nextjs-shadcn/lib/auth/routes.ts +4 -17
- package/templates/storefront-nextjs-shadcn/lib/graphql/client.ts +22 -99
- package/templates/storefront-nextjs-shadcn/lib/graphql/config.ts +32 -0
- package/templates/storefront-nextjs-shadcn/lib/graphql/fragments.ts +34 -0
- package/templates/storefront-nextjs-shadcn/lib/graphql/hooks.ts +687 -632
- package/templates/storefront-nextjs-shadcn/lib/graphql/query-keys.ts +86 -0
- package/templates/storefront-nextjs-shadcn/lib/graphql/server.ts +131 -182
- package/templates/storefront-nextjs-shadcn/lib/graphql/types.ts +62 -0
- package/templates/storefront-nextjs-shadcn/lib/theme/theme-config.ts +0 -17
- package/templates/storefront-nextjs-shadcn/next-env.d.ts +6 -0
- package/templates/storefront-nextjs-shadcn/package.dev.json +1 -3
- package/templates/storefront-nextjs-shadcn/package.json +12 -13
- package/templates/storefront-nextjs-shadcn/package.json.template +6 -7
- package/templates/storefront-nextjs-shadcn/proxy.ts +3 -4
- package/templates/storefront-nextjs-shadcn/stores/cart-store.ts +41 -39
- package/templates/storefront-nextjs-shadcn/stores/checkout-store.ts +64 -75
- package/templates/storefront-nextjs-shadcn/stores/wishlist-store.ts +178 -177
- package/templates/storefront-nextjs-shadcn/tsconfig.json +23 -5
- package/templates/storefront-nextjs-shadcn/wrangler.toml +4 -0
- package/templates/storefront-nextjs-shadcn/CART_INTEGRATION.md +0 -282
- package/templates/storefront-nextjs-shadcn/GRAPHQL_DOCUMENT_NAMES.md +0 -190
- package/templates/storefront-nextjs-shadcn/GRAPHQL_ERROR_HANDLING.md +0 -263
- package/templates/storefront-nextjs-shadcn/GRAPHQL_FIXES_SUMMARY.md +0 -135
- package/templates/storefront-nextjs-shadcn/GRAPHQL_INTEGRATION_COMPLETE.md +0 -142
- package/templates/storefront-nextjs-shadcn/INTEGRATION_CHECKLIST.md +0 -448
- package/templates/storefront-nextjs-shadcn/PRODUCT_DETAIL_PAGE_IMPLEMENTATION.md +0 -307
- package/templates/storefront-nextjs-shadcn/THEME_CUSTOMIZATION.md +0 -245
- package/templates/storefront-nextjs-shadcn/components/providers/currency-provider.tsx +0 -103
- package/templates/storefront-nextjs-shadcn/graphql/collections.example.ts +0 -168
- package/templates/storefront-nextjs-shadcn/graphql/products.example.ts +0 -160
- package/templates/storefront-nextjs-shadcn/lib/auth/cookies.ts +0 -220
- package/templates/storefront-nextjs-shadcn/lib/config.ts +0 -46
- package/templates/storefront-nextjs-shadcn/lib/currency/IMPLEMENTATION_SUMMARY.md +0 -254
- package/templates/storefront-nextjs-shadcn/lib/currency/README.md +0 -464
- package/templates/storefront-nextjs-shadcn/lib/currency/cookie-manager.test.ts +0 -328
- package/templates/storefront-nextjs-shadcn/lib/currency/cookie-manager.ts +0 -295
- package/templates/storefront-nextjs-shadcn/lib/currency/index.ts +0 -27
- package/templates/storefront-nextjs-shadcn/lib/format.ts +0 -226
- package/templates/storefront-nextjs-shadcn/lib/hooks.ts +0 -30
- package/templates/storefront-nextjs-shadcn/stores/auth-store.ts +0 -66
- package/templates/storefront-nextjs-shadcn/stores/currency-store.ts +0 -103
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { NextResponse } from "next/server";
|
|
2
2
|
import type { NextRequest } from "next/server";
|
|
3
|
+
import { AUTH_COOKIE_NAME, matchesRoute } from "@doswiftly/storefront-sdk";
|
|
3
4
|
import {
|
|
4
5
|
protectedRoutes,
|
|
5
6
|
guestOnlyRoutes,
|
|
6
|
-
AUTH_COOKIE_NAME,
|
|
7
7
|
redirects,
|
|
8
|
-
matchesRoute,
|
|
9
8
|
} from "@/lib/auth/routes";
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
|
-
* Authentication Proxy Function (Next.js
|
|
11
|
+
* Authentication Proxy Function (Next.js 16+)
|
|
13
12
|
*
|
|
14
13
|
* Security Model (3 layers):
|
|
15
14
|
* 1. Proxy function (this file) - Fast redirect based on cookie existence (UX layer)
|
|
@@ -75,6 +74,6 @@ export const config = {
|
|
|
75
74
|
* - public folder files (images, etc.)
|
|
76
75
|
* - API routes (handled separately)
|
|
77
76
|
*/
|
|
78
|
-
"/((?!_next/static|_next/image|favicon.ico
|
|
77
|
+
"/((?!_next/static|_next/image|favicon.ico|.*\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
|
|
79
78
|
],
|
|
80
79
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStore } from 'zustand/vanilla';
|
|
2
2
|
import { persist } from 'zustand/middleware';
|
|
3
|
+
import { createStoreContext } from '@doswiftly/storefront-sdk/react';
|
|
3
4
|
|
|
4
5
|
export interface CartState {
|
|
5
6
|
// State
|
|
6
7
|
cartId: string | null;
|
|
7
8
|
isOpen: boolean;
|
|
8
|
-
isHydrated: boolean;
|
|
9
9
|
|
|
10
10
|
// Actions
|
|
11
11
|
setCartId: (cartId: string | null) => void;
|
|
@@ -15,42 +15,44 @@ export interface CartState {
|
|
|
15
15
|
toggleCart: () => void;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
18
|
+
export function createCartStore() {
|
|
19
|
+
return createStore<CartState>()(
|
|
20
|
+
persist(
|
|
21
|
+
(set) => ({
|
|
22
|
+
cartId: null,
|
|
23
|
+
isOpen: false,
|
|
24
|
+
|
|
25
|
+
setCartId: (cartId: string | null) => {
|
|
26
|
+
set({ cartId });
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
clearCart: () => {
|
|
30
|
+
set({ cartId: null, isOpen: false });
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
openCart: () => {
|
|
34
|
+
set({ isOpen: true });
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
closeCart: () => {
|
|
38
|
+
set({ isOpen: false });
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
toggleCart: () => {
|
|
42
|
+
set((state) => ({ isOpen: !state.isOpen }));
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
{
|
|
46
|
+
name: 'cart-storage',
|
|
47
|
+
// Persist only cartId — server is the source of truth for items
|
|
48
|
+
partialize: (state) => ({ cartId: state.cartId }),
|
|
39
49
|
},
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
40
53
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
name: 'cart-storage',
|
|
47
|
-
// Persist only cartId — server is the source of truth for items
|
|
48
|
-
partialize: (state) => ({ cartId: state.cartId }),
|
|
49
|
-
onRehydrateStorage: () => (state) => {
|
|
50
|
-
if (state) {
|
|
51
|
-
state.isHydrated = true;
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
}
|
|
55
|
-
)
|
|
56
|
-
);
|
|
54
|
+
export const {
|
|
55
|
+
Provider: CartProvider,
|
|
56
|
+
useStore: useCartStore,
|
|
57
|
+
useApi: useCartStoreApi,
|
|
58
|
+
} = createStoreContext<CartState>('CartStore');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createStore } from 'zustand/vanilla';
|
|
2
2
|
import { persist } from 'zustand/middleware';
|
|
3
|
+
import { createStoreContext } from '@doswiftly/storefront-sdk/react';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Address form state
|
|
@@ -19,7 +20,6 @@ export interface AddressForm {
|
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Checkout state interface
|
|
22
|
-
* Requirements: 22.4
|
|
23
23
|
*/
|
|
24
24
|
export interface CheckoutState {
|
|
25
25
|
// Checkout ID from backend
|
|
@@ -48,9 +48,6 @@ export interface CheckoutState {
|
|
|
48
48
|
acceptTerms: boolean;
|
|
49
49
|
acceptMarketing: boolean;
|
|
50
50
|
|
|
51
|
-
// Hydration state
|
|
52
|
-
isHydrated: boolean;
|
|
53
|
-
|
|
54
51
|
// Actions
|
|
55
52
|
setCheckoutId: (id: string | null) => void;
|
|
56
53
|
setEmail: (email: string) => void;
|
|
@@ -94,91 +91,83 @@ const initialState = {
|
|
|
94
91
|
appliedDiscountCodes: [],
|
|
95
92
|
acceptTerms: false,
|
|
96
93
|
acceptMarketing: false,
|
|
97
|
-
isHydrated: false,
|
|
98
94
|
};
|
|
99
95
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
* Requirements: 22.4
|
|
107
|
-
*/
|
|
108
|
-
export const useCheckoutStore = create<CheckoutState>()(
|
|
109
|
-
persist(
|
|
110
|
-
(set) => ({
|
|
111
|
-
...initialState,
|
|
96
|
+
export function createCheckoutStore() {
|
|
97
|
+
return createStore<CheckoutState>()(
|
|
98
|
+
persist(
|
|
99
|
+
(set) => ({
|
|
100
|
+
...initialState,
|
|
112
101
|
|
|
113
|
-
|
|
102
|
+
setCheckoutId: (id) => set({ checkoutId: id }),
|
|
114
103
|
|
|
115
|
-
|
|
104
|
+
setEmail: (email) => set({ email }),
|
|
116
105
|
|
|
117
|
-
|
|
106
|
+
setPhone: (phone) => set({ phone }),
|
|
118
107
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
108
|
+
setShippingAddress: (address) =>
|
|
109
|
+
set((state) => ({
|
|
110
|
+
shippingAddress: { ...state.shippingAddress, ...address },
|
|
111
|
+
})),
|
|
123
112
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
113
|
+
setBillingAddress: (address) =>
|
|
114
|
+
set((state) => ({
|
|
115
|
+
billingAddress: { ...state.billingAddress, ...address },
|
|
116
|
+
})),
|
|
128
117
|
|
|
129
|
-
|
|
118
|
+
setSameAsBilling: (same) => set({ sameAsBilling: same }),
|
|
130
119
|
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
setSelectedShippingRateHandle: (handle) =>
|
|
121
|
+
set({ selectedShippingRateHandle: handle }),
|
|
133
122
|
|
|
134
|
-
|
|
135
|
-
|
|
123
|
+
setSelectedPaymentMethodId: (id) =>
|
|
124
|
+
set({ selectedPaymentMethodId: id }),
|
|
136
125
|
|
|
137
|
-
|
|
126
|
+
setDiscountCode: (code) => set({ discountCode: code }),
|
|
138
127
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
128
|
+
addAppliedDiscountCode: (code) =>
|
|
129
|
+
set((state) => ({
|
|
130
|
+
appliedDiscountCodes: [...state.appliedDiscountCodes, code],
|
|
131
|
+
discountCode: '',
|
|
132
|
+
})),
|
|
144
133
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
134
|
+
removeAppliedDiscountCode: (code) =>
|
|
135
|
+
set((state) => ({
|
|
136
|
+
appliedDiscountCodes: state.appliedDiscountCodes.filter(
|
|
137
|
+
(c) => c !== code,
|
|
138
|
+
),
|
|
139
|
+
})),
|
|
151
140
|
|
|
152
|
-
|
|
141
|
+
setAcceptTerms: (accept) => set({ acceptTerms: accept }),
|
|
153
142
|
|
|
154
|
-
|
|
143
|
+
setAcceptMarketing: (accept) => set({ acceptMarketing: accept }),
|
|
155
144
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}),
|
|
161
|
-
}),
|
|
162
|
-
{
|
|
163
|
-
name: 'checkout-storage',
|
|
164
|
-
// Persist only essential checkout state
|
|
165
|
-
partialize: (state) => ({
|
|
166
|
-
checkoutId: state.checkoutId,
|
|
167
|
-
email: state.email,
|
|
168
|
-
phone: state.phone,
|
|
169
|
-
shippingAddress: state.shippingAddress,
|
|
170
|
-
billingAddress: state.billingAddress,
|
|
171
|
-
sameAsBilling: state.sameAsBilling,
|
|
172
|
-
selectedShippingRateHandle: state.selectedShippingRateHandle,
|
|
173
|
-
selectedPaymentMethodId: state.selectedPaymentMethodId,
|
|
174
|
-
appliedDiscountCodes: state.appliedDiscountCodes,
|
|
175
|
-
acceptMarketing: state.acceptMarketing,
|
|
145
|
+
resetCheckout: () =>
|
|
146
|
+
set({
|
|
147
|
+
...initialState,
|
|
148
|
+
}),
|
|
176
149
|
}),
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
150
|
+
{
|
|
151
|
+
name: 'checkout-storage',
|
|
152
|
+
partialize: (state) => ({
|
|
153
|
+
checkoutId: state.checkoutId,
|
|
154
|
+
email: state.email,
|
|
155
|
+
phone: state.phone,
|
|
156
|
+
shippingAddress: state.shippingAddress,
|
|
157
|
+
billingAddress: state.billingAddress,
|
|
158
|
+
sameAsBilling: state.sameAsBilling,
|
|
159
|
+
selectedShippingRateHandle: state.selectedShippingRateHandle,
|
|
160
|
+
selectedPaymentMethodId: state.selectedPaymentMethodId,
|
|
161
|
+
appliedDiscountCodes: state.appliedDiscountCodes,
|
|
162
|
+
acceptMarketing: state.acceptMarketing,
|
|
163
|
+
}),
|
|
181
164
|
},
|
|
182
|
-
|
|
183
|
-
)
|
|
184
|
-
|
|
165
|
+
),
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const {
|
|
170
|
+
Provider: CheckoutProvider,
|
|
171
|
+
useStore: useCheckoutStore,
|
|
172
|
+
useApi: useCheckoutStoreApi,
|
|
173
|
+
} = createStoreContext<CheckoutState>('CheckoutStore');
|