@rebuy/rebuy-hydrogen 3.0.0-beta.2 → 3.0.0-beta.4
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/components/AddToCartBtn/AddToCartBtn.d.ts.map +1 -1
- package/dist/components/AddToCartBtn/HydrogenAddToCartBtn.d.ts.map +1 -1
- package/dist/components/AddToCartBtn/HydrogenReactAddToCartBtn.d.ts.map +1 -1
- package/dist/components/ProductCard/ProductCard.d.ts.map +1 -1
- package/dist/components/ProductPrice/ProductPrice.d.ts +1 -1
- package/dist/components/ProductPrice/ProductPrice.d.ts.map +1 -1
- package/dist/components/VariantSelect/VariantSelect.d.ts +1 -1
- package/dist/components/VariantSelect/VariantSelect.d.ts.map +1 -1
- package/dist/hooks/titleLevel.d.ts.map +1 -1
- package/dist/index.css +88 -88
- package/dist/index.css.map +4 -4
- package/dist/index.js +187 -401
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +187 -410
- package/dist/index.mjs.map +4 -4
- package/dist/providers/RebuyHydrogenContextProvider.d.ts +1 -1
- package/dist/providers/RebuyHydrogenContextProvider.d.ts.map +1 -1
- package/dist/providers/RebuyHydrogenReactContextProvider.d.ts.map +1 -1
- package/dist/providers/types.d.ts +1 -1
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/types/rebuyCustom.d.ts.map +1 -1
- package/dist/types/shopify.d.ts.map +1 -1
- package/dist/types/widgets.d.ts +1 -1
- package/dist/types/widgets.d.ts.map +1 -1
- package/dist/utils/convertToRebuyProduct.d.ts.map +1 -1
- package/dist/utils/createContextParameters.d.ts.map +1 -1
- package/dist/utils/getEncodedAttributes.d.ts.map +1 -1
- package/dist/utils/getRebuyConfig.d.ts.map +1 -1
- package/dist/widgetContainer/RebuyWidgetContainer.d.ts +1 -1
- package/dist/widgetContainer/RebuyWidgetContainer.d.ts.map +1 -1
- package/dist/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.d.ts.map +1 -1
- package/dist/widgets/RebuyDynamicBundleProducts/BundleImages.d.ts.map +1 -1
- package/dist/widgets/RebuyDynamicBundleProducts/BundlePrice.d.ts.map +1 -1
- package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts +1 -1
- package/dist/widgets/RebuyDynamicBundleProducts/BundleSelection.d.ts.map +1 -1
- package/dist/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.d.ts.map +1 -1
- package/dist/widgets/RebuyDynamicBundleProducts/Select.d.ts.map +1 -1
- package/dist/widgets/RebuyProductAddOns/RebuyProductAddOnCard.d.ts.map +1 -1
- package/dist/widgets/RebuyProductAddOns/RebuyProductAddOns.d.ts.map +1 -1
- package/dist/widgets/RebuyProductAddOns/types.d.ts.map +1 -1
- package/dist/widgets/RebuyProductRecommendations/RebuyProductRecommendations.d.ts.map +1 -1
- package/package.json +66 -35
- package/src/components/AddToCartBtn/AddToCartBtn.tsx +0 -45
- package/src/components/AddToCartBtn/HydrogenAddToCartBtn.tsx +0 -43
- package/src/components/AddToCartBtn/HydrogenReactAddToCartBtn.tsx +0 -35
- package/src/components/AddToCartBtn/index.ts +0 -1
- package/src/components/AddToCartBtn/types.ts +0 -27
- package/src/components/ProductCard/ProductCard.tsx +0 -70
- package/src/components/ProductCard/index.ts +0 -1
- package/src/components/ProductCard/types.ts +0 -10
- package/src/components/ProductPrice/ProductPrice.tsx +0 -49
- package/src/components/ProductPrice/index.ts +0 -1
- package/src/components/Title/Title.tsx +0 -19
- package/src/components/Title/index.ts +0 -1
- package/src/components/Title/types.ts +0 -7
- package/src/components/VariantSelect/VariantSelect.tsx +0 -45
- package/src/components/VariantSelect/index.ts +0 -1
- package/src/components/VariantSelect/types.ts +0 -6
- package/src/context/RebuyContext.tsx +0 -9
- package/src/hooks/titleLevel.tsx +0 -42
- package/src/index.ts +0 -7
- package/src/providers/RebuyHydrogenContextProvider.tsx +0 -112
- package/src/providers/RebuyHydrogenReactContextProvider.tsx +0 -192
- package/src/providers/types.ts +0 -58
- package/src/queries/cart.queries.ts +0 -467
- package/src/types/common.ts +0 -8
- package/src/types/css.d.ts +0 -11
- package/src/types/env.d.ts +0 -12
- package/src/types/rebuy.d.ts +0 -31
- package/src/types/rebuyCustom.ts +0 -263
- package/src/types/rebuySmartCart.ts +0 -188
- package/src/types/shopify.ts +0 -142
- package/src/types/widgets.ts +0 -29
- package/src/utils/convertToRebuyProduct.tsx +0 -319
- package/src/utils/createContextParameters.ts +0 -142
- package/src/utils/getEncodedAttributes.ts +0 -11
- package/src/utils/getRebuyConfig.ts +0 -31
- package/src/widgetContainer/RebuyWidgetContainer.tsx +0 -183
- package/src/widgets/RebuyCompleteTheLook/RebuyCompleteTheLook.tsx +0 -50
- package/src/widgets/RebuyCompleteTheLook/index.ts +0 -1
- package/src/widgets/RebuyCompleteTheLook/types.ts +0 -5
- package/src/widgets/RebuyDynamicBundleProducts/BundleImages.tsx +0 -62
- package/src/widgets/RebuyDynamicBundleProducts/BundlePrice.tsx +0 -93
- package/src/widgets/RebuyDynamicBundleProducts/BundleSelection.tsx +0 -65
- package/src/widgets/RebuyDynamicBundleProducts/RebuyDynamicBundleProducts.tsx +0 -118
- package/src/widgets/RebuyDynamicBundleProducts/Select.tsx +0 -41
- package/src/widgets/RebuyDynamicBundleProducts/index.ts +0 -1
- package/src/widgets/RebuyDynamicBundleProducts/types.ts +0 -23
- package/src/widgets/RebuyProductAddOns/RebuyProductAddOnCard.tsx +0 -66
- package/src/widgets/RebuyProductAddOns/RebuyProductAddOns.tsx +0 -218
- package/src/widgets/RebuyProductAddOns/index.ts +0 -1
- package/src/widgets/RebuyProductAddOns/types.ts +0 -24
- package/src/widgets/RebuyProductRecommendations/RebuyProductRecommendations.tsx +0 -50
- package/src/widgets/RebuyProductRecommendations/index.ts +0 -1
- package/src/widgets/RebuyProductRecommendations/types.ts +0 -5
@@ -1,49 +0,0 @@
|
|
1
|
-
import { Money } from '@shopify/hydrogen';
|
2
|
-
|
3
|
-
import styles from './ProductPrice.module.css';
|
4
|
-
|
5
|
-
import type { MoneyV2 } from '@shopify/hydrogen-react/storefront-api-types';
|
6
|
-
import type { RebuyProductVariant } from '~/types/rebuyCustom';
|
7
|
-
|
8
|
-
export const RebuyProductPrice = ({
|
9
|
-
selectedVariant,
|
10
|
-
}: {
|
11
|
-
selectedVariant: RebuyProductVariant;
|
12
|
-
}) => {
|
13
|
-
if (!selectedVariant) return null;
|
14
|
-
const { compareAtPriceV2: compareAtPrice, priceV2: price } =
|
15
|
-
selectedVariant;
|
16
|
-
|
17
|
-
const isDiscounted = (
|
18
|
-
price: MoneyV2 | null,
|
19
|
-
compareAtPrice: MoneyV2 | null
|
20
|
-
) => Number(compareAtPrice?.amount) > Number(price?.amount);
|
21
|
-
|
22
|
-
const CompareAtPrice = ({
|
23
|
-
data: compareAtPrice,
|
24
|
-
}: {
|
25
|
-
data: MoneyV2 | null;
|
26
|
-
}) => {
|
27
|
-
return (
|
28
|
-
compareAtPrice && (
|
29
|
-
<Money
|
30
|
-
as="span"
|
31
|
-
className={styles.compareAtPrice}
|
32
|
-
data={compareAtPrice}
|
33
|
-
withoutTrailingZeros
|
34
|
-
/>
|
35
|
-
)
|
36
|
-
);
|
37
|
-
};
|
38
|
-
|
39
|
-
return (
|
40
|
-
price && (
|
41
|
-
<div className={styles.priceContainer}>
|
42
|
-
<Money data={price} withoutTrailingZeros />
|
43
|
-
{compareAtPrice && isDiscounted(price, compareAtPrice) && (
|
44
|
-
<CompareAtPrice data={compareAtPrice} />
|
45
|
-
)}
|
46
|
-
</div>
|
47
|
-
)
|
48
|
-
);
|
49
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './ProductPrice';
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import type { TitleProps } from '~/components/Title/types';
|
2
|
-
|
3
|
-
export const Title = ({ level, style, text }: TitleProps) => {
|
4
|
-
switch (level) {
|
5
|
-
case 'h1':
|
6
|
-
return <h1 style={style}>{text}</h1>;
|
7
|
-
default:
|
8
|
-
case 'h2':
|
9
|
-
return <h2 style={style}>{text}</h2>;
|
10
|
-
case 'h3':
|
11
|
-
return <h3 style={style}>{text}</h3>;
|
12
|
-
case 'h4':
|
13
|
-
return <h4 style={style}>{text}</h4>;
|
14
|
-
case 'h5':
|
15
|
-
return <h5 style={style}>{text}</h5>;
|
16
|
-
case 'h6':
|
17
|
-
return <h6 style={style}>{text}</h6>;
|
18
|
-
}
|
19
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './Title';
|
@@ -1,45 +0,0 @@
|
|
1
|
-
import styles from './VariantSelect.module.css';
|
2
|
-
|
3
|
-
import type { VariantSelectProps } from '~/components/VariantSelect/types';
|
4
|
-
import type { RebuyProduct } from '~/types/rebuyCustom';
|
5
|
-
|
6
|
-
export const VariantSelect = ({
|
7
|
-
handleSelectedVariant,
|
8
|
-
product,
|
9
|
-
}: VariantSelectProps) => {
|
10
|
-
const getOptionsLabel = (product: RebuyProduct) => {
|
11
|
-
const options = product.variants.nodes[0].selectedOptions;
|
12
|
-
const optionsFromKeys = options ? Object.keys(options[0]) : [];
|
13
|
-
const optionsFromValues = options
|
14
|
-
? options.map((option) => option.name)
|
15
|
-
: [];
|
16
|
-
const useValues = optionsFromKeys.every((key) =>
|
17
|
-
['name', 'value'].includes(key)
|
18
|
-
);
|
19
|
-
|
20
|
-
// Return delimited label for available option(s) e.g. Color / Size, Scent, etc
|
21
|
-
return (useValues ? optionsFromValues : optionsFromKeys).join(' / ');
|
22
|
-
};
|
23
|
-
|
24
|
-
return (
|
25
|
-
product?.variants.nodes.length > 1 && (
|
26
|
-
<div>
|
27
|
-
<select
|
28
|
-
aria-label="select variant"
|
29
|
-
className={styles.select}
|
30
|
-
onChange={(e) =>
|
31
|
-
handleSelectedVariant(product, e.target.value)
|
32
|
-
}
|
33
|
-
>
|
34
|
-
<optgroup label={getOptionsLabel(product)}>
|
35
|
-
{product.variants.nodes.map(({ id, title }) => (
|
36
|
-
<option key={id + '-variant'} value={id}>
|
37
|
-
{title}
|
38
|
-
</option>
|
39
|
-
))}
|
40
|
-
</optgroup>
|
41
|
-
</select>
|
42
|
-
</div>
|
43
|
-
)
|
44
|
-
);
|
45
|
-
};
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './VariantSelect';
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import { createContext } from 'react';
|
2
|
-
|
3
|
-
import { type ContextParameters } from '~/types/rebuyCustom';
|
4
|
-
|
5
|
-
export type RebuyContextType = {
|
6
|
-
contextParameters: ContextParameters;
|
7
|
-
};
|
8
|
-
|
9
|
-
export const RebuyContext = createContext<RebuyContextType | null>(null);
|
package/src/hooks/titleLevel.tsx
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
import { ProductCardTitleLevel } from '~/types/common';
|
2
|
-
|
3
|
-
// Convert the string header level to enum
|
4
|
-
export const getTitleLevel = (
|
5
|
-
level: string,
|
6
|
-
decreaseLevel: boolean = false
|
7
|
-
): ProductCardTitleLevel => {
|
8
|
-
switch (level) {
|
9
|
-
case 'h1':
|
10
|
-
if (decreaseLevel) {
|
11
|
-
return ProductCardTitleLevel.H2;
|
12
|
-
}
|
13
|
-
return ProductCardTitleLevel.H1;
|
14
|
-
case 'h2':
|
15
|
-
if (decreaseLevel) {
|
16
|
-
return ProductCardTitleLevel.H3;
|
17
|
-
}
|
18
|
-
return ProductCardTitleLevel.H2;
|
19
|
-
case 'h3':
|
20
|
-
if (decreaseLevel) {
|
21
|
-
return ProductCardTitleLevel.H4;
|
22
|
-
}
|
23
|
-
return ProductCardTitleLevel.H3;
|
24
|
-
case 'h4':
|
25
|
-
if (decreaseLevel) {
|
26
|
-
return ProductCardTitleLevel.H5;
|
27
|
-
}
|
28
|
-
return ProductCardTitleLevel.H4;
|
29
|
-
case 'h5':
|
30
|
-
if (decreaseLevel) {
|
31
|
-
return ProductCardTitleLevel.H6;
|
32
|
-
}
|
33
|
-
return ProductCardTitleLevel.H5;
|
34
|
-
case 'h6':
|
35
|
-
if (decreaseLevel) {
|
36
|
-
return ProductCardTitleLevel.H6;
|
37
|
-
}
|
38
|
-
return ProductCardTitleLevel.H6;
|
39
|
-
default:
|
40
|
-
return ProductCardTitleLevel.H2;
|
41
|
-
}
|
42
|
-
};
|
package/src/index.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
export * from './providers/RebuyHydrogenContextProvider';
|
2
|
-
export * from './providers/RebuyHydrogenReactContextProvider';
|
3
|
-
export * from './widgetContainer/RebuyWidgetContainer';
|
4
|
-
export * from './widgets/RebuyCompleteTheLook';
|
5
|
-
export * from './widgets/RebuyDynamicBundleProducts';
|
6
|
-
export * from './widgets/RebuyProductAddOns';
|
7
|
-
export * from './widgets/RebuyProductRecommendations';
|
@@ -1,112 +0,0 @@
|
|
1
|
-
import * as Utilities from '@rebuy/rebuy/utilities';
|
2
|
-
import { Await, useLocation } from '@remix-run/react';
|
3
|
-
import { useEffect, useMemo, useState } from 'react';
|
4
|
-
|
5
|
-
import type { CartReturn } from '@shopify/hydrogen';
|
6
|
-
import type {
|
7
|
-
RebuyHydrogenContextProviderProps,
|
8
|
-
RebuyHydrogenProps,
|
9
|
-
} from '~/providers/types';
|
10
|
-
|
11
|
-
import { RebuyContext } from '~/context/RebuyContext';
|
12
|
-
import { RebuyConfig } from '~/types/rebuyCustom';
|
13
|
-
import { createContextParameters } from '~/utils/createContextParameters';
|
14
|
-
import { getRebuyConfig } from '~/utils/getRebuyConfig';
|
15
|
-
|
16
|
-
const RebuyHydrogenContext = ({
|
17
|
-
cartAttributes,
|
18
|
-
cartCost,
|
19
|
-
cartId,
|
20
|
-
cartLines,
|
21
|
-
cartNote,
|
22
|
-
cartQuantity,
|
23
|
-
children,
|
24
|
-
}: RebuyHydrogenProps) => {
|
25
|
-
const primaryDomain = import.meta.env.PRIMARY_DOMAIN;
|
26
|
-
const rebuyKey = import.meta.env.PUBLIC_REBUY_API_KEY;
|
27
|
-
const storeDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
|
28
|
-
|
29
|
-
const [rebuyConfig, setRebuyConfig] = useState<RebuyConfig | null>(null);
|
30
|
-
const location = useLocation();
|
31
|
-
const queryObject = Utilities.queryStringToObject(location.search);
|
32
|
-
const windowUrl = `${primaryDomain}${location.pathname}${location.search}`;
|
33
|
-
|
34
|
-
// Initialization
|
35
|
-
useEffect(() => {
|
36
|
-
const initConfig = async () => {
|
37
|
-
const config = await getRebuyConfig(rebuyKey, storeDomain);
|
38
|
-
setRebuyConfig(config);
|
39
|
-
};
|
40
|
-
|
41
|
-
if (!rebuyConfig?.shop) {
|
42
|
-
initConfig();
|
43
|
-
}
|
44
|
-
}, [rebuyConfig, rebuyKey, storeDomain]);
|
45
|
-
|
46
|
-
const contextParameters = useMemo(
|
47
|
-
() =>
|
48
|
-
createContextParameters({
|
49
|
-
cacheKey: rebuyConfig?.shop?.cache_key,
|
50
|
-
cartAttributes,
|
51
|
-
cartId,
|
52
|
-
cartLines,
|
53
|
-
cartLinesLength: cartLines?.length,
|
54
|
-
cartNote: cartNote as string,
|
55
|
-
cartSubtotal: cartCost,
|
56
|
-
cartTotalQuantity: cartQuantity,
|
57
|
-
isHydrogenReact: false,
|
58
|
-
queryObject,
|
59
|
-
windowUrl,
|
60
|
-
}),
|
61
|
-
[
|
62
|
-
rebuyConfig,
|
63
|
-
windowUrl,
|
64
|
-
queryObject,
|
65
|
-
cartAttributes,
|
66
|
-
cartCost,
|
67
|
-
cartId,
|
68
|
-
cartLines,
|
69
|
-
cartQuantity,
|
70
|
-
cartNote,
|
71
|
-
]
|
72
|
-
);
|
73
|
-
|
74
|
-
// Static reference (JSON) + memoization
|
75
|
-
// ^ prevent re-rendering children when context params are unchanged
|
76
|
-
const contextParametersJSON = JSON.stringify(contextParameters);
|
77
|
-
const contextValue = useMemo(
|
78
|
-
() => ({ contextParameters: JSON.parse(contextParametersJSON) }),
|
79
|
-
[contextParametersJSON]
|
80
|
-
);
|
81
|
-
|
82
|
-
return (
|
83
|
-
<RebuyContext.Provider value={contextValue}>
|
84
|
-
{children}
|
85
|
-
</RebuyContext.Provider>
|
86
|
-
);
|
87
|
-
};
|
88
|
-
|
89
|
-
export const RebuyHydrogenContextProvider = ({
|
90
|
-
cart,
|
91
|
-
children,
|
92
|
-
}: RebuyHydrogenContextProviderProps) => {
|
93
|
-
return (
|
94
|
-
<Await resolve={cart}>
|
95
|
-
{(resolvedCart) => {
|
96
|
-
const cart = resolvedCart as CartReturn;
|
97
|
-
return (
|
98
|
-
<RebuyHydrogenContext
|
99
|
-
cartAttributes={cart?.attributes}
|
100
|
-
cartCost={cart?.cost?.subtotalAmount?.amount}
|
101
|
-
cartId={cart?.id}
|
102
|
-
cartLines={cart?.lines?.nodes}
|
103
|
-
cartNote={cart?.note}
|
104
|
-
cartQuantity={cart?.totalQuantity}
|
105
|
-
>
|
106
|
-
{children}
|
107
|
-
</RebuyHydrogenContext>
|
108
|
-
);
|
109
|
-
}}
|
110
|
-
</Await>
|
111
|
-
);
|
112
|
-
};
|
@@ -1,192 +0,0 @@
|
|
1
|
-
import * as Utilities from '@rebuy/rebuy/utilities';
|
2
|
-
import { useLocation } from '@remix-run/react';
|
3
|
-
import {
|
4
|
-
CartProvider,
|
5
|
-
ShopifyProvider,
|
6
|
-
useCart,
|
7
|
-
} from '@shopify/hydrogen-react';
|
8
|
-
import { useEffect, useMemo, useState } from 'react';
|
9
|
-
|
10
|
-
import type { Attribute } from '@shopify/hydrogen-react/storefront-api-types';
|
11
|
-
import type {
|
12
|
-
RebuyHydrogenReactContextProviderProps,
|
13
|
-
RebuyHydrogenReactProps,
|
14
|
-
} from '~/providers/types';
|
15
|
-
import type { RebuyConfig } from '~/types/rebuyCustom';
|
16
|
-
|
17
|
-
import { RebuyContext } from '~/context/RebuyContext';
|
18
|
-
import { CART_FRAGMENT } from '~/queries/cart.queries';
|
19
|
-
import { createContextParameters } from '~/utils/createContextParameters';
|
20
|
-
import { getRebuyConfig } from '~/utils/getRebuyConfig';
|
21
|
-
|
22
|
-
const RebuyHydrogenReactContext = ({ children }: RebuyHydrogenReactProps) => {
|
23
|
-
const primaryDomain = import.meta.env.PRIMARY_DOMAIN;
|
24
|
-
const rebuyKey = import.meta.env.PUBLIC_REBUY_API_KEY;
|
25
|
-
const storeDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
|
26
|
-
|
27
|
-
const [rebuyConfig, setRebuyConfig] = useState<RebuyConfig | null>(null);
|
28
|
-
const location = useLocation();
|
29
|
-
const queryObject = Utilities.queryStringToObject(location.search);
|
30
|
-
const windowUrl = `${primaryDomain}${location.pathname}${location.search}`;
|
31
|
-
|
32
|
-
// This is the cart object from Hydrogen-React
|
33
|
-
const cart = useCart();
|
34
|
-
|
35
|
-
// Initialization
|
36
|
-
useEffect(() => {
|
37
|
-
const initConfig = async () => {
|
38
|
-
const config = await getRebuyConfig(rebuyKey, storeDomain);
|
39
|
-
setRebuyConfig(config);
|
40
|
-
};
|
41
|
-
|
42
|
-
if (!rebuyConfig?.shop) {
|
43
|
-
initConfig();
|
44
|
-
}
|
45
|
-
}, [rebuyConfig, rebuyKey, storeDomain]);
|
46
|
-
|
47
|
-
const contextParameters = useMemo(
|
48
|
-
() =>
|
49
|
-
createContextParameters({
|
50
|
-
cacheKey: rebuyConfig?.shop?.cache_key,
|
51
|
-
cartAttributes: cart?.attributes as Attribute[],
|
52
|
-
cartId: cart?.id,
|
53
|
-
cartLines: cart?.lines,
|
54
|
-
cartLinesLength: cart?.lines?.length,
|
55
|
-
cartSubtotal: cart?.cost?.subtotalAmount?.amount,
|
56
|
-
cartTotalQuantity: cart?.totalQuantity,
|
57
|
-
isHydrogenReact: true,
|
58
|
-
queryObject,
|
59
|
-
windowUrl,
|
60
|
-
}),
|
61
|
-
[rebuyConfig, windowUrl, queryObject, cart]
|
62
|
-
);
|
63
|
-
|
64
|
-
// Static reference (JSON) + memoization
|
65
|
-
// ^ prevent re-rendering children when context params are unchanged
|
66
|
-
const contextParametersJSON = JSON.stringify(contextParameters);
|
67
|
-
const contextValue = useMemo(
|
68
|
-
() => ({ contextParameters: JSON.parse(contextParametersJSON) }),
|
69
|
-
[contextParametersJSON]
|
70
|
-
);
|
71
|
-
|
72
|
-
return (
|
73
|
-
<RebuyContext.Provider value={contextValue}>
|
74
|
-
{children}
|
75
|
-
</RebuyContext.Provider>
|
76
|
-
);
|
77
|
-
};
|
78
|
-
|
79
|
-
export const RebuyHydrogenReactContextProvider = ({
|
80
|
-
cartFragment = CART_FRAGMENT,
|
81
|
-
children,
|
82
|
-
countryIsoCode = 'US',
|
83
|
-
customerAccessToken = '',
|
84
|
-
data,
|
85
|
-
languageIsoCode = 'EN',
|
86
|
-
numCartLines,
|
87
|
-
onAttributesUpdate,
|
88
|
-
onAttributesUpdateComplete,
|
89
|
-
onBuyerIdentityUpdate,
|
90
|
-
onBuyerIdentityUpdateComplete,
|
91
|
-
onCreate,
|
92
|
-
onCreateComplete,
|
93
|
-
onDiscountCodesUpdate,
|
94
|
-
onDiscountCodesUpdateComplete,
|
95
|
-
onLineAdd,
|
96
|
-
onLineAddComplete,
|
97
|
-
onLineRemove,
|
98
|
-
onLineRemoveComplete,
|
99
|
-
onLineUpdate,
|
100
|
-
onLineUpdateComplete,
|
101
|
-
onNoteUpdate,
|
102
|
-
onNoteUpdateComplete,
|
103
|
-
storefrontApiVersion = '2025-01',
|
104
|
-
}: RebuyHydrogenReactContextProviderProps) => {
|
105
|
-
const publicStoreDomain = import.meta.env.PUBLIC_STORE_DOMAIN;
|
106
|
-
const storefrontId = import.meta.env.PUBLIC_STOREFRONT_ID;
|
107
|
-
const storefrontToken = import.meta.env.PUBLIC_STOREFRONT_API_TOKEN || '';
|
108
|
-
const adapted = {
|
109
|
-
onAttributesUpdate: onAttributesUpdate
|
110
|
-
? () => onAttributesUpdate()
|
111
|
-
: undefined,
|
112
|
-
onAttributesUpdateComplete: onAttributesUpdateComplete
|
113
|
-
? () => onAttributesUpdateComplete()
|
114
|
-
: undefined,
|
115
|
-
onBuyerIdentityUpdate: onBuyerIdentityUpdate
|
116
|
-
? () => onBuyerIdentityUpdate()
|
117
|
-
: undefined,
|
118
|
-
onBuyerIdentityUpdateComplete: onBuyerIdentityUpdateComplete
|
119
|
-
? () => onBuyerIdentityUpdateComplete()
|
120
|
-
: undefined,
|
121
|
-
onCreate: onCreate ? () => onCreate() : undefined,
|
122
|
-
onCreateComplete: onCreateComplete
|
123
|
-
? () => onCreateComplete()
|
124
|
-
: undefined,
|
125
|
-
onDiscountCodesUpdate: onDiscountCodesUpdate
|
126
|
-
? () => onDiscountCodesUpdate()
|
127
|
-
: undefined,
|
128
|
-
onDiscountCodesUpdateComplete: onDiscountCodesUpdateComplete
|
129
|
-
? () => onDiscountCodesUpdateComplete()
|
130
|
-
: undefined,
|
131
|
-
onLineAdd: onLineAdd ? () => onLineAdd() : undefined,
|
132
|
-
onLineAddComplete: onLineAddComplete
|
133
|
-
? () => onLineAddComplete()
|
134
|
-
: undefined,
|
135
|
-
onLineRemove: onLineRemove ? () => onLineRemove() : undefined,
|
136
|
-
onLineRemoveComplete: onLineRemoveComplete
|
137
|
-
? () => onLineRemoveComplete()
|
138
|
-
: undefined,
|
139
|
-
onLineUpdate: onLineUpdate ? () => onLineUpdate() : undefined,
|
140
|
-
onLineUpdateComplete: onLineUpdateComplete
|
141
|
-
? () => onLineUpdateComplete()
|
142
|
-
: undefined,
|
143
|
-
onNoteUpdate: onNoteUpdate ? () => onNoteUpdate() : undefined,
|
144
|
-
onNoteUpdateComplete: onNoteUpdateComplete
|
145
|
-
? () => onNoteUpdateComplete()
|
146
|
-
: undefined,
|
147
|
-
};
|
148
|
-
|
149
|
-
return (
|
150
|
-
<ShopifyProvider
|
151
|
-
countryIsoCode={countryIsoCode}
|
152
|
-
languageIsoCode={languageIsoCode}
|
153
|
-
storeDomain={publicStoreDomain}
|
154
|
-
storefrontApiVersion={storefrontApiVersion}
|
155
|
-
storefrontId={storefrontId}
|
156
|
-
storefrontToken={storefrontToken}
|
157
|
-
>
|
158
|
-
<CartProvider
|
159
|
-
cartFragment={cartFragment}
|
160
|
-
countryCode={countryIsoCode}
|
161
|
-
customerAccessToken={customerAccessToken}
|
162
|
-
data={data}
|
163
|
-
languageCode={languageIsoCode}
|
164
|
-
numCartLines={numCartLines}
|
165
|
-
onAttributesUpdate={adapted.onAttributesUpdate}
|
166
|
-
onAttributesUpdateComplete={adapted.onAttributesUpdateComplete}
|
167
|
-
onBuyerIdentityUpdate={adapted.onBuyerIdentityUpdate}
|
168
|
-
onBuyerIdentityUpdateComplete={
|
169
|
-
adapted.onBuyerIdentityUpdateComplete
|
170
|
-
}
|
171
|
-
onCreate={adapted.onCreate}
|
172
|
-
onCreateComplete={adapted.onCreateComplete}
|
173
|
-
onDiscountCodesUpdate={adapted.onDiscountCodesUpdate}
|
174
|
-
onDiscountCodesUpdateComplete={
|
175
|
-
adapted.onDiscountCodesUpdateComplete
|
176
|
-
}
|
177
|
-
onLineAdd={adapted.onLineAdd}
|
178
|
-
onLineAddComplete={adapted.onLineAddComplete}
|
179
|
-
onLineRemove={adapted.onLineRemove}
|
180
|
-
onLineRemoveComplete={adapted.onLineRemoveComplete}
|
181
|
-
onLineUpdate={adapted.onLineUpdate}
|
182
|
-
onLineUpdateComplete={adapted.onLineUpdateComplete}
|
183
|
-
onNoteUpdate={adapted.onNoteUpdate}
|
184
|
-
onNoteUpdateComplete={adapted.onNoteUpdateComplete}
|
185
|
-
>
|
186
|
-
<RebuyHydrogenReactContext>
|
187
|
-
{children}
|
188
|
-
</RebuyHydrogenReactContext>
|
189
|
-
</CartProvider>
|
190
|
-
</ShopifyProvider>
|
191
|
-
);
|
192
|
-
};
|
package/src/providers/types.ts
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
import { PartialDeep } from 'type-fest';
|
2
|
-
|
3
|
-
import type { CartReturn } from '@shopify/hydrogen';
|
4
|
-
import type {
|
5
|
-
Attribute,
|
6
|
-
Cart,
|
7
|
-
CartLine,
|
8
|
-
ComponentizableCartLine,
|
9
|
-
CountryCode,
|
10
|
-
LanguageCode,
|
11
|
-
Maybe,
|
12
|
-
} from '@shopify/hydrogen-react/storefront-api-types';
|
13
|
-
|
14
|
-
export type RebuyHydrogenContextProviderProps = {
|
15
|
-
cart: CartReturn;
|
16
|
-
children: React.ReactNode;
|
17
|
-
};
|
18
|
-
|
19
|
-
export type RebuyHydrogenProps = {
|
20
|
-
cartAttributes?: Attribute[];
|
21
|
-
cartCost?: string;
|
22
|
-
cartId?: string;
|
23
|
-
cartLines?: (CartLine | ComponentizableCartLine)[];
|
24
|
-
cartNote?: Maybe<string>;
|
25
|
-
cartQuantity?: number;
|
26
|
-
children: React.ReactNode;
|
27
|
-
};
|
28
|
-
|
29
|
-
export type RebuyHydrogenReactProps = {
|
30
|
-
children: React.ReactNode;
|
31
|
-
};
|
32
|
-
|
33
|
-
export type RebuyHydrogenReactContextProviderProps = {
|
34
|
-
cartFragment?: string;
|
35
|
-
children: React.ReactNode;
|
36
|
-
countryIsoCode?: CountryCode;
|
37
|
-
customerAccessToken?: string;
|
38
|
-
data?: PartialDeep<Cart, { recurseIntoArrays: true }>;
|
39
|
-
languageIsoCode?: LanguageCode;
|
40
|
-
numCartLines?: number;
|
41
|
-
onAttributesUpdate?: () => void;
|
42
|
-
onAttributesUpdateComplete?: () => void;
|
43
|
-
onBuyerIdentityUpdate?: () => void;
|
44
|
-
onBuyerIdentityUpdateComplete?: () => void;
|
45
|
-
onCreate?: () => void;
|
46
|
-
onCreateComplete?: () => void;
|
47
|
-
onDiscountCodesUpdate?: () => void;
|
48
|
-
onDiscountCodesUpdateComplete?: () => void;
|
49
|
-
onLineAdd?: () => void;
|
50
|
-
onLineAddComplete?: () => void;
|
51
|
-
onLineRemove?: () => void;
|
52
|
-
onLineRemoveComplete?: () => void;
|
53
|
-
onLineUpdate?: () => void;
|
54
|
-
onLineUpdateComplete?: () => void;
|
55
|
-
onNoteUpdate?: () => void;
|
56
|
-
onNoteUpdateComplete?: () => void;
|
57
|
-
storefrontApiVersion?: string;
|
58
|
-
};
|