@graphcommerce/magento-cart-payment-method 8.1.0-canary.2 → 8.1.0-canary.20
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/PaymentMethodContext.graphql +1 -1
- package/CHANGELOG.md +109 -1
- package/PaymentMethodActionCardList/PaymentMethodActionCardListForm.tsx +21 -19
- package/PaymentMethodButton/PaymentMethodButton.tsx +1 -1
- package/PaymentMethodContext/PaymentMethodContext.tsx +9 -30
- package/PaymentMethodContext/paymentMethodContextType.ts +28 -0
- package/PaymentMethodOptions/PaymentMethodOptions.tsx +1 -1
- package/PaymentMethodPlaceOrder/PaymentMethodPlaceOrder.tsx +3 -2
- package/PaymentMethodPlaceOrderNoop/PaymentMethodPlaceOrderNoop.tsx +3 -2
- package/PaymentMethodToggles/PaymentMethodToggles.tsx +3 -4
- package/hooks/useCartLock.ts +7 -3
- package/index.ts +1 -0
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,114 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
## 8.1.0-canary.
|
|
3
|
+
## 8.1.0-canary.20
|
|
4
|
+
|
|
5
|
+
## 8.1.0-canary.19
|
|
6
|
+
|
|
7
|
+
## 8.1.0-canary.18
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- [#2277](https://github.com/graphcommerce-org/graphcommerce/pull/2277) [`f9199f7`](https://github.com/graphcommerce-org/graphcommerce/commit/f9199f798583138a68dd641ea6637375c487f29b) - Solve issue where Braintree wouldn't place the order after successfully validating a Credit Card.
|
|
12
|
+
([@paales](https://github.com/paales))
|
|
13
|
+
|
|
14
|
+
## 8.1.0-canary.17
|
|
15
|
+
|
|
16
|
+
## 8.1.0-canary.16
|
|
17
|
+
|
|
18
|
+
## 8.1.0-canary.15
|
|
19
|
+
|
|
20
|
+
## 8.1.0-canary.14
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- [`831d7cd`](https://github.com/graphcommerce-org/graphcommerce/commit/831d7cd64a40b7b58748fd9637199b88938e75b7) - Compatibility with Magento 2.4.7
|
|
25
|
+
([@paales](https://github.com/paales))
|
|
26
|
+
|
|
27
|
+
## 8.1.0-canary.13
|
|
28
|
+
|
|
29
|
+
## 8.1.0-canary.12
|
|
30
|
+
|
|
31
|
+
## 8.1.0-canary.11
|
|
32
|
+
|
|
33
|
+
## 8.1.0-canary.10
|
|
34
|
+
|
|
35
|
+
## 8.1.0-canary.9
|
|
36
|
+
|
|
37
|
+
## 8.1.0-canary.8
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- [#2247](https://github.com/graphcommerce-org/graphcommerce/pull/2247) [`d345474`](https://github.com/graphcommerce-org/graphcommerce/commit/d345474fb190d158629cd5fd5e68a78724fa2fb6) - Due to a cyclic dependency the actual PaymentMethodPlaceOrder button would sometimes be undefined.
|
|
42
|
+
([@paales](https://github.com/paales))
|
|
43
|
+
|
|
44
|
+
## 8.1.0-canary.7
|
|
45
|
+
|
|
46
|
+
## 8.1.0-canary.6
|
|
47
|
+
|
|
48
|
+
## 8.1.0-canary.5
|
|
49
|
+
|
|
50
|
+
## 8.0.6-canary.4
|
|
51
|
+
|
|
52
|
+
## 8.0.6-canary.3
|
|
53
|
+
|
|
54
|
+
## 8.0.6-canary.2
|
|
55
|
+
|
|
56
|
+
### Patch Changes
|
|
57
|
+
|
|
58
|
+
- [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Use the non resolved payment methods as a placeholder for the actual payment methods
|
|
59
|
+
([@FrankHarland](https://github.com/FrankHarland))
|
|
60
|
+
|
|
61
|
+
- [#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.
|
|
62
|
+
([@FrankHarland](https://github.com/FrankHarland))
|
|
63
|
+
|
|
64
|
+
- [#2234](https://github.com/graphcommerce-org/graphcommerce/pull/2234) [`43bd04a`](https://github.com/graphcommerce-org/graphcommerce/commit/43bd04a777c5800cc7e01bee1e123a5aad82f194) - Prevent BillingPage query from rerunning on each mutation
|
|
65
|
+
([@FrankHarland](https://github.com/FrankHarland))
|
|
66
|
+
|
|
67
|
+
## 8.0.6-canary.1
|
|
68
|
+
|
|
69
|
+
## 8.0.6-canary.0
|
|
70
|
+
|
|
71
|
+
## 8.0.5
|
|
72
|
+
|
|
73
|
+
## 8.0.5-canary.10
|
|
74
|
+
|
|
75
|
+
## 8.0.5-canary.9
|
|
76
|
+
|
|
77
|
+
## 8.0.5-canary.8
|
|
78
|
+
|
|
79
|
+
## 8.0.5-canary.7
|
|
80
|
+
|
|
81
|
+
## 8.0.5-canary.6
|
|
82
|
+
|
|
83
|
+
## 8.0.5-canary.5
|
|
84
|
+
|
|
85
|
+
## 8.0.5-canary.4
|
|
86
|
+
|
|
87
|
+
## 8.0.5-canary.3
|
|
88
|
+
|
|
89
|
+
## 8.0.5-canary.2
|
|
90
|
+
|
|
91
|
+
## 8.0.5-canary.1
|
|
92
|
+
|
|
93
|
+
## 8.0.5-canary.0
|
|
94
|
+
|
|
95
|
+
## 8.0.4
|
|
96
|
+
|
|
97
|
+
## 8.0.4-canary.1
|
|
98
|
+
|
|
99
|
+
## 8.0.4-canary.0
|
|
100
|
+
|
|
101
|
+
## 8.0.3
|
|
102
|
+
|
|
103
|
+
## 8.0.3-canary.6
|
|
104
|
+
|
|
105
|
+
## 8.0.3-canary.5
|
|
106
|
+
|
|
107
|
+
## 8.0.3-canary.4
|
|
108
|
+
|
|
109
|
+
## 8.0.3-canary.3
|
|
110
|
+
|
|
111
|
+
## 8.0.3-canary.2
|
|
4
112
|
|
|
5
113
|
## 8.0.3-canary.1
|
|
6
114
|
|
|
@@ -7,17 +7,17 @@ import {
|
|
|
7
7
|
ActionCardProps,
|
|
8
8
|
} from '@graphcommerce/next-ui'
|
|
9
9
|
import {
|
|
10
|
+
FormPersist,
|
|
10
11
|
useForm,
|
|
11
12
|
useFormCompose,
|
|
12
13
|
UseFormComposeOptions,
|
|
13
|
-
useFormPersist,
|
|
14
14
|
} from '@graphcommerce/react-hook-form'
|
|
15
15
|
import { i18n } from '@lingui/core'
|
|
16
16
|
import { Trans } from '@lingui/react'
|
|
17
17
|
import { SxProps, Theme } from '@mui/material'
|
|
18
18
|
import { useEffect } from 'react'
|
|
19
19
|
import { PaymentOptionsProps } from '../Api/PaymentMethod'
|
|
20
|
-
import { usePaymentMethodContext } from '../PaymentMethodContext/
|
|
20
|
+
import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
|
|
21
21
|
import { useCartLock } from '../hooks'
|
|
22
22
|
|
|
23
23
|
function PaymentMethodActionCard(
|
|
@@ -84,7 +84,6 @@ export function PaymentMethodActionCardListForm(props: PaymentMethodActionCardLi
|
|
|
84
84
|
|
|
85
85
|
const paymentMethod = watch('paymentMethod')
|
|
86
86
|
|
|
87
|
-
useFormPersist({ form, name: 'PaymentMethodActionCardList' })
|
|
88
87
|
useFormCompose({ form, step: 1, submit, key: 'PaymentMethodActionCardList' })
|
|
89
88
|
|
|
90
89
|
// todo: Do not useEffect to set value, usePaymentMethodContext should calculate these values.
|
|
@@ -109,21 +108,24 @@ export function PaymentMethodActionCardListForm(props: PaymentMethodActionCardLi
|
|
|
109
108
|
if (!methods || methods.length < 1) return null
|
|
110
109
|
|
|
111
110
|
return (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
111
|
+
<>
|
|
112
|
+
<FormPersist form={form} name='PaymentMethodActionCardList' />
|
|
113
|
+
<ActionCardListForm<PaymentOptionsProps & ActionCardProps, FormFields>
|
|
114
|
+
control={control}
|
|
115
|
+
name='paymentMethod'
|
|
116
|
+
errorMessage={i18n._(/* i18n */ 'Please select a payment method')}
|
|
117
|
+
collapse
|
|
118
|
+
size='large'
|
|
119
|
+
color='secondary'
|
|
120
|
+
items={methods.map((method) => ({
|
|
121
|
+
...method,
|
|
122
|
+
value: `${method.code}___${method.child}`,
|
|
123
|
+
step,
|
|
124
|
+
Container: FormDiv,
|
|
125
|
+
disabled: !modules?.[method.code ?? ''],
|
|
126
|
+
}))}
|
|
127
|
+
render={PaymentMethodActionCard}
|
|
128
|
+
/>
|
|
129
|
+
</>
|
|
128
130
|
)
|
|
129
131
|
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
ComposedSubmitProps,
|
|
6
6
|
ComposedSubmitRenderComponentProps,
|
|
7
7
|
} from '@graphcommerce/react-hook-form'
|
|
8
|
-
import { usePaymentMethodContext } from '../PaymentMethodContext/
|
|
8
|
+
import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
|
|
9
9
|
|
|
10
10
|
export type PaymentMethodButtonProps = LinkOrButtonProps & { display?: 'inline' | 'block' } & Pick<
|
|
11
11
|
ComposedSubmitProps,
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useApolloClient } from '@graphcommerce/graphql'
|
|
2
2
|
import { useCartQuery, useClearCurrentCartId } from '@graphcommerce/magento-cart'
|
|
3
|
+
import { filterNonNullableKeys } from '@graphcommerce/next-ui'
|
|
3
4
|
import { useEventCallback } from '@mui/material'
|
|
4
5
|
import { useRouter } from 'next/router'
|
|
5
|
-
import React, {
|
|
6
|
+
import React, { useEffect, useMemo, useState } from 'react'
|
|
6
7
|
import {
|
|
7
8
|
ExpandPaymentMethodsContext,
|
|
8
9
|
PaymentMethod,
|
|
@@ -11,19 +12,7 @@ import {
|
|
|
11
12
|
} from '../Api/PaymentMethod'
|
|
12
13
|
import { PaymentMethodContextFragment } from '../Api/PaymentMethodContext.gql'
|
|
13
14
|
import { GetPaymentMethodContextDocument } from './GetPaymentMethodContext.gql'
|
|
14
|
-
|
|
15
|
-
type PaymentMethodContextProps = {
|
|
16
|
-
methods: PaymentMethod[]
|
|
17
|
-
selectedMethod?: PaymentMethod
|
|
18
|
-
setSelectedMethod: (method: PaymentMethod | undefined) => void
|
|
19
|
-
modules: PaymentMethodModules
|
|
20
|
-
selectedModule?: PaymentModule
|
|
21
|
-
setSelectedModule: (module: PaymentModule | undefined) => void
|
|
22
|
-
onSuccess: (orderNumber: string) => Promise<void>
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const paymentMethodContext = React.createContext<PaymentMethodContextProps | undefined>(undefined)
|
|
26
|
-
paymentMethodContext.displayName = 'PaymentMethodContext'
|
|
15
|
+
import { PaymentMethodContextType, paymentMethodContext } from './paymentMethodContextType'
|
|
27
16
|
|
|
28
17
|
export type PaymentMethodContextProviderProps = {
|
|
29
18
|
modules?: PaymentMethodModules
|
|
@@ -54,7 +43,7 @@ export function PaymentMethodContextProvider(props: PaymentMethodContextProvider
|
|
|
54
43
|
[client, context?.data?.cart],
|
|
55
44
|
)
|
|
56
45
|
|
|
57
|
-
const onSuccessCb: NonNullable<
|
|
46
|
+
const onSuccessCb: NonNullable<PaymentMethodContextType['onSuccess']> = useEventCallback(
|
|
58
47
|
async (orderNumber) => {
|
|
59
48
|
await onSuccess?.(orderNumber, context.data?.cart)
|
|
60
49
|
await push({
|
|
@@ -65,17 +54,20 @@ export function PaymentMethodContextProvider(props: PaymentMethodContextProvider
|
|
|
65
54
|
},
|
|
66
55
|
)
|
|
67
56
|
|
|
68
|
-
const [methods, setMethods] = useState<PaymentMethod[]>([])
|
|
69
57
|
const [selectedMethod, setSelectedMethod] = useState<PaymentMethod>()
|
|
70
58
|
const [selectedModule, setSelectedModule] = useState<PaymentModule>()
|
|
71
59
|
|
|
72
60
|
const availableMethods = useMemo(() => {
|
|
73
|
-
const allMethods = cartContext?.available_payment_methods
|
|
61
|
+
const allMethods = filterNonNullableKeys(cartContext?.available_payment_methods)
|
|
74
62
|
const free = allMethods.find((method) => method?.code === 'free')
|
|
75
63
|
|
|
76
64
|
return free ? [free] : allMethods
|
|
77
65
|
}, [cartContext?.available_payment_methods])
|
|
78
66
|
|
|
67
|
+
const [methods, setMethods] = useState<PaymentMethod[]>(
|
|
68
|
+
availableMethods.map((m) => ({ ...m, code: `${m.code}_placeholder`, child: '' })),
|
|
69
|
+
)
|
|
70
|
+
|
|
79
71
|
// Expand the payment methods
|
|
80
72
|
useEffect(() => {
|
|
81
73
|
if (!cartContext) return // eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -113,16 +105,3 @@ export function PaymentMethodContextProvider(props: PaymentMethodContextProvider
|
|
|
113
105
|
</paymentMethodContext.Provider>
|
|
114
106
|
)
|
|
115
107
|
}
|
|
116
|
-
|
|
117
|
-
export function usePaymentMethodContext(optional: true): PaymentMethodContextProps | undefined
|
|
118
|
-
export function usePaymentMethodContext(optional?: false): PaymentMethodContextProps
|
|
119
|
-
export function usePaymentMethodContext(optional = false) {
|
|
120
|
-
const context = useContext(paymentMethodContext)
|
|
121
|
-
if (!optional && typeof context === 'undefined') {
|
|
122
|
-
throw Error(
|
|
123
|
-
'usePaymentMethodContext must be used within a PaymentMethodContextProvider or provide the optional=true argument',
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return useContext(paymentMethodContext)
|
|
128
|
-
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react'
|
|
2
|
+
import type { PaymentMethod, PaymentMethodModules, PaymentModule } from '../Api/PaymentMethod'
|
|
3
|
+
|
|
4
|
+
export type PaymentMethodContextType = {
|
|
5
|
+
methods: PaymentMethod[]
|
|
6
|
+
selectedMethod?: PaymentMethod
|
|
7
|
+
setSelectedMethod: (method: PaymentMethod | undefined) => void
|
|
8
|
+
modules: PaymentMethodModules
|
|
9
|
+
selectedModule?: PaymentModule
|
|
10
|
+
setSelectedModule: (module: PaymentModule | undefined) => void
|
|
11
|
+
onSuccess: (orderNumber: string) => Promise<void>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const paymentMethodContext = createContext<PaymentMethodContextType | undefined>(undefined)
|
|
15
|
+
paymentMethodContext.displayName = 'PaymentMethodContext'
|
|
16
|
+
|
|
17
|
+
export function usePaymentMethodContext(optional: true): PaymentMethodContextType | undefined
|
|
18
|
+
export function usePaymentMethodContext(optional?: false): PaymentMethodContextType
|
|
19
|
+
export function usePaymentMethodContext(optional = false) {
|
|
20
|
+
const context = useContext(paymentMethodContext)
|
|
21
|
+
if (!optional && typeof context === 'undefined') {
|
|
22
|
+
throw Error(
|
|
23
|
+
'usePaymentMethodContext must be used within a PaymentMethodContextProvider or provide the optional=true argument',
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return useContext(paymentMethodContext)
|
|
28
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { extendableComponent } from '@graphcommerce/next-ui'
|
|
2
2
|
import { Box, SxProps, Theme } from '@mui/material'
|
|
3
3
|
import { PaymentMethodOptionsProps } from '../Api/PaymentMethod'
|
|
4
|
-
import { usePaymentMethodContext } from '../PaymentMethodContext/
|
|
4
|
+
import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
|
|
5
5
|
|
|
6
6
|
const name = 'PaymentMethodOptions' as const
|
|
7
7
|
const parts = ['root'] as const
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseFormComposeOptions } from '@graphcommerce/react-hook-form'
|
|
2
|
-
import { usePaymentMethodContext } from '../PaymentMethodContext/
|
|
2
|
+
import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
|
|
3
3
|
|
|
4
4
|
export type PaymentMethodPlaceOrderProps = Pick<UseFormComposeOptions, 'step'>
|
|
5
5
|
|
|
@@ -7,6 +7,7 @@ export function PaymentMethodPlaceOrder(props: PaymentMethodPlaceOrderProps) {
|
|
|
7
7
|
const { step } = props
|
|
8
8
|
const { selectedMethod, selectedModule } = usePaymentMethodContext()
|
|
9
9
|
|
|
10
|
-
if (!selectedModule || !selectedMethod?.code) return null
|
|
10
|
+
if (!selectedModule || !selectedMethod?.code || !selectedModule.PaymentPlaceOrder) return null
|
|
11
|
+
|
|
11
12
|
return <selectedModule.PaymentPlaceOrder {...selectedMethod} step={step} />
|
|
12
13
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useFormGqlMutationCart } from '@graphcommerce/magento-cart'
|
|
2
2
|
import { useFormCompose } from '@graphcommerce/react-hook-form'
|
|
3
3
|
import { PaymentPlaceOrderProps } from '../Api/PaymentMethod'
|
|
4
|
-
import { usePaymentMethodContext } from '../PaymentMethodContext/
|
|
4
|
+
import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
|
|
5
5
|
import { PaymentMethodPlaceOrderNoopDocument } from './PaymentMethodPlaceOrderNoop.gql'
|
|
6
6
|
|
|
7
7
|
export function PaymentMethodPlaceOrderNoop(props: PaymentPlaceOrderProps) {
|
|
@@ -10,9 +10,10 @@ export function PaymentMethodPlaceOrderNoop(props: PaymentPlaceOrderProps) {
|
|
|
10
10
|
|
|
11
11
|
const form = useFormGqlMutationCart(PaymentMethodPlaceOrderNoopDocument, {
|
|
12
12
|
onComplete: async (result) => {
|
|
13
|
-
if (!result.data?.placeOrder) return
|
|
13
|
+
if (!result.data?.placeOrder?.order) return
|
|
14
14
|
await onSuccess(result.data.placeOrder.order.order_number)
|
|
15
15
|
},
|
|
16
|
+
submitWhileLocked: true,
|
|
16
17
|
})
|
|
17
18
|
|
|
18
19
|
const { handleSubmit } = form
|
|
@@ -11,15 +11,15 @@ import {
|
|
|
11
11
|
} from '@graphcommerce/next-ui'
|
|
12
12
|
import {
|
|
13
13
|
Controller,
|
|
14
|
+
FormPersist,
|
|
14
15
|
useForm,
|
|
15
16
|
useFormCompose,
|
|
16
17
|
UseFormComposeOptions,
|
|
17
|
-
useFormPersist,
|
|
18
18
|
} from '@graphcommerce/react-hook-form'
|
|
19
19
|
import { i18n } from '@lingui/core'
|
|
20
20
|
import { Box, FormControl, FormHelperText, SxProps, Theme } from '@mui/material'
|
|
21
21
|
import { useEffect } from 'react'
|
|
22
|
-
import { usePaymentMethodContext } from '../PaymentMethodContext/
|
|
22
|
+
import { usePaymentMethodContext } from '../PaymentMethodContext/paymentMethodContextType'
|
|
23
23
|
import { useCartLock } from '../hooks/useCartLock'
|
|
24
24
|
|
|
25
25
|
export type PaymentMethodTogglesProps = Pick<UseFormComposeOptions, 'step'> & {
|
|
@@ -51,8 +51,6 @@ export function PaymentMethodToggles(props: PaymentMethodTogglesProps) {
|
|
|
51
51
|
defaultValues: { code: lockState.method },
|
|
52
52
|
})
|
|
53
53
|
|
|
54
|
-
useFormPersist({ form, name: 'PaymentMethodToggle' })
|
|
55
|
-
|
|
56
54
|
const { control, handleSubmit, watch, register, setValue, formState } = form
|
|
57
55
|
|
|
58
56
|
const submitHandler = handleSubmit(() => {})
|
|
@@ -92,6 +90,7 @@ export function PaymentMethodToggles(props: PaymentMethodTogglesProps) {
|
|
|
92
90
|
...(Array.isArray(sx) ? sx : [sx]),
|
|
93
91
|
]}
|
|
94
92
|
>
|
|
93
|
+
<FormPersist form={form} name='PaymentMethodToggles' />
|
|
95
94
|
<input type='hidden' {...register('code', { required: true })} required />
|
|
96
95
|
<FormRow className={classes.root} sx={{ position: 'relative', padding: 0 }}>
|
|
97
96
|
<ScrollerProvider scrollSnapAlign='center'>
|
package/hooks/useCartLock.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useApolloClient } from '@graphcommerce/graphql'
|
|
2
|
+
import { cartLock, useCurrentCartId } from '@graphcommerce/magento-cart'
|
|
2
3
|
import { useUrlQuery } from '@graphcommerce/next-ui'
|
|
3
4
|
import { useEffect, useState } from 'react'
|
|
4
5
|
|
|
@@ -19,9 +20,10 @@ let justLocked = false
|
|
|
19
20
|
* Todo: Block all operations on the cart while the cart is being blocked.
|
|
20
21
|
*/
|
|
21
22
|
export function useCartLock<E extends CartLockState>() {
|
|
22
|
-
const { currentCartId } = useCurrentCartId()
|
|
23
|
+
const { currentCartId, locked } = useCurrentCartId()
|
|
23
24
|
const [queryState, setRouterQuery] = useUrlQuery<E>()
|
|
24
25
|
const [, setForceRender] = useState(0)
|
|
26
|
+
const client = useApolloClient()
|
|
25
27
|
|
|
26
28
|
useEffect(() => {
|
|
27
29
|
const pageshow = (e: PageTransitionEvent) => {
|
|
@@ -38,6 +40,7 @@ export function useCartLock<E extends CartLockState>() {
|
|
|
38
40
|
const lock = (params: Omit<E, 'locked' | 'cart_id'>) => {
|
|
39
41
|
if (!currentCartId) return undefined
|
|
40
42
|
justLocked = true
|
|
43
|
+
cartLock(client.cache, true)
|
|
41
44
|
return setRouterQuery({
|
|
42
45
|
locked: '1',
|
|
43
46
|
cart_id: currentCartId,
|
|
@@ -46,13 +49,14 @@ export function useCartLock<E extends CartLockState>() {
|
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
const unlock = async (params: Omit<E, 'locked' | 'cart_id' | 'method'>) => {
|
|
52
|
+
cartLock(client.cache, false)
|
|
49
53
|
await setRouterQuery({ cart_id: null, locked: null, method: null, ...params } as E)
|
|
50
54
|
return queryState
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
const resulting: Omit<E, 'locked'> & { locked: boolean; justLocked: boolean } = {
|
|
54
58
|
...queryState,
|
|
55
|
-
locked: queryState.locked === '1' || Boolean(queryState.PayerID),
|
|
59
|
+
locked: locked || queryState.locked === '1' || Boolean(queryState.PayerID),
|
|
56
60
|
justLocked,
|
|
57
61
|
}
|
|
58
62
|
|
package/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './Api/PaymentMethod'
|
|
|
2
2
|
export * from './hooks'
|
|
3
3
|
export * from './PaymentMethodButton/PaymentMethodButton'
|
|
4
4
|
export * from './PaymentMethodContext/PaymentMethodContext'
|
|
5
|
+
export * from './PaymentMethodContext/paymentMethodContextType'
|
|
5
6
|
export * from './PaymentMethodOptions/PaymentMethodOptions'
|
|
6
7
|
export * from './PaymentMethodOptionsNoop/PaymentMethodOptionsNoop'
|
|
7
8
|
export * from './PaymentMethodOptionsNoop/PaymentMethodOptionsNoop.gql'
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/magento-cart-payment-method",
|
|
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.20",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,17 +12,17 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "^8.1.0-canary.
|
|
16
|
-
"@graphcommerce/framer-scroller": "^8.1.0-canary.
|
|
17
|
-
"@graphcommerce/graphql": "^8.1.0-canary.
|
|
18
|
-
"@graphcommerce/image": "^8.1.0-canary.
|
|
19
|
-
"@graphcommerce/magento-cart": "^8.1.0-canary.
|
|
20
|
-
"@graphcommerce/magento-cart-shipping-address": "^8.1.0-canary.
|
|
21
|
-
"@graphcommerce/magento-store": "^8.1.0-canary.
|
|
22
|
-
"@graphcommerce/next-ui": "^8.1.0-canary.
|
|
23
|
-
"@graphcommerce/prettier-config-pwa": "^8.1.0-canary.
|
|
24
|
-
"@graphcommerce/react-hook-form": "^8.1.0-canary.
|
|
25
|
-
"@graphcommerce/typescript-config-pwa": "^8.1.0-canary.
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "^8.1.0-canary.20",
|
|
16
|
+
"@graphcommerce/framer-scroller": "^8.1.0-canary.20",
|
|
17
|
+
"@graphcommerce/graphql": "^8.1.0-canary.20",
|
|
18
|
+
"@graphcommerce/image": "^8.1.0-canary.20",
|
|
19
|
+
"@graphcommerce/magento-cart": "^8.1.0-canary.20",
|
|
20
|
+
"@graphcommerce/magento-cart-shipping-address": "^8.1.0-canary.20",
|
|
21
|
+
"@graphcommerce/magento-store": "^8.1.0-canary.20",
|
|
22
|
+
"@graphcommerce/next-ui": "^8.1.0-canary.20",
|
|
23
|
+
"@graphcommerce/prettier-config-pwa": "^8.1.0-canary.20",
|
|
24
|
+
"@graphcommerce/react-hook-form": "^8.1.0-canary.20",
|
|
25
|
+
"@graphcommerce/typescript-config-pwa": "^8.1.0-canary.20",
|
|
26
26
|
"@lingui/core": "^4.2.1",
|
|
27
27
|
"@lingui/macro": "^4.2.1",
|
|
28
28
|
"@lingui/react": "^4.2.1",
|