@graphcommerce/magento-compare 6.2.0-canary.9

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/Config.graphqls +17 -0
  3. package/components/CompareFab.tsx +100 -0
  4. package/components/CompareListAttributes.tsx +45 -0
  5. package/components/CompareListForm.tsx +83 -0
  6. package/components/CompareListIntroText.tsx +21 -0
  7. package/components/CompareListItems.tsx +28 -0
  8. package/components/CompareListRow.tsx +62 -0
  9. package/components/CompareListRowMoreInformation.tsx +58 -0
  10. package/components/CompareListSelect.tsx +77 -0
  11. package/components/CompareMessageSnackbar.tsx +59 -0
  12. package/components/CompareProductButton.tsx +59 -0
  13. package/components/CompareProductToggle.tsx +155 -0
  14. package/components/EmptyCompareList.tsx +19 -0
  15. package/components/EmptyCompareListButton.tsx +58 -0
  16. package/components/index.ts +13 -0
  17. package/graphql/AddProductsToCompareList.graphql +5 -0
  18. package/graphql/AssignCustomerToCompareList.graphql +5 -0
  19. package/graphql/ComparableItem.graphql +11 -0
  20. package/graphql/CompareList.graphql +5 -0
  21. package/graphql/CompareListFragment.graphql +12 -0
  22. package/graphql/CompareProductIdInternal.graphql +6 -0
  23. package/graphql/CompareSummary.graphql +5 -0
  24. package/graphql/CompareSummaryFragment.graphql +7 -0
  25. package/graphql/CreateCompareList.graphql +5 -0
  26. package/graphql/CurrentCompareUid.graphql +6 -0
  27. package/graphql/CurrentCompareUid.graphqls +7 -0
  28. package/graphql/CustomerCompareList.graphql +7 -0
  29. package/graphql/DeleteCompareList.graphql +5 -0
  30. package/graphql/RemoveProductsFromCompareList.graphql +5 -0
  31. package/graphql/index.ts +12 -0
  32. package/hooks/index.ts +6 -0
  33. package/hooks/useAssignCurrentCompareListUid.ts +16 -0
  34. package/hooks/useClearCurrentCompareListUid.ts +15 -0
  35. package/hooks/useCompareList.ts +10 -0
  36. package/hooks/useCompareListStyles.ts +21 -0
  37. package/hooks/useCompareListUidCreate.ts +27 -0
  38. package/hooks/useCompareSummary.ts +13 -0
  39. package/index.ts +3 -0
  40. package/next-env.d.ts +4 -0
  41. package/package.json +38 -0
  42. package/plugins/AddCompareFabNextToCart.tsx +19 -0
  43. package/plugins/AddCompareToProductPage.tsx +36 -0
  44. package/plugins/AddCompareTypePolicies.tsx +25 -0
  45. package/plugins/CompareAbleProductListItem.tsx +41 -0
  46. package/tsconfig.json +5 -0
  47. package/typePolicies.ts +12 -0
