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

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.1.0-canary.10
4
+
5
+ ## 8.1.0-canary.9
6
+
7
+ ## 8.1.0-canary.8
8
+
9
+ ### Patch Changes
10
+
11
+ - [#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.
12
+ ([@paales](https://github.com/paales))
13
+
14
+ ## 8.1.0-canary.7
15
+
16
+ ## 8.1.0-canary.6
17
+
18
+ ## 8.1.0-canary.5
19
+
20
+ ## 8.0.6-canary.4
21
+
3
22
  ## 8.0.6-canary.3
4
23
 
5
24
  ## 8.0.6-canary.2
@@ -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(
@@ -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) {
@@ -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'> & {
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.0.6-canary.3",
5
+ "version": "8.1.0-canary.10",
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.3",
16
- "@graphcommerce/framer-scroller": "^8.0.6-canary.3",
17
- "@graphcommerce/graphql": "^8.0.6-canary.3",
18
- "@graphcommerce/image": "^8.0.6-canary.3",
19
- "@graphcommerce/magento-cart": "^8.0.6-canary.3",
20
- "@graphcommerce/magento-cart-shipping-address": "^8.0.6-canary.3",
21
- "@graphcommerce/magento-store": "^8.0.6-canary.3",
22
- "@graphcommerce/next-ui": "^8.0.6-canary.3",
23
- "@graphcommerce/prettier-config-pwa": "^8.0.6-canary.3",
24
- "@graphcommerce/react-hook-form": "^8.0.6-canary.3",
25
- "@graphcommerce/typescript-config-pwa": "^8.0.6-canary.3",
15
+ "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.10",
16
+ "@graphcommerce/framer-scroller": "^8.1.0-canary.10",
17
+ "@graphcommerce/graphql": "^8.1.0-canary.10",
18
+ "@graphcommerce/image": "^8.1.0-canary.10",
19
+ "@graphcommerce/magento-cart": "^8.1.0-canary.10",
20
+ "@graphcommerce/magento-cart-shipping-address": "^8.1.0-canary.10",
21
+ "@graphcommerce/magento-store": "^8.1.0-canary.10",
22
+ "@graphcommerce/next-ui": "^8.1.0-canary.10",
23
+ "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.10",
24
+ "@graphcommerce/react-hook-form": "^8.1.0-canary.10",
25
+ "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.10",
26
26
  "@lingui/core": "^4.2.1",
27
27
  "@lingui/macro": "^4.2.1",
28
28
  "@lingui/react": "^4.2.1",