@graphcommerce/magento-cart 9.0.0-canary.98 → 9.0.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 +103 -1083
- package/Config.graphqls +7 -0
- package/components/ApolloCartError/ApolloCartErrorAlert.tsx +2 -4
- package/components/ApolloCartError/ApolloCartErrorFullPage.tsx +3 -5
- package/components/ApolloCartError/ApolloCartErrorSnackbar.tsx +2 -4
- package/components/CartAddressMultiLine/CartAddressMultiLine.tsx +1 -1
- package/components/CartAddressSingleLine/CartAddressSingleLine.tsx +2 -1
- package/components/CartAgreementsForm/CartAgreementsForm.tsx +7 -10
- package/components/CartFab/CartFab.tsx +11 -8
- package/components/CartItemSummary/CartItemSummary.tsx +9 -7
- package/components/CartStartCheckout/CartStartCheckout.tsx +4 -3
- package/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx +4 -3
- package/components/CartSummary/CartSummary.tsx +6 -5
- package/components/CartTotals/CartTotals.tsx +5 -4
- package/components/EmptyCart/EmptyCart.tsx +5 -8
- package/components/InlineAccount/InlineAccount.tsx +4 -7
- package/hooks/useAssignCurrentCartId.ts +2 -1
- package/hooks/useCartQuery.ts +4 -8
- package/hooks/useCurrentCartId.ts +4 -6
- package/hooks/useFormGqlMutationCart.ts +4 -8
- package/hooks/useMergeCustomerCart.ts +1 -0
- package/index.ts +0 -1
- package/link/cartLink.ts +8 -5
- package/package.json +16 -16
- package/plugins/CartDebuggerPlugin.tsx +42 -0
- package/plugins/MagentoCartGraphqlProvider.tsx +2 -2
- package/plugins/useSignInFormMergeCart.ts +2 -2
- package/test/fillCartAgreementsForm.ts +2 -2
- package/typePolicies.ts +13 -8
- package/utils/cartPermissions.ts +4 -0
- package/components/CartDebugger/CartDebugger.tsx +0 -30
package/Config.graphqls
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
ApolloCustomerErrorAlertProps,
|
|
4
|
-
} from '@graphcommerce/magento-customer'
|
|
1
|
+
import type { ApolloCustomerErrorAlertProps } from '@graphcommerce/magento-customer'
|
|
2
|
+
import { ApolloCustomerErrorAlert } from '@graphcommerce/magento-customer'
|
|
5
3
|
|
|
6
4
|
export type ApolloCartErrorAlertProps = ApolloCustomerErrorAlertProps
|
|
7
5
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from '@graphcommerce/magento-customer'
|
|
5
|
-
import { iconShoppingBag, IconSvg } from '@graphcommerce/next-ui'
|
|
1
|
+
import type { ApolloCustomerErrorFullPageProps } from '@graphcommerce/magento-customer'
|
|
2
|
+
import { ApolloCustomerErrorFullPage } from '@graphcommerce/magento-customer'
|
|
3
|
+
import { IconSvg, iconShoppingBag } from '@graphcommerce/next-ui'
|
|
6
4
|
|
|
7
5
|
export type ApolloCartErrorFullPageProps = Omit<ApolloCustomerErrorFullPageProps, 'icon'>
|
|
8
6
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
ApolloCustomerErrorSnackbarProps,
|
|
4
|
-
} from '@graphcommerce/magento-customer'
|
|
1
|
+
import type { ApolloCustomerErrorSnackbarProps } from '@graphcommerce/magento-customer'
|
|
2
|
+
import { ApolloCustomerErrorSnackbar } from '@graphcommerce/magento-customer'
|
|
5
3
|
|
|
6
4
|
export type ApolloCartErrorSnackbarProps = ApolloCustomerErrorSnackbarProps
|
|
7
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CountryCodeEnum } from '@graphcommerce/graphql-mesh'
|
|
2
2
|
import { AddressMultiLine } from '@graphcommerce/magento-customer'
|
|
3
3
|
import React from 'react'
|
|
4
|
-
import { CartAddressFragment } from '../CartAddress/CartAddress.gql'
|
|
4
|
+
import type { CartAddressFragment } from '../CartAddress/CartAddress.gql'
|
|
5
5
|
|
|
6
6
|
export type CartAddressMultiLineProps = Partial<CartAddressFragment>
|
|
7
7
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { CountryCodeEnum } from '@graphcommerce/graphql-mesh'
|
|
2
2
|
import { AddressSingleLine } from '@graphcommerce/magento-customer'
|
|
3
3
|
import React from 'react'
|
|
4
|
-
import { CartAddressFragment } from '../CartAddress/CartAddress.gql'
|
|
4
|
+
import type { CartAddressFragment } from '../CartAddress/CartAddress.gql'
|
|
5
5
|
|
|
6
6
|
export type CartAddressSingleLineProps = CartAddressFragment & { locale?: CountryCodeEnum }
|
|
7
7
|
|
|
8
|
+
/** @public */
|
|
8
9
|
export function CartAddressSingleLine(props: CartAddressSingleLineProps) {
|
|
9
10
|
const { locale } = props
|
|
10
11
|
return <AddressSingleLine {...props} country_code={locale} />
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { CheckboxElement } from '@graphcommerce/ecommerce-ui'
|
|
2
2
|
import { useQuery } from '@graphcommerce/graphql'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
useForm,
|
|
7
|
-
useFormCompose,
|
|
8
|
-
UseFormComposeOptions,
|
|
9
|
-
} from '@graphcommerce/react-hook-form'
|
|
3
|
+
import { FormDiv, extendableComponent } from '@graphcommerce/next-ui'
|
|
4
|
+
import type { UseFormComposeOptions } from '@graphcommerce/react-hook-form'
|
|
5
|
+
import { FormPersist, useForm, useFormCompose } from '@graphcommerce/react-hook-form'
|
|
10
6
|
import { i18n } from '@lingui/core'
|
|
11
|
-
import {
|
|
7
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
8
|
+
import { Box, Link, Typography } from '@mui/material'
|
|
12
9
|
import React from 'react'
|
|
13
10
|
import { CartAgreementsDocument } from './CartAgreements.gql'
|
|
14
11
|
|
|
15
12
|
export type CartAgreementsFormProps = Pick<UseFormComposeOptions, 'step'> & { sx?: SxProps<Theme> }
|
|
16
13
|
|
|
17
|
-
const componentName = 'CartAgreementsForm'
|
|
14
|
+
const componentName = 'CartAgreementsForm'
|
|
18
15
|
const parts = ['form', 'formInner', 'formControlRoot', 'manualCheck'] as const
|
|
19
16
|
const { classes } = extendableComponent(componentName, parts)
|
|
20
17
|
|
|
@@ -117,7 +114,7 @@ export function CartAgreementsForm(props: CartAgreementsFormProps) {
|
|
|
117
114
|
label={labelContent}
|
|
118
115
|
/>
|
|
119
116
|
) : (
|
|
120
|
-
<Box className={classes.manualCheck} sx={{ padding:
|
|
117
|
+
<Box className={classes.manualCheck} sx={{ padding: '9px 0' }}>
|
|
121
118
|
{labelContent}
|
|
122
119
|
</Box>
|
|
123
120
|
)}
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
import { WaitForQueries } from '@graphcommerce/ecommerce-ui'
|
|
2
2
|
import {
|
|
3
|
-
extendableComponent,
|
|
4
|
-
iconShoppingBag,
|
|
5
3
|
DesktopHeaderBadge,
|
|
6
4
|
IconSvg,
|
|
7
|
-
|
|
5
|
+
extendableComponent,
|
|
6
|
+
iconShoppingBag,
|
|
8
7
|
useFabSize,
|
|
8
|
+
useScrollY,
|
|
9
9
|
} from '@graphcommerce/next-ui'
|
|
10
10
|
import { i18n } from '@lingui/core'
|
|
11
|
-
import {
|
|
11
|
+
import type { BadgeProps, FabProps, SxProps, Theme } from '@mui/material'
|
|
12
|
+
import { Box, Fab, alpha, styled, useTheme } from '@mui/material'
|
|
12
13
|
import { m, useTransform } from 'framer-motion'
|
|
13
14
|
import React from 'react'
|
|
14
15
|
import { useCartEnabled, useCartShouldLoginToContinue } from '../../hooks'
|
|
15
16
|
import { useCartQuery } from '../../hooks/useCartQuery'
|
|
16
17
|
import { CartFabDocument } from './CartFab.gql'
|
|
17
|
-
import { CartTotalQuantityFragment } from './CartTotalQuantity.gql'
|
|
18
|
+
import type { CartTotalQuantityFragment } from './CartTotalQuantity.gql'
|
|
18
19
|
|
|
19
20
|
export type CartFabProps = {
|
|
20
21
|
icon?: React.ReactNode
|
|
21
22
|
sx?: SxProps<Theme>
|
|
23
|
+
BadgeProps?: BadgeProps
|
|
22
24
|
} & Pick<FabProps, 'color' | 'size' | 'variant'>
|
|
23
25
|
|
|
24
|
-
type CartFabContentProps = CartFabProps & CartTotalQuantityFragment
|
|
26
|
+
export type CartFabContentProps = CartFabProps & CartTotalQuantityFragment
|
|
25
27
|
|
|
26
28
|
const MotionDiv = styled(m.div)({})
|
|
27
29
|
|
|
28
|
-
const MotionFab = m(
|
|
30
|
+
const MotionFab = m.create(
|
|
29
31
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
32
|
React.forwardRef<any, Omit<FabProps, 'style' | 'onDrag'>>((props, ref) => (
|
|
31
33
|
<Fab {...props} ref={ref} />
|
|
@@ -35,7 +37,7 @@ const MotionFab = m(
|
|
|
35
37
|
const { classes } = extendableComponent('CartFab', ['root', 'cart', 'shadow'] as const)
|
|
36
38
|
|
|
37
39
|
function CartFabContent(props: CartFabContentProps) {
|
|
38
|
-
const { total_quantity, icon, sx = [], ...fabProps } = props
|
|
40
|
+
const { total_quantity, icon, sx = [], BadgeProps, ...fabProps } = props
|
|
39
41
|
|
|
40
42
|
const theme2 = useTheme()
|
|
41
43
|
const scrollY = useScrollY()
|
|
@@ -75,6 +77,7 @@ function CartFabContent(props: CartFabContentProps) {
|
|
|
75
77
|
variant='dot'
|
|
76
78
|
overlap='circular'
|
|
77
79
|
badgeContent={total_quantity}
|
|
80
|
+
{...BadgeProps}
|
|
78
81
|
>
|
|
79
82
|
{cartIcon}
|
|
80
83
|
</DesktopHeaderBadge>
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CartItemActionCardProps } from '@graphcommerce/magento-cart-items'
|
|
2
|
+
import { CartItemActionCard } from '@graphcommerce/magento-cart-items'
|
|
3
|
+
import type { ActionCardLayoutProps } from '@graphcommerce/next-ui'
|
|
2
4
|
import {
|
|
5
|
+
ActionCardLayout,
|
|
3
6
|
SectionContainer,
|
|
4
|
-
extendableComponent,
|
|
5
7
|
breakpointVal,
|
|
8
|
+
extendableComponent,
|
|
6
9
|
nonNullable,
|
|
7
|
-
ActionCardLayoutProps,
|
|
8
|
-
ActionCardLayout,
|
|
9
10
|
} from '@graphcommerce/next-ui'
|
|
10
11
|
import { Trans } from '@lingui/react'
|
|
11
|
-
import {
|
|
12
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
13
|
+
import { Box, Divider } from '@mui/material'
|
|
12
14
|
import { useCartQuery } from '../../hooks'
|
|
13
15
|
import { CartTotals } from '../CartTotals/CartTotals'
|
|
14
16
|
import { CartItemSummaryDocument } from './GetCartItemSummary.gql'
|
|
15
17
|
|
|
16
|
-
const name = 'CartItemSummary'
|
|
18
|
+
const name = 'CartItemSummary'
|
|
17
19
|
const parts = [
|
|
18
20
|
'root',
|
|
19
21
|
'imageScrollerContainer',
|
|
@@ -28,7 +30,7 @@ const parts = [
|
|
|
28
30
|
] as const
|
|
29
31
|
const { classes } = extendableComponent(name, parts)
|
|
30
32
|
|
|
31
|
-
type OrderSummaryProps = ActionCardLayoutProps & {
|
|
33
|
+
export type OrderSummaryProps = ActionCardLayoutProps & {
|
|
32
34
|
sx?: SxProps<Theme>
|
|
33
35
|
itemProps?: Omit<
|
|
34
36
|
CartItemActionCardProps,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Money } from '@graphcommerce/magento-store'
|
|
2
|
-
import {
|
|
2
|
+
import { IconSvg, extendableComponent, iconChevronRight } from '@graphcommerce/next-ui'
|
|
3
3
|
import { Trans } from '@lingui/macro'
|
|
4
|
-
import {
|
|
4
|
+
import type { ButtonProps, SxProps, Theme } from '@mui/material'
|
|
5
|
+
import { Box, Button, Link } from '@mui/material'
|
|
5
6
|
import React from 'react'
|
|
6
7
|
import { useCheckoutShouldLoginToContinue } from '../../hooks'
|
|
7
|
-
import { CartStartCheckoutFragment } from './CartStartCheckout.gql'
|
|
8
|
+
import type { CartStartCheckoutFragment } from './CartStartCheckout.gql'
|
|
8
9
|
|
|
9
10
|
export type CartStartCheckoutProps = {
|
|
10
11
|
children?: React.ReactNode
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LinkOrButtonProps } from '@graphcommerce/next-ui'
|
|
2
|
+
import { IconSvg, LinkOrButton, iconChevronRight } from '@graphcommerce/next-ui'
|
|
2
3
|
import { Trans } from '@lingui/react'
|
|
3
|
-
import { SxProps, Theme } from '@mui/material'
|
|
4
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
4
5
|
import React from 'react'
|
|
5
6
|
import { useCheckoutShouldLoginToContinue } from '../../hooks'
|
|
6
|
-
import { CartStartCheckoutFragment } from './CartStartCheckout.gql'
|
|
7
|
+
import type { CartStartCheckoutFragment } from './CartStartCheckout.gql'
|
|
7
8
|
|
|
8
9
|
export type CartStartCheckoutLinkOrButtonProps = {
|
|
9
10
|
children?: React.ReactNode
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useHistoryLink } from '@graphcommerce/framer-next-pages'
|
|
2
|
-
import { SectionContainer,
|
|
2
|
+
import { SectionContainer, breakpointVal, extendableComponent } from '@graphcommerce/next-ui'
|
|
3
3
|
import { Trans } from '@lingui/react'
|
|
4
|
-
import {
|
|
4
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
5
|
+
import { Box, Link, Typography, lighten } from '@mui/material'
|
|
5
6
|
import React from 'react'
|
|
6
7
|
import { useCartQuery } from '../../hooks'
|
|
7
8
|
import { CartAddressMultiLine } from '../CartAddressMultiLine/CartAddressMultiLine'
|
|
@@ -14,7 +15,7 @@ export type CartSummaryProps = {
|
|
|
14
15
|
|
|
15
16
|
type OwnerState = { editable?: boolean }
|
|
16
17
|
|
|
17
|
-
const compName = 'CartSummary'
|
|
18
|
+
const compName = 'CartSummary'
|
|
18
19
|
const parts = ['root', 'detailsContainer', 'sectionHeaderWrapper'] as const
|
|
19
20
|
const { classes } = extendableComponent<OwnerState, typeof compName, typeof parts>(compName, parts)
|
|
20
21
|
|
|
@@ -77,9 +78,9 @@ export function CartSummary(props: CartSummaryProps) {
|
|
|
77
78
|
padding: theme.spacings.sm,
|
|
78
79
|
gridColumnGap: theme.spacings.xxl,
|
|
79
80
|
gridRowGap: theme.spacings.sm,
|
|
80
|
-
display:
|
|
81
|
+
display: 'grid',
|
|
81
82
|
[theme.breakpoints.up('sm')]: {
|
|
82
|
-
gridTemplateColumns:
|
|
83
|
+
gridTemplateColumns: '1fr 1fr',
|
|
83
84
|
marginTop: theme.spacings.xxs,
|
|
84
85
|
},
|
|
85
86
|
})}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Money } from '@graphcommerce/magento-store'
|
|
2
|
-
import {
|
|
2
|
+
import { breakpointVal, extendableComponent } from '@graphcommerce/next-ui'
|
|
3
3
|
import { Trans } from '@lingui/react'
|
|
4
|
-
import {
|
|
4
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
5
|
+
import { Box, Divider, lighten } from '@mui/material'
|
|
5
6
|
import { useCartQuery, useDisplayInclTax } from '../../hooks'
|
|
6
7
|
import { GetCartTotalsDocument } from './GetCartTotals.gql'
|
|
7
8
|
|
|
@@ -12,7 +13,7 @@ export type CartTotalsProps = OwnerProps & {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
type OwnerProps = { containerMargin?: boolean }
|
|
15
|
-
const name = 'CartTotals'
|
|
16
|
+
const name = 'CartTotals'
|
|
16
17
|
const parts = [
|
|
17
18
|
'root',
|
|
18
19
|
'costsDivider',
|
|
@@ -156,7 +157,7 @@ export function CartTotals(props: CartTotalsProps) {
|
|
|
156
157
|
{additionalSubtotals}
|
|
157
158
|
|
|
158
159
|
<Box key='divider'>
|
|
159
|
-
<Divider className={classes.costsDivider} sx={{ margin:
|
|
160
|
+
<Divider className={classes.costsDivider} sx={{ margin: '1em 0' }} />
|
|
160
161
|
</Box>
|
|
161
162
|
|
|
162
163
|
{prices?.grand_total && (
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
IconSvg,
|
|
4
|
-
iconShoppingBag,
|
|
5
|
-
FullPageMessageProps,
|
|
6
|
-
} from '@graphcommerce/next-ui'
|
|
1
|
+
import type { FullPageMessageProps } from '@graphcommerce/next-ui'
|
|
2
|
+
import { FullPageMessage, IconSvg, iconShoppingBag } from '@graphcommerce/next-ui'
|
|
7
3
|
import { Trans } from '@lingui/react'
|
|
8
|
-
import {
|
|
4
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
5
|
+
import { Button } from '@mui/material'
|
|
9
6
|
import React from 'react'
|
|
10
7
|
|
|
11
|
-
type EmptyCartProps = {
|
|
8
|
+
export type EmptyCartProps = {
|
|
12
9
|
children?: React.ReactNode
|
|
13
10
|
sx?: SxProps<Theme>
|
|
14
11
|
} & Pick<FullPageMessageProps, 'button' | 'disableMargin'>
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SignUpFormInline,
|
|
3
2
|
IsEmailAvailableDocument,
|
|
3
|
+
SignUpFormInline,
|
|
4
|
+
useCustomerAccountCanSignIn,
|
|
4
5
|
useCustomerSession,
|
|
5
6
|
useGuestQuery,
|
|
6
|
-
useCustomerAccountCanSignIn,
|
|
7
7
|
} from '@graphcommerce/magento-customer'
|
|
8
8
|
import { Button, FormRow, extendableComponent } from '@graphcommerce/next-ui'
|
|
9
9
|
import { Trans } from '@lingui/react'
|
|
10
|
-
import {
|
|
10
|
+
import type { SxProps, Theme } from '@mui/material'
|
|
11
|
+
import { Box, TextField, Typography } from '@mui/material'
|
|
11
12
|
import React, { useState } from 'react'
|
|
12
13
|
import { useCartQuery } from '../../hooks/useCartQuery'
|
|
13
14
|
import { InlineAccountDocument } from './InlineAccount.gql'
|
|
@@ -15,10 +16,6 @@ import { InlineAccountDocument } from './InlineAccount.gql'
|
|
|
15
16
|
export type InlineAccountProps = {
|
|
16
17
|
title?: React.ReactNode
|
|
17
18
|
description?: React.ReactNode
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated This is not used anymore.
|
|
20
|
-
*/
|
|
21
|
-
accountHref: string
|
|
22
19
|
sx?: SxProps<Theme>
|
|
23
20
|
}
|
|
24
21
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { ApolloCache
|
|
1
|
+
import type { ApolloCache } from '@graphcommerce/graphql'
|
|
2
|
+
import { useApolloClient } from '@graphcommerce/graphql'
|
|
2
3
|
import { cookie } from '@graphcommerce/next-ui'
|
|
3
4
|
import { useCallback } from 'react'
|
|
4
5
|
import { CurrentCartIdDocument } from './CurrentCartId.gql'
|
package/hooks/useCartQuery.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { QueryHookOptions, TypedDocumentNode } from '@graphcommerce/graphql'
|
|
2
|
+
import { ApolloError, useQuery } from '@graphcommerce/graphql'
|
|
2
3
|
import { GraphQLError } from 'graphql'
|
|
3
4
|
import { useRouter } from 'next/router'
|
|
4
5
|
import { useCartShouldLoginToContinue } from './useCartPermissions'
|
|
@@ -16,14 +17,9 @@ import { useCurrentCartId } from './useCurrentCartId'
|
|
|
16
17
|
*/
|
|
17
18
|
export function useCartQuery<Q, V extends { cartId: string; [index: string]: unknown }>(
|
|
18
19
|
document: TypedDocumentNode<Q, V>,
|
|
19
|
-
options: QueryHookOptions<Q, Omit<V, 'cartId'>>
|
|
20
|
-
/**
|
|
21
|
-
* @deprecated Not used anymore, when the cart_id is in the URL, it will always be used.
|
|
22
|
-
*/
|
|
23
|
-
allowUrl?: boolean
|
|
24
|
-
} = {},
|
|
20
|
+
options: QueryHookOptions<Q, Omit<V, 'cartId'>> = {},
|
|
25
21
|
) {
|
|
26
|
-
const {
|
|
22
|
+
const { ...queryOptions } = options
|
|
27
23
|
|
|
28
24
|
const router = useRouter()
|
|
29
25
|
const { currentCartId, locked } = useCurrentCartId()
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { QueryHookOptions
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
CurrentCartIdQueryVariables,
|
|
6
|
-
} from './CurrentCartId.gql'
|
|
1
|
+
import type { QueryHookOptions } from '@graphcommerce/graphql'
|
|
2
|
+
import { useQuery } from '@graphcommerce/graphql'
|
|
3
|
+
import type { CurrentCartIdQuery, CurrentCartIdQueryVariables } from './CurrentCartId.gql'
|
|
4
|
+
import { CurrentCartIdDocument } from './CurrentCartId.gql'
|
|
7
5
|
|
|
8
6
|
export function useCurrentCartId<
|
|
9
7
|
Q extends CurrentCartIdQuery,
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
TypedDocumentNode,
|
|
5
|
-
useApolloClient,
|
|
6
|
-
} from '@graphcommerce/graphql'
|
|
7
|
-
import {
|
|
8
|
-
useFormGqlMutation,
|
|
1
|
+
import type { MutationHookOptions, TypedDocumentNode } from '@graphcommerce/graphql'
|
|
2
|
+
import { ApolloError, useApolloClient } from '@graphcommerce/graphql'
|
|
3
|
+
import type {
|
|
9
4
|
UseFormGqlMutationReturn,
|
|
10
5
|
UseFormGraphQlOptions,
|
|
11
6
|
} from '@graphcommerce/react-hook-form'
|
|
7
|
+
import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
|
|
12
8
|
import { GraphQLError, Kind } from 'graphql'
|
|
13
9
|
import { isProtectedCartOperation } from '../link/isProtectedCartOperation'
|
|
14
10
|
import { CurrentCartIdDocument } from './CurrentCartId.gql'
|
package/index.ts
CHANGED
package/link/cartLink.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Operation } from '@graphcommerce/graphql'
|
|
2
|
+
import { fromPromise, globalApolloClient } from '@graphcommerce/graphql'
|
|
2
3
|
import { ApolloLink, Observable, onError } from '@graphcommerce/graphql/apollo'
|
|
3
4
|
import { CustomerTokenDocument, getCustomerAccountCanSignIn } from '@graphcommerce/magento-customer'
|
|
4
|
-
import { PushRouter
|
|
5
|
-
import {
|
|
5
|
+
import type { PushRouter } from '@graphcommerce/magento-customer/link/customerLink'
|
|
6
|
+
import { pushWithPromise } from '@graphcommerce/magento-customer/link/customerLink'
|
|
7
|
+
import type { ErrorCategory } from '@graphcommerce/magento-graphql'
|
|
6
8
|
import { t } from '@lingui/macro'
|
|
9
|
+
import type { GraphQLFormattedError } from 'graphql'
|
|
7
10
|
import { GraphQLError } from 'graphql'
|
|
8
11
|
import { writeCartId } from '../hooks'
|
|
9
12
|
import { CreateEmptyCartDocument } from '../hooks/CreateEmptyCart.gql'
|
|
@@ -28,10 +31,10 @@ const cartErrorLink = onError(({ graphQLErrors, operation, forward }) => {
|
|
|
28
31
|
|
|
29
32
|
if (!isCartOperation(operation) || !graphQLErrors) return undefined
|
|
30
33
|
|
|
31
|
-
const isErrorCategory = (err:
|
|
34
|
+
const isErrorCategory = (err: GraphQLFormattedError, category: ErrorCategory) =>
|
|
32
35
|
err.extensions?.category === category
|
|
33
36
|
|
|
34
|
-
const isNoSuchEntityError = (err:
|
|
37
|
+
const isNoSuchEntityError = (err: GraphQLFormattedError) =>
|
|
35
38
|
isErrorCategory(err, 'graphql-no-such-entity') &&
|
|
36
39
|
errorIsIncluded(err.path, [
|
|
37
40
|
'cart',
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-cart",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0.0
|
|
5
|
+
"version": "9.0.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,25 +12,25 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/ecommerce-ui": "^9.0.0
|
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^9.0.0
|
|
17
|
-
"@graphcommerce/framer-next-pages": "^9.0.0
|
|
18
|
-
"@graphcommerce/framer-scroller": "^9.0.0
|
|
19
|
-
"@graphcommerce/framer-utils": "^9.0.0
|
|
20
|
-
"@graphcommerce/graphql": "^9.0.0
|
|
21
|
-
"@graphcommerce/image": "^9.0.0
|
|
22
|
-
"@graphcommerce/magento-customer": "^9.0.0
|
|
23
|
-
"@graphcommerce/magento-graphql": "^9.0.0
|
|
24
|
-
"@graphcommerce/magento-store": "^9.0.0
|
|
25
|
-
"@graphcommerce/next-ui": "^9.0.0
|
|
26
|
-
"@graphcommerce/prettier-config-pwa": "^9.0.0
|
|
27
|
-
"@graphcommerce/react-hook-form": "^9.0.0
|
|
28
|
-
"@graphcommerce/typescript-config-pwa": "^9.0.0
|
|
15
|
+
"@graphcommerce/ecommerce-ui": "^9.0.0",
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0",
|
|
17
|
+
"@graphcommerce/framer-next-pages": "^9.0.0",
|
|
18
|
+
"@graphcommerce/framer-scroller": "^9.0.0",
|
|
19
|
+
"@graphcommerce/framer-utils": "^9.0.0",
|
|
20
|
+
"@graphcommerce/graphql": "^9.0.0",
|
|
21
|
+
"@graphcommerce/image": "^9.0.0",
|
|
22
|
+
"@graphcommerce/magento-customer": "^9.0.0",
|
|
23
|
+
"@graphcommerce/magento-graphql": "^9.0.0",
|
|
24
|
+
"@graphcommerce/magento-store": "^9.0.0",
|
|
25
|
+
"@graphcommerce/next-ui": "^9.0.0",
|
|
26
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0",
|
|
27
|
+
"@graphcommerce/react-hook-form": "^9.0.0",
|
|
28
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0",
|
|
29
29
|
"@lingui/core": "^4.2.1",
|
|
30
30
|
"@lingui/macro": "^4.2.1",
|
|
31
31
|
"@lingui/react": "^4.2.1",
|
|
32
32
|
"@mui/material": "^5.10.16",
|
|
33
|
-
"framer-motion": "^
|
|
33
|
+
"framer-motion": "^11.0.0",
|
|
34
34
|
"graphql": "^16.0.0",
|
|
35
35
|
"next": "*",
|
|
36
36
|
"react": "^18.2.0",
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PagesProps } from '@graphcommerce/framer-next-pages'
|
|
2
|
+
import { useApolloClient } from '@graphcommerce/graphql/apollo'
|
|
3
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
4
|
+
import { Button } from '@mui/material'
|
|
5
|
+
import { readCartId, writeCartId } from '../hooks/useAssignCurrentCartId'
|
|
6
|
+
|
|
7
|
+
export const config: PluginConfig = {
|
|
8
|
+
type: 'component',
|
|
9
|
+
module: '@graphcommerce/framer-next-pages',
|
|
10
|
+
ifConfig: 'debug.cart',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function FramerNextPages(props: PluginProps<PagesProps>) {
|
|
14
|
+
const { Prev, ...rest } = props
|
|
15
|
+
const client = useApolloClient()
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
<Prev {...rest} />
|
|
20
|
+
<div style={{ position: 'fixed', bottom: 20, right: 0, zIndex: 1, opacity: 0.3 }}>
|
|
21
|
+
<Button
|
|
22
|
+
type='button'
|
|
23
|
+
variant='text'
|
|
24
|
+
size='small'
|
|
25
|
+
onClick={() => {
|
|
26
|
+
const currentCartId = readCartId(client.cache)
|
|
27
|
+
if (!currentCartId) {
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log('No customerToken available, nothing to break')
|
|
30
|
+
} else {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
32
|
+
console.log('Changing current token to a random one')
|
|
33
|
+
writeCartId(client.cache, `${Math.random().toString(36).slice(2)}random-cardId`)
|
|
34
|
+
}
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
break cart token
|
|
38
|
+
</Button>
|
|
39
|
+
</div>
|
|
40
|
+
</>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GraphQLProviderProps } from '@graphcommerce/graphql'
|
|
1
|
+
import type { GraphQLProviderProps } from '@graphcommerce/graphql'
|
|
2
2
|
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
3
|
import { useEventCallback } from '@mui/material'
|
|
4
|
-
import { NextRouter } from 'next/router'
|
|
4
|
+
import type { NextRouter } from 'next/router'
|
|
5
5
|
import { useMemo } from 'react'
|
|
6
6
|
import { cartLink } from '../link/cartLink'
|
|
7
7
|
import { cartTypePolicies, migrateCart } from '../typePolicies'
|
|
@@ -10,11 +10,11 @@ export const config: PluginConfig = {
|
|
|
10
10
|
module: '@graphcommerce/magento-customer',
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const useSignInForm: FunctionPlugin<typeof useSignInFormType> = (
|
|
13
|
+
export const useSignInForm: FunctionPlugin<typeof useSignInFormType> = (useSignIn, options) => {
|
|
14
14
|
const client = useApolloClient()
|
|
15
15
|
const assignCurrentCartId = useAssignCurrentCartId()
|
|
16
16
|
|
|
17
|
-
return
|
|
17
|
+
return useSignIn({
|
|
18
18
|
...options,
|
|
19
19
|
onComplete: async (data, variables) => {
|
|
20
20
|
await options.onComplete?.(data, variables)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
import { ApolloClient, NormalizedCacheObject } from '@graphcommerce/graphql'
|
|
3
|
-
import { Page } from '@playwright/test'
|
|
2
|
+
import type { ApolloClient, NormalizedCacheObject } from '@graphcommerce/graphql'
|
|
3
|
+
import type { Page } from '@playwright/test'
|
|
4
4
|
import { CartAgreementsDocument } from '../components/CartAgreementsForm/CartAgreements.gql'
|
|
5
5
|
|
|
6
6
|
export async function fillCartAgreementsForm(
|
package/typePolicies.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ApolloCache,
|
|
3
|
+
NormalizedCacheObject,
|
|
4
|
+
StrictTypedTypePolicies,
|
|
5
|
+
} from '@graphcommerce/graphql'
|
|
3
6
|
import type { CartPrices, QuerycartArgs, ShippingCartAddress } from '@graphcommerce/graphql-mesh'
|
|
4
7
|
import { CartFabDocument } from './components/CartFab/CartFab.gql'
|
|
5
8
|
import { readCartId, writeCartId } from './hooks'
|
|
@@ -64,11 +67,13 @@ export const migrateCart = (
|
|
|
64
67
|
|
|
65
68
|
// We have special handling for the CartFab because it tries to load data only from the cache.
|
|
66
69
|
const cartFab = oldCache.readQuery({ query: CartFabDocument })
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
if (cartFab) {
|
|
71
|
+
newCache.writeQuery({
|
|
72
|
+
query: CartFabDocument,
|
|
73
|
+
data: cartFab,
|
|
74
|
+
variables: { cartId },
|
|
75
|
+
broadcast: true,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
73
78
|
}
|
|
74
79
|
}
|