@graphcommerce/magento-cart-payment-method 3.0.5 → 3.0.6

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,5 @@
1
- fragment PaymentMethodContext on Cart @injectable {
1
+ fragment PaymentMethodContext on Cart @injectable @inject(into: ["ShippingMethodSelected"]) {
2
+ id
2
3
  available_payment_methods {
3
4
  ...AvailablePaymentMethod
4
5
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1369](https://github.com/graphcommerce-org/graphcommerce/pull/1369) [`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9) Thanks [@paales](https://github.com/paales)! - Upgraded dependencies
8
+
9
+ * [#1368](https://github.com/graphcommerce-org/graphcommerce/pull/1368) [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a) Thanks [@paales](https://github.com/paales)! - Fix issue where the cart couldn't be properly restored when a payment was cancelled
10
+
11
+ * Updated dependencies [[`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a), [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a), [`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9), [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a), [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a)]:
12
+ - @graphcommerce/graphql@3.0.6
13
+ - @graphcommerce/next-ui@4.5.0
14
+ - @graphcommerce/framer-scroller@2.1.3
15
+ - @graphcommerce/image@3.1.2
16
+ - @graphcommerce/magento-cart@4.2.2
17
+ - @graphcommerce/magento-store@4.1.4
18
+ - @graphcommerce/react-hook-form@3.0.6
19
+
3
20
  ## 3.0.5
4
21
 
5
22
  ### Patch Changes
@@ -1,4 +1,4 @@
1
- import { ApolloCartErrorAlert } from '@graphcommerce/magento-cart'
1
+ import { ApolloCartErrorSnackbar } from '@graphcommerce/magento-cart'
2
2
  import { LinkOrButton, LinkOrButtonProps } from '@graphcommerce/next-ui'
3
3
  import { ComposedSubmit, ComposedSubmitRenderComponentProps } from '@graphcommerce/react-hook-form'
4
4
  import { usePaymentMethodContext } from '../PaymentMethodContext/PaymentMethodContext'
@@ -11,19 +11,17 @@ function PaymentMethodButtonRenderer(
11
11
  const { buttonProps, error, buttonState, submit } = props
12
12
  const { selectedMethod, selectedModule } = usePaymentMethodContext()
13
13
 
14
- const btnProps = { ...buttonProps, name: 'placeOrder' }
15
-
16
14
  const PaymentButton = selectedModule?.PaymentButton
17
15
 
18
16
  return (
19
17
  <>
20
18
  {!PaymentButton || !selectedMethod?.code ? (
21
19
  <LinkOrButton
22
- {...btnProps}
20
+ {...buttonProps}
23
21
  onClick={submit}
24
22
  loading={buttonState.isSubmitting || (buttonState.isSubmitSuccessful && !error)}
25
23
  >
26
- {btnProps.children}
24
+ {buttonProps.children}
27
25
  {selectedMethod?.title && (
28
26
  <>
29
27
  {' '}
@@ -35,7 +33,7 @@ function PaymentMethodButtonRenderer(
35
33
  <PaymentButton
36
34
  {...selectedMethod}
37
35
  buttonProps={{
38
- ...btnProps,
36
+ ...buttonProps,
39
37
  onClick: submit,
40
38
  loading: buttonState.isSubmitting || (buttonState.isSubmitSuccessful && !error),
41
39
  }}
@@ -65,7 +63,7 @@ export function PaymentMethodButton(props: PaymentMethodButtonProps) {
65
63
  ) : (
66
64
  <>
67
65
  {button}
68
- <ApolloCartErrorAlert key='error' error={errorVal} />
66
+ <ApolloCartErrorSnackbar key='error' error={errorVal} />
69
67
  </>
70
68
  )
71
69
  }}
@@ -23,7 +23,7 @@ export function PaymentMethodPlaceOrderNoop(props: PaymentPlaceOrderProps) {
23
23
  if (!data?.placeOrder?.order || error || !cartId) return
24
24
  clearCurrentCartId()
25
25
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
26
- push({ pathname: '/checkout/success', query: { cartId } })
26
+ push({ pathname: '/checkout/success', query: { cart_id: cartId } })
27
27
  }, [cartId, clearCurrentCartId, data?.placeOrder?.order, error, push])
28
28
 
29
29
  const submit = handleSubmit(() => {})
@@ -141,7 +141,7 @@ export function PaymentMethodToggles(props: PaymentMethodTogglesProps) {
141
141
  }}
142
142
  >
143
143
  {methods?.map((pm) => {
144
- const buttonValue = `${pm.code}___${pm.child}`
144
+ const buttonValue = pm.child ? `${pm.code}___${pm.child}` : pm.code
145
145
  return (
146
146
  <ToggleButton
147
147
  name={name}
@@ -1,7 +1,10 @@
1
- import { useApolloClient } from '@graphcommerce/graphql'
2
- import { useCartQuery, useCurrentCartId } from '@graphcommerce/magento-cart'
3
- import { useCallback } from 'react'
4
- import { UseCartLockDocument } from './UseCartLock.gql'
1
+ import { useCurrentCartId } from '@graphcommerce/magento-cart'
2
+ import { useUrlQuery } from '@graphcommerce/next-ui'
3
+
4
+ export type CartLockState = {
5
+ cart_id?: string
6
+ locked?: string
7
+ }
5
8
 
6
9
  /**
7
10
  * Locking a cart might is usefull in the following cases: We want to disable cart modifications
@@ -9,25 +12,15 @@ import { UseCartLockDocument } from './UseCartLock.gql'
9
12
  *
10
13
  * Todo: Block all operations on the cart while the cart is being blocked.
11
14
  */
12
- export function useCartLock() {
13
- const { cache } = useApolloClient()
14
- const cartId = useCurrentCartId()
15
-
16
- const locked = useCartQuery(UseCartLockDocument, { allowUrl: true }).data?.cart?.locked ?? false
15
+ export function useCartLock<E extends Record<string, string | undefined>>() {
16
+ const currentCartId = useCurrentCartId()
17
17
 
18
- const lock = useCallback(
19
- (locking: boolean) => {
20
- if (!cartId) return
18
+ const [queryState, setRouterQuery] = useUrlQuery<CartLockState & E>((params) => params)
21
19
 
22
- cache.writeQuery({
23
- query: UseCartLockDocument,
24
- data: { cart: { __typename: 'Cart', id: cartId, locked: locking } },
25
- variables: { cartId },
26
- broadcast: true,
27
- })
28
- },
29
- [cache, cartId],
30
- )
20
+ const lock = (params: CartLockState & E) => {
21
+ if (!currentCartId) return
22
+ setRouterQuery({ locked: '1', cart_id: currentCartId, ...params })
23
+ }
31
24
 
32
- return { locked, lock }
25
+ return [queryState, lock] as const
33
26
  }
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": "3.0.5",
5
+ "version": "3.0.6",
6
6
  "sideEffects": false,
7
7
  "engines": {
8
8
  "node": "14.x"
@@ -15,20 +15,20 @@
15
15
  }
16
16
  },
17
17
  "devDependencies": {
18
- "@graphcommerce/eslint-config-pwa": "^4.0.5",
19
- "@graphcommerce/prettier-config-pwa": "^4.0.3",
18
+ "@graphcommerce/eslint-config-pwa": "^4.1.3",
19
+ "@graphcommerce/prettier-config-pwa": "^4.0.5",
20
20
  "@graphcommerce/typescript-config-pwa": "^4.0.2",
21
- "@playwright/test": "^1.19.2"
21
+ "@playwright/test": "^1.20.1",
22
+ "type-fest": "2.12.1"
22
23
  },
23
24
  "dependencies": {
24
- "@graphcommerce/framer-scroller": "^2.0.6",
25
- "@graphcommerce/graphql": "^3.0.4",
26
- "@graphcommerce/image": "^3.1.1",
27
- "@graphcommerce/magento-cart": "^4.1.4",
28
- "@graphcommerce/magento-store": "^4.1.2",
29
- "@graphcommerce/next-ui": "^4.2.4",
30
- "@graphcommerce/react-hook-form": "^3.0.4",
31
- "type-fest": "^2.12.0"
25
+ "@graphcommerce/framer-scroller": "^2.1.3",
26
+ "@graphcommerce/graphql": "^3.0.6",
27
+ "@graphcommerce/image": "^3.1.2",
28
+ "@graphcommerce/magento-cart": "^4.2.2",
29
+ "@graphcommerce/magento-store": "^4.1.4",
30
+ "@graphcommerce/next-ui": "^4.5.0",
31
+ "@graphcommerce/react-hook-form": "^3.0.6"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@lingui/macro": "^3.13.2",
@@ -0,0 +1,25 @@
1
+ import { ApolloClient, NormalizedCacheObject } from '@graphcommerce/graphql'
2
+ import { fillShippingAddressForm } from '@graphcommerce/magento-cart-shipping-address/test/fillShippingAddressForm'
3
+ import { fillCartAgreementsForm } from '@graphcommerce/magento-cart/test/fillCartAgreementsForm'
4
+ import { Page } from '@playwright/test'
5
+
6
+ export const goToPayment = async (
7
+ page: Page,
8
+ apolloClient: ApolloClient<NormalizedCacheObject>,
9
+ ) => {
10
+ await page.locator('a:has-text("View shopping cart")').click()
11
+
12
+ await page.locator('text=Start Checkout').click()
13
+
14
+ const email = page.locator('input[name="email"]')
15
+ await email.click()
16
+ await email.fill('test@test.com')
17
+
18
+ await fillShippingAddressForm(page)
19
+
20
+ await page.click('button[value=flatrate-flatrate]')
21
+ await page.click('#next')
22
+
23
+ // Fill in the agreements
24
+ await fillCartAgreementsForm(page, apolloClient)
25
+ }
@@ -1,7 +0,0 @@
1
- query UseCartLock($cartId: String!) {
2
- cart(cart_id: $cartId) @client {
3
- __typename
4
- id
5
- locked
6
- }
7
- }
@@ -1,7 +0,0 @@
1
- extend type Mutation {
2
- lockCart(lock: Boolean): Boolean
3
- }
4
-
5
- extend type Cart {
6
- locked: Boolean!
7
- }