@shopify/hydrogen 0.25.1 → 0.26.0
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/CHANGELOG.md +72 -0
- package/dist/esnext/components/{CartEstimatedCost/CartEstimatedCost.client.d.ts → CartCost/CartCost.client.d.ts} +3 -3
- package/dist/esnext/components/{CartEstimatedCost/CartEstimatedCost.client.js → CartCost/CartCost.client.js} +7 -7
- package/dist/esnext/components/CartCost/index.d.ts +1 -0
- package/dist/esnext/components/CartCost/index.js +1 -0
- package/dist/esnext/components/CartLinePrice/CartLinePrice.client.js +2 -2
- package/dist/esnext/components/CartLineProvider/context.d.ts +3 -3
- package/dist/esnext/components/CartProvider/CartProvider.client.js +37 -27
- package/dist/esnext/components/CartProvider/cart-queries.d.ts +1 -1
- package/dist/esnext/components/CartProvider/cart-queries.js +3 -3
- package/dist/esnext/components/CartProvider/graphql/CartAttributesUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartBuyerIdentityUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartCreateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartDiscountCodesUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartFragment.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartLineAddMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartLineRemoveMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartLineUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartNoteUpdateMutation.d.ts +5 -5
- package/dist/esnext/components/CartProvider/graphql/CartQuery.d.ts +5 -5
- package/dist/esnext/components/CartProvider/hooks.client.d.ts +1 -1
- package/dist/esnext/components/CartProvider/hooks.client.js +16 -11
- package/dist/esnext/components/CartProvider/types.d.ts +3 -3
- package/dist/esnext/components/CartShopPayButton/CartShopPayButton.client.d.ts +1 -3
- package/dist/esnext/components/CartShopPayButton/CartShopPayButton.client.js +2 -4
- package/dist/esnext/components/Link/Link.client.d.ts +2 -0
- package/dist/esnext/components/Link/Link.client.js +8 -4
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.d.ts +2 -2
- package/dist/esnext/components/LocalizationProvider/LocalizationClientProvider.client.js +1 -1
- package/dist/esnext/components/LocalizationProvider/LocalizationContext.client.d.ts +6 -3
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.d.ts +8 -20
- package/dist/esnext/components/LocalizationProvider/LocalizationProvider.server.js +17 -33
- package/dist/esnext/components/LocalizationProvider/index.d.ts +0 -1
- package/dist/esnext/components/LocalizationProvider/index.js +0 -1
- package/dist/esnext/components/Metafield/Metafield.client.js +3 -3
- package/dist/esnext/components/Seo/DefaultPageSeo.client.js +3 -3
- package/dist/esnext/components/Seo/DescriptionSeo.client.js +1 -1
- package/dist/esnext/components/Seo/HomePageSeo.client.d.ts +1 -1
- package/dist/esnext/components/Seo/HomePageSeo.client.js +3 -3
- package/dist/esnext/components/Seo/ImageSeo.client.js +1 -1
- package/dist/esnext/components/Seo/NoIndexSeo.client.js +3 -3
- package/dist/esnext/components/Seo/ProductSeo.client.js +2 -2
- package/dist/esnext/components/Seo/Seo.client.js +1 -1
- package/dist/esnext/components/Seo/TitleSeo.client.js +1 -1
- package/dist/esnext/components/Seo/TwitterSeo.client.js +1 -1
- package/dist/esnext/components/Seo/seo-types.d.ts +1 -0
- package/dist/esnext/components/ShopPayButton/ShopPayButton.client.d.ts +3 -1
- package/dist/esnext/components/ShopPayButton/ShopPayButton.client.js +8 -3
- package/dist/esnext/components/index.d.ts +2 -2
- package/dist/esnext/components/index.js +2 -2
- package/dist/esnext/constants.d.ts +1 -1
- package/dist/esnext/constants.js +1 -1
- package/dist/esnext/entry-client.js +7 -5
- package/dist/esnext/entry-server.js +21 -34
- package/dist/esnext/foundation/Analytics/connectors/PerformanceMetrics/PerformanceMetricsDebug.client.js +1 -1
- package/dist/esnext/foundation/Analytics/connectors/Shopify/ShopifyAnalytics.client.js +1 -1
- package/dist/esnext/foundation/FileRoutes/FileRoutes.server.js +1 -1
- package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.d.ts +9 -1
- package/dist/esnext/foundation/HydrogenRequest/HydrogenRequest.server.js +6 -0
- package/dist/esnext/foundation/Route/Route.server.js +1 -1
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.d.ts +5 -4
- package/dist/esnext/foundation/ServerRequestProvider/ServerRequestProvider.js +9 -7
- package/dist/esnext/foundation/ShopifyProvider/ShopifyProvider.server.js +4 -0
- package/dist/esnext/foundation/ShopifyProvider/types.d.ts +1 -0
- package/dist/esnext/foundation/useNavigate/useNavigate.d.ts +2 -0
- package/dist/esnext/foundation/useNavigate/useNavigate.js +13 -0
- package/dist/esnext/foundation/useQuery/hooks.js +1 -4
- package/dist/esnext/foundation/useRouteParams/RouteParamsProvider.client.d.ts +3 -0
- package/dist/esnext/foundation/useRouteParams/RouteParamsProvider.client.js +8 -3
- package/dist/esnext/framework/cache/in-memory.d.ts +12 -7
- package/dist/esnext/framework/cache/in-memory.js +49 -21
- package/dist/esnext/framework/load-config.d.ts +6 -0
- package/dist/esnext/framework/load-config.js +10 -0
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-client-middleware.js +2 -3
- package/dist/esnext/framework/plugins/vite-plugin-hydrogen-virtual-files.js +21 -4
- package/dist/esnext/framework/viteception.d.ts +2 -1
- package/dist/esnext/framework/viteception.js +2 -1
- package/dist/esnext/hooks/useCartLine/useCartLine.d.ts +3 -3
- package/dist/esnext/hooks/useLocalization/useLocalization.d.ts +4 -0
- package/dist/esnext/hooks/useLocalization/useLocalization.js +14 -0
- package/dist/esnext/hooks/useMeasurement/hooks.js +2 -2
- package/dist/esnext/hooks/useMoney/hooks.js +2 -2
- package/dist/esnext/index.d.ts +3 -0
- package/dist/esnext/index.js +1 -0
- package/dist/esnext/platforms/node.d.ts +1 -1
- package/dist/esnext/platforms/node.js +2 -1
- package/dist/esnext/storefront-api-types.d.ts +105 -3
- package/dist/esnext/storefront-api-types.js +8 -0
- package/dist/esnext/types.d.ts +10 -0
- package/dist/esnext/utilities/apiRoutes.d.ts +4 -3
- package/dist/esnext/utilities/log/log-cache-api-status.js +3 -0
- package/dist/esnext/utilities/storefrontApi.d.ts +1 -0
- package/dist/esnext/utilities/storefrontApi.js +1 -1
- package/dist/esnext/version.d.ts +1 -1
- package/dist/esnext/version.js +1 -1
- package/dist/node/framework/cache/in-memory.d.ts +12 -7
- package/dist/node/framework/cache/in-memory.js +49 -21
- package/dist/node/framework/load-config.d.ts +6 -0
- package/dist/node/framework/load-config.js +14 -0
- package/dist/node/framework/plugins/vite-plugin-hydrogen-client-middleware.js +2 -3
- package/dist/node/framework/plugins/vite-plugin-hydrogen-virtual-files.js +21 -4
- package/dist/node/framework/viteception.d.ts +2 -1
- package/dist/node/framework/viteception.js +2 -1
- package/package.json +13 -3
- package/vendor/react-server-dom-vite/cjs/react-server-dom-vite-plugin.js +21 -6
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-client-proxy.js +2 -1
- package/vendor/react-server-dom-vite/esm/react-server-dom-vite-plugin.js +21 -6
- package/dist/esnext/components/CartEstimatedCost/index.d.ts +0 -1
- package/dist/esnext/components/CartEstimatedCost/index.js +0 -1
- package/dist/esnext/hooks/useCountry/index.d.ts +0 -1
- package/dist/esnext/hooks/useCountry/index.js +0 -1
- package/dist/esnext/hooks/useCountry/useCountry.d.ts +0 -7
- package/dist/esnext/hooks/useCountry/useCountry.js +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,77 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.26.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1615](https://github.com/Shopify/hydrogen/pull/1615) [`20bfc438`](https://github.com/Shopify/hydrogen/commit/20bfc4388ed400dc215a41cca44fe8cd4a11022a) Thanks [@frehner](https://github.com/frehner)! - `<CartEstimatedCost/>` has been renamed to `<CartCost/>` to match a recent update to the Storefront API, in which `cart.estimatedCost` is being deprecated in favor of `cart.cost`.
|
|
8
|
+
|
|
9
|
+
Additionally, `cart.cost.compareAtAmount` was renamed to `cart.cost.compareAtAmountPerQuantity`.
|
|
10
|
+
|
|
11
|
+
* [#1619](https://github.com/Shopify/hydrogen/pull/1619) [`b0c13696`](https://github.com/Shopify/hydrogen/commit/b0c13696b6030ab8697147fdbe3ccdf2522a3913) Thanks [@blittle](https://github.com/blittle)! - We have reworked how localization works in Hydrogen. By default the `useLocalization()` hook returns the default locale defined within your [Hydrogen configuration file](https://shopify.dev/custom-storefronts/hydrogen/framework/hydrogen-config). The `<LocalizationProvider>` component now takes `countryCode` and `languageCode` as optional props. Any props given to `<LocalizationProvider>` will also be used by the `useLocalization` hook.
|
|
12
|
+
|
|
13
|
+
**Breaking Change**
|
|
14
|
+
|
|
15
|
+
The `useCountry` hook has been removed. Instead use the [`useLocalization` hook](https://shopify.dev/api/hydrogen/hooks/localization/uselocalization).
|
|
16
|
+
|
|
17
|
+
```diff
|
|
18
|
+
- import {useCountry, gql} from '@shopify/hydrogen';
|
|
19
|
+
+ import {useLocalization, gql} from '@shopify/hydrogen';
|
|
20
|
+
|
|
21
|
+
export function MyComponent() {
|
|
22
|
+
|
|
23
|
+
- const [country] = useCountry();
|
|
24
|
+
+ const {country} = useLocalization();
|
|
25
|
+
|
|
26
|
+
return ( /* Your JSX */ );
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The `Link` component now respects the `basePath` property defined within it's parent `FileRoutes` component. For example, given `<FileRoutes basePath="/cn">`, a route within that renders `<Link to="/products">` will actually produce an anchor tag prefixed with `/cn`: `<a href="/cn/products">`. You can override the `basePath` with a `basePath` prop on the `Link` component.
|
|
31
|
+
|
|
32
|
+
- [#1646](https://github.com/Shopify/hydrogen/pull/1646) [`1103fb57`](https://github.com/Shopify/hydrogen/commit/1103fb575e51d5948c6bd4885bcd911be1f8bf7e) Thanks [@benjaminsehl](https://github.com/benjaminsehl)! - Updates default SEO titleTemplate for the Homepage
|
|
33
|
+
|
|
34
|
+
### Patch Changes
|
|
35
|
+
|
|
36
|
+
- [#1569](https://github.com/Shopify/hydrogen/pull/1569) [`e5896a3e`](https://github.com/Shopify/hydrogen/commit/e5896a3e20b0bf2760b238e713a7bc04f7e95e2d) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - Clean up full page cache work with `waitUntil`
|
|
37
|
+
|
|
38
|
+
* [#1643](https://github.com/Shopify/hydrogen/pull/1643) [`3b849606`](https://github.com/Shopify/hydrogen/commit/3b849606c4999d19920330f86c535a6f892dcc65) Thanks [@frandiox](https://github.com/frandiox)! - Do not cache client components in browser when using TypeScript.
|
|
39
|
+
|
|
40
|
+
- [#1605](https://github.com/Shopify/hydrogen/pull/1605) [`2eb2c461`](https://github.com/Shopify/hydrogen/commit/2eb2c4615210cafadab8ed154909f3516c72db3e) Thanks [@frandiox](https://github.com/frandiox)! - Fix hydration issues with `useId`.
|
|
41
|
+
|
|
42
|
+
* [#1613](https://github.com/Shopify/hydrogen/pull/1613) [`c45ebd3c`](https://github.com/Shopify/hydrogen/commit/c45ebd3cf468c9f596ef399712506bd766dea54d) Thanks [@frehner](https://github.com/frehner)! - The `<ShopPayButton/>` and `<CartShopPayButton/>` now take in a `width` prop to help customize how wide the `<shop-pay-button>` custom element is, by using the newly added CSS custom property (variable) `--shop-pay-button-width`.
|
|
43
|
+
|
|
44
|
+
- [#1651](https://github.com/Shopify/hydrogen/pull/1651) [`a19be2b2`](https://github.com/Shopify/hydrogen/commit/a19be2b22cee63bf95ade3a4f5803c460651a473) Thanks [@blittle](https://github.com/blittle)! - Fixes to the cart:
|
|
45
|
+
|
|
46
|
+
1. Fix bug when providing a lower-case country code to the `LocalizationProvider`
|
|
47
|
+
2. Make sure that the Cart always logs API errors
|
|
48
|
+
|
|
49
|
+
* [#1649](https://github.com/Shopify/hydrogen/pull/1649) [`df0e01ff`](https://github.com/Shopify/hydrogen/commit/df0e01fff6afae22a30be8c0bb750aed016326a4) Thanks [@blittle](https://github.com/blittle)! - Add a `x-powered-by: Shopify-Hydrogen` header which can be disabled with the Hydrogen config property: `poweredByHeader: false`
|
|
50
|
+
|
|
51
|
+
- [#1566](https://github.com/Shopify/hydrogen/pull/1566) [`cfe7385e`](https://github.com/Shopify/hydrogen/commit/cfe7385e0c64c3dc465d1bcd34ad9c7040db9969) Thanks [@wizardlyhel](https://github.com/wizardlyhel)! - Add storefont id to cart provider query
|
|
52
|
+
|
|
53
|
+
* [#1551](https://github.com/Shopify/hydrogen/pull/1551) [`3d20e92d`](https://github.com/Shopify/hydrogen/commit/3d20e92db3402e356c16d0bc5fc4450f9d8c0df5) Thanks [@jplhomer](https://github.com/jplhomer)! - In-Memory caching is now enabled by default in production for Node.js runtimes.
|
|
54
|
+
|
|
55
|
+
- [#1604](https://github.com/Shopify/hydrogen/pull/1604) [`f3827d31`](https://github.com/Shopify/hydrogen/commit/f3827d31263352689c5149a5509b51d1fdb572d4) Thanks [@cartogram](https://github.com/cartogram)! - Adds new `load-config` entry point that exposes a `loadConfig()` function that will return the configuration object and the path to the found configuration file for a given Hydrogen project root.
|
|
56
|
+
|
|
57
|
+
Example:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import {loadConfig} from '@shopify/hydrogen/load-config';
|
|
61
|
+
|
|
62
|
+
const {configuration, configurationPath} = await loadConfig({
|
|
63
|
+
root: 'path/to/hydrogen-app',
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
* [#1626](https://github.com/Shopify/hydrogen/pull/1626) [`29218452`](https://github.com/Shopify/hydrogen/commit/29218452a1679be629616993d8cc23ad7077667b) Thanks [@frandiox](https://github.com/frandiox)! - Fix import aliases.
|
|
68
|
+
|
|
69
|
+
- [#1622](https://github.com/Shopify/hydrogen/pull/1622) [`d339239d`](https://github.com/Shopify/hydrogen/commit/d339239d23b074cba3ee637166f8120512a6afee) Thanks [@frandiox](https://github.com/frandiox)! - Fix module resolution after HMR in some scenarios.
|
|
70
|
+
|
|
71
|
+
* [#1608](https://github.com/Shopify/hydrogen/pull/1608) [`b834dfdc`](https://github.com/Shopify/hydrogen/commit/b834dfdcddc56c78bb6fbb7e0a681cc3c977b62d) Thanks [@jplhomer](https://github.com/jplhomer)! - Add type exports for `HydrogenRouteProps`, `HydrogenApiRoute`, and `HydrogenApiRouteOptions`.
|
|
72
|
+
|
|
73
|
+
- [#1603](https://github.com/Shopify/hydrogen/pull/1603) [`e1bb5810`](https://github.com/Shopify/hydrogen/commit/e1bb5810f218acc5b7debb60bcdebc6c9594f86c) Thanks [@frandiox](https://github.com/frandiox)! - Do not trigger prefetch when `to` prop is missing in the `Link` component.
|
|
74
|
+
|
|
3
75
|
## 0.25.1
|
|
4
76
|
|
|
5
77
|
## 0.25.0
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Money } from '../Money';
|
|
3
|
-
export interface
|
|
3
|
+
export interface CartCostProps {
|
|
4
4
|
/** A string type that defines the type of cost needed. Valid values: `total`, `subtotal`, `tax`, or `duty`. */
|
|
5
5
|
amountType?: 'total' | 'subtotal' | 'tax' | 'duty';
|
|
6
6
|
/** A function that takes an object return by the `useMoney` hook and returns a `ReactNode`. */
|
|
7
7
|
children?: React.ReactNode;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
-
* The `
|
|
10
|
+
* The `CartCost` component renders a `Money` component with the
|
|
11
11
|
* cost associated with the `amountType` prop. If no `amountType` prop is specified, then it defaults to `totalAmount`.
|
|
12
12
|
* If `children` is a function, then it will pass down the render props provided by the parent component.
|
|
13
13
|
*/
|
|
14
|
-
export declare function
|
|
14
|
+
export declare function CartCost(props: Omit<React.ComponentProps<typeof Money>, 'data'> & CartCostProps): JSX.Element | null;
|
|
@@ -2,25 +2,25 @@ import React from 'react';
|
|
|
2
2
|
import { useCart } from '../CartProvider';
|
|
3
3
|
import { Money } from '../Money';
|
|
4
4
|
/**
|
|
5
|
-
* The `
|
|
5
|
+
* The `CartCost` component renders a `Money` component with the
|
|
6
6
|
* cost associated with the `amountType` prop. If no `amountType` prop is specified, then it defaults to `totalAmount`.
|
|
7
7
|
* If `children` is a function, then it will pass down the render props provided by the parent component.
|
|
8
8
|
*/
|
|
9
|
-
export function
|
|
10
|
-
const {
|
|
9
|
+
export function CartCost(props) {
|
|
10
|
+
const { cost } = useCart();
|
|
11
11
|
const { amountType = 'total', children, ...passthroughProps } = props;
|
|
12
12
|
let amount;
|
|
13
13
|
if (amountType == 'total') {
|
|
14
|
-
amount =
|
|
14
|
+
amount = cost?.totalAmount;
|
|
15
15
|
}
|
|
16
16
|
else if (amountType == 'subtotal') {
|
|
17
|
-
amount =
|
|
17
|
+
amount = cost?.subtotalAmount;
|
|
18
18
|
}
|
|
19
19
|
else if (amountType == 'tax') {
|
|
20
|
-
amount =
|
|
20
|
+
amount = cost?.totalTaxAmount;
|
|
21
21
|
}
|
|
22
22
|
else if (amountType == 'duty') {
|
|
23
|
-
amount =
|
|
23
|
+
amount = cost?.totalDutyAmount;
|
|
24
24
|
}
|
|
25
25
|
if (amount == null) {
|
|
26
26
|
return null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CartCost } from './CartCost.client';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CartCost } from './CartCost.client';
|
|
@@ -9,8 +9,8 @@ export function CartLinePrice(props) {
|
|
|
9
9
|
const cartLine = useCartLine();
|
|
10
10
|
const { priceType = 'regular', ...passthroughProps } = props;
|
|
11
11
|
const moneyV2 = priceType === 'regular'
|
|
12
|
-
? cartLine.
|
|
13
|
-
: cartLine.
|
|
12
|
+
? cartLine.cost.totalAmount
|
|
13
|
+
: cartLine.cost.compareAtAmountPerQuantity;
|
|
14
14
|
if (moneyV2 == null) {
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
@@ -4,13 +4,13 @@ export declare const CartLineContext: import("react").Context<({
|
|
|
4
4
|
attributes: ({
|
|
5
5
|
__typename?: "Attribute" | undefined;
|
|
6
6
|
} & Pick<import("../../storefront-api-types").Attribute, "key" | "value">)[];
|
|
7
|
-
|
|
8
|
-
__typename?: "
|
|
7
|
+
cost: {
|
|
8
|
+
__typename?: "CartLineCost" | undefined;
|
|
9
9
|
} & {
|
|
10
10
|
totalAmount: {
|
|
11
11
|
__typename?: "MoneyV2" | undefined;
|
|
12
12
|
} & Pick<import("../../storefront-api-types").MoneyV2, "currencyCode" | "amount">;
|
|
13
|
-
|
|
13
|
+
compareAtAmountPerQuantity?: import("../../storefront-api-types").Maybe<{
|
|
14
14
|
__typename?: "MoneyV2" | undefined;
|
|
15
15
|
} & Pick<import("../../storefront-api-types").MoneyV2, "currencyCode" | "amount">> | undefined;
|
|
16
16
|
};
|
|
@@ -35,14 +35,21 @@ function cartReducer(state, action) {
|
|
|
35
35
|
break;
|
|
36
36
|
}
|
|
37
37
|
case 'reject': {
|
|
38
|
+
if (action.errors) {
|
|
39
|
+
console.group('%cCart Error:', 'color:red');
|
|
40
|
+
for (const [i, error] of action.errors.entries()) {
|
|
41
|
+
console.log(`%c${i + 1}. ` + error.message, 'color:red');
|
|
42
|
+
}
|
|
43
|
+
console.groupEnd();
|
|
44
|
+
}
|
|
38
45
|
if (state.status === 'fetching' || state.status === 'creating') {
|
|
39
|
-
return { status: 'uninitialized', error: action.
|
|
46
|
+
return { status: 'uninitialized', error: action.errors };
|
|
40
47
|
}
|
|
41
48
|
else if (state.status === 'updating') {
|
|
42
49
|
return {
|
|
43
50
|
status: 'idle',
|
|
44
51
|
cart: state.lastValidCart,
|
|
45
|
-
error: action.
|
|
52
|
+
error: action.errors,
|
|
46
53
|
};
|
|
47
54
|
}
|
|
48
55
|
break;
|
|
@@ -151,13 +158,16 @@ function cartReducer(state, action) {
|
|
|
151
158
|
* You must use this component if you want to use the `useCart` hook or related hooks, or if you would like to use the `AddToCartButton` component.
|
|
152
159
|
*/
|
|
153
160
|
export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLineRemove, onLineUpdate, onNoteUpdate, onBuyerIdentityUpdate, onAttributesUpdate, onDiscountCodesUpdate, data: cart, cartFragment = defaultCartFragment, customerAccessToken, countryCode = CountryCode.Us, }) {
|
|
161
|
+
if (countryCode)
|
|
162
|
+
countryCode = countryCode.toUpperCase();
|
|
154
163
|
const initialStatus = cart
|
|
155
164
|
? { status: 'idle', cart: cartFromGraphQL(cart) }
|
|
156
165
|
: { status: 'uninitialized' };
|
|
157
166
|
const [state, dispatch] = useReducer((state, dispatch) => cartReducer(state, dispatch), initialStatus);
|
|
158
167
|
const fetchCart = useCartFetch();
|
|
159
168
|
const countryChanged = state.status === 'idle' &&
|
|
160
|
-
countryCode !== state?.cart?.buyerIdentity?.countryCode
|
|
169
|
+
countryCode !== state?.cart?.buyerIdentity?.countryCode &&
|
|
170
|
+
!state.error;
|
|
161
171
|
const cartFetch = useCallback(async (cartId) => {
|
|
162
172
|
dispatch({ type: 'cartFetch' });
|
|
163
173
|
const { data } = await fetchCart({
|
|
@@ -190,7 +200,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
190
200
|
}
|
|
191
201
|
cart.buyerIdentity.customerAccessToken = customerAccessToken;
|
|
192
202
|
}
|
|
193
|
-
const { data,
|
|
203
|
+
const { data, errors } = await fetchCart({
|
|
194
204
|
query: CartCreate(cartFragment),
|
|
195
205
|
variables: {
|
|
196
206
|
input: cart,
|
|
@@ -198,10 +208,10 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
198
208
|
country: countryCode,
|
|
199
209
|
},
|
|
200
210
|
});
|
|
201
|
-
if (
|
|
211
|
+
if (errors) {
|
|
202
212
|
dispatch({
|
|
203
213
|
type: 'reject',
|
|
204
|
-
|
|
214
|
+
errors,
|
|
205
215
|
});
|
|
206
216
|
}
|
|
207
217
|
if (data?.cartCreate?.cart) {
|
|
@@ -229,7 +239,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
229
239
|
if (state.status === 'idle') {
|
|
230
240
|
dispatch({ type: 'addLineItem' });
|
|
231
241
|
onLineAdd?.();
|
|
232
|
-
const { data,
|
|
242
|
+
const { data, errors } = await fetchCart({
|
|
233
243
|
query: CartLineAdd(cartFragment),
|
|
234
244
|
variables: {
|
|
235
245
|
cartId: state.cart.id,
|
|
@@ -238,10 +248,10 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
238
248
|
country: countryCode,
|
|
239
249
|
},
|
|
240
250
|
});
|
|
241
|
-
if (
|
|
251
|
+
if (errors) {
|
|
242
252
|
dispatch({
|
|
243
253
|
type: 'reject',
|
|
244
|
-
|
|
254
|
+
errors,
|
|
245
255
|
});
|
|
246
256
|
}
|
|
247
257
|
if (data?.cartLinesAdd?.cart) {
|
|
@@ -260,7 +270,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
260
270
|
if (state.status === 'idle') {
|
|
261
271
|
dispatch({ type: 'removeLineItem', lines });
|
|
262
272
|
onLineRemove?.();
|
|
263
|
-
const { data,
|
|
273
|
+
const { data, errors } = await fetchCart({
|
|
264
274
|
query: CartLineRemove(cartFragment),
|
|
265
275
|
variables: {
|
|
266
276
|
cartId: state.cart.id,
|
|
@@ -269,10 +279,10 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
269
279
|
country: countryCode,
|
|
270
280
|
},
|
|
271
281
|
});
|
|
272
|
-
if (
|
|
282
|
+
if (errors) {
|
|
273
283
|
dispatch({
|
|
274
284
|
type: 'reject',
|
|
275
|
-
|
|
285
|
+
errors,
|
|
276
286
|
});
|
|
277
287
|
}
|
|
278
288
|
if (data?.cartLinesRemove?.cart) {
|
|
@@ -291,7 +301,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
291
301
|
if (state.status === 'idle') {
|
|
292
302
|
dispatch({ type: 'updateLineItem', lines });
|
|
293
303
|
onLineUpdate?.();
|
|
294
|
-
const { data,
|
|
304
|
+
const { data, errors } = await fetchCart({
|
|
295
305
|
query: CartLineUpdate(cartFragment),
|
|
296
306
|
variables: {
|
|
297
307
|
cartId: state.cart.id,
|
|
@@ -300,10 +310,10 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
300
310
|
country: countryCode,
|
|
301
311
|
},
|
|
302
312
|
});
|
|
303
|
-
if (
|
|
313
|
+
if (errors) {
|
|
304
314
|
dispatch({
|
|
305
315
|
type: 'reject',
|
|
306
|
-
|
|
316
|
+
errors,
|
|
307
317
|
});
|
|
308
318
|
}
|
|
309
319
|
if (data?.cartLinesUpdate?.cart) {
|
|
@@ -322,7 +332,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
322
332
|
if (state.status === 'idle') {
|
|
323
333
|
dispatch({ type: 'noteUpdate' });
|
|
324
334
|
onNoteUpdate?.();
|
|
325
|
-
const { data,
|
|
335
|
+
const { data, errors } = await fetchCart({
|
|
326
336
|
query: CartNoteUpdate(cartFragment),
|
|
327
337
|
variables: {
|
|
328
338
|
cartId: state.cart.id,
|
|
@@ -331,10 +341,10 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
331
341
|
country: countryCode,
|
|
332
342
|
},
|
|
333
343
|
});
|
|
334
|
-
if (
|
|
344
|
+
if (errors) {
|
|
335
345
|
dispatch({
|
|
336
346
|
type: 'reject',
|
|
337
|
-
|
|
347
|
+
errors,
|
|
338
348
|
});
|
|
339
349
|
}
|
|
340
350
|
if (data?.cartNoteUpdate?.cart) {
|
|
@@ -349,7 +359,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
349
359
|
if (state.status === 'idle') {
|
|
350
360
|
dispatch({ type: 'buyerIdentityUpdate' });
|
|
351
361
|
onBuyerIdentityUpdate?.();
|
|
352
|
-
const { data,
|
|
362
|
+
const { data, errors } = await fetchCart({
|
|
353
363
|
query: CartBuyerIdentityUpdate(cartFragment),
|
|
354
364
|
variables: {
|
|
355
365
|
cartId: state.cart.id,
|
|
@@ -358,10 +368,10 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
358
368
|
country: countryCode,
|
|
359
369
|
},
|
|
360
370
|
});
|
|
361
|
-
if (
|
|
371
|
+
if (errors) {
|
|
362
372
|
dispatch({
|
|
363
373
|
type: 'reject',
|
|
364
|
-
|
|
374
|
+
errors,
|
|
365
375
|
});
|
|
366
376
|
}
|
|
367
377
|
if (data?.cartBuyerIdentityUpdate?.cart) {
|
|
@@ -376,7 +386,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
376
386
|
if (state.status === 'idle') {
|
|
377
387
|
dispatch({ type: 'cartAttributesUpdate' });
|
|
378
388
|
onAttributesUpdate?.();
|
|
379
|
-
const { data,
|
|
389
|
+
const { data, errors } = await fetchCart({
|
|
380
390
|
query: CartAttributesUpdate(cartFragment),
|
|
381
391
|
variables: {
|
|
382
392
|
cartId: state.cart.id,
|
|
@@ -385,10 +395,10 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
385
395
|
country: countryCode,
|
|
386
396
|
},
|
|
387
397
|
});
|
|
388
|
-
if (
|
|
398
|
+
if (errors) {
|
|
389
399
|
dispatch({
|
|
390
400
|
type: 'reject',
|
|
391
|
-
|
|
401
|
+
errors,
|
|
392
402
|
});
|
|
393
403
|
}
|
|
394
404
|
if (data?.cartAttributesUpdate?.cart) {
|
|
@@ -403,7 +413,7 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
403
413
|
if (state.status === 'idle') {
|
|
404
414
|
dispatch({ type: 'discountCodesUpdate' });
|
|
405
415
|
onDiscountCodesUpdate?.();
|
|
406
|
-
const { data,
|
|
416
|
+
const { data, errors } = await fetchCart({
|
|
407
417
|
query: CartDiscountCodesUpdate(cartFragment),
|
|
408
418
|
variables: {
|
|
409
419
|
cartId: state.cart.id,
|
|
@@ -412,10 +422,10 @@ export function CartProvider({ children, numCartLines, onCreate, onLineAdd, onLi
|
|
|
412
422
|
country: countryCode,
|
|
413
423
|
},
|
|
414
424
|
});
|
|
415
|
-
if (
|
|
425
|
+
if (errors) {
|
|
416
426
|
dispatch({
|
|
417
427
|
type: 'reject',
|
|
418
|
-
|
|
428
|
+
errors,
|
|
419
429
|
});
|
|
420
430
|
}
|
|
421
431
|
if (data?.cartDiscountCodesUpdate?.cart) {
|
|
@@ -7,4 +7,4 @@ export declare const CartBuyerIdentityUpdate: (cartFragment: string) => string;
|
|
|
7
7
|
export declare const CartAttributesUpdate: (cartFragment: string) => string;
|
|
8
8
|
export declare const CartDiscountCodesUpdate: (cartFragment: string) => string;
|
|
9
9
|
export declare const CartQuery: (cartFragment: string) => string;
|
|
10
|
-
export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n
|
|
10
|
+
export declare const defaultCartFragment = "\nfragment CartFragment on Cart {\n id\n checkoutUrl\n totalQuantity\n buyerIdentity {\n countryCode\n customer {\n id\n email\n firstName\n lastName\n displayName\n }\n email\n phone\n }\n lines(first: $numCartLines) {\n edges {\n node {\n id\n quantity\n attributes {\n key\n value\n }\n cost {\n totalAmount {\n amount\n currencyCode\n }\n compareAtAmountPerQuantity {\n amount\n currencyCode\n }\n }\n merchandise {\n ... on ProductVariant {\n id\n availableForSale\n compareAtPriceV2 {\n ...MoneyFragment\n }\n priceV2 {\n ...MoneyFragment\n }\n requiresShipping\n title\n image {\n ...ImageFragment\n }\n product {\n handle\n title\n }\n selectedOptions {\n name\n value\n }\n }\n }\n }\n }\n }\n cost {\n subtotalAmount {\n ...MoneyFragment\n }\n totalAmount {\n ...MoneyFragment\n }\n totalDutyAmount {\n ...MoneyFragment\n }\n totalTaxAmount {\n ...MoneyFragment\n }\n }\n note\n attributes {\n key\n value\n }\n discountCodes {\n code\n }\n}\n\nfragment MoneyFragment on MoneyV2 {\n currencyCode\n amount\n}\nfragment ImageFragment on Image {\n id\n url\n altText\n width\n height\n}\n";
|
|
@@ -126,12 +126,12 @@ fragment CartFragment on Cart {
|
|
|
126
126
|
key
|
|
127
127
|
value
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
cost {
|
|
130
130
|
totalAmount {
|
|
131
131
|
amount
|
|
132
132
|
currencyCode
|
|
133
133
|
}
|
|
134
|
-
|
|
134
|
+
compareAtAmountPerQuantity {
|
|
135
135
|
amount
|
|
136
136
|
currencyCode
|
|
137
137
|
}
|
|
@@ -164,7 +164,7 @@ fragment CartFragment on Cart {
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
|
-
|
|
167
|
+
cost {
|
|
168
168
|
subtotalAmount {
|
|
169
169
|
...MoneyFragment
|
|
170
170
|
}
|
|
@@ -37,13 +37,13 @@ export declare type CartAttributesUpdateMutation = {
|
|
|
37
37
|
attributes: Array<{
|
|
38
38
|
__typename?: 'Attribute';
|
|
39
39
|
} & Pick<Types.Attribute, 'key' | 'value'>>;
|
|
40
|
-
|
|
41
|
-
__typename?: '
|
|
40
|
+
cost: {
|
|
41
|
+
__typename?: 'CartLineCost';
|
|
42
42
|
} & {
|
|
43
43
|
totalAmount: {
|
|
44
44
|
__typename?: 'MoneyV2';
|
|
45
45
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
|
|
46
|
-
|
|
46
|
+
compareAtAmountPerQuantity?: Types.Maybe<{
|
|
47
47
|
__typename?: 'MoneyV2';
|
|
48
48
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
|
|
49
49
|
};
|
|
@@ -69,8 +69,8 @@ export declare type CartAttributesUpdateMutation = {
|
|
|
69
69
|
};
|
|
70
70
|
}>;
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
__typename?: '
|
|
72
|
+
cost: {
|
|
73
|
+
__typename?: 'CartCost';
|
|
74
74
|
} & {
|
|
75
75
|
subtotalAmount: {
|
|
76
76
|
__typename?: 'MoneyV2';
|
|
@@ -37,13 +37,13 @@ export declare type CartBuyerIdentityUpdateMutation = {
|
|
|
37
37
|
attributes: Array<{
|
|
38
38
|
__typename?: 'Attribute';
|
|
39
39
|
} & Pick<Types.Attribute, 'key' | 'value'>>;
|
|
40
|
-
|
|
41
|
-
__typename?: '
|
|
40
|
+
cost: {
|
|
41
|
+
__typename?: 'CartLineCost';
|
|
42
42
|
} & {
|
|
43
43
|
totalAmount: {
|
|
44
44
|
__typename?: 'MoneyV2';
|
|
45
45
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
|
|
46
|
-
|
|
46
|
+
compareAtAmountPerQuantity?: Types.Maybe<{
|
|
47
47
|
__typename?: 'MoneyV2';
|
|
48
48
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
|
|
49
49
|
};
|
|
@@ -69,8 +69,8 @@ export declare type CartBuyerIdentityUpdateMutation = {
|
|
|
69
69
|
};
|
|
70
70
|
}>;
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
__typename?: '
|
|
72
|
+
cost: {
|
|
73
|
+
__typename?: 'CartCost';
|
|
74
74
|
} & {
|
|
75
75
|
subtotalAmount: {
|
|
76
76
|
__typename?: 'MoneyV2';
|
|
@@ -36,13 +36,13 @@ export declare type CartCreateMutation = {
|
|
|
36
36
|
attributes: Array<{
|
|
37
37
|
__typename?: 'Attribute';
|
|
38
38
|
} & Pick<Types.Attribute, 'key' | 'value'>>;
|
|
39
|
-
|
|
40
|
-
__typename?: '
|
|
39
|
+
cost: {
|
|
40
|
+
__typename?: 'CartLineCost';
|
|
41
41
|
} & {
|
|
42
42
|
totalAmount: {
|
|
43
43
|
__typename?: 'MoneyV2';
|
|
44
44
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
|
|
45
|
-
|
|
45
|
+
compareAtAmountPerQuantity?: Types.Maybe<{
|
|
46
46
|
__typename?: 'MoneyV2';
|
|
47
47
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
|
|
48
48
|
};
|
|
@@ -68,8 +68,8 @@ export declare type CartCreateMutation = {
|
|
|
68
68
|
};
|
|
69
69
|
}>;
|
|
70
70
|
};
|
|
71
|
-
|
|
72
|
-
__typename?: '
|
|
71
|
+
cost: {
|
|
72
|
+
__typename?: 'CartCost';
|
|
73
73
|
} & {
|
|
74
74
|
subtotalAmount: {
|
|
75
75
|
__typename?: 'MoneyV2';
|
|
@@ -37,13 +37,13 @@ export declare type CartDiscountCodesUpdateMutation = {
|
|
|
37
37
|
attributes: Array<{
|
|
38
38
|
__typename?: 'Attribute';
|
|
39
39
|
} & Pick<Types.Attribute, 'key' | 'value'>>;
|
|
40
|
-
|
|
41
|
-
__typename?: '
|
|
40
|
+
cost: {
|
|
41
|
+
__typename?: 'CartLineCost';
|
|
42
42
|
} & {
|
|
43
43
|
totalAmount: {
|
|
44
44
|
__typename?: 'MoneyV2';
|
|
45
45
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
|
|
46
|
-
|
|
46
|
+
compareAtAmountPerQuantity?: Types.Maybe<{
|
|
47
47
|
__typename?: 'MoneyV2';
|
|
48
48
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
|
|
49
49
|
};
|
|
@@ -69,8 +69,8 @@ export declare type CartDiscountCodesUpdateMutation = {
|
|
|
69
69
|
};
|
|
70
70
|
}>;
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
__typename?: '
|
|
72
|
+
cost: {
|
|
73
|
+
__typename?: 'CartCost';
|
|
74
74
|
} & {
|
|
75
75
|
subtotalAmount: {
|
|
76
76
|
__typename?: 'MoneyV2';
|
|
@@ -25,13 +25,13 @@ export declare type CartFragmentFragment = {
|
|
|
25
25
|
attributes: Array<{
|
|
26
26
|
__typename?: 'Attribute';
|
|
27
27
|
} & Pick<Types.Attribute, 'key' | 'value'>>;
|
|
28
|
-
|
|
29
|
-
__typename?: '
|
|
28
|
+
cost: {
|
|
29
|
+
__typename?: 'CartLineCost';
|
|
30
30
|
} & {
|
|
31
31
|
totalAmount: {
|
|
32
32
|
__typename?: 'MoneyV2';
|
|
33
33
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
|
|
34
|
-
|
|
34
|
+
compareAtAmountPerQuantity?: Types.Maybe<{
|
|
35
35
|
__typename?: 'MoneyV2';
|
|
36
36
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
|
|
37
37
|
};
|
|
@@ -57,8 +57,8 @@ export declare type CartFragmentFragment = {
|
|
|
57
57
|
};
|
|
58
58
|
}>;
|
|
59
59
|
};
|
|
60
|
-
|
|
61
|
-
__typename?: '
|
|
60
|
+
cost: {
|
|
61
|
+
__typename?: 'CartCost';
|
|
62
62
|
} & {
|
|
63
63
|
subtotalAmount: {
|
|
64
64
|
__typename?: 'MoneyV2';
|
|
@@ -37,13 +37,13 @@ export declare type CartLineAddMutation = {
|
|
|
37
37
|
attributes: Array<{
|
|
38
38
|
__typename?: 'Attribute';
|
|
39
39
|
} & Pick<Types.Attribute, 'key' | 'value'>>;
|
|
40
|
-
|
|
41
|
-
__typename?: '
|
|
40
|
+
cost: {
|
|
41
|
+
__typename?: 'CartLineCost';
|
|
42
42
|
} & {
|
|
43
43
|
totalAmount: {
|
|
44
44
|
__typename?: 'MoneyV2';
|
|
45
45
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
|
|
46
|
-
|
|
46
|
+
compareAtAmountPerQuantity?: Types.Maybe<{
|
|
47
47
|
__typename?: 'MoneyV2';
|
|
48
48
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
|
|
49
49
|
};
|
|
@@ -69,8 +69,8 @@ export declare type CartLineAddMutation = {
|
|
|
69
69
|
};
|
|
70
70
|
}>;
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
__typename?: '
|
|
72
|
+
cost: {
|
|
73
|
+
__typename?: 'CartCost';
|
|
74
74
|
} & {
|
|
75
75
|
subtotalAmount: {
|
|
76
76
|
__typename?: 'MoneyV2';
|
|
@@ -37,13 +37,13 @@ export declare type CartLineRemoveMutation = {
|
|
|
37
37
|
attributes: Array<{
|
|
38
38
|
__typename?: 'Attribute';
|
|
39
39
|
} & Pick<Types.Attribute, 'key' | 'value'>>;
|
|
40
|
-
|
|
41
|
-
__typename?: '
|
|
40
|
+
cost: {
|
|
41
|
+
__typename?: 'CartLineCost';
|
|
42
42
|
} & {
|
|
43
43
|
totalAmount: {
|
|
44
44
|
__typename?: 'MoneyV2';
|
|
45
45
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>;
|
|
46
|
-
|
|
46
|
+
compareAtAmountPerQuantity?: Types.Maybe<{
|
|
47
47
|
__typename?: 'MoneyV2';
|
|
48
48
|
} & Pick<Types.MoneyV2, 'amount' | 'currencyCode'>>;
|
|
49
49
|
};
|
|
@@ -69,8 +69,8 @@ export declare type CartLineRemoveMutation = {
|
|
|
69
69
|
};
|
|
70
70
|
}>;
|
|
71
71
|
};
|
|
72
|
-
|
|
73
|
-
__typename?: '
|
|
72
|
+
cost: {
|
|
73
|
+
__typename?: 'CartCost';
|
|
74
74
|
} & {
|
|
75
75
|
subtotalAmount: {
|
|
76
76
|
__typename?: 'MoneyV2';
|