@graphcommerce/magento-cart 8.1.0-canary.3 → 8.1.0-canary.30
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/Api/CartItemCountChanged.graphql +1 -1
- package/CHANGELOG.md +141 -2
- package/components/CartAgreementsForm/CartAgreementsForm.tsx +59 -26
- package/components/CartStartCheckout/CartStartCheckout.graphql +1 -2
- package/components/CartStartCheckout/CartStartCheckout.tsx +10 -6
- package/components/CartStartCheckout/CartStartCheckoutLinkOrButton.tsx +6 -5
- package/components/CartSummary/CartSummary.tsx +1 -1
- package/components/CartTotals/CartTotals.graphql +2 -4
- package/components/OrderSucces/OrderSuccesPage.graphql +1 -1
- package/hooks/useFormGqlMutationCart.ts +18 -7
- package/package.json +15 -15
- package/plugins/MagentoCartGraphqlProvider.tsx +6 -6
- package/plugins/useSignInFormMergeCart.ts +2 -2
- package/typePolicies.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,126 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
## 8.1.0-canary.
|
|
3
|
+
## 8.1.0-canary.30
|
|
4
|
+
|
|
5
|
+
## 8.1.0-canary.29
|
|
6
|
+
|
|
7
|
+
## 8.1.0-canary.28
|
|
8
|
+
|
|
9
|
+
## 8.1.0-canary.27
|
|
10
|
+
|
|
11
|
+
## 8.1.0-canary.26
|
|
12
|
+
|
|
13
|
+
## 8.1.0-canary.25
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#2266](https://github.com/graphcommerce-org/graphcommerce/pull/2266) [`0d1fe7a`](https://github.com/graphcommerce-org/graphcommerce/commit/0d1fe7a26ed2d18510c8767795294654c478fb88) - Enable the use of one or more anchor links within the 'checkbox_text' field and customize their paths.
|
|
18
|
+
([@carlocarels90](https://github.com/carlocarels90))
|
|
19
|
+
|
|
20
|
+
## 8.1.0-canary.24
|
|
21
|
+
|
|
22
|
+
## 8.1.0-canary.23
|
|
23
|
+
|
|
24
|
+
## 8.1.0-canary.22
|
|
25
|
+
|
|
26
|
+
## 8.1.0-canary.21
|
|
27
|
+
|
|
28
|
+
## 8.1.0-canary.20
|
|
29
|
+
|
|
30
|
+
## 8.1.0-canary.19
|
|
31
|
+
|
|
32
|
+
## 8.1.0-canary.18
|
|
33
|
+
|
|
34
|
+
## 8.1.0-canary.17
|
|
35
|
+
|
|
36
|
+
## 8.1.0-canary.16
|
|
37
|
+
|
|
38
|
+
## 8.1.0-canary.15
|
|
39
|
+
|
|
40
|
+
## 8.1.0-canary.14
|
|
41
|
+
|
|
42
|
+
## 8.1.0-canary.13
|
|
43
|
+
|
|
44
|
+
## 8.1.0-canary.12
|
|
45
|
+
|
|
46
|
+
## 8.1.0-canary.11
|
|
47
|
+
|
|
48
|
+
## 8.1.0-canary.10
|
|
49
|
+
|
|
50
|
+
## 8.1.0-canary.9
|
|
51
|
+
|
|
52
|
+
## 8.1.0-canary.8
|
|
53
|
+
|
|
54
|
+
### Patch Changes
|
|
55
|
+
|
|
56
|
+
- [#2247](https://github.com/graphcommerce-org/graphcommerce/pull/2247) [`a56a7c6`](https://github.com/graphcommerce-org/graphcommerce/commit/a56a7c67cf27dfb91bf763a873beeec562ab3156) - Solve an issue where the cart would be sometimes undefined, but Partial was too eleborate
|
|
57
|
+
([@paales](https://github.com/paales))
|
|
58
|
+
|
|
59
|
+
## 8.1.0-canary.7
|
|
60
|
+
|
|
61
|
+
## 8.1.0-canary.6
|
|
62
|
+
|
|
63
|
+
## 8.1.0-canary.5
|
|
64
|
+
|
|
65
|
+
## 8.0.6-canary.4
|
|
66
|
+
|
|
67
|
+
## 8.0.6-canary.3
|
|
68
|
+
|
|
69
|
+
## 8.0.6-canary.2
|
|
70
|
+
|
|
71
|
+
### Patch Changes
|
|
72
|
+
|
|
73
|
+
- [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`0767bc4`](https://github.com/graphcommerce-org/graphcommerce/commit/0767bc40f7b596209f24ca4e745ff0441f3275c9) - Upgrade input components to no longer use muiRegister, which improves INP scores
|
|
74
|
+
([@FrankHarland](https://github.com/FrankHarland))
|
|
75
|
+
|
|
76
|
+
- [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`530076e`](https://github.com/graphcommerce-org/graphcommerce/commit/530076e3664703cb8b577b7fcf1998a420819f60) - Moved all usages of useFormPersist to the <FormPersist/> component to prevent rerenders.
|
|
77
|
+
([@FrankHarland](https://github.com/FrankHarland))
|
|
78
|
+
|
|
79
|
+
## 8.0.6-canary.1
|
|
80
|
+
|
|
81
|
+
## 8.0.6-canary.0
|
|
82
|
+
|
|
83
|
+
## 8.0.5
|
|
84
|
+
|
|
85
|
+
## 8.0.5-canary.10
|
|
86
|
+
|
|
87
|
+
## 8.0.5-canary.9
|
|
88
|
+
|
|
89
|
+
## 8.0.5-canary.8
|
|
90
|
+
|
|
91
|
+
## 8.0.5-canary.7
|
|
92
|
+
|
|
93
|
+
## 8.0.5-canary.6
|
|
94
|
+
|
|
95
|
+
## 8.0.5-canary.5
|
|
96
|
+
|
|
97
|
+
## 8.0.5-canary.4
|
|
98
|
+
|
|
99
|
+
## 8.0.5-canary.3
|
|
100
|
+
|
|
101
|
+
## 8.0.5-canary.2
|
|
102
|
+
|
|
103
|
+
## 8.0.5-canary.1
|
|
104
|
+
|
|
105
|
+
## 8.0.5-canary.0
|
|
106
|
+
|
|
107
|
+
## 8.0.4
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- [#2221](https://github.com/graphcommerce-org/graphcommerce/pull/2221) [`0ba1fdc`](https://github.com/graphcommerce-org/graphcommerce/commit/0ba1fdc9a2d005f47cd1725fe723e77da4cc5b9d) - After a user just logged in the checkout, the useFormGqlMutationCart would still run even though the cart was locked.
|
|
112
|
+
([@paales](https://github.com/paales))
|
|
113
|
+
|
|
114
|
+
## 8.0.4-canary.1
|
|
115
|
+
|
|
116
|
+
## 8.0.4-canary.0
|
|
117
|
+
|
|
118
|
+
### Patch Changes
|
|
119
|
+
|
|
120
|
+
- [#2221](https://github.com/graphcommerce-org/graphcommerce/pull/2221) [`0ba1fdc`](https://github.com/graphcommerce-org/graphcommerce/commit/0ba1fdc9a2d005f47cd1725fe723e77da4cc5b9d) - After a user just logged in the checkout, the useFormGqlMutationCart would still run even though the cart was locked.
|
|
121
|
+
([@paales](https://github.com/paales))
|
|
122
|
+
|
|
123
|
+
## 8.0.3
|
|
4
124
|
|
|
5
125
|
### Patch Changes
|
|
6
126
|
|
|
@@ -10,7 +130,26 @@
|
|
|
10
130
|
- [#2205](https://github.com/graphcommerce-org/graphcommerce/pull/2205) [`3fbf3da`](https://github.com/graphcommerce-org/graphcommerce/commit/3fbf3da8a67f2fbaa7fa974a37cbbf34613844e4) - Solve an issue where the user would be presented with the Session expired dialog when the user would be logging in during the checkout process.
|
|
11
131
|
([@paales](https://github.com/paales))
|
|
12
132
|
|
|
13
|
-
|
|
133
|
+
- [#2207](https://github.com/graphcommerce-org/graphcommerce/pull/2207) [`9876b13`](https://github.com/graphcommerce-org/graphcommerce/commit/9876b139b2c12c860a16af97eddea761d1059110) - Remove redundant query on the success page for logged in customers
|
|
134
|
+
([@paales](https://github.com/paales))
|
|
135
|
+
|
|
136
|
+
## 8.0.3-canary.6
|
|
137
|
+
|
|
138
|
+
## 8.0.3-canary.5
|
|
139
|
+
|
|
140
|
+
## 8.0.3-canary.4
|
|
141
|
+
|
|
142
|
+
## 8.0.3-canary.3
|
|
143
|
+
|
|
144
|
+
## 8.0.3-canary.2
|
|
145
|
+
|
|
146
|
+
### Patch Changes
|
|
147
|
+
|
|
148
|
+
- [#2205](https://github.com/graphcommerce-org/graphcommerce/pull/2205) [`d67c89d`](https://github.com/graphcommerce-org/graphcommerce/commit/d67c89d464a60f0e2618dab670b63a39f6291341) - Deprecate the allowUrl option for useCartQuery, it was already enabled by default and should never be set to false.
|
|
149
|
+
([@paales](https://github.com/paales))
|
|
150
|
+
|
|
151
|
+
- [#2205](https://github.com/graphcommerce-org/graphcommerce/pull/2205) [`3fbf3da`](https://github.com/graphcommerce-org/graphcommerce/commit/3fbf3da8a67f2fbaa7fa974a37cbbf34613844e4) - Solve an issue where the user would be presented with the Session expired dialog when the user would be logging in during the checkout process.
|
|
152
|
+
([@paales](https://github.com/paales))
|
|
14
153
|
|
|
15
154
|
## 8.0.3-canary.1
|
|
16
155
|
|
|
@@ -2,13 +2,13 @@ import { CheckboxElement } from '@graphcommerce/ecommerce-ui'
|
|
|
2
2
|
import { useQuery } from '@graphcommerce/graphql'
|
|
3
3
|
import { extendableComponent, FormDiv } from '@graphcommerce/next-ui'
|
|
4
4
|
import {
|
|
5
|
+
FormPersist,
|
|
5
6
|
useForm,
|
|
6
7
|
useFormCompose,
|
|
7
8
|
UseFormComposeOptions,
|
|
8
|
-
useFormPersist,
|
|
9
9
|
} from '@graphcommerce/react-hook-form'
|
|
10
10
|
import { i18n } from '@lingui/core'
|
|
11
|
-
import { Box, Link, SxProps, Theme } from '@mui/material'
|
|
11
|
+
import { Box, Link, SxProps, Theme, Typography } from '@mui/material'
|
|
12
12
|
import React from 'react'
|
|
13
13
|
import { CartAgreementsDocument } from './CartAgreements.gql'
|
|
14
14
|
|
|
@@ -18,16 +18,27 @@ const componentName = 'CartAgreementsForm' as const
|
|
|
18
18
|
const parts = ['form', 'formInner', 'formControlRoot', 'manualCheck'] as const
|
|
19
19
|
const { classes } = extendableComponent(componentName, parts)
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Checks if a string contains an anchor tag (<a> ... </a>).
|
|
23
|
+
* @param {string} str - The string to check.
|
|
24
|
+
* @returns {boolean} - True if the string contains an anchor tag, otherwise false.
|
|
25
|
+
*/
|
|
26
|
+
const containsAnchorTag = (str: string): boolean => {
|
|
27
|
+
const anchorTagRegex = /<a\s+[^>]*>(.*?)<\/a>/i
|
|
28
|
+
return anchorTagRegex.test(str)
|
|
29
|
+
}
|
|
30
|
+
|
|
21
31
|
export function CartAgreementsForm(props: CartAgreementsFormProps) {
|
|
22
32
|
const { step, sx = [] } = props
|
|
23
33
|
const { data } = useQuery(CartAgreementsDocument)
|
|
24
34
|
|
|
25
35
|
// sort conditions so checkboxes will be placed first
|
|
26
36
|
const sortedAgreements = data?.checkoutAgreements
|
|
27
|
-
? [...data.checkoutAgreements]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
? [...data.checkoutAgreements]?.sort((a, b) => {
|
|
38
|
+
if (a?.mode === 'MANUAL') return -1
|
|
39
|
+
if (b?.mode === 'MANUAL') return 1
|
|
40
|
+
return 0
|
|
41
|
+
})
|
|
31
42
|
: []
|
|
32
43
|
|
|
33
44
|
const form = useForm()
|
|
@@ -39,8 +50,6 @@ export function CartAgreementsForm(props: CartAgreementsFormProps) {
|
|
|
39
50
|
console.log(values)
|
|
40
51
|
})
|
|
41
52
|
|
|
42
|
-
useFormPersist({ form, name: 'PaymentAgreementsForm' })
|
|
43
|
-
|
|
44
53
|
useFormCompose({ form, step, submit, key: 'PaymentAgreementsForm' })
|
|
45
54
|
|
|
46
55
|
if (data?.checkoutAgreements?.length === 0) return null
|
|
@@ -50,6 +59,7 @@ export function CartAgreementsForm(props: CartAgreementsFormProps) {
|
|
|
50
59
|
className={classes.form}
|
|
51
60
|
sx={[(theme) => ({ pt: theme.spacings.md }), ...(Array.isArray(sx) ? sx : [sx])]}
|
|
52
61
|
>
|
|
62
|
+
<FormPersist form={form} name='PaymentAgreementsForm' />
|
|
53
63
|
<form noValidate onSubmit={submit} name='cartAgreements'>
|
|
54
64
|
<Box className={classes.formInner} sx={{ typography: 'body1', display: 'inline-block' }}>
|
|
55
65
|
{data?.checkoutAgreements &&
|
|
@@ -57,6 +67,45 @@ export function CartAgreementsForm(props: CartAgreementsFormProps) {
|
|
|
57
67
|
if (!agreement) return null
|
|
58
68
|
const href = `/checkout/terms/${agreement.name?.toLowerCase().replace(/\s+/g, '-')}`
|
|
59
69
|
const agreementTextParts = agreement.checkbox_text.split(agreement.name)
|
|
70
|
+
// check if the agreement text contains an anchor tag
|
|
71
|
+
const containsLink = containsAnchorTag(agreement.checkbox_text)
|
|
72
|
+
let labelContent: React.ReactNode
|
|
73
|
+
|
|
74
|
+
if (containsLink) {
|
|
75
|
+
labelContent = (
|
|
76
|
+
<Typography
|
|
77
|
+
dangerouslySetInnerHTML={{ __html: agreement.checkbox_text }}
|
|
78
|
+
sx={{
|
|
79
|
+
'& a': {
|
|
80
|
+
color: 'secondary.main',
|
|
81
|
+
textDecoration: 'none',
|
|
82
|
+
'&:hover, &:focus, &:active': {
|
|
83
|
+
textDecoration: 'underline',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
}}
|
|
87
|
+
/>
|
|
88
|
+
)
|
|
89
|
+
} else if (
|
|
90
|
+
agreement.mode === 'MANUAL' &&
|
|
91
|
+
agreement.checkbox_text.includes(agreement.name)
|
|
92
|
+
) {
|
|
93
|
+
labelContent = (
|
|
94
|
+
<>
|
|
95
|
+
{agreementTextParts[0]}
|
|
96
|
+
<Link href={href} color='secondary' underline='hover'>
|
|
97
|
+
{agreement.name}
|
|
98
|
+
</Link>
|
|
99
|
+
{agreementTextParts[1]}
|
|
100
|
+
</>
|
|
101
|
+
)
|
|
102
|
+
} else {
|
|
103
|
+
labelContent = (
|
|
104
|
+
<Link href={href} color='secondary' underline='hover'>
|
|
105
|
+
{agreement.checkbox_text}
|
|
106
|
+
</Link>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
60
109
|
|
|
61
110
|
return (
|
|
62
111
|
<React.Fragment key={agreement.agreement_id}>
|
|
@@ -73,27 +122,11 @@ export function CartAgreementsForm(props: CartAgreementsFormProps) {
|
|
|
73
122
|
rules={{
|
|
74
123
|
required: i18n._(/* i18n */ 'You have to agree in order to proceed'),
|
|
75
124
|
}}
|
|
76
|
-
label={
|
|
77
|
-
agreement.checkbox_text.includes(agreement.name) ? (
|
|
78
|
-
<>
|
|
79
|
-
{agreementTextParts[0]}
|
|
80
|
-
<Link href={href} color='secondary' underline='hover'>
|
|
81
|
-
{agreement.name}
|
|
82
|
-
</Link>
|
|
83
|
-
{agreementTextParts[1]}
|
|
84
|
-
</>
|
|
85
|
-
) : (
|
|
86
|
-
<Link href={href} color='secondary' underline='hover'>
|
|
87
|
-
{agreement.checkbox_text}
|
|
88
|
-
</Link>
|
|
89
|
-
)
|
|
90
|
-
}
|
|
125
|
+
label={labelContent}
|
|
91
126
|
/>
|
|
92
127
|
) : (
|
|
93
128
|
<Box className={classes.manualCheck} sx={{ padding: `9px 0` }}>
|
|
94
|
-
|
|
95
|
-
{agreement.checkbox_text}
|
|
96
|
-
</Link>
|
|
129
|
+
{labelContent}
|
|
97
130
|
</Box>
|
|
98
131
|
)}
|
|
99
132
|
</React.Fragment>
|
|
@@ -5,12 +5,16 @@ import { Box, Button, ButtonProps, SxProps, Theme } from '@mui/material'
|
|
|
5
5
|
import React from 'react'
|
|
6
6
|
import { CartStartCheckoutFragment } from './CartStartCheckout.gql'
|
|
7
7
|
|
|
8
|
-
export type CartStartCheckoutProps =
|
|
8
|
+
export type CartStartCheckoutProps = {
|
|
9
9
|
children?: React.ReactNode
|
|
10
10
|
sx?: SxProps<Theme>
|
|
11
11
|
buttonProps?: ButtonProps<'button'>
|
|
12
12
|
disabled?: boolean
|
|
13
|
-
|
|
13
|
+
cart?: CartStartCheckoutFragment | null | undefined
|
|
14
|
+
onStart?: (
|
|
15
|
+
e: React.MouseEvent<HTMLButtonElement>,
|
|
16
|
+
cart: CartStartCheckoutFragment | null | undefined,
|
|
17
|
+
) => void
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
const name = 'CartStartCheckout' as const
|
|
@@ -29,11 +33,11 @@ export function CartStartCheckout(props: CartStartCheckoutProps) {
|
|
|
29
33
|
buttonProps: { onClick, ...buttonProps } = {},
|
|
30
34
|
disabled,
|
|
31
35
|
sx = [],
|
|
32
|
-
|
|
36
|
+
cart,
|
|
33
37
|
} = props
|
|
34
38
|
|
|
35
|
-
const hasTotals = (cart
|
|
36
|
-
const hasErrors = cart
|
|
39
|
+
const hasTotals = (cart?.prices?.grand_total?.value ?? 0) > 0
|
|
40
|
+
const hasErrors = cart?.items?.some((item) => (item?.errors?.length ?? 0) > 0)
|
|
37
41
|
|
|
38
42
|
return (
|
|
39
43
|
<Box
|
|
@@ -71,7 +75,7 @@ export function CartStartCheckout(props: CartStartCheckoutProps) {
|
|
|
71
75
|
</Box>{' '}
|
|
72
76
|
{hasTotals && (
|
|
73
77
|
<span className={classes.checkoutMoney}>
|
|
74
|
-
<Money {...cart
|
|
78
|
+
<Money {...cart?.prices?.grand_total} />
|
|
75
79
|
</span>
|
|
76
80
|
)}
|
|
77
81
|
</Button>
|
|
@@ -4,13 +4,14 @@ import { SxProps, Theme } from '@mui/material'
|
|
|
4
4
|
import React from 'react'
|
|
5
5
|
import { CartStartCheckoutFragment } from './CartStartCheckout.gql'
|
|
6
6
|
|
|
7
|
-
export type CartStartCheckoutLinkOrButtonProps =
|
|
7
|
+
export type CartStartCheckoutLinkOrButtonProps = {
|
|
8
8
|
children?: React.ReactNode
|
|
9
9
|
sx?: SxProps<Theme>
|
|
10
10
|
disabled?: boolean
|
|
11
|
+
cart?: CartStartCheckoutFragment | null | undefined
|
|
11
12
|
onStart?: (
|
|
12
13
|
e: React.MouseEvent<HTMLButtonElement & HTMLAnchorElement & HTMLSpanElement>,
|
|
13
|
-
cart: CartStartCheckoutFragment,
|
|
14
|
+
cart: CartStartCheckoutFragment | null | undefined,
|
|
14
15
|
) => void
|
|
15
16
|
linkOrButtonProps?: LinkOrButtonProps
|
|
16
17
|
}
|
|
@@ -21,11 +22,11 @@ export function CartStartCheckoutLinkOrButton(props: CartStartCheckoutLinkOrButt
|
|
|
21
22
|
onStart,
|
|
22
23
|
disabled,
|
|
23
24
|
linkOrButtonProps: { onClick, button, ...linkOrButtonProps } = {},
|
|
24
|
-
|
|
25
|
+
cart,
|
|
25
26
|
} = props
|
|
26
27
|
|
|
27
|
-
const hasTotals = (cart
|
|
28
|
-
const hasErrors = cart
|
|
28
|
+
const hasTotals = (cart?.prices?.grand_total?.value ?? 0) > 0
|
|
29
|
+
const hasErrors = cart?.items?.some((item) => (item?.errors?.length ?? 0) > 0)
|
|
29
30
|
|
|
30
31
|
return (
|
|
31
32
|
<LinkOrButton
|
|
@@ -21,7 +21,7 @@ const { classes } = extendableComponent<OwnerState, typeof compName, typeof part
|
|
|
21
21
|
export function CartSummary(props: CartSummaryProps) {
|
|
22
22
|
const { children, editable, sx = [] } = props
|
|
23
23
|
|
|
24
|
-
const { data } = useCartQuery(GetCartSummaryDocument
|
|
24
|
+
const { data } = useCartQuery(GetCartSummaryDocument)
|
|
25
25
|
const { href: historyHref, onClick: historyOnClick } = useHistoryLink({
|
|
26
26
|
href: '/checkout',
|
|
27
27
|
})
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
fragment CartTotals on Cart
|
|
2
|
-
@injectable
|
|
3
|
-
@inject(into: ["CartItemCountChanged", "PaymentMethodUpdated"]) {
|
|
1
|
+
fragment CartTotals on Cart @inject(into: ["CartItemCountChanged", "PaymentMethodUpdated"]) {
|
|
4
2
|
shipping_addresses {
|
|
5
3
|
selected_shipping_method {
|
|
6
4
|
carrier_code
|
|
@@ -11,7 +9,7 @@ fragment CartTotals on Cart
|
|
|
11
9
|
...Money
|
|
12
10
|
}
|
|
13
11
|
}
|
|
14
|
-
# https://github.com/magento/magento2/pull/31322
|
|
12
|
+
# todo: https://github.com/magento/magento2/pull/31322
|
|
15
13
|
available_shipping_methods {
|
|
16
14
|
carrier_code
|
|
17
15
|
method_code
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { MutationHookOptions, TypedDocumentNode } from '@graphcommerce/graphql'
|
|
1
|
+
import { MutationHookOptions, TypedDocumentNode, useApolloClient } from '@graphcommerce/graphql'
|
|
2
2
|
import {
|
|
3
3
|
useFormGqlMutation,
|
|
4
4
|
UseFormGqlMutationReturn,
|
|
5
5
|
UseFormGraphQlOptions,
|
|
6
6
|
} from '@graphcommerce/react-hook-form'
|
|
7
|
+
import { CurrentCartIdDocument } from './CurrentCartId.gql'
|
|
7
8
|
import { useCartIdCreate } from './useCartIdCreate'
|
|
8
9
|
|
|
9
10
|
export function useFormGqlMutationCart<
|
|
@@ -11,18 +12,28 @@ export function useFormGqlMutationCart<
|
|
|
11
12
|
V extends { cartId: string; [index: string]: unknown },
|
|
12
13
|
>(
|
|
13
14
|
document: TypedDocumentNode<Q, V>,
|
|
14
|
-
options: UseFormGraphQlOptions<Q, V> = {},
|
|
15
|
+
options: UseFormGraphQlOptions<Q, V> & { submitWhileLocked?: boolean } = {},
|
|
15
16
|
operationOptions?: MutationHookOptions<Q, V>,
|
|
16
17
|
): UseFormGqlMutationReturn<Q, V> {
|
|
17
18
|
const cartId = useCartIdCreate()
|
|
19
|
+
const client = useApolloClient()
|
|
18
20
|
|
|
19
|
-
const onBeforeSubmit = async (variables: V) => {
|
|
20
|
-
const vars = { ...variables, cartId: await cartId() }
|
|
21
|
-
return options.onBeforeSubmit ? options.onBeforeSubmit(vars) : vars
|
|
22
|
-
}
|
|
23
21
|
const result = useFormGqlMutation<Q, V>(
|
|
24
22
|
document,
|
|
25
|
-
{
|
|
23
|
+
{
|
|
24
|
+
...options,
|
|
25
|
+
onBeforeSubmit: async (variables) => {
|
|
26
|
+
const vars = { ...variables, cartId: await cartId() }
|
|
27
|
+
|
|
28
|
+
const res = client.cache.readQuery({ query: CurrentCartIdDocument })
|
|
29
|
+
if (!options.submitWhileLocked && res?.currentCartId?.locked) {
|
|
30
|
+
console.log('Could not submit form, cart is locked', res.currentCartId.locked)
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return options.onBeforeSubmit ? options.onBeforeSubmit(vars) : vars
|
|
35
|
+
},
|
|
36
|
+
},
|
|
26
37
|
{ errorPolicy: 'all', ...operationOptions },
|
|
27
38
|
)
|
|
28
39
|
|
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": "8.1.0-canary.
|
|
5
|
+
"version": "8.1.0-canary.30",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,20 +12,20 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/ecommerce-ui": "^8.1.0-canary.
|
|
16
|
-
"@graphcommerce/eslint-config-pwa": "^8.1.0-canary.
|
|
17
|
-
"@graphcommerce/framer-next-pages": "^8.1.0-canary.
|
|
18
|
-
"@graphcommerce/framer-scroller": "^8.1.0-canary.
|
|
19
|
-
"@graphcommerce/framer-utils": "^8.1.0-canary.
|
|
20
|
-
"@graphcommerce/graphql": "^8.1.0-canary.
|
|
21
|
-
"@graphcommerce/image": "^8.1.0-canary.
|
|
22
|
-
"@graphcommerce/magento-customer": "^8.1.0-canary.
|
|
23
|
-
"@graphcommerce/magento-graphql": "^8.1.0-canary.
|
|
24
|
-
"@graphcommerce/magento-store": "^8.1.0-canary.
|
|
25
|
-
"@graphcommerce/next-ui": "^8.1.0-canary.
|
|
26
|
-
"@graphcommerce/prettier-config-pwa": "^8.1.0-canary.
|
|
27
|
-
"@graphcommerce/react-hook-form": "^8.1.0-canary.
|
|
28
|
-
"@graphcommerce/typescript-config-pwa": "^8.1.0-canary.
|
|
15
|
+
"@graphcommerce/ecommerce-ui": "^8.1.0-canary.30",
|
|
16
|
+
"@graphcommerce/eslint-config-pwa": "^8.1.0-canary.30",
|
|
17
|
+
"@graphcommerce/framer-next-pages": "^8.1.0-canary.30",
|
|
18
|
+
"@graphcommerce/framer-scroller": "^8.1.0-canary.30",
|
|
19
|
+
"@graphcommerce/framer-utils": "^8.1.0-canary.30",
|
|
20
|
+
"@graphcommerce/graphql": "^8.1.0-canary.30",
|
|
21
|
+
"@graphcommerce/image": "^8.1.0-canary.30",
|
|
22
|
+
"@graphcommerce/magento-customer": "^8.1.0-canary.30",
|
|
23
|
+
"@graphcommerce/magento-graphql": "^8.1.0-canary.30",
|
|
24
|
+
"@graphcommerce/magento-store": "^8.1.0-canary.30",
|
|
25
|
+
"@graphcommerce/next-ui": "^8.1.0-canary.30",
|
|
26
|
+
"@graphcommerce/prettier-config-pwa": "^8.1.0-canary.30",
|
|
27
|
+
"@graphcommerce/react-hook-form": "^8.1.0-canary.30",
|
|
28
|
+
"@graphcommerce/typescript-config-pwa": "^8.1.0-canary.30",
|
|
29
29
|
"@lingui/core": "^4.2.1",
|
|
30
30
|
"@lingui/macro": "^4.2.1",
|
|
31
31
|
"@lingui/react": "^4.2.1",
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { GraphQLProviderProps } from '@graphcommerce/graphql'
|
|
2
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
2
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
3
|
import { cartErrorLink } from '../link/createCartErrorLink'
|
|
4
4
|
import { cartTypePolicies, migrateCart } from '../typePolicies'
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
|
|
6
|
+
export const config: PluginConfig = {
|
|
7
|
+
type: 'component',
|
|
8
|
+
module: '@graphcommerce/graphql',
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
function
|
|
11
|
+
export function GraphQLProvider(props: PluginProps<GraphQLProviderProps>) {
|
|
10
12
|
const { Prev, links = [], policies = [], migrations = [], ...rest } = props
|
|
11
13
|
return (
|
|
12
14
|
<Prev
|
|
@@ -17,5 +19,3 @@ function MagentoCartGraphqlProvider(props: PluginProps<GraphQLProviderProps>) {
|
|
|
17
19
|
/>
|
|
18
20
|
)
|
|
19
21
|
}
|
|
20
|
-
|
|
21
|
-
export const Plugin = MagentoCartGraphqlProvider
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useApolloClient } from '@graphcommerce/graphql'
|
|
2
|
-
import type { useSignInForm } from '@graphcommerce/magento-customer
|
|
2
|
+
import type { useSignInForm } from '@graphcommerce/magento-customer'
|
|
3
3
|
import type { MethodPlugin } from '@graphcommerce/next-config'
|
|
4
4
|
import { cartLock, readCartId, useAssignCurrentCartId } from '../hooks'
|
|
5
5
|
import { CustomerCartDocument } from '../hooks/CustomerCart.gql'
|
|
6
6
|
import { MergeCartsDocument } from '../hooks/MergeCarts.gql'
|
|
7
7
|
|
|
8
8
|
export const func = 'useSignInForm'
|
|
9
|
-
export const exported = '@graphcommerce/magento-customer
|
|
9
|
+
export const exported = '@graphcommerce/magento-customer'
|
|
10
10
|
|
|
11
11
|
const useSignInFormMergeCart: MethodPlugin<typeof useSignInForm> = (useSignInForm, options) => {
|
|
12
12
|
const client = useApolloClient()
|
package/typePolicies.ts
CHANGED
|
@@ -9,6 +9,9 @@ export const cartTypePolicies: StrictTypedTypePolicies = {
|
|
|
9
9
|
CartPrices: {
|
|
10
10
|
merge: (exiting, incoming, { mergeObjects }) => mergeObjects(exiting, incoming),
|
|
11
11
|
},
|
|
12
|
+
CartItemPrices: {
|
|
13
|
+
merge: (exiting, incoming, { mergeObjects }) => mergeObjects(exiting, incoming),
|
|
14
|
+
},
|
|
12
15
|
Cart: {
|
|
13
16
|
fields: {
|
|
14
17
|
shipping_addresses: {
|
|
@@ -21,6 +24,7 @@ export const cartTypePolicies: StrictTypedTypePolicies = {
|
|
|
21
24
|
return merged ? [merged] : []
|
|
22
25
|
},
|
|
23
26
|
},
|
|
27
|
+
items: { merge: (_, incoming) => incoming },
|
|
24
28
|
prices: {
|
|
25
29
|
merge: (existing: CartPrices[] | undefined, incoming: CartPrices[], options) =>
|
|
26
30
|
options.mergeObjects(existing ?? {}, incoming),
|