@graphcommerce/magento-cart-payment-method 8.0.6-canary.0 → 8.0.6-canary.2

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.
@@ -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
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.0.6-canary.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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
8
+ ([@FrankHarland](https://github.com/FrankHarland))
9
+
10
+ - [#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.
11
+ ([@FrankHarland](https://github.com/FrankHarland))
12
+
13
+ - [#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
14
+ ([@FrankHarland](https://github.com/FrankHarland))
15
+
16
+ ## 8.0.6-canary.1
17
+
3
18
  ## 8.0.6-canary.0
4
19
 
5
20
  ## 8.0.5
@@ -7,10 +7,10 @@ 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'
@@ -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
  }
@@ -11,6 +11,7 @@ import {
11
11
  } from '../Api/PaymentMethod'
12
12
  import { PaymentMethodContextFragment } from '../Api/PaymentMethodContext.gql'
13
13
  import { GetPaymentMethodContextDocument } from './GetPaymentMethodContext.gql'
14
+ import { filterNonNullableKeys, nonNullable } from '@graphcommerce/next-ui'
14
15
 
15
16
  type PaymentMethodContextProps = {
16
17
  methods: PaymentMethod[]
@@ -65,17 +66,20 @@ export function PaymentMethodContextProvider(props: PaymentMethodContextProvider
65
66
  },
66
67
  )
67
68
 
68
- const [methods, setMethods] = useState<PaymentMethod[]>([])
69
69
  const [selectedMethod, setSelectedMethod] = useState<PaymentMethod>()
70
70
  const [selectedModule, setSelectedModule] = useState<PaymentModule>()
71
71
 
72
72
  const availableMethods = useMemo(() => {
73
- const allMethods = cartContext?.available_payment_methods ?? []
73
+ const allMethods = filterNonNullableKeys(cartContext?.available_payment_methods)
74
74
  const free = allMethods.find((method) => method?.code === 'free')
75
75
 
76
76
  return free ? [free] : allMethods
77
77
  }, [cartContext?.available_payment_methods])
78
78
 
79
+ const [methods, setMethods] = useState<PaymentMethod[]>(
80
+ availableMethods.map((m) => ({ ...m, code: `${m.code}_placeholder`, child: '' })),
81
+ )
82
+
79
83
  // Expand the payment methods
80
84
  useEffect(() => {
81
85
  if (!cartContext) return // eslint-disable-next-line @typescript-eslint/no-floating-promises
@@ -11,10 +11,10 @@ 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'
@@ -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/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.0.6-canary.0",
5
+ "version": "8.0.6-canary.2",
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.0.6-canary.0",
16
- "@graphcommerce/framer-scroller": "^8.0.6-canary.0",
17
- "@graphcommerce/graphql": "^8.0.6-canary.0",
18
- "@graphcommerce/image": "^8.0.6-canary.0",
19
- "@graphcommerce/magento-cart": "^8.0.6-canary.0",
20
- "@graphcommerce/magento-cart-shipping-address": "^8.0.6-canary.0",
21
- "@graphcommerce/magento-store": "^8.0.6-canary.0",
22
- "@graphcommerce/next-ui": "^8.0.6-canary.0",
23
- "@graphcommerce/prettier-config-pwa": "^8.0.6-canary.0",
24
- "@graphcommerce/react-hook-form": "^8.0.6-canary.0",
25
- "@graphcommerce/typescript-config-pwa": "^8.0.6-canary.0",
15
+ "@graphcommerce/eslint-config-pwa": "^8.0.6-canary.2",
16
+ "@graphcommerce/framer-scroller": "^8.0.6-canary.2",
17
+ "@graphcommerce/graphql": "^8.0.6-canary.2",
18
+ "@graphcommerce/image": "^8.0.6-canary.2",
19
+ "@graphcommerce/magento-cart": "^8.0.6-canary.2",
20
+ "@graphcommerce/magento-cart-shipping-address": "^8.0.6-canary.2",
21
+ "@graphcommerce/magento-store": "^8.0.6-canary.2",
22
+ "@graphcommerce/next-ui": "^8.0.6-canary.2",
23
+ "@graphcommerce/prettier-config-pwa": "^8.0.6-canary.2",
24
+ "@graphcommerce/react-hook-form": "^8.0.6-canary.2",
25
+ "@graphcommerce/typescript-config-pwa": "^8.0.6-canary.2",
26
26
  "@lingui/core": "^4.2.1",
27
27
  "@lingui/macro": "^4.2.1",
28
28
  "@lingui/react": "^4.2.1",