@graphcommerce/magento-cart 4.4.7 → 4.5.1

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,49 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`8d8fda262`](https://github.com/graphcommerce-org/graphcommerce/commit/8d8fda2623e561cb43441110c67ffa34b692668a), [`d41cff721`](https://github.com/graphcommerce-org/graphcommerce/commit/d41cff7211230561ceeb7786cf75790efd6377cd), [`cefa7b365`](https://github.com/graphcommerce-org/graphcommerce/commit/cefa7b3652b55108d2178927e3c5d98a111cf373), [`584b683a2`](https://github.com/graphcommerce-org/graphcommerce/commit/584b683a2aedcdf5067644c8dcc0e63a5b9e894c)]:
8
+ - @graphcommerce/next-ui@4.13.0
9
+ - @graphcommerce/magento-store@4.2.16
10
+ - @graphcommerce/framer-scroller@2.1.22
11
+ - @graphcommerce/ecommerce-ui@1.1.1
12
+ - @graphcommerce/magento-customer@4.7.1
13
+
14
+ ## 4.5.0
15
+
16
+ ### Minor Changes
17
+
18
+ - [#1544](https://github.com/graphcommerce-org/graphcommerce/pull/1544) [`5f927ebdc`](https://github.com/graphcommerce-org/graphcommerce/commit/5f927ebdc6f0331833e02b96e4f169bfe475ac6b) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - Fixed hydration errors on account, cart and wishlist
19
+
20
+ ### Patch Changes
21
+
22
+ - [#1545](https://github.com/graphcommerce-org/graphcommerce/pull/1545) [`c87a28e7d`](https://github.com/graphcommerce-org/graphcommerce/commit/c87a28e7dad87bffd0bd125ad5fdca65aaa389cc) Thanks [@paales](https://github.com/paales)! - Faster hydration with useLayoutEffect
23
+
24
+ - Updated dependencies [[`5f927ebdc`](https://github.com/graphcommerce-org/graphcommerce/commit/5f927ebdc6f0331833e02b96e4f169bfe475ac6b), [`c87a28e7d`](https://github.com/graphcommerce-org/graphcommerce/commit/c87a28e7dad87bffd0bd125ad5fdca65aaa389cc), [`c756f42e5`](https://github.com/graphcommerce-org/graphcommerce/commit/c756f42e503761a497e4a5a7a02d02141df231c3)]:
25
+ - @graphcommerce/ecommerce-ui@1.1.0
26
+ - @graphcommerce/graphql@3.4.0
27
+ - @graphcommerce/magento-customer@4.7.0
28
+ - @graphcommerce/magento-graphql@3.1.0
29
+ - @graphcommerce/react-hook-form@3.3.0
30
+ - @graphcommerce/next-ui@4.12.0
31
+ - @graphcommerce/magento-store@4.2.15
32
+ - @graphcommerce/framer-scroller@2.1.21
33
+
34
+ ## 4.4.8
35
+
36
+ ### Patch Changes
37
+
38
+ - [#1538](https://github.com/graphcommerce-org/graphcommerce/pull/1538) [`fe4baa42d`](https://github.com/graphcommerce-org/graphcommerce/commit/fe4baa42db0081ed960d62aef688bd36a7ac974f) Thanks [@paales](https://github.com/paales)! - add missing translations
39
+
40
+ - Updated dependencies [[`fe4baa42d`](https://github.com/graphcommerce-org/graphcommerce/commit/fe4baa42db0081ed960d62aef688bd36a7ac974f)]:
41
+ - @graphcommerce/magento-customer@4.6.3
42
+ - @graphcommerce/next-ui@4.11.2
43
+ - @graphcommerce/ecommerce-ui@1.0.23
44
+ - @graphcommerce/framer-scroller@2.1.20
45
+ - @graphcommerce/magento-store@4.2.14
46
+
3
47
  ## 4.4.7
4
48
 
5
49
  ### Patch Changes
@@ -74,7 +74,7 @@ export function CartAgreementsForm(props: CartAgreementsFormProps) {
74
74
  name={`agreement[${agreement.agreement_id}]`}
75
75
  control={control}
76
76
  rules={{
77
- required: i18n._(/* i18n */ `You have to agree in order to proceed`),
77
+ required: i18n._(/* i18n */ 'You have to agree in order to proceed'),
78
78
  }}
79
79
  render={({
80
80
  field: { onChange, value, name, ref, onBlur },
@@ -58,7 +58,7 @@ function CartFabContent(props: CartFabContentProps) {
58
58
  <PageLink href='/cart' passHref>
59
59
  <MotionFab
60
60
  className={classes.cart}
61
- aria-label={i18n._(/* i18n */ `Cart`)}
61
+ aria-label={i18n._(/* i18n */ 'Cart')}
62
62
  color='inherit'
63
63
  size='responsive'
64
64
  style={{ backgroundColor }}
@@ -109,15 +109,15 @@ function CartFabContent(props: CartFabContentProps) {
109
109
  * product to the cart. This would mean that it would immediately start executing this query.
110
110
  */
111
111
  export function CartFab(props: CartFabProps) {
112
- const { data } = useCartQuery(CartFabDocument, {
112
+ const { data, loading, called } = useCartQuery(CartFabDocument, {
113
113
  fetchPolicy: 'cache-only',
114
114
  nextFetchPolicy: 'cache-first',
115
115
  })
116
116
  const qty = data?.cart?.total_quantity ?? 0
117
117
 
118
- return (
119
- <NoSsr fallback={<CartFabContent {...props} total_quantity={0} />}>
120
- <CartFabContent total_quantity={qty} {...props} />
121
- </NoSsr>
122
- )
118
+ if (loading || !called) {
119
+ return <CartFabContent {...props} total_quantity={0} />
120
+ }
121
+
122
+ return <CartFabContent total_quantity={qty} {...props} />
123
123
  }
@@ -5,15 +5,15 @@ import { useAssignCurrentCartId } from './useAssignCurrentCartId'
5
5
  import { useCurrentCartId } from './useCurrentCartId'
6
6
 
7
7
  export function useCartIdCreate() {
8
- const cartId = useCurrentCartId()
8
+ const { currentCartId } = useCurrentCartId()
9
9
  const [create] = useMutation(CreateEmptyCartDocument)
10
10
  const assignCurrentCartId = useAssignCurrentCartId()
11
11
 
12
12
  return async (): Promise<string> => {
13
- if (cartId) return cartId
13
+ if (currentCartId) return currentCartId
14
14
 
15
15
  const { data } = await create()
16
- if (!data?.createEmptyCart) throw Error(i18n._(/* i18n */ `Could not create an empty cart`))
16
+ if (!data?.createEmptyCart) throw Error(i18n._(/* i18n */ 'Could not create an empty cart'))
17
17
 
18
18
  // We store the cartId that is returned as the currentCartId result
19
19
  assignCurrentCartId(data.createEmptyCart)
@@ -1,5 +1,6 @@
1
1
  import { useQuery, TypedDocumentNode, QueryHookOptions } from '@graphcommerce/graphql'
2
2
  import { useRouter } from 'next/router'
3
+ import { useEffect, useState } from 'react'
3
4
  import { useCurrentCartId } from './useCurrentCartId'
4
5
 
5
6
  /**
@@ -17,12 +18,10 @@ export function useCartQuery<Q, V extends { cartId: string; [index: string]: unk
17
18
  options: QueryHookOptions<Q, Omit<V, 'cartId'>> & { allowUrl?: boolean } = {},
18
19
  ) {
19
20
  const { allowUrl = true, ...queryOptions } = options
20
-
21
21
  const router = useRouter()
22
- const currentCartId = useCurrentCartId()
22
+ const { currentCartId } = useCurrentCartId()
23
23
  const urlCartId = router.query.cart_id
24
24
  const usingUrl = allowUrl && typeof urlCartId === 'string'
25
-
26
25
  const cartId = usingUrl ? urlCartId : currentCartId
27
26
 
28
27
  if (usingUrl && typeof queryOptions.fetchPolicy === 'undefined')
@@ -1,6 +1,23 @@
1
- import { useQuery } from '@graphcommerce/graphql'
2
- import { CurrentCartIdDocument } from './CurrentCartId.gql'
1
+ import { useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils'
2
+ import { QueryHookOptions, useQuery } from '@graphcommerce/graphql'
3
+ import { useState } from 'react'
4
+ import { CurrentCartIdDocument, CurrentCartIdQuery } from './CurrentCartId.gql'
3
5
 
4
- export function useCurrentCartId() {
5
- return useQuery(CurrentCartIdDocument, { ssr: false }).data?.currentCartId?.id ?? undefined
6
+ export function useCurrentCartId<Q, V>(
7
+ options: QueryHookOptions<Q & Pick<CurrentCartIdQuery, 'currentCartId'>, Omit<V, 'skip'>> = {},
8
+ ) {
9
+ const [skip, setSkip] = useState(true)
10
+ const { data, ...queryResults } = useQuery(CurrentCartIdDocument, {
11
+ ...options,
12
+ skip,
13
+ })
14
+
15
+ useIsomorphicLayoutEffect(() => {
16
+ if (skip) setSkip(false)
17
+ }, [skip])
18
+
19
+ return {
20
+ currentCartId: data?.currentCartId?.id || '',
21
+ ...queryResults,
22
+ }
6
23
  }
@@ -13,7 +13,7 @@ import { useCurrentCartId } from './useCurrentCartId'
13
13
  * @todo: Implement the assignCustomerToGuestCart when available: https://github.com/magento/magento2/pull/33106
14
14
  */
15
15
  export function useMergeCustomerCart() {
16
- const sourceCartId = useCurrentCartId()
16
+ const { currentCartId } = useCurrentCartId()
17
17
  const assignCurrentCartId = useAssignCurrentCartId()
18
18
  const [merge] = useMutation(UseMergeCustomerCartDocument, { errorPolicy: 'all' })
19
19
 
@@ -27,21 +27,21 @@ export function useMergeCustomerCart() {
27
27
  if (!destinationCartId) return
28
28
 
29
29
  // If the vistor cart is the same as the customer cart, we're done
30
- if (sourceCartId === destinationCartId) return
30
+ if (currentCartId === destinationCartId) return
31
31
 
32
32
  // If there is no visitor cart, assign the customer cart as the current cart
33
- if (!sourceCartId) {
33
+ if (!currentCartId) {
34
34
  assignCurrentCartId(destinationCartId)
35
35
  return
36
36
  }
37
37
 
38
38
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
39
39
  ;(async () => {
40
- const result = await merge({ variables: { sourceCartId, destinationCartId } })
40
+ const result = await merge({ variables: { sourceCartId: currentCartId, destinationCartId } })
41
41
 
42
42
  if (!result.data?.mergeCarts.id) return
43
43
 
44
44
  assignCurrentCartId(result.data?.mergeCarts.id)
45
45
  })()
46
- }, [assignCurrentCartId, sourceCartId, destinationCartId, merge])
46
+ }, [assignCurrentCartId, destinationCartId, merge, currentCartId])
47
47
  }
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": "4.4.7",
5
+ "version": "4.5.1",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -18,16 +18,17 @@
18
18
  "@playwright/test": "^1.21.1"
19
19
  },
20
20
  "dependencies": {
21
- "@graphcommerce/ecommerce-ui": "1.0.22",
21
+ "@graphcommerce/ecommerce-ui": "1.1.1",
22
+ "@graphcommerce/framer-utils": "3.1.4",
22
23
  "@graphcommerce/framer-next-pages": "3.2.3",
23
- "@graphcommerce/framer-scroller": "2.1.19",
24
- "@graphcommerce/graphql": "3.3.0",
24
+ "@graphcommerce/framer-scroller": "2.1.22",
25
+ "@graphcommerce/graphql": "3.4.0",
25
26
  "@graphcommerce/image": "3.1.7",
26
- "@graphcommerce/magento-customer": "4.6.2",
27
- "@graphcommerce/magento-graphql": "3.0.15",
28
- "@graphcommerce/magento-store": "4.2.13",
29
- "@graphcommerce/next-ui": "4.11.1",
30
- "@graphcommerce/react-hook-form": "3.2.2"
27
+ "@graphcommerce/magento-customer": "4.7.1",
28
+ "@graphcommerce/magento-graphql": "3.1.0",
29
+ "@graphcommerce/magento-store": "4.2.16",
30
+ "@graphcommerce/next-ui": "4.13.0",
31
+ "@graphcommerce/react-hook-form": "3.3.0"
31
32
  },
32
33
  "peerDependencies": {
33
34
  "@lingui/react": "^3.13.2",