@graphcommerce/magento-wishlist 1.1.1 → 1.2.2

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,48 @@
1
1
  # @graphcommerce/magento-wishlist
2
2
 
3
+ ## 1.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`c63ab89c2`](https://github.com/graphcommerce-org/graphcommerce/commit/c63ab89c20cb81d79188900d57f3d65a7bba71cc), [`238aa4d34`](https://github.com/graphcommerce-org/graphcommerce/commit/238aa4d3478773b8cb0973f4112c9829e59e16d6), [`afc67103d`](https://github.com/graphcommerce-org/graphcommerce/commit/afc67103d0e00583e274465036fd287537f95e79)]:
8
+ - @graphcommerce/magento-product-configurable@4.1.9
9
+ - @graphcommerce/magento-product@4.4.2
10
+ - @graphcommerce/magento-customer@4.4.1
11
+ - @graphcommerce/next-ui@4.8.3
12
+ - @graphcommerce/magento-cart@4.3.3
13
+ - @graphcommerce/magento-store@4.2.7
14
+
15
+ ## 1.2.1
16
+
17
+ ### Patch Changes
18
+
19
+ - [#1485](https://github.com/graphcommerce-org/graphcommerce/pull/1485) [`d6262de71`](https://github.com/graphcommerce-org/graphcommerce/commit/d6262de71d2254a2b0b492e1a60f9e141767470e) Thanks [@paales](https://github.com/paales)! - move to useCustomerSession instead of using the tokenquery directly and fix ssr issues
20
+
21
+ - Updated dependencies [[`d6262de71`](https://github.com/graphcommerce-org/graphcommerce/commit/d6262de71d2254a2b0b492e1a60f9e141767470e), [`c8c246b8a`](https://github.com/graphcommerce-org/graphcommerce/commit/c8c246b8aaab0621b68a2fca2a1c529a56fad962), [`e3005fe63`](https://github.com/graphcommerce-org/graphcommerce/commit/e3005fe6306093d47b08c6756c21c8175649e30b)]:
22
+ - @graphcommerce/magento-customer@4.4.0
23
+ - @graphcommerce/magento-cart@4.3.2
24
+ - @graphcommerce/next-ui@4.8.2
25
+ - @graphcommerce/magento-product-configurable@4.1.8
26
+ - @graphcommerce/magento-product@4.4.1
27
+ - @graphcommerce/magento-store@4.2.6
28
+
29
+ ## 1.2.0
30
+
31
+ ### Minor Changes
32
+
33
+ - [#1482](https://github.com/graphcommerce-org/graphcommerce/pull/1482) [`b359fe252`](https://github.com/graphcommerce-org/graphcommerce/commit/b359fe252a50bb8195601ba97c3eef6a7be146ba) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - Added selectedOptions to AddToCart mutation
34
+
35
+ ### Patch Changes
36
+
37
+ - Updated dependencies [[`a9df81310`](https://github.com/graphcommerce-org/graphcommerce/commit/a9df81310c051876dd82fb2819105dece47cc213), [`b359fe252`](https://github.com/graphcommerce-org/graphcommerce/commit/b359fe252a50bb8195601ba97c3eef6a7be146ba), [`f167f9963`](https://github.com/graphcommerce-org/graphcommerce/commit/f167f99630966a7de43717937d43669e66132494)]:
38
+ - @graphcommerce/next-ui@4.8.1
39
+ - @graphcommerce/magento-product@4.4.0
40
+ - @graphcommerce/magento-cart@4.3.1
41
+ - @graphcommerce/magento-customer@4.3.2
42
+ - @graphcommerce/magento-product-configurable@4.1.7
43
+ - @graphcommerce/magento-store@4.2.5
44
+ - @graphcommerce/image@3.1.6
45
+
3
46
  ## 1.1.1
4
47
 
5
48
  ### Patch Changes
@@ -1,5 +1,9 @@
1
- import { useQuery, useMutation, useApolloClient } from '@graphcommerce/graphql'
2
- import { CustomerTokenDocument } from '@graphcommerce/magento-customer'
1
+ import { useMutation, useApolloClient } from '@graphcommerce/graphql'
2
+ import {
3
+ useCustomerQuery,
4
+ useCustomerSession,
5
+ useGuestQuery,
6
+ } from '@graphcommerce/magento-customer'
3
7
  import {
4
8
  IconSvg,
5
9
  iconHeart,
@@ -39,19 +43,13 @@ export function ProductWishlistChipBase(props: ProductWishlistChipProps) {
39
43
  const [inWishlist, setInWishlist] = useState(false)
40
44
  const [displayMessageBar, setDisplayMessageBar] = useState(false)
41
45
 
42
- const { data: token } = useQuery(CustomerTokenDocument)
46
+ const { loggedIn } = useCustomerSession()
43
47
  const [addWishlistItem] = useMutation(AddProductToWishlistDocument)
44
48
  const [removeWishlistItem] = useMutation(RemoveProductFromWishlistDocument)
45
- const isLoggedIn = token?.customerToken && token?.customerToken.valid
46
49
 
47
- const { data: GetCustomerWishlistData, loading } = useQuery(GetIsInWishlistsDocument, {
48
- skip: !isLoggedIn,
49
- })
50
+ const { data: GetCustomerWishlistData, loading } = useCustomerQuery(GetIsInWishlistsDocument)
50
51
 
51
- const { data: guestWishlistData } = useQuery(GuestWishlistDocument, {
52
- ssr: false,
53
- skip: isLoggedIn === true,
54
- })
52
+ const { data: guestWishlistData } = useGuestQuery(GuestWishlistDocument)
55
53
 
56
54
  const { cache } = useApolloClient()
57
55
 
@@ -80,7 +78,7 @@ export function ProductWishlistChipBase(props: ProductWishlistChipProps) {
80
78
 
81
79
  useEffect(() => {
82
80
  // Do not display wishlist UI to guests when configured as customer only
83
- if (hideForGuest && !isLoggedIn) {
81
+ if (hideForGuest && !loggedIn) {
84
82
  return
85
83
  }
86
84
 
@@ -89,17 +87,17 @@ export function ProductWishlistChipBase(props: ProductWishlistChipProps) {
89
87
  }
90
88
 
91
89
  // Mark as active when product is available in either customer or guest wishlist
92
- if (isLoggedIn && !loading) {
90
+ if (loggedIn && !loading) {
93
91
  const inWishlistTest =
94
92
  GetCustomerWishlistData?.customer?.wishlists[0]?.items_v2?.items.map(
95
93
  (item) => item?.product?.sku,
96
94
  ) || []
97
95
  setInWishlist(inWishlistTest.includes(sku))
98
- } else if (!isLoggedIn) {
96
+ } else if (!loggedIn) {
99
97
  const inWishlistTest = guestWishlistData?.guestWishlist?.items.map((item) => item?.sku) || []
100
98
  setInWishlist(inWishlistTest.includes(sku))
101
99
  }
102
- }, [isLoggedIn, sku, loading, GetCustomerWishlistData, guestWishlistData])
100
+ }, [loggedIn, sku, loading, GetCustomerWishlistData, guestWishlistData])
103
101
 
104
102
  const preventAnimationBubble: React.MouseEventHandler<HTMLButtonElement> = (e) => {
105
103
  e.preventDefault()
@@ -113,7 +111,7 @@ export function ProductWishlistChipBase(props: ProductWishlistChipProps) {
113
111
  return
114
112
  }
115
113
 
116
- if (isLoggedIn) {
114
+ if (loggedIn) {
117
115
  if (inWishlist && !ignoreProductWishlistStatus) {
118
116
  const wishlistItemsInSession =
119
117
  GetCustomerWishlistData?.customer?.wishlists[0]?.items_v2?.items || []
@@ -218,7 +216,7 @@ export function ProductWishlistChipBase(props: ProductWishlistChipProps) {
218
216
  </Box>
219
217
  )
220
218
 
221
- return !hideForGuest || isLoggedIn ? output : null
219
+ return !hideForGuest || loggedIn ? output : null
222
220
  }
223
221
 
224
222
  ProductWishlistChipBase.defaultProps = {
@@ -1,10 +1,13 @@
1
- import { useQuery } from '@graphcommerce/graphql'
2
- import { CustomerTokenDocument } from '@graphcommerce/magento-customer'
1
+ import {
2
+ useCustomerQuery,
3
+ useCustomerSession,
4
+ useGuestQuery,
5
+ } from '@graphcommerce/magento-customer'
3
6
  import { iconHeart, DesktopHeaderBadge, IconSvg, extendableComponent } from '@graphcommerce/next-ui'
4
7
  import { i18n } from '@lingui/core'
5
8
  import { Fab, FabProps as FabPropsType, NoSsr, SxProps, Theme } from '@mui/material'
6
9
  import PageLink from 'next/link'
7
- import React, { useEffect } from 'react'
10
+ import React from 'react'
8
11
  import { useWishlistEnabled } from '../../hooks'
9
12
  import { GetIsInWishlistsDocument } from '../../queries/GetIsInWishlists.gql'
10
13
  import { GuestWishlistDocument } from '../../queries/GuestWishlist.gql'
@@ -13,6 +16,7 @@ type WishlistFabContentProps = {
13
16
  icon?: React.ReactNode
14
17
  FabProps?: Omit<FabPropsType, 'children'>
15
18
  sx?: SxProps<Theme>
19
+ activeWishlist: boolean
16
20
  }
17
21
 
18
22
  const name = 'WishlistFab'
@@ -22,31 +26,7 @@ const { classes } = extendableComponent(name, parts)
22
26
  const hideForGuest = process.env.NEXT_PUBLIC_WISHLIST_HIDE_FOR_GUEST === '1'
23
27
 
24
28
  function WishlistFabContent(props: WishlistFabContentProps) {
25
- const { icon, FabProps, sx } = props
26
-
27
- const { data: token } = useQuery(CustomerTokenDocument)
28
- const isLoggedIn = token?.customerToken && token?.customerToken.valid
29
-
30
- const { data: GetCustomerWishlistData, loading } = useQuery(GetIsInWishlistsDocument, {
31
- skip: !isLoggedIn,
32
- })
33
-
34
- const { data: guestWishlistData, loading: loadingGuestWishlistData } = useQuery(
35
- GuestWishlistDocument,
36
- {
37
- ssr: false,
38
- skip: isLoggedIn === true,
39
- },
40
- )
41
-
42
- let activeWishlist = false
43
- if (isLoggedIn) {
44
- const wishlistItemCount = GetCustomerWishlistData?.customer?.wishlists[0]?.items_count || 0
45
- activeWishlist = wishlistItemCount > 0
46
- } else {
47
- const wishlist = guestWishlistData?.guestWishlist?.items || []
48
- activeWishlist = wishlist.length > 0
49
- }
29
+ const { icon, FabProps, sx, activeWishlist } = props
50
30
 
51
31
  const wishlistIcon = icon ?? <IconSvg src={iconHeart} size='large' />
52
32
 
@@ -73,19 +53,30 @@ function WishlistFabContent(props: WishlistFabContentProps) {
73
53
  )
74
54
  }
75
55
 
76
- export function WishlistFab(props: WishlistFabContentProps) {
56
+ export type WishlistFabProps = Omit<WishlistFabContentProps, 'activeWishlist'>
57
+
58
+ export function WishlistFab(props: WishlistFabProps) {
77
59
  const isWishlistEnabled = useWishlistEnabled()
78
60
 
79
- const { data: token } = useQuery(CustomerTokenDocument)
80
- const isLoggedIn = token?.customerToken && token?.customerToken.valid
61
+ const { loggedIn } = useCustomerSession()
62
+
63
+ const { data: GetCustomerWishlistData } = useCustomerQuery(GetIsInWishlistsDocument)
64
+ const { data: guestWishlistData } = useGuestQuery(GuestWishlistDocument)
65
+
66
+ let activeWishlist = false
67
+ if (loggedIn) {
68
+ const wishlistItemCount = GetCustomerWishlistData?.customer?.wishlists[0]?.items_count || 0
69
+ activeWishlist = wishlistItemCount > 0
70
+ } else {
71
+ const wishlist = guestWishlistData?.guestWishlist?.items || []
72
+ activeWishlist = wishlist.length > 0
73
+ }
74
+
75
+ if (!isWishlistEnabled || hideForGuest) return null
81
76
 
82
77
  return (
83
- <>
84
- {isWishlistEnabled && (!hideForGuest || isLoggedIn) && (
85
- <NoSsr>
86
- <WishlistFabContent {...props} />
87
- </NoSsr>
88
- )}
89
- </>
78
+ <NoSsr fallback={<WishlistFabContent {...props} activeWishlist={false} />}>
79
+ <WishlistFabContent {...props} activeWishlist={activeWishlist} />
80
+ </NoSsr>
90
81
  )
91
82
  }
@@ -51,9 +51,9 @@ export function ProductAddToCart(
51
51
  return (
52
52
  <Box component='form' onSubmit={submitHandler} noValidate className={classes.root}>
53
53
  <Box
54
- sx={(theme) => ({
54
+ sx={{
55
55
  gridArea: 'itemQuantity',
56
- })}
56
+ }}
57
57
  >
58
58
  <TextInputNumber
59
59
  variant='outlined'
@@ -64,21 +64,21 @@ export function ProductAddToCart(
64
64
  helperText={formState.isSubmitted && formState.errors.quantity}
65
65
  disabled={formState.isSubmitting}
66
66
  size='small'
67
- sx={(theme) => ({
67
+ sx={{
68
68
  alignSelf: 'flex-start',
69
- })}
69
+ }}
70
70
  />
71
71
  </Box>
72
72
  {children}
73
73
  <Box
74
74
  className={classes.buttonWrapper}
75
- sx={(theme) => ({
75
+ sx={{
76
76
  gridArea: 'itemCartButton',
77
77
  alignSelf: 'flex-start',
78
78
  position: 'absolute',
79
79
  left: '0',
80
80
  bottom: '-35px',
81
- })}
81
+ }}
82
82
  >
83
83
  <Button
84
84
  type='submit'
@@ -1,3 +1,4 @@
1
+ import { InputMaybe } from '@graphcommerce/graphql-mesh'
1
2
  import { SxProps, Theme } from '@mui/material'
2
3
  import { PropsWithChildren } from 'react'
3
4
  import { ProductAddToCart } from './ProductAddToCart'
@@ -10,15 +11,16 @@ type OptionalProductWishlistParent = {
10
11
 
11
12
  export type WishlistItemProps = PropsWithChildren<WishlistItemProductFragment> & {
12
13
  sx?: SxProps<Theme>
14
+ selectedOptions?: InputMaybe<InputMaybe<string> | InputMaybe<string>[]> | undefined
13
15
  } & OptionalProductWishlistParent
14
16
 
15
17
  export function WishlistItem(props: WishlistItemProps) {
16
- const { sku, name, price_range } = props
18
+ const { sku, name, price_range, selectedOptions } = props
17
19
 
18
20
  return (
19
21
  <WishlistItemBase {...props}>
20
22
  <ProductAddToCart
21
- variables={{ sku: sku ?? '', quantity: 1 }}
23
+ variables={{ sku: sku ?? '', quantity: 1, selectedOptions }}
22
24
  name={name ?? ''}
23
25
  price={price_range.minimum_price.final_price}
24
26
  />
@@ -1,6 +1,6 @@
1
- import { useQuery, useMutation, useApolloClient } from '@graphcommerce/graphql'
1
+ import { useMutation, useApolloClient } from '@graphcommerce/graphql'
2
2
  import { Image } from '@graphcommerce/image'
3
- import { CustomerTokenDocument } from '@graphcommerce/magento-customer'
3
+ import { useCustomerQuery, useCustomerSession } from '@graphcommerce/magento-customer'
4
4
  import { useProductLink } from '@graphcommerce/magento-product'
5
5
  import { Money } from '@graphcommerce/magento-store'
6
6
  import { responsiveVal, extendableComponent, iconEllypsis, IconSvg } from '@graphcommerce/next-ui'
@@ -57,12 +57,9 @@ export function WishlistItemBase(props: WishlistItemBaseProps) {
57
57
  const productLink = useProductLink({ url_key, __typename: productType })
58
58
  const { cache } = useApolloClient()
59
59
 
60
- const { data: token } = useQuery(CustomerTokenDocument)
61
- const isLoggedIn = token?.customerToken && token?.customerToken.valid
60
+ const { loggedIn } = useCustomerSession()
62
61
 
63
- const { data: GetCustomerWishlistData } = useQuery(GetIsInWishlistsDocument, {
64
- skip: !isLoggedIn,
65
- })
62
+ const { data: GetCustomerWishlistData } = useCustomerQuery(GetIsInWishlistsDocument)
66
63
 
67
64
  const [removeWishlistItem] = useMutation(RemoveProductFromWishlistDocument)
68
65
 
@@ -75,7 +72,7 @@ export function WishlistItemBase(props: WishlistItemBaseProps) {
75
72
 
76
73
  const handleClose = (event) => {
77
74
  if (event.target.id === 'remove') {
78
- if (isLoggedIn) {
75
+ if (loggedIn) {
79
76
  let itemIdToDelete = wishlistItemId
80
77
 
81
78
  /** When no internal ID is provided, fetch it by sku */
@@ -1,5 +1,8 @@
1
- import { useQuery } from '@graphcommerce/graphql'
2
- import { CustomerTokenDocument } from '@graphcommerce/magento-customer'
1
+ import {
2
+ useCustomerQuery,
3
+ useCustomerSession,
4
+ useGuestQuery,
5
+ } from '@graphcommerce/magento-customer'
3
6
  import { MenuFabSecondaryItem, iconHeart, IconSvg } from '@graphcommerce/next-ui'
4
7
  import { Badge, NoSsr, SxProps, Theme } from '@mui/material'
5
8
  import React from 'react'
@@ -7,38 +10,17 @@ import { useWishlistEnabled } from '../../hooks'
7
10
  import { GetIsInWishlistsDocument } from '../../queries/GetIsInWishlists.gql'
8
11
  import { GuestWishlistDocument } from '../../queries/GuestWishlist.gql'
9
12
 
10
- type WishlistMenuFabItemProps = {
13
+ type WishlistMenuFabItemContentProps = {
11
14
  icon?: React.ReactNode
12
15
  children: React.ReactNode
13
16
  sx?: SxProps<Theme>
17
+ activeWishlist: boolean
14
18
  }
15
19
 
16
20
  const hideForGuest = process.env.NEXT_PUBLIC_WISHLIST_HIDE_FOR_GUEST === '1'
17
21
 
18
- function WishlistMenuFabItemContent(props: WishlistMenuFabItemProps) {
19
- const { icon, children, sx = [] } = props
20
-
21
- const { data: token } = useQuery(CustomerTokenDocument)
22
- const isLoggedIn = token?.customerToken && token?.customerToken.valid
23
-
24
- const { data: GetCustomerWishlistData } = useQuery(GetIsInWishlistsDocument, {
25
- ssr: false,
26
- skip: !isLoggedIn,
27
- })
28
-
29
- const { data: guestWishlistData } = useQuery(GuestWishlistDocument, {
30
- ssr: false,
31
- skip: isLoggedIn === true,
32
- })
33
-
34
- let activeWishlist
35
- if (isLoggedIn) {
36
- const wishlistItemCount = GetCustomerWishlistData?.customer?.wishlists[0]?.items_count || 0
37
- activeWishlist = wishlistItemCount > 0
38
- } else {
39
- const wishlist = guestWishlistData?.guestWishlist?.items || []
40
- activeWishlist = wishlist.length > 0
41
- }
22
+ function WishlistMenuFabItemContent(props: WishlistMenuFabItemContentProps) {
23
+ const { icon, children, sx = [], activeWishlist } = props
42
24
 
43
25
  return (
44
26
  <MenuFabSecondaryItem
@@ -60,19 +42,29 @@ function WishlistMenuFabItemContent(props: WishlistMenuFabItemProps) {
60
42
  )
61
43
  }
62
44
 
45
+ export type WishlistMenuFabItemProps = Omit<WishlistMenuFabItemContentProps, 'activeWishlist'>
46
+
63
47
  export function WishlistMenuFabItem(props: WishlistMenuFabItemProps) {
64
48
  const isWishlistEnabled = useWishlistEnabled()
49
+ const { loggedIn } = useCustomerSession()
65
50
 
66
- const { data: token } = useQuery(CustomerTokenDocument)
67
- const isLoggedIn = token?.customerToken && token?.customerToken.valid
51
+ const { data: GetCustomerWishlistData } = useCustomerQuery(GetIsInWishlistsDocument)
52
+ const { data: guestWishlistData } = useGuestQuery(GuestWishlistDocument)
53
+
54
+ let activeWishlist: boolean
55
+ if (loggedIn) {
56
+ const wishlistItemCount = GetCustomerWishlistData?.customer?.wishlists[0]?.items_count ?? 0
57
+ activeWishlist = wishlistItemCount > 0
58
+ } else {
59
+ const wishlist = guestWishlistData?.guestWishlist?.items ?? []
60
+ activeWishlist = wishlist.length > 0
61
+ }
68
62
 
63
+ if (hideForGuest) return null
64
+ if (!isWishlistEnabled) return null
69
65
  return (
70
- <>
71
- {isWishlistEnabled && (!hideForGuest || isLoggedIn) && (
72
- <NoSsr fallback={<WishlistMenuFabItemContent {...props} />}>
73
- <WishlistMenuFabItemContent {...props} />
74
- </NoSsr>
75
- )}
76
- </>
66
+ <NoSsr fallback={<WishlistMenuFabItemContent {...props} activeWishlist={false} />}>
67
+ <WishlistMenuFabItemContent {...props} activeWishlist={activeWishlist} />
68
+ </NoSsr>
77
69
  )
78
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/magento-wishlist",
3
- "version": "1.1.1",
3
+ "version": "1.2.2",
4
4
  "sideEffects": false,
5
5
  "prettier": "@graphcommerce/prettier-config-pwa",
6
6
  "browserslist": [
@@ -21,13 +21,13 @@
21
21
  "dependencies": {
22
22
  "@graphcommerce/graphql": "3.1.3",
23
23
  "@graphcommerce/graphql-mesh": "4.1.3",
24
- "@graphcommerce/image": "3.1.5",
25
- "@graphcommerce/magento-cart": "4.3.0",
26
- "@graphcommerce/magento-customer": "4.3.1",
27
- "@graphcommerce/magento-product": "4.3.6",
28
- "@graphcommerce/magento-product-configurable": "4.1.6",
29
- "@graphcommerce/magento-store": "4.2.4",
30
- "@graphcommerce/next-ui": "4.8.0"
24
+ "@graphcommerce/image": "3.1.6",
25
+ "@graphcommerce/magento-cart": "4.3.3",
26
+ "@graphcommerce/magento-customer": "4.4.1",
27
+ "@graphcommerce/magento-product": "4.4.2",
28
+ "@graphcommerce/magento-product-configurable": "4.1.9",
29
+ "@graphcommerce/magento-store": "4.2.7",
30
+ "@graphcommerce/next-ui": "4.8.3"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@lingui/react": "^3.13.2",