@graphcommerce/magento-cart-payment-method 8.1.0-canary.3 → 8.1.0-canary.31

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.
@@ -1,4 +1,4 @@
1
- fragment AvailablePaymentMethod on AvailablePaymentMethod @injectable {
1
+ fragment AvailablePaymentMethod on AvailablePaymentMethod {
2
2
  code
3
3
  title
4
4
  }
@@ -1,4 +1,4 @@
1
- fragment PaymentMethodContext on Cart @injectable {
1
+ fragment PaymentMethodContext on Cart {
2
2
  id
3
3
  available_payment_methods {
4
4
  ...AvailablePaymentMethod
@@ -9,7 +9,7 @@ fragment PaymentMethodContext on Cart @injectable {
9
9
  prices {
10
10
  applied_taxes {
11
11
  amount {
12
- value
12
+ ...Money
13
13
  }
14
14
  }
15
15
  }
@@ -1,4 +1,4 @@
1
- fragment PaymentMethodUpdated on Cart @injectable {
1
+ fragment PaymentMethodUpdated on Cart {
2
2
  id
3
3
  selected_payment_method {
4
4
  ...SelectedPaymentMethod
@@ -1,4 +1,4 @@
1
- fragment SelectedPaymentMethod on SelectedPaymentMethod @injectable {
1
+ fragment SelectedPaymentMethod on SelectedPaymentMethod {
2
2
  code
3
3
  title
4
4
  }
package/CHANGELOG.md CHANGED
@@ -1,8 +1,136 @@
1
1
  # Change Log
2
2
 
3
- ## 8.1.0-canary.3
3
+ ## 8.1.0-canary.31
4
4
 
5
- ## 8.1.0-canary.2
5
+ ## 8.1.0-canary.30
6
+
7
+ ## 8.1.0-canary.29
8
+
9
+ ## 8.1.0-canary.28
10
+
11
+ ## 8.1.0-canary.27
12
+
13
+ ## 8.1.0-canary.26
14
+
15
+ ## 8.1.0-canary.25
16
+
17
+ ## 8.1.0-canary.24
18
+
19
+ ## 8.1.0-canary.23
20
+
21
+ ## 8.1.0-canary.22
22
+
23
+ ## 8.1.0-canary.21
24
+
25
+ ## 8.1.0-canary.20
26
+
27
+ ## 8.1.0-canary.19
28
+
29
+ ## 8.1.0-canary.18
30
+
31
+ ### Patch Changes
32
+
33
+ - [#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.
34
+ ([@paales](https://github.com/paales))
35
+
36
+ ## 8.1.0-canary.17
37
+
38
+ ## 8.1.0-canary.16
39
+
40
+ ## 8.1.0-canary.15
41
+
42
+ ## 8.1.0-canary.14
43
+
44
+ ### Patch Changes
45
+
46
+ - [`831d7cd`](https://github.com/graphcommerce-org/graphcommerce/commit/831d7cd64a40b7b58748fd9637199b88938e75b7) - Compatibility with Magento 2.4.7
47
+ ([@paales](https://github.com/paales))
48
+
49
+ ## 8.1.0-canary.13
50
+
51
+ ## 8.1.0-canary.12
52
+
53
+ ## 8.1.0-canary.11
54
+
55
+ ## 8.1.0-canary.10
56
+
57
+ ## 8.1.0-canary.9
58
+
59
+ ## 8.1.0-canary.8
60
+
61
+ ### Patch Changes
62
+
63
+ - [#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.
64
+ ([@paales](https://github.com/paales))
65
+
66
+ ## 8.1.0-canary.7
67
+
68
+ ## 8.1.0-canary.6
69
+
70
+ ## 8.1.0-canary.5
71
+
72
+ ## 8.0.6-canary.4
73
+
74
+ ## 8.0.6-canary.3
75
+
76
+ ## 8.0.6-canary.2
77
+
78
+ ### Patch Changes
79
+
80
+ - [#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
81
+ ([@FrankHarland](https://github.com/FrankHarland))
82
+
83
+ - [#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.
84
+ ([@FrankHarland](https://github.com/FrankHarland))
85
+
86
+ - [#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
87
+ ([@FrankHarland](https://github.com/FrankHarland))
88
+
89
+ ## 8.0.6-canary.1
90
+
91
+ ## 8.0.6-canary.0
92
+
93
+ ## 8.0.5
94
+
95
+ ## 8.0.5-canary.10
96
+
97
+ ## 8.0.5-canary.9
98
+
99
+ ## 8.0.5-canary.8
100
+
101
+ ## 8.0.5-canary.7
102
+
103
+ ## 8.0.5-canary.6
104
+
105
+ ## 8.0.5-canary.5
106
+
107
+ ## 8.0.5-canary.4
108
+
109
+ ## 8.0.5-canary.3
110
+
111
+ ## 8.0.5-canary.2
112
+
113
+ ## 8.0.5-canary.1
114
+
115
+ ## 8.0.5-canary.0
116
+
117
+ ## 8.0.4
118
+
119
+ ## 8.0.4-canary.1
120
+
121
+ ## 8.0.4-canary.0
122
+
123
+ ## 8.0.3
124
+
125
+ ## 8.0.3-canary.6
126
+
127
+ ## 8.0.3-canary.5
128
+
129
+ ## 8.0.3-canary.4
130
+
131
+ ## 8.0.3-canary.3
132
+
133
+ ## 8.0.3-canary.2
6
134
 
7
135
  ## 8.0.3-canary.1
8
136
 
@@ -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/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
- <ActionCardListForm<PaymentOptionsProps & ActionCardProps, FormFields>
113
- control={control}
114
- name='paymentMethod'
115
- errorMessage={i18n._(/* i18n */ 'Please select a payment method')}
116
- collapse
117
- size='large'
118
- color='secondary'
119
- items={methods.map((method) => ({
120
- ...method,
121
- value: `${method.code}___${method.child}`,
122
- step,
123
- Container: FormDiv,
124
- disabled: !modules?.[method.code ?? ''],
125
- }))}
126
- render={PaymentMethodActionCard}
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/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, { useContext, useEffect, useMemo, useState } from '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<PaymentMethodContextProps['onSuccess']> = useEventCallback(
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/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/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/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/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/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.3",
5
+ "version": "8.1.0-canary.31",
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.3",
16
- "@graphcommerce/framer-scroller": "^8.1.0-canary.3",
17
- "@graphcommerce/graphql": "^8.1.0-canary.3",
18
- "@graphcommerce/image": "^8.1.0-canary.3",
19
- "@graphcommerce/magento-cart": "^8.1.0-canary.3",
20
- "@graphcommerce/magento-cart-shipping-address": "^8.1.0-canary.3",
21
- "@graphcommerce/magento-store": "^8.1.0-canary.3",
22
- "@graphcommerce/next-ui": "^8.1.0-canary.3",
23
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.3",
24
- "@graphcommerce/react-hook-form": "^8.1.0-canary.3",
25
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.3",
15
+ "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.31",
16
+ "@graphcommerce/framer-scroller": "^8.1.0-canary.31",
17
+ "@graphcommerce/graphql": "^8.1.0-canary.31",
18
+ "@graphcommerce/image": "^8.1.0-canary.31",
19
+ "@graphcommerce/magento-cart": "^8.1.0-canary.31",
20
+ "@graphcommerce/magento-cart-shipping-address": "^8.1.0-canary.31",
21
+ "@graphcommerce/magento-store": "^8.1.0-canary.31",
22
+ "@graphcommerce/next-ui": "^8.1.0-canary.31",
23
+ "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.31",
24
+ "@graphcommerce/react-hook-form": "^8.1.0-canary.31",
25
+ "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.31",
26
26
  "@lingui/core": "^4.2.1",
27
27
  "@lingui/macro": "^4.2.1",
28
28
  "@lingui/react": "^4.2.1",