@graphcommerce/magento-cart-payment-method 8.1.0-canary.5 → 8.1.0-canary.52

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
@@ -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,5 +1,119 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.1.0-canary.52
4
+
5
+ ## 8.1.0-canary.51
6
+
7
+ ## 8.1.0-canary.50
8
+
9
+ ## 8.1.0-canary.49
10
+
11
+ ## 8.1.0-canary.48
12
+
13
+ ## 8.1.0-canary.47
14
+
15
+ ## 8.1.0-canary.46
16
+
17
+ ## 8.1.0-canary.45
18
+
19
+ ## 8.1.0-canary.44
20
+
21
+ ## 8.1.0-canary.43
22
+
23
+ ## 8.1.0-canary.42
24
+
25
+ ## 8.1.0-canary.41
26
+
27
+ ## 8.1.0-canary.40
28
+
29
+ ## 8.1.0-canary.39
30
+
31
+ ## 8.1.0-canary.38
32
+
33
+ ### Patch Changes
34
+
35
+ - [#2305](https://github.com/graphcommerce-org/graphcommerce/pull/2305) [`77e8297`](https://github.com/graphcommerce-org/graphcommerce/commit/77e82976816994336c616208a651cb18ce9ea270) - Fix bug with persist not applying saved changes by moving <FromPersist/> below the form components
36
+ ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
37
+
38
+ ## 8.1.0-canary.37
39
+
40
+ ## 8.1.0-canary.36
41
+
42
+ ## 8.1.0-canary.35
43
+
44
+ ## 8.1.0-canary.34
45
+
46
+ ## 8.1.0-canary.33
47
+
48
+ ## 8.1.0-canary.32
49
+
50
+ ## 8.1.0-canary.31
51
+
52
+ ## 8.1.0-canary.30
53
+
54
+ ## 8.1.0-canary.29
55
+
56
+ ## 8.1.0-canary.28
57
+
58
+ ## 8.1.0-canary.27
59
+
60
+ ## 8.1.0-canary.26
61
+
62
+ ## 8.1.0-canary.25
63
+
64
+ ## 8.1.0-canary.24
65
+
66
+ ## 8.1.0-canary.23
67
+
68
+ ## 8.1.0-canary.22
69
+
70
+ ## 8.1.0-canary.21
71
+
72
+ ## 8.1.0-canary.20
73
+
74
+ ## 8.1.0-canary.19
75
+
76
+ ## 8.1.0-canary.18
77
+
78
+ ### Patch Changes
79
+
80
+ - [#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.
81
+ ([@paales](https://github.com/paales))
82
+
83
+ ## 8.1.0-canary.17
84
+
85
+ ## 8.1.0-canary.16
86
+
87
+ ## 8.1.0-canary.15
88
+
89
+ ## 8.1.0-canary.14
90
+
91
+ ### Patch Changes
92
+
93
+ - [`831d7cd`](https://github.com/graphcommerce-org/graphcommerce/commit/831d7cd64a40b7b58748fd9637199b88938e75b7) - Compatibility with Magento 2.4.7
94
+ ([@paales](https://github.com/paales))
95
+
96
+ ## 8.1.0-canary.13
97
+
98
+ ## 8.1.0-canary.12
99
+
100
+ ## 8.1.0-canary.11
101
+
102
+ ## 8.1.0-canary.10
103
+
104
+ ## 8.1.0-canary.9
105
+
106
+ ## 8.1.0-canary.8
107
+
108
+ ### Patch Changes
109
+
110
+ - [#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.
111
+ ([@paales](https://github.com/paales))
112
+
113
+ ## 8.1.0-canary.7
114
+
115
+ ## 8.1.0-canary.6
116
+
3
117
  ## 8.1.0-canary.5
4
118
 
5
119
  ## 8.0.6-canary.4
@@ -17,7 +17,7 @@ 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(
@@ -109,7 +109,6 @@ export function PaymentMethodActionCardListForm(props: PaymentMethodActionCardLi
109
109
 
110
110
  return (
111
111
  <>
112
- <FormPersist form={form} name='PaymentMethodActionCardList' />
113
112
  <ActionCardListForm<PaymentOptionsProps & ActionCardProps, FormFields>
114
113
  control={control}
115
114
  name='paymentMethod'
@@ -126,6 +125,7 @@ export function PaymentMethodActionCardListForm(props: PaymentMethodActionCardLi
126
125
  }))}
127
126
  render={PaymentMethodActionCard}
128
127
  />
128
+ <FormPersist form={form} name='PaymentMethodActionCardList' />
129
129
  </>
130
130
  )
131
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,20 +12,7 @@ import {
11
12
  } from '../Api/PaymentMethod'
12
13
  import { PaymentMethodContextFragment } from '../Api/PaymentMethodContext.gql'
13
14
  import { GetPaymentMethodContextDocument } from './GetPaymentMethodContext.gql'
14
- import { filterNonNullableKeys, nonNullable } from '@graphcommerce/next-ui'
15
-
16
- type PaymentMethodContextProps = {
17
- methods: PaymentMethod[]
18
- selectedMethod?: PaymentMethod
19
- setSelectedMethod: (method: PaymentMethod | undefined) => void
20
- modules: PaymentMethodModules
21
- selectedModule?: PaymentModule
22
- setSelectedModule: (module: PaymentModule | undefined) => void
23
- onSuccess: (orderNumber: string) => Promise<void>
24
- }
25
-
26
- const paymentMethodContext = React.createContext<PaymentMethodContextProps | undefined>(undefined)
27
- paymentMethodContext.displayName = 'PaymentMethodContext'
15
+ import { PaymentMethodContextType, paymentMethodContext } from './paymentMethodContextType'
28
16
 
29
17
  export type PaymentMethodContextProviderProps = {
30
18
  modules?: PaymentMethodModules
@@ -55,7 +43,7 @@ export function PaymentMethodContextProvider(props: PaymentMethodContextProvider
55
43
  [client, context?.data?.cart],
56
44
  )
57
45
 
58
- const onSuccessCb: NonNullable<PaymentMethodContextProps['onSuccess']> = useEventCallback(
46
+ const onSuccessCb: NonNullable<PaymentMethodContextType['onSuccess']> = useEventCallback(
59
47
  async (orderNumber) => {
60
48
  await onSuccess?.(orderNumber, context.data?.cart)
61
49
  await push({
@@ -117,16 +105,3 @@ export function PaymentMethodContextProvider(props: PaymentMethodContextProvider
117
105
  </paymentMethodContext.Provider>
118
106
  )
119
107
  }
120
-
121
- export function usePaymentMethodContext(optional: true): PaymentMethodContextProps | undefined
122
- export function usePaymentMethodContext(optional?: false): PaymentMethodContextProps
123
- export function usePaymentMethodContext(optional = false) {
124
- const context = useContext(paymentMethodContext)
125
- if (!optional && typeof context === 'undefined') {
126
- throw Error(
127
- 'usePaymentMethodContext must be used within a PaymentMethodContextProvider or provide the optional=true argument',
128
- )
129
- }
130
-
131
- return useContext(paymentMethodContext)
132
- }
@@ -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
@@ -19,7 +19,7 @@ import {
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'> & {
@@ -90,7 +90,6 @@ export function PaymentMethodToggles(props: PaymentMethodTogglesProps) {
90
90
  ...(Array.isArray(sx) ? sx : [sx]),
91
91
  ]}
92
92
  >
93
- <FormPersist form={form} name='PaymentMethodToggles' />
94
93
  <input type='hidden' {...register('code', { required: true })} required />
95
94
  <FormRow className={classes.root} sx={{ position: 'relative', padding: 0 }}>
96
95
  <ScrollerProvider scrollSnapAlign='center'>
@@ -215,6 +214,7 @@ export function PaymentMethodToggles(props: PaymentMethodTogglesProps) {
215
214
  </Box>
216
215
  </ScrollerProvider>
217
216
  </FormRow>
217
+ <FormPersist form={form} name='PaymentMethodToggles' />
218
218
  </Form>
219
219
  )
220
220
  }
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",
5
+ "version": "8.1.0-canary.52",
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.5",
16
- "@graphcommerce/framer-scroller": "^8.1.0-canary.5",
17
- "@graphcommerce/graphql": "^8.1.0-canary.5",
18
- "@graphcommerce/image": "^8.1.0-canary.5",
19
- "@graphcommerce/magento-cart": "^8.1.0-canary.5",
20
- "@graphcommerce/magento-cart-shipping-address": "^8.1.0-canary.5",
21
- "@graphcommerce/magento-store": "^8.1.0-canary.5",
22
- "@graphcommerce/next-ui": "^8.1.0-canary.5",
23
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.5",
24
- "@graphcommerce/react-hook-form": "^8.1.0-canary.5",
25
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.5",
15
+ "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.52",
16
+ "@graphcommerce/framer-scroller": "^8.1.0-canary.52",
17
+ "@graphcommerce/graphql": "^8.1.0-canary.52",
18
+ "@graphcommerce/image": "^8.1.0-canary.52",
19
+ "@graphcommerce/magento-cart": "^8.1.0-canary.52",
20
+ "@graphcommerce/magento-cart-shipping-address": "^8.1.0-canary.52",
21
+ "@graphcommerce/magento-store": "^8.1.0-canary.52",
22
+ "@graphcommerce/next-ui": "^8.1.0-canary.52",
23
+ "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.52",
24
+ "@graphcommerce/react-hook-form": "^8.1.0-canary.52",
25
+ "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.52",
26
26
  "@lingui/core": "^4.2.1",
27
27
  "@lingui/macro": "^4.2.1",
28
28
  "@lingui/react": "^4.2.1",