@graphcommerce/magento-cart 8.0.3 → 8.0.4-canary.0

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,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.0.4-canary.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2221](https://github.com/graphcommerce-org/graphcommerce/pull/2221) [`0ba1fdc`](https://github.com/graphcommerce-org/graphcommerce/commit/0ba1fdc9a2d005f47cd1725fe723e77da4cc5b9d) - After a user just logged in the checkout, the useFormGqlMutationCart would still run even though the cart was locked.
8
+ ([@paales](https://github.com/paales))
9
+
3
10
  ## 8.0.3
4
11
 
5
12
  ### Patch Changes
@@ -1,9 +1,10 @@
1
- import { MutationHookOptions, TypedDocumentNode } from '@graphcommerce/graphql'
1
+ import { MutationHookOptions, TypedDocumentNode, useApolloClient } from '@graphcommerce/graphql'
2
2
  import {
3
3
  useFormGqlMutation,
4
4
  UseFormGqlMutationReturn,
5
5
  UseFormGraphQlOptions,
6
6
  } from '@graphcommerce/react-hook-form'
7
+ import { CurrentCartIdDocument } from './CurrentCartId.gql'
7
8
  import { useCartIdCreate } from './useCartIdCreate'
8
9
 
9
10
  export function useFormGqlMutationCart<
@@ -15,14 +16,20 @@ export function useFormGqlMutationCart<
15
16
  operationOptions?: MutationHookOptions<Q, V>,
16
17
  ): UseFormGqlMutationReturn<Q, V> {
17
18
  const cartId = useCartIdCreate()
19
+ const client = useApolloClient()
18
20
 
19
- const onBeforeSubmit = async (variables: V) => {
20
- const vars = { ...variables, cartId: await cartId() }
21
- return options.onBeforeSubmit ? options.onBeforeSubmit(vars) : vars
22
- }
23
21
  const result = useFormGqlMutation<Q, V>(
24
22
  document,
25
- { ...options, onBeforeSubmit },
23
+ {
24
+ ...options,
25
+ onBeforeSubmit: async (variables) => {
26
+ const vars = { ...variables, cartId: await cartId() }
27
+
28
+ const res = client.cache.readQuery({ query: CurrentCartIdDocument })
29
+ if (res?.currentCartId?.locked) return false
30
+ return options.onBeforeSubmit ? options.onBeforeSubmit(vars) : vars
31
+ },
32
+ },
26
33
  { errorPolicy: 'all', ...operationOptions },
27
34
  )
28
35
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-cart",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.0.3",
5
+ "version": "8.0.4-canary.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,20 +12,20 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/ecommerce-ui": "^8.0.3",
16
- "@graphcommerce/eslint-config-pwa": "^8.0.3",
17
- "@graphcommerce/framer-next-pages": "^8.0.3",
18
- "@graphcommerce/framer-scroller": "^8.0.3",
19
- "@graphcommerce/framer-utils": "^8.0.3",
20
- "@graphcommerce/graphql": "^8.0.3",
21
- "@graphcommerce/image": "^8.0.3",
22
- "@graphcommerce/magento-customer": "^8.0.3",
23
- "@graphcommerce/magento-graphql": "^8.0.3",
24
- "@graphcommerce/magento-store": "^8.0.3",
25
- "@graphcommerce/next-ui": "^8.0.3",
26
- "@graphcommerce/prettier-config-pwa": "^8.0.3",
27
- "@graphcommerce/react-hook-form": "^8.0.3",
28
- "@graphcommerce/typescript-config-pwa": "^8.0.3",
15
+ "@graphcommerce/ecommerce-ui": "^8.0.4-canary.0",
16
+ "@graphcommerce/eslint-config-pwa": "^8.0.4-canary.0",
17
+ "@graphcommerce/framer-next-pages": "^8.0.4-canary.0",
18
+ "@graphcommerce/framer-scroller": "^8.0.4-canary.0",
19
+ "@graphcommerce/framer-utils": "^8.0.4-canary.0",
20
+ "@graphcommerce/graphql": "^8.0.4-canary.0",
21
+ "@graphcommerce/image": "^8.0.4-canary.0",
22
+ "@graphcommerce/magento-customer": "^8.0.4-canary.0",
23
+ "@graphcommerce/magento-graphql": "^8.0.4-canary.0",
24
+ "@graphcommerce/magento-store": "^8.0.4-canary.0",
25
+ "@graphcommerce/next-ui": "^8.0.4-canary.0",
26
+ "@graphcommerce/prettier-config-pwa": "^8.0.4-canary.0",
27
+ "@graphcommerce/react-hook-form": "^8.0.4-canary.0",
28
+ "@graphcommerce/typescript-config-pwa": "^8.0.4-canary.0",
29
29
  "@lingui/core": "^4.2.1",
30
30
  "@lingui/macro": "^4.2.1",
31
31
  "@lingui/react": "^4.2.1",