@shophost/react 2.0.39 → 2.0.40
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/admin-client.cjs +1 -1
- package/admin-client.js +1535 -1529
- package/package.json +3 -3
- package/react.css +1 -1
- package/storefront/exports.d.ts +1 -0
- package/storefront/hooks/useModifierSelection.d.ts +5 -10
- package/storefront/providers/cart-provider.d.ts +5 -2
- package/storefront/providers/modifiers-provider.d.ts +2 -1
- package/storefront/reducers/cart.reducer.d.ts +2 -4
- package/storefront/types/cart.types.d.ts +41 -7
- package/storefront/utils/cart.util.d.ts +10 -11
package/storefront/exports.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { useModifierSelection } from './hooks/useModifierSelection';
|
|
|
16
16
|
export { useLocalization } from './hooks/useLocalization';
|
|
17
17
|
export { calculateCartTotal, formatPrice, getFormattedModifiers, findCartItem, productRequiresModifiers, } from './utils/cart.util';
|
|
18
18
|
export { mockProducts } from './mock/products';
|
|
19
|
+
export type { AddToCartInput, AddToCartResult, CartModifierGroupInput, RemoveCartItemInput, UpdateCartItemInput, } from './types/cart.types';
|
|
19
20
|
export type { CartItem } from './schemas/cart.schema';
|
|
20
21
|
export * from './components/modifiers';
|
|
21
22
|
export * from './hooks/useModifierSelection';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
modifierIds: string[];
|
|
4
|
-
}
|
|
5
|
-
export declare const useModifierSelection: (product: any) => {
|
|
1
|
+
import { CartProductModifierGroup, ModifierSelection } from '../types/cart.types';
|
|
2
|
+
export declare const useModifierSelection: (modifierGroups?: CartProductModifierGroup[]) => {
|
|
6
3
|
selections: ModifierSelection[];
|
|
7
|
-
initializeSelections: () => void;
|
|
8
4
|
toggleModifier: (groupId: string, modifierId: string) => void;
|
|
9
5
|
selectModifier: (groupId: string, modifierId: string) => void;
|
|
10
6
|
isModifierSelected: (groupId: string, modifierId: string) => boolean;
|
|
@@ -12,10 +8,9 @@ export declare const useModifierSelection: (product: any) => {
|
|
|
12
8
|
validationError: string | null;
|
|
13
9
|
getCartModifierGroups: () => {
|
|
14
10
|
id: string;
|
|
15
|
-
modifiers: {
|
|
11
|
+
modifiers: Array<{
|
|
16
12
|
id: string;
|
|
17
|
-
quantity
|
|
18
|
-
}
|
|
13
|
+
quantity?: number;
|
|
14
|
+
}>;
|
|
19
15
|
}[];
|
|
20
16
|
};
|
|
21
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CartItem, Locale, LocalizedProduct, Product, ShippingMethod } from '../../../../client/src/index.ts';
|
|
2
2
|
import { default as React } from 'react';
|
|
3
|
-
import { CartContextType } from '../types/cart.types';
|
|
3
|
+
import { AddToCartInput, AddToCartResult, CartContextType, RemoveCartItemInput, UpdateCartItemInput } from '../types/cart.types';
|
|
4
4
|
interface CartProviderProps {
|
|
5
5
|
organizationId: string;
|
|
6
6
|
children: React.ReactNode;
|
|
@@ -14,7 +14,10 @@ export declare const useCart: () => {
|
|
|
14
14
|
shipping: number | undefined;
|
|
15
15
|
loading: boolean;
|
|
16
16
|
formattedCartItems: import('../types/cart.types').FormattedCartItem[];
|
|
17
|
-
|
|
17
|
+
add: ({ productId, quantity, modifierGroups, product, onAdded, }: AddToCartInput) => Promise<AddToCartResult>;
|
|
18
|
+
update: ({ productId, quantity, modifierGroups }: UpdateCartItemInput) => void;
|
|
19
|
+
remove: ({ productId, modifierGroups }: RemoveCartItemInput) => void;
|
|
20
|
+
addProductToCart: (product: Product | LocalizedProduct) => Promise<AddToCartResult>;
|
|
18
21
|
clearCart: () => void;
|
|
19
22
|
itemCount: number;
|
|
20
23
|
rawCart: CartItem[];
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
+
import { CartProductInput } from '../types/cart.types';
|
|
2
3
|
interface ModifiersContextType {
|
|
3
4
|
isOpen: boolean;
|
|
4
5
|
onClose: () => void;
|
|
5
|
-
product:
|
|
6
|
+
product: CartProductInput | null;
|
|
6
7
|
productName: string;
|
|
7
8
|
hasModifiers: boolean;
|
|
8
9
|
quantity: number;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { CartItem } from '../../../../client/src/index.ts';
|
|
2
|
-
import { CartAction } from '../types/cart.types';
|
|
2
|
+
import { CartAction, ModifierModalState } from '../types/cart.types';
|
|
3
3
|
export interface CartState {
|
|
4
4
|
items: CartItem[];
|
|
5
5
|
isInitialized: boolean;
|
|
6
|
-
|
|
7
|
-
selectedProduct: any | null;
|
|
8
|
-
onModalAddToCart: (() => void) | undefined;
|
|
6
|
+
modifierModal: ModifierModalState | null;
|
|
9
7
|
totalAmount: number;
|
|
10
8
|
itemCount: number;
|
|
11
9
|
removedItemsAlert?: boolean;
|
|
@@ -1,7 +1,39 @@
|
|
|
1
|
-
import { CartItem, LocalizedProduct, PaymentMethodDetails, ShippingMethod, UploadedFile } from '../../../../client/src/index.ts';
|
|
1
|
+
import { CartItem, LocalizedModifierGroup, LocalizedProduct, ModifierGroup, PaymentMethodDetails, Product, ShippingMethod, UploadedFile } from '../../../../client/src/index.ts';
|
|
2
2
|
import { default as React } from 'react';
|
|
3
|
+
export type CartModifierGroupInput = NonNullable<CartItem["modifierGroups"]>;
|
|
4
|
+
export type CartProductInput = Product | LocalizedProduct;
|
|
5
|
+
export type CartProductModifierGroup = ModifierGroup | LocalizedModifierGroup;
|
|
6
|
+
export interface ModifierModalState {
|
|
7
|
+
product: CartProductInput;
|
|
8
|
+
quantity: number;
|
|
9
|
+
onAdded?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface ModifierSelection {
|
|
12
|
+
groupId: string;
|
|
13
|
+
modifierIds: string[];
|
|
14
|
+
}
|
|
15
|
+
export interface AddToCartInput {
|
|
16
|
+
productId: string;
|
|
17
|
+
quantity?: number;
|
|
18
|
+
modifierGroups?: CartModifierGroupInput;
|
|
19
|
+
product?: CartProductInput;
|
|
20
|
+
onAdded?: () => void;
|
|
21
|
+
}
|
|
22
|
+
export interface UpdateCartItemInput {
|
|
23
|
+
productId: string;
|
|
24
|
+
quantity: number;
|
|
25
|
+
modifierGroups?: CartModifierGroupInput;
|
|
26
|
+
}
|
|
27
|
+
export interface RemoveCartItemInput {
|
|
28
|
+
productId: string;
|
|
29
|
+
modifierGroups?: CartModifierGroupInput;
|
|
30
|
+
}
|
|
31
|
+
export interface AddToCartResult {
|
|
32
|
+
openedModifiers: boolean;
|
|
33
|
+
}
|
|
3
34
|
export interface CartContextType {
|
|
4
35
|
locale: string;
|
|
36
|
+
organizationId: string;
|
|
5
37
|
items: CartItem[];
|
|
6
38
|
total: number;
|
|
7
39
|
shipping?: number;
|
|
@@ -25,10 +57,15 @@ export interface CartContextType {
|
|
|
25
57
|
itemCount: number;
|
|
26
58
|
totalAmount: number;
|
|
27
59
|
onCheckoutClick: () => void;
|
|
28
|
-
openModifiersModal: (product:
|
|
60
|
+
openModifiersModal: (product: CartProductInput, options?: {
|
|
61
|
+
onAdded?: () => void;
|
|
62
|
+
quantity?: number;
|
|
63
|
+
}) => void;
|
|
29
64
|
closeModifiersModal: () => void;
|
|
65
|
+
modifierModal: ModifierModalState | null;
|
|
30
66
|
isModifiersModalOpen: boolean;
|
|
31
|
-
selectedProduct:
|
|
67
|
+
selectedProduct: CartProductInput | null;
|
|
68
|
+
pendingModalQuantity: number;
|
|
32
69
|
onModalAddToCart: (() => void) | undefined;
|
|
33
70
|
products: Record<string, LocalizedProduct>;
|
|
34
71
|
isProductsLoading: boolean;
|
|
@@ -84,10 +121,7 @@ export type CartAction = {
|
|
|
84
121
|
type: "CLEAR_CART";
|
|
85
122
|
} | {
|
|
86
123
|
type: "OPEN_MODIFIERS_MODAL";
|
|
87
|
-
payload:
|
|
88
|
-
product: any;
|
|
89
|
-
onAddToCart?: () => void;
|
|
90
|
-
};
|
|
124
|
+
payload: ModifierModalState;
|
|
91
125
|
} | {
|
|
92
126
|
type: "CLOSE_MODIFIERS_MODAL";
|
|
93
127
|
} | {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CartItem } from '../../../../client/src/index.ts';
|
|
2
|
+
import { CartModifierGroupInput, CartProductModifierGroup, ModifierSelection } from '../types/cart.types';
|
|
2
3
|
/**
|
|
3
4
|
* Calculate the total price of a cart based on product data
|
|
4
5
|
*/
|
|
@@ -14,13 +15,14 @@ export declare const getFormattedModifiers: (item: CartItem, getProductDetails:
|
|
|
14
15
|
/**
|
|
15
16
|
* Find a cart item by product ID and optional modifier groups
|
|
16
17
|
*/
|
|
17
|
-
export declare const findCartItem: (items: CartItem[], productId: string, modifierGroups?:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
export declare const findCartItem: (items: CartItem[], productId: string, modifierGroups?: CartModifierGroupInput) => CartItem | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Check whether a cart item matches a product and modifier selection
|
|
21
|
+
*/
|
|
22
|
+
export declare const matchesCartItem: (item: CartItem, target: {
|
|
23
|
+
productId: string;
|
|
24
|
+
modifierGroups?: CartModifierGroupInput;
|
|
25
|
+
}) => boolean;
|
|
24
26
|
/**
|
|
25
27
|
* Helper function to compare modifier groups
|
|
26
28
|
*/
|
|
@@ -44,10 +46,7 @@ export declare const productRequiresModifiers: (product: any) => boolean;
|
|
|
44
46
|
/**
|
|
45
47
|
* Validate if selected modifiers meet the requirements
|
|
46
48
|
*/
|
|
47
|
-
export declare const validateModifierSelections: (
|
|
48
|
-
groupId: string;
|
|
49
|
-
modifierIds: string[];
|
|
50
|
-
}[]) => {
|
|
49
|
+
export declare const validateModifierSelections: (modifierGroups: CartProductModifierGroup[], selectedModifiers: ModifierSelection[]) => {
|
|
51
50
|
valid: boolean;
|
|
52
51
|
message?: string;
|
|
53
52
|
};
|