@@ -0,0 +1,155 @@
1
+ import { useMutation } from '@graphcommerce/graphql'
2
+ import { iconCompare, Button, Fab, FabProps } from '@graphcommerce/next-ui'
3
+ import { i18n } from '@lingui/core'
4
+ import { Trans } from '@lingui/react'
5
+ import { alpha, Checkbox, NoSsr, SxProps, Theme, useTheme } from '@mui/material'
6
+ import { useState } from 'react'
7
+ import { CompareProductIdInternalFragment } from '../graphql'
8
+ import { AddProductsToCompareListDocument } from '../graphql/AddProductsToCompareList.gql'
9
+ import { RemoveProductsFromCompareListDocument } from '../graphql/RemoveProductsFromCompareList.gql'
10
+ import { useCompareSummary } from '../hooks'
11
+ import { useCompareListUidCreate } from '../hooks/useCompareListUidCreate'
12
+ import { CompareMessageSnackbar } from './CompareMessageSnackbar'
13
+
14
+ type CompareProductToggleProps = {
15
+ sx?: SxProps<Theme>
16
+ product: CompareProductIdInternalFragment
17
+ } & Pick<FabProps, 'color'>
18
+
19
+ function CompareProductToggleBase(
20
+ props: CompareProductToggleProps & { inCompareList: boolean; id: string },
21
+ ) {
22
+ const { id, sx, inCompareList, product, color = 'inherit' } = props
23
+ const create = useCompareListUidCreate()
24
+ const compareList = useCompareSummary()
25
+
26
+ const [add, addResult] = useMutation(AddProductsToCompareListDocument)
27
+ const [remove, removeResult] = useMutation(RemoveProductsFromCompareListDocument)
28
+ const loading = addResult.loading || removeResult.loading
29
+
30
+ const [displayMessageBar, setDisplayMessageBar] = useState(false)
31
+ const label = inCompareList
32
+ ? i18n._(/* i18n */ 'Remove from comparison')
33
+ : i18n._(/* i18n */ 'Add to comparison')
34
+
35
+ const handleClick: React.MouseEventHandler<HTMLButtonElement> = async (e) => {
36
+ e.preventDefault()
37
+
38
+ if (inCompareList) {
39
+ await remove({ variables: { products: [id], uid: await create() } })
40
+ } else {
41
+ await add({ variables: { products: [id], uid: await create() } })
42
+ setDisplayMessageBar(true)
43
+ }
44
+ }
45
+
46
+ const preventAnimationBubble = (
47
+ e: React.TouchEvent<HTMLButtonElement> | React.MouseEvent<HTMLButtonElement>,
48
+ ) => {
49
+ e.stopPropagation()
50
+ if (e.type === 'mousedown') {
51
+ e.preventDefault()
52
+ }
53
+ }
54
+
55
+ const theme2 = useTheme()
56
+
57
+ let strokeColorPlp: string
58
+ if (!inCompareList) {
59
+ strokeColorPlp =
60
+ theme2.palette.mode === 'light'
61
+ ? theme2.palette.text.secondary
62
+ : theme2.palette.background.paper
63
+ } else {
64
+ strokeColorPlp = theme2.palette.primary.main
65
+ }
66
+
67
+ let strokeColorPdp: string
68
+ if (!inCompareList) {
69
+ strokeColorPdp =
70
+ theme2.palette.mode === 'light'
71
+ ? theme2.palette.text.secondary
72
+ : theme2.palette.primary.contrastText
73
+ } else {
74
+ strokeColorPdp = theme2.palette.primary.main
75
+ }
76
+
77
+ return (
78
+ <>
79
+ {import.meta.graphCommerce.compareVariant === 'CHECKBOX' ? (
80
+ <Button
81
+ variant='text'
82
+ size='small'
83
+ onMouseDown={preventAnimationBubble}
84
+ onTouchStart={preventAnimationBubble}
85
+ onClick={handleClick}
86
+ sx={{
87
+ padding: 0,
88
+ '&:hover': {
89
+ background: 'transparent',
90
+ },
91
+ }}
92
+ title={label}
93
+ aria-label={label}
94
+ loading={loading}
95
+ >
96
+ <Checkbox checked={inCompareList} />
97
+ <Trans id='Compare' />
98
+ </Button>
99
+ ) : (
100
+ <Fab
101
+ onClick={handleClick}
102
+ onMouseDown={preventAnimationBubble}
103
+ onTouchStart={preventAnimationBubble}
104
+ size='responsive'
105
+ color={color}
106
+ sx={[
107
+ (theme) => ({
108
+ flex: `0 0 auto`,
109
+ '& svg': {
110
+ stroke: strokeColorPlp,
111
+ },
112
+ '&:hover': {
113
+ backgroundColor: alpha(
114
+ theme.palette.text.primary,
115
+ theme.palette.action.hoverOpacity,
116
+ ),
117
+ },
118
+ '.SidebarGallery-root & svg': {
119
+ stroke: strokeColorPdp,
120
+ },
121
+ }),
122
+ ...(Array.isArray(sx) ? sx : [sx]),
123
+ ]}
124
+ title={label}
125
+ aria-label={label}
126
+ icon={iconCompare}
127
+ loading={loading}
128
+ />
129
+ )}
130
+
131
+ {displayMessageBar && (
132
+ <CompareMessageSnackbar
133
+ displayMessageBar={displayMessageBar}
134
+ setDisplayMessageBar={setDisplayMessageBar}
135
+ count={compareList.data?.compareList?.item_count}
136
+ name={product.name}
137
+ />
138
+ )}
139
+ </>
140
+ )
141
+ }
142
+
143
+ export function CompareProductToggle(props: CompareProductToggleProps) {
144
+ const { product } = props
145
+ const compareList = useCompareSummary()
146
+ const idString = String(product.compare_product_id)
147
+ const inCompareList =
148
+ compareList.data?.compareList?.items?.some((i) => i?.uid === idString) ?? false
149
+
150
+ return (
151
+ <NoSsr fallback={<CompareProductToggleBase {...props} inCompareList={false} id={idString} />}>
152
+ <CompareProductToggleBase {...props} inCompareList={inCompareList} id={idString} />
153
+ </NoSsr>
154
+ )
155
+ }
@@ -0,0 +1,19 @@
1
+ import { FullPageMessage, IconSvg, iconCompare } from '@graphcommerce/next-ui'
2
+ import { Trans } from '@lingui/react'
3
+ import { Button } from '@mui/material'
4
+
5
+ export function EmptyCompareList() {
6
+ return (
7
+ <FullPageMessage
8
+ title={<Trans id='Your comparelist is empty' />}
9
+ icon={<IconSvg src={iconCompare} size='xxl' />}
10
+ button={
11
+ <Button href='/' variant='pill' color='secondary' size='large'>
12
+ <Trans id='Continue shopping' />
13
+ </Button>
14
+ }
15
+ >
16
+ <Trans id='Discover our collection and add items to your comparelist!' />
17
+ </FullPageMessage>
18
+ )
19
+ }
@@ -0,0 +1,58 @@
1
+ import { usePageContext, useGo } from '@graphcommerce/framer-next-pages'
2
+ import { useMutation } from '@graphcommerce/graphql'
3
+ import { LinkOrButton, LinkOrButtonProps } from '@graphcommerce/next-ui'
4
+ import { Trans } from '@lingui/react'
5
+ import { DeleteCompareListDocument } from '../graphql/DeleteCompareList.gql'
6
+ import { useCompareList } from '../hooks'
7
+ import { useClearCurrentCompareListUid } from '../hooks/useClearCurrentCompareListUid'
8
+
9
+ type EmptyCompareListButtonProps = Omit<LinkOrButtonProps, 'onClick' | 'children'>
10
+
11
+ export function EmptyCompareListButton(props: EmptyCompareListButtonProps) {
12
+ const { button = {}, link = {} } = props
13
+ const compareList = useCompareList()
14
+
15
+ const onCompleted = useClearCurrentCompareListUid()
16
+ const [deleteCompareList] = useMutation(DeleteCompareListDocument, {
17
+ variables: { uid: compareList.data?.compareList?.uid ?? '' },
18
+ onCompleted,
19
+ })
20
+ const { closeSteps } = usePageContext()
21
+ const go = useGo(closeSteps * -1)
22
+
23
+ if (!compareList.data?.compareList?.uid) return null
24
+
25
+ return (
26
+ <LinkOrButton
27
+ {...props}
28
+ color='secondary'
29
+ button={{
30
+ variant: 'pill',
31
+ ...button,
32
+ sx: [
33
+ {
34
+ whiteSpace: 'nowrap',
35
+ },
36
+ ...(Array.isArray(button.sx) ? button.sx : [button.sx]),
37
+ ],
38
+ }}
39
+ link={{
40
+ ...link,
41
+ sx: [
42
+ {
43
+ whiteSpace: 'nowrap',
44
+ },
45
+ ...(Array.isArray(link.sx) ? link.sx : [link.sx]),
46
+ ],
47
+ }}
48
+ onClick={() => {
49
+ go()
50
+
51
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
52
+ deleteCompareList()
53
+ }}
54
+ >
55
+ <Trans id='Empty comparelist' />
56
+ </LinkOrButton>
57
+ )
58
+ }
@@ -0,0 +1,13 @@
1
+ export * from './CompareFab'
2
+ export * from './CompareListAttributes'
3
+ export * from './CompareListForm'
4
+ export * from './CompareListIntroText'
5
+ export * from './CompareListItems'
6
+ export * from './CompareListSelect'
7
+ export * from './CompareMessageSnackbar'
8
+ export * from './CompareProductButton'
9
+ export * from './CompareProductToggle'
10
+ export * from './CompareListRow'
11
+ export * from './EmptyCompareList'
12
+ export * from './EmptyCompareListButton'
13
+ export * from './CompareListRowMoreInformation'
@@ -0,0 +1,5 @@
1
+ mutation AddProductsToCompareList($uid: ID!, $products: [ID!]!) {
2
+ compareList: addProductsToCompareList(input: { uid: $uid, products: $products }) {
3
+ ...CompareSummaryFragment
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ mutation AssignCompareListToCustomer($uid: ID!) {
2
+ assignCompareListToCustomer(uid: $uid) {
3
+ result
4
+ }
5
+ }
@@ -0,0 +1,11 @@
1
+ fragment ComparableItem on ComparableItem {
2
+ uid
3
+ attributes {
4
+ code
5
+ value
6
+ }
7
+ product {
8
+ uid
9
+ ...ProductListItem
10
+ }
11
+ }
@@ -0,0 +1,5 @@
1
+ query CompareList($uid: ID!) {
2
+ compareList(uid: $uid) {
3
+ ...CompareListFragment
4
+ }
5
+ }
@@ -0,0 +1,12 @@
1
+ fragment CompareListFragment on CompareList {
2
+ uid
3
+ attributes {
4
+ code
5
+ label
6
+ }
7
+ item_count
8
+
9
+ items {
10
+ ...ComparableItem
11
+ }
12
+ }
@@ -0,0 +1,6 @@
1
+ fragment CompareProductIdInternal on ProductInterface
2
+ @inject(into: ["UseAddProductsToCartAction", "ProductListItem"]) {
3
+ __typename
4
+ compare_product_id: id
5
+ name
6
+ }
@@ -0,0 +1,5 @@
1
+ query CompareSummary($uid: ID!) {
2
+ compareList(uid: $uid) {
3
+ ...CompareSummaryFragment
4
+ }
5
+ }
@@ -0,0 +1,7 @@
1
+ fragment CompareSummaryFragment on CompareList {
2
+ uid
3
+ item_count
4
+ items {
5
+ uid
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ mutation CreateCompareList($products: [ID!]!) {
2
+ createCompareList(input: { products: $products }) {
3
+ ...CompareSummaryFragment
4
+ }
5
+ }
@@ -0,0 +1,6 @@
1
+ query CurrentCompareUid {
2
+ currentCompareUid @client {
3
+ __typename
4
+ uid
5
+ }
6
+ }
@@ -0,0 +1,7 @@
1
+ extend type Query {
2
+ currentCompareUid: CurrentCompareUid
3
+ }
4
+
5
+ type CurrentCompareUid {
6
+ uid: String
7
+ }
@@ -0,0 +1,7 @@
1
+ query CustomerCompareList {
2
+ customer {
3
+ compare_list {
4
+ ...CompareListFragment
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ mutation DeleteCompareList($uid: ID!) {
2
+ deleteCompareList(uid: $uid) {
3
+ result
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ mutation RemoveProductsFromCompareList($uid: ID!, $products: [ID!]!) {
2
+ compareList: removeProductsFromCompareList(input: { uid: $uid, products: $products }) {
3
+ ...CompareSummaryFragment
4
+ }
5
+ }
@@ -0,0 +1,12 @@
1
+ export * from './AddProductsToCompareList.gql'
2
+ export * from './AssignCustomerToCompareList.gql'
3
+ export * from './CompareList.gql'
4
+ export * from './CompareListFragment.gql'
5
+ export * from './CompareProductIdInternal.gql'
6
+ export * from './CreateCompareList.gql'
7
+ export * from './CurrentCompareUid.gql'
8
+ export * from './CustomerCompareList.gql'
9
+ export * from './DeleteCompareList.gql'
10
+ export * from './RemoveProductsFromCompareList.gql'
11
+ export * from './CompareSummary.gql'
12
+ export * from './ComparableItem.gql'
package/hooks/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './useAssignCurrentCompareListUid'
2
+ export * from './useClearCurrentCompareListUid'
3
+ export * from './useCompareList'
4
+ export * from './useCompareListStyles'
5
+ export * from './useCompareListUidCreate'
6
+ export * from './useCompareSummary'
@@ -0,0 +1,16 @@
1
+ import { ApolloCache, useApolloClient } from '@graphcommerce/graphql'
2
+ import { useCallback } from 'react'
3
+ import { CurrentCompareUidDocument } from '../graphql'
4
+
5
+ function writeCompareUid(cache: ApolloCache<object>, uid: string | null = null) {
6
+ cache.writeQuery({
7
+ query: CurrentCompareUidDocument,
8
+ data: { currentCompareUid: { __typename: 'CurrentCompareUid', uid } },
9
+ broadcast: true,
10
+ })
11
+ }
12
+
13
+ export function useAssignCurrentCompareListUid() {
14
+ const { cache } = useApolloClient()
15
+ return useCallback((uid: string) => writeCompareUid(cache, uid), [cache])
16
+ }
@@ -0,0 +1,15 @@
1
+ import { useApolloClient } from '@graphcommerce/graphql'
2
+ import { CurrentCompareUidDocument } from '../graphql'
3
+
4
+ export function useClearCurrentCompareListUid() {
5
+ const { cache } = useApolloClient()
6
+
7
+ return () => {
8
+ const id = cache.readQuery({ query: CurrentCompareUidDocument })?.currentCompareUid?.uid
9
+ if (!id) return
10
+
11
+ cache.evict({ fieldName: 'currentCompareUid', broadcast: true })
12
+ cache.evict({ fieldName: 'compareList', broadcast: true })
13
+ cache.gc()
14
+ }
15
+ }
@@ -0,0 +1,10 @@
1
+ import { useQuery } from '@graphcommerce/graphql'
2
+ import { CompareListDocument, CurrentCompareUidDocument } from '../graphql'
3
+
4
+ export function useCompareList() {
5
+ const currentCompareUid = useQuery(CurrentCompareUidDocument)
6
+ const uid = currentCompareUid.data?.currentCompareUid?.uid
7
+ const compareList = useQuery(CompareListDocument, { variables: { uid: uid ?? '' }, skip: !uid })
8
+
9
+ return compareList
10
+ }
@@ -0,0 +1,21 @@
1
+ import { useTheme } from '@mui/material'
2
+
3
+ export function useCompareListStyles() {
4
+ const theme = useTheme()
5
+ return {
6
+ display: 'flex ',
7
+ justifyContent: 'center',
8
+ gap: theme.spacings.md,
9
+ '& > *': {
10
+ width: {
11
+ md: `calc(100% / 3)`,
12
+ xs: `calc(100% / 2)`,
13
+ },
14
+ },
15
+ [theme.breakpoints.down('md')]: {
16
+ '> *:nth-of-type(2) ~ *': {
17
+ display: 'none',
18
+ },
19
+ },
20
+ }
21
+ }
@@ -0,0 +1,27 @@
1
+ import { useApolloClient } from '@graphcommerce/graphql'
2
+ import { i18n } from '@lingui/core'
3
+ import { CreateCompareListDocument, CurrentCompareUidDocument } from '../graphql'
4
+ import { useAssignCurrentCompareListUid } from './useAssignCurrentCompareListUid'
5
+
6
+ export function useCompareListUidCreate() {
7
+ const client = useApolloClient()
8
+ const assign = useAssignCurrentCompareListUid()
9
+
10
+ return async (): Promise<string> => {
11
+ const uid = client.cache.readQuery({ query: CurrentCompareUidDocument })?.currentCompareUid?.uid
12
+
13
+ if (uid) return uid
14
+
15
+ const { data } = await client.mutate({
16
+ mutation: CreateCompareListDocument,
17
+ variables: { products: [] },
18
+ })
19
+ if (!data?.createCompareList)
20
+ throw Error(i18n._(/* i18n */ 'Could not create a new compare list'))
21
+
22
+ // We store the uid that is returned as the currentCompareList result
23
+ assign(data.createCompareList.uid)
24
+
25
+ return data.createCompareList.uid
26
+ }
27
+ }
@@ -0,0 +1,13 @@
1
+ import { useQuery } from '@graphcommerce/graphql'
2
+ import { CurrentCompareUidDocument, CompareSummaryDocument } from '../graphql'
3
+
4
+ export function useCompareSummary() {
5
+ const currentCompareUid = useQuery(CurrentCompareUidDocument)
6
+ const uid = currentCompareUid.data?.currentCompareUid?.uid
7
+ const compareList = useQuery(CompareSummaryDocument, {
8
+ variables: { uid: uid ?? '' },
9
+ skip: !uid,
10
+ })
11
+
12
+ return compareList
13
+ }
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './components'
2
+ export * from './graphql'
3
+ export * from './hooks'
package/next-env.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /// <reference types="next" />
2
+ /// <reference types="next/types/global" />
3
+ /// <reference types="next/image-types/global" />
4
+ /// <reference types="@graphcommerce/next-ui/types" />
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@graphcommerce/magento-compare",
3
+ "homepage": "https://www.graphcommerce.org/",
4
+ "repository": "github:graphcommerce-org/graphcommerce",
5
+ "version": "6.2.0-canary.9",
6
+ "sideEffects": false,
7
+ "prettier": "@graphcommerce/prettier-config-pwa",
8
+ "eslintConfig": {
9
+ "extends": "@graphcommerce/eslint-config-pwa",
10
+ "parserOptions": {
11
+ "project": "./tsconfig.json"
12
+ }
13
+ },
14
+ "devDependencies": {
15
+ "@graphcommerce/eslint-config-pwa": "6.2.0-canary.9",
16
+ "@graphcommerce/prettier-config-pwa": "6.2.0-canary.9",
17
+ "@graphcommerce/typescript-config-pwa": "6.2.0-canary.9"
18
+ },
19
+ "dependencies": {
20
+ "@graphcommerce/ecommerce-ui": "6.2.0-canary.9",
21
+ "@graphcommerce/framer-utils": "6.2.0-canary.9",
22
+ "@graphcommerce/magento-cart": "6.2.0-canary.9",
23
+ "@graphcommerce/magento-product": "6.2.0-canary.9",
24
+ "@graphcommerce/framer-next-pages": "6.2.0-canary.9",
25
+ "@graphcommerce/graphql": "6.2.0-canary.9",
26
+ "@graphcommerce/next-ui": "6.2.0-canary.9"
27
+ },
28
+ "peerDependencies": {
29
+ "@lingui/react": "^3.13.2",
30
+ "@lingui/core": "^3.13.2",
31
+ "@mui/material": "^5.10.16",
32
+ "framer-motion": "^10.0.0",
33
+ "graphql": "^16.0.0",
34
+ "next": "^13.2.0",
35
+ "react": "^18.2.0",
36
+ "react-dom": "^18.2.0"
37
+ }
38
+ }
@@ -0,0 +1,19 @@
1
+ import { CartFabProps } from '@graphcommerce/magento-cart'
2
+ import type { IfConfig, PluginProps } from '@graphcommerce/next-config'
3
+ import { CompareFab } from '../components'
4
+
5
+ export const component = 'CartFab'
6
+ export const exported = '@graphcommerce/magento-cart'
7
+ export const ifConfig: IfConfig = 'compare'
8
+
9
+ function MagentoCompareListGraphqlProvider(props: PluginProps<CartFabProps>) {
10
+ const { Prev, ...rest } = props
11
+ return (
12
+ <>
13
+ <Prev {...rest} />
14
+ <CompareFab />
15
+ </>
16
+ )
17
+ }
18
+
19
+ export const Plugin = MagentoCompareListGraphqlProvider
@@ -0,0 +1,36 @@
1
+ import { ProductPageAddToCartRowProps } from '@graphcommerce/magento-product'
2
+ import type { IfConfig, PluginProps } from '@graphcommerce/next-config'
3
+ import { CompareProductToggle } from '../components'
4
+
5
+ export const component = 'ProductPageAddToCartActionsRow'
6
+ export const exported = '@graphcommerce/magento-product'
7
+ export const ifConfig: IfConfig = 'compare'
8
+
9
+ function AddCompareToProductPage(props: PluginProps<ProductPageAddToCartRowProps>) {
10
+ const { Prev, ...rest } = props
11
+ const { children, after, product } = props
12
+ if (import.meta.graphCommerce.compareVariant === 'CHECKBOX')
13
+ return (
14
+ <Prev
15
+ {...rest}
16
+ after={
17
+ <>
18
+ {after}
19
+ <CompareProductToggle product={product} />
20
+ </>
21
+ }
22
+ />
23
+ )
24
+
25
+ if (
26
+ import.meta.graphCommerce.compareVariant === 'ICON' ||
27
+ !import.meta.graphCommerce.compareVariant
28
+ )
29
+ return (
30
+ <Prev {...rest}>
31
+ {children}
32
+ <CompareProductToggle product={product} color='default' />
33
+ </Prev>
34
+ )
35
+ }
36
+ export const Plugin = AddCompareToProductPage
@@ -0,0 +1,25 @@
1
+ import { GraphQLProviderProps } from '@graphcommerce/graphql'
2
+ import type { IfConfig, PluginProps } from '@graphcommerce/next-config'
3
+ import { compareTypePolicies } from '../typePolicies'
4
+
5
+ export const component = 'GraphQLProvider'
6
+ export const exported = '@graphcommerce/graphql'
7
+ export const ifConfig: IfConfig = 'compare'
8
+
9
+ function MagentoCompareListGraphqlProvider(props: PluginProps<GraphQLProviderProps>) {
10
+ const {
11
+ Prev,
12
+ policies = [],
13
+ // migrations = [],
14
+ ...rest
15
+ } = props
16
+ return (
17
+ <Prev
18
+ {...rest}
19
+ policies={[...policies, compareTypePolicies]}
20
+ // migrations={[...migrations, migrateCart]}
21
+ />
22
+ )
23
+ }
24
+
25
+ export const Plugin = MagentoCompareListGraphqlProvider