@graphcommerce/magento-product 3.0.2 → 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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.0.5](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-product@3.0.4...@graphcommerce/magento-product@3.0.5) (2021-09-28)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * add to cart button ([8a69454](https://github.com/ho-nl/m2-pwa/commit/8a69454b1372a563020e1ef1b7c50363b8d29717))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [3.0.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-product@3.0.0...@graphcommerce/magento-product@3.0.1) (2021-09-27)
7
18
 
8
19
  **Note:** Version bump only for package @graphcommerce/magento-product
@@ -0,0 +1,121 @@
1
+ import { ProductInterface } from '@graphcommerce/graphql'
2
+ import { ApolloCartErrorAlert, useFormGqlMutationCart } from '@graphcommerce/magento-cart'
3
+ import { Money, MoneyProps } from '@graphcommerce/magento-store'
4
+ import {
5
+ Button,
6
+ ButtonProps,
7
+ MessageSnackbar,
8
+ SvgImage,
9
+ TextInputNumber,
10
+ iconCheckmark,
11
+ iconChevronRight,
12
+ } from '@graphcommerce/next-ui'
13
+ import { Divider, makeStyles, Theme, Typography } from '@material-ui/core'
14
+ import PageLink from 'next/link'
15
+ import React from 'react'
16
+ import { ProductAddToCartDocument, ProductAddToCartMutationVariables } from './ProductAddToCart.gql'
17
+
18
+ const useStyles = makeStyles(
19
+ (theme: Theme) => ({
20
+ button: {
21
+ marginTop: theme.spacings.sm,
22
+ width: '100%',
23
+ },
24
+ messageIcon: {
25
+ marginBottom: '-2px',
26
+ marginRight: 5,
27
+ },
28
+ price: {
29
+ fontWeight: theme.typography.fontWeightBold,
30
+ margin: `${theme.spacings.sm} 0`,
31
+ },
32
+ divider: {
33
+ margin: `${theme.spacings.xs} 0`,
34
+ },
35
+ }),
36
+ { name: 'AddToCart' },
37
+ )
38
+
39
+ export type AddToCartProps = React.ComponentProps<typeof ProductAddToCart>
40
+
41
+ export default function ProductAddToCart(
42
+ props: Pick<ProductInterface, 'name'> & {
43
+ variables: Omit<ProductAddToCartMutationVariables, 'cartId'>
44
+ name: string
45
+ price: MoneyProps
46
+ children?: React.ReactNode
47
+ } & Omit<ButtonProps, 'type' | 'name'>,
48
+ ) {
49
+ const { name, children, variables, price, ...buttonProps } = props
50
+
51
+ const form = useFormGqlMutationCart(ProductAddToCartDocument, {
52
+ defaultValues: variables,
53
+ })
54
+
55
+ const { handleSubmit, formState, error, muiRegister, required } = form
56
+ const submitHandler = handleSubmit(() => {})
57
+ const classes = useStyles()
58
+
59
+ return (
60
+ <form onSubmit={submitHandler} noValidate>
61
+ <Divider className={classes.divider} />
62
+
63
+ <Typography variant='h4' className={classes.price}>
64
+ <Money {...price} />
65
+ </Typography>
66
+
67
+ <TextInputNumber
68
+ variant='outlined'
69
+ error={formState.isSubmitted && !!formState.errors.quantity}
70
+ required={required.quantity}
71
+ inputProps={{ min: 1 }}
72
+ {...muiRegister('quantity', { required: required.quantity })}
73
+ helperText={formState.isSubmitted && formState.errors.quantity}
74
+ disabled={formState.isSubmitting}
75
+ size='small'
76
+ />
77
+ {children}
78
+ <Button
79
+ type='submit'
80
+ classes={{ root: classes.button }}
81
+ loading={formState.isSubmitting}
82
+ color='primary'
83
+ variant='pill'
84
+ size='large'
85
+ {...buttonProps}
86
+ >
87
+ Add to Cart
88
+ </Button>
89
+
90
+ <ApolloCartErrorAlert error={error} />
91
+
92
+ <MessageSnackbar
93
+ open={!formState.isSubmitting && formState.isSubmitSuccessful && !error?.message}
94
+ variant='pill'
95
+ color='default'
96
+ action={
97
+ <PageLink href='/cart'>
98
+ <Button
99
+ size='medium'
100
+ variant='pill'
101
+ color='secondary'
102
+ endIcon={<SvgImage src={iconChevronRight} shade='inverted' alt='chevron right' />}
103
+ >
104
+ View shopping cart
105
+ </Button>
106
+ </PageLink>
107
+ }
108
+ >
109
+ <div>
110
+ <SvgImage
111
+ src={iconCheckmark}
112
+ loading='eager'
113
+ alt='checkmark'
114
+ className={classes.messageIcon}
115
+ />
116
+ <strong>{name}</strong>&nbsp;has been added to your shopping cart!
117
+ </div>
118
+ </MessageSnackbar>
119
+ </form>
120
+ )
121
+ }
@@ -1,5 +1,5 @@
1
- import { makeStyles, Theme } from '@material-ui/core'
2
1
  import { UseStyles, responsiveVal } from '@graphcommerce/next-ui'
2
+ import { makeStyles, Theme } from '@material-ui/core'
3
3
 
4
4
  import { ProductListCountFragment } from './ProductListCount.gql'
5
5
 
@@ -1,6 +1,6 @@
1
1
  import { cloneDeep } from '@apollo/client/utilities'
2
- import { Chip, ChipProps } from '@material-ui/core'
3
2
  import { useChipMenuStyles, SvgImage, iconCloseCircle } from '@graphcommerce/next-ui'
3
+ import { Chip, ChipProps } from '@material-ui/core'
4
4
  import clsx from 'clsx'
5
5
  import React from 'react'
6
6
  import { useProductListLinkPush } from '../../hooks/useProductListLinkPush'
@@ -1,4 +1,6 @@
1
1
  import { cloneDeep } from '@apollo/client/utilities'
2
+ import { FilterEqualTypeInput } from '@graphcommerce/graphql'
3
+ import { ChipMenu, ChipMenuProps, responsiveVal } from '@graphcommerce/next-ui'
2
4
  import {
3
5
  Checkbox,
4
6
  ListItem,
@@ -7,8 +9,6 @@ import {
7
9
  makeStyles,
8
10
  Theme,
9
11
  } from '@material-ui/core'
10
- import { FilterEqualTypeInput } from '@graphcommerce/graphql'
11
- import { ChipMenu, ChipMenuProps, responsiveVal } from '@graphcommerce/next-ui'
12
12
  import React from 'react'
13
13
  import { SetRequired } from 'type-fest'
14
14
  import { useProductListLinkPush } from '../../hooks/useProductListLinkPush'
@@ -1,8 +1,8 @@
1
1
  import { cloneDeep } from '@apollo/client/utilities'
2
- import { makeStyles, Mark, Slider, Theme } from '@material-ui/core'
3
2
  import { FilterRangeTypeInput } from '@graphcommerce/graphql'
4
3
  import { Money } from '@graphcommerce/magento-store'
5
4
  import { ChipMenu, ChipMenuProps } from '@graphcommerce/next-ui'
5
+ import { makeStyles, Mark, Slider, Theme } from '@material-ui/core'
6
6
  import React from 'react'
7
7
  import { useProductListLinkPush } from '../../hooks/useProductListLinkPush'
8
8
  import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
@@ -1,4 +1,3 @@
1
- import { makeStyles, Theme } from '@material-ui/core'
2
1
  import { Scroller, ScrollerButton, ScrollerProvider } from '@graphcommerce/framer-scroller'
3
2
  import {
4
3
  iconChevronLeft,
@@ -6,6 +5,7 @@ import {
6
5
  SvgImageSimple,
7
6
  UseStyles,
8
7
  } from '@graphcommerce/next-ui'
8
+ import { makeStyles, Theme } from '@material-ui/core'
9
9
  import clsx from 'clsx'
10
10
  import { m, useMotionTemplate, useTransform, useViewportScroll } from 'framer-motion'
11
11
  import React, { PropsWithChildren, useEffect, useRef, useState } from 'react'
@@ -1,6 +1,6 @@
1
- import { Link as MuiLink, makeStyles, Theme, Typography } from '@material-ui/core'
2
1
  import { Image, ImageProps } from '@graphcommerce/image'
3
2
  import { UseStyles, responsiveVal } from '@graphcommerce/next-ui'
3
+ import { Link as MuiLink, makeStyles, Theme, Typography } from '@material-ui/core'
4
4
  import clsx from 'clsx'
5
5
  import PageLink from 'next/link'
6
6
  import { useRouter } from 'next/router'
@@ -1,6 +1,6 @@
1
- import { Theme, makeStyles } from '@material-ui/core'
2
1
  import { Maybe } from '@graphcommerce/graphql'
3
2
  import { RenderType, UseStyles, responsiveVal } from '@graphcommerce/next-ui'
3
+ import { Theme, makeStyles } from '@material-ui/core'
4
4
  import clsx from 'clsx'
5
5
  import React from 'react'
6
6
  import { ProductListItemFragment } from '../../Api/ProductListItem.gql'
@@ -1,5 +1,5 @@
1
- import { PaginationProps } from '@material-ui/lab'
2
1
  import { Pagination } from '@graphcommerce/next-ui'
2
+ import { PaginationProps } from '@material-ui/lab'
3
3
  import React from 'react'
4
4
  import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
5
5
  import ProductListLink from '../ProductListLink/ProductListLink'
@@ -1,6 +1,6 @@
1
- import { makeStyles, Theme, Typography } from '@material-ui/core'
2
1
  import { Money } from '@graphcommerce/magento-store'
3
2
  import { UseStyles } from '@graphcommerce/next-ui'
3
+ import { makeStyles, Theme, Typography } from '@material-ui/core'
4
4
  import React from 'react'
5
5
  import { ProductListPriceFragment } from './ProductListPrice.gql'
6
6
 
@@ -1,8 +1,8 @@
1
1
  import { useQuery } from '@apollo/client'
2
2
  import { cloneDeep } from '@apollo/client/utilities'
3
- import { ListItem, ListItemText } from '@material-ui/core'
4
3
  import { StoreConfigDocument } from '@graphcommerce/magento-store'
5
4
  import { ChipMenu, ChipMenuProps } from '@graphcommerce/next-ui'
5
+ import { ListItem, ListItemText } from '@material-ui/core'
6
6
  import React from 'react'
7
7
  import { useProductListLinkPush } from '../../hooks/useProductListLinkPush'
8
8
  import { useProductListParamsContext } from '../../hooks/useProductListParamsContext'
@@ -1,5 +1,5 @@
1
- import { makeStyles, Theme, Typography } from '@material-ui/core'
2
1
  import { SvgImage, responsiveVal, iconBox } from '@graphcommerce/next-ui'
2
+ import { makeStyles, Theme, Typography } from '@material-ui/core'
3
3
  import React from 'react'
4
4
 
5
5
  const useStyles = makeStyles(
@@ -1,5 +1,5 @@
1
- import { makeStyles, Theme } from '@material-ui/core'
2
1
  import { UseStyles, responsiveVal } from '@graphcommerce/next-ui'
2
+ import { makeStyles, Theme } from '@material-ui/core'
3
3
  import { ProductSpecsFragment } from './ProductSpecs.gql'
4
4
 
5
5
  const useStyles = makeStyles((theme: Theme) => ({
@@ -1,5 +1,7 @@
1
1
  export * from './JsonLdProduct'
2
- export * from './ProductAddToCart/ProductAddToCart.gql'
2
+
3
+ export * from './ProductAddToCart/ProductAddToCart'
4
+ export { default as ProductAddToCart } from './ProductAddToCart/ProductAddToCart'
3
5
 
4
6
  export * from './ProductList/ProductList.gql'
5
7
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/magento-product",
3
- "version": "3.0.2",
3
+ "version": "3.0.6",
4
4
  "sideEffects": false,
5
5
  "prettier": "@graphcommerce/prettier-config-pwa",
6
6
  "browserslist": [
@@ -14,18 +14,19 @@
14
14
  },
15
15
  "devDependencies": {
16
16
  "@graphcommerce/browserslist-config-pwa": "^3.0.1",
17
- "@graphcommerce/eslint-config-pwa": "^3.0.1",
18
- "@graphcommerce/prettier-config-pwa": "^3.0.1",
19
- "@graphcommerce/typescript-config-pwa": "^3.0.1",
20
- "@playwright/test": "^1.14.1"
17
+ "@graphcommerce/eslint-config-pwa": "^3.0.4",
18
+ "@graphcommerce/prettier-config-pwa": "^3.0.2",
19
+ "@graphcommerce/typescript-config-pwa": "^3.1.0",
20
+ "@playwright/test": "^1.15.0"
21
21
  },
22
22
  "dependencies": {
23
23
  "@apollo/client": "^3.3.21",
24
- "@graphcommerce/framer-scroller": "^0.2.2",
25
- "@graphcommerce/graphql": "^2.103.1",
26
- "@graphcommerce/image": "^2.104.2",
27
- "@graphcommerce/magento-store": "^3.0.2",
28
- "@graphcommerce/next-ui": "^3.0.2",
24
+ "@graphcommerce/framer-scroller": "^0.2.5",
25
+ "@graphcommerce/graphql": "^2.103.4",
26
+ "@graphcommerce/image": "^2.104.5",
27
+ "@graphcommerce/magento-cart": "^3.0.6",
28
+ "@graphcommerce/magento-store": "^3.0.6",
29
+ "@graphcommerce/next-ui": "^3.0.6",
29
30
  "@graphql-typed-document-node/core": "^3.1.0",
30
31
  "@material-ui/core": "^4.12.3",
31
32
  "@material-ui/lab": "^4.0.0-alpha.60",
@@ -35,7 +36,7 @@
35
36
  "react": "^17.0.2",
36
37
  "react-dom": "^17.0.2",
37
38
  "schema-dts": "^1.0.0",
38
- "type-fest": "^2.1.0"
39
+ "type-fest": "^2.3.4"
39
40
  },
40
- "gitHead": "05d36d5da1bee914defba6d0ddb50d7fe1932866"
41
+ "gitHead": "cf2b61fa96aca043ff841b018334ca8c28e5e6cf"
41
42
  }