@graphcommerce/magento-cart-email 2.104.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.
@@ -0,0 +1,4 @@
1
+ /* eslint-disable */
2
+ import * as Types from '@graphcommerce/graphql';
3
+
4
+ export type GuestEmailChangedFragment = { id: string };
@@ -0,0 +1,3 @@
1
+ fragment GuestEmailChanged on Cart @injectable {
2
+ id
3
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,113 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [2.104.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.104.0...@graphcommerce/magento-cart-email@2.104.1) (2021-09-27)
7
+
8
+ **Note:** Version bump only for package @graphcommerce/magento-cart-email
9
+
10
+
11
+
12
+
13
+
14
+ # 2.104.0 (2021-09-27)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * adjust imports to correct ones ([c6e3092](https://github.com/ho-nl/m2-pwa/commit/c6e3092569d1c49fe138b3810704da8e04acbbe2))
20
+ * email field not filled in checkout ([910caca](https://github.com/ho-nl/m2-pwa/commit/910cacaa49fc5fef2ee4066df828c5a6dd4a2700))
21
+ * ignore md files from triggering version updates ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
22
+ * implement next-ui barrel imports ([75bea70](https://github.com/ho-nl/m2-pwa/commit/75bea703dba898f18a2a1dfa3243ebd0a4e6f0e1))
23
+ * make sure ComposedForm actually submits correctly ([c6499d9](https://github.com/ho-nl/m2-pwa/commit/c6499d9d36f874cd65b310cbf7f63f5a88fa86cd))
24
+ * make sure the session token gets deactivated when trying to merge carts when it cant ([2a9416b](https://github.com/ho-nl/m2-pwa/commit/2a9416b5c9efcd28a27f4183922ab419f62ea767))
25
+ * ref couldn't be forwarded for ShippingAddressForm ([1f90f1a](https://github.com/ho-nl/m2-pwa/commit/1f90f1a30437d656fcf841026ad13bb2b45d831b))
26
+ * rename NextButton to Button, change imports ([976adb0](https://github.com/ho-nl/m2-pwa/commit/976adb0bf906310d1efce888dcc9be1e28ce0f1b))
27
+
28
+
29
+ ### Features
30
+
31
+ * add barrel file for magento-customer ([02fb7f0](https://github.com/ho-nl/m2-pwa/commit/02fb7f004de968ee968b00e364b2b370f4f7d4f1))
32
+ * **cart:** merge customer and guest carts when logging in ([25ebc0f](https://github.com/ho-nl/m2-pwa/commit/25ebc0f4e825f8512e2c3f1e01bf23a2d019b0d3))
33
+ * **cart:** when a cart is not active anymore show a clear cart button ([5d04a14](https://github.com/ho-nl/m2-pwa/commit/5d04a14726c040b20b34c0b88f923aee1dff22e5))
34
+ * **graphql:** introduced new graphql package that holds all generated files ([a3e7aa0](https://github.com/ho-nl/m2-pwa/commit/a3e7aa05540540533b5ced9a95f1f802ecbe499f))
35
+ * **image:** introduced completely rewritten Image component ([e3413b3](https://github.com/ho-nl/m2-pwa/commit/e3413b3a57392d6571ea64cb8d9c8dca05ea31df))
36
+ * **inline-account:** re-added the component ([c508d34](https://github.com/ho-nl/m2-pwa/commit/c508d341ca34daa26a6db13ead72f7f4bdc72160))
37
+ * next.js 11 ([7d61407](https://github.com/ho-nl/m2-pwa/commit/7d614075a778f488045034f74be4f75b93f63c43))
38
+ * **playwright:** added new playwright package to enable browser testing ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
39
+ * renamed all packages to use [@graphcommerce](https://github.com/graphcommerce) instead of [@reachdigital](https://github.com/reachdigital) ([491e4ce](https://github.com/ho-nl/m2-pwa/commit/491e4cec9a2686472dac36b79f999257c0811ffe))
40
+ * submit composed form sequentially ([890d839](https://github.com/ho-nl/m2-pwa/commit/890d8393d635c3777aa17cfa8d4dafc13c2e6cdc))
41
+ * upgraded to nextjs 11 ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
42
+ * useFormMutationCart and simpler imports ([012f090](https://github.com/ho-nl/m2-pwa/commit/012f090e8f54d09f35d393c61ad1e2319f5a90ff))
43
+
44
+
45
+ ### Reverts
46
+
47
+ * Revert "chore: upgrade @apollo/client" ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
48
+
49
+
50
+
51
+
52
+
53
+ # Change Log
54
+
55
+ All notable changes to this project will be documented in this file. See
56
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
57
+
58
+ # [2.103.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.102.19...@graphcommerce/magento-cart-email@2.103.0) (2021-09-24)
59
+
60
+ ### Features
61
+
62
+ - **inline-account:** re-added the component
63
+ ([c508d34](https://github.com/ho-nl/m2-pwa/commit/c508d341ca34daa26a6db13ead72f7f4bdc72160))
64
+
65
+ ## [2.102.8](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.102.7...@graphcommerce/magento-cart-email@2.102.8) (2021-08-18)
66
+
67
+ ### Bug Fixes
68
+
69
+ - make sure the session token gets deactivated when trying to merge carts when
70
+ it cant
71
+ ([2a9416b](https://github.com/ho-nl/m2-pwa/commit/2a9416b5c9efcd28a27f4183922ab419f62ea767))
72
+
73
+ ## [2.102.5](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.102.4...@graphcommerce/magento-cart-email@2.102.5) (2021-08-13)
74
+
75
+ ### Bug Fixes
76
+
77
+ - ref couldn't be forwarded for ShippingAddressForm
78
+ ([1f90f1a](https://github.com/ho-nl/m2-pwa/commit/1f90f1a30437d656fcf841026ad13bb2b45d831b))
79
+
80
+ # [2.102.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.101.10...@graphcommerce/magento-cart-email@2.102.0) (2021-08-12)
81
+
82
+ ### Features
83
+
84
+ - upgraded to nextjs 11
85
+ ([0053beb](https://github.com/ho-nl/m2-pwa/commit/0053beb7ef597c190add7264256a0eaec35868da))
86
+
87
+ ## [2.101.9](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.101.8...@graphcommerce/magento-cart-email@2.101.9) (2021-08-09)
88
+
89
+ ### Reverts
90
+
91
+ - Revert "chore: upgrade @apollo/client"
92
+ ([55ff24e](https://github.com/ho-nl/m2-pwa/commit/55ff24ede0e56c85b8095edadadd1ec5e0b1b8d2))
93
+
94
+ # [2.101.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.100.19...@graphcommerce/magento-cart-email@2.101.0) (2021-07-26)
95
+
96
+ ### Features
97
+
98
+ - **playwright:** added new playwright package to enable browser testing
99
+ ([6f49ec7](https://github.com/ho-nl/m2-pwa/commit/6f49ec7595563775b96ebf21c27e39da1282e8d9))
100
+
101
+ ## [2.100.17](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.100.16...@graphcommerce/magento-cart-email@2.100.17) (2021-07-23)
102
+
103
+ ### Bug Fixes
104
+
105
+ - adjust imports to correct ones
106
+ ([c6e3092](https://github.com/ho-nl/m2-pwa/commit/c6e3092569d1c49fe138b3810704da8e04acbbe2))
107
+
108
+ ## [2.100.11](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/magento-cart-email@2.100.10...@graphcommerce/magento-cart-email@2.100.11) (2021-07-20)
109
+
110
+ ### Bug Fixes
111
+
112
+ - ignore md files from triggering version updates
113
+ ([4f98392](https://github.com/ho-nl/m2-pwa/commit/4f9839250b3a32d3070da5290e5efcc5e2243fba))
@@ -0,0 +1,12 @@
1
+ /* eslint-disable */
2
+ import * as Types from '@graphcommerce/graphql';
3
+
4
+ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
5
+
6
+ export const CartEmailDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"CartEmail"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"cartId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cart"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"cart_id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"cartId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"email"}}]}}]}}]} as unknown as DocumentNode<CartEmailQuery, CartEmailQueryVariables>;
7
+ export type CartEmailQueryVariables = Types.Exact<{
8
+ cartId: Types.Scalars['String'];
9
+ }>;
10
+
11
+
12
+ export type CartEmailQuery = { cart?: Types.Maybe<{ id: string, email?: Types.Maybe<string> }> };
@@ -0,0 +1,5 @@
1
+ query CartEmail($cartId: String!) {
2
+ cart(cart_id: $cartId) {
3
+ ...EmailForm
4
+ }
5
+ }
@@ -0,0 +1,4 @@
1
+ /* eslint-disable */
2
+ import * as Types from '@graphcommerce/graphql';
3
+
4
+ export type EmailFormFragment = { id: string, email?: Types.Maybe<string> };
@@ -0,0 +1,4 @@
1
+ fragment EmailForm on Cart {
2
+ id
3
+ email
4
+ }
@@ -0,0 +1,138 @@
1
+ import { useMutation } from '@apollo/client'
2
+ import { CircularProgress, makeStyles, TextField } from '@material-ui/core'
3
+ import { Alert } from '@material-ui/lab'
4
+ import {
5
+ ApolloCartErrorAlert,
6
+ useCartQuery,
7
+ useMergeCustomerCart,
8
+ } from '@graphcommerce/magento-cart'
9
+ import {
10
+ SignInFormInline,
11
+ SignUpFormInline,
12
+ useFormIsEmailAvailable,
13
+ } from '@graphcommerce/magento-customer'
14
+ import { AnimatedRow, Button, FormDiv, FormRow } from '@graphcommerce/next-ui'
15
+ import { emailPattern, useFormCompose, UseFormComposeOptions } from '@graphcommerce/react-hook-form'
16
+ import { AnimatePresence } from 'framer-motion'
17
+ import React, { useEffect, useState } from 'react'
18
+ import EmailHelperList from '../EmailHelperList'
19
+ import { CartEmailDocument } from './CartEmail.gql'
20
+ import { SetGuestEmailOnCartDocument } from './SetGuestEmailOnCart.gql'
21
+
22
+ const useStyles = makeStyles(
23
+ () => ({
24
+ helperList: {
25
+ marginBottom: 0,
26
+ },
27
+ }),
28
+ { name: 'EmailForm' },
29
+ )
30
+
31
+ export type EmailFormProps = Pick<UseFormComposeOptions, 'step'>
32
+
33
+ export default function EmailForm(props: EmailFormProps) {
34
+ const { step } = props
35
+ const classes = useStyles()
36
+ const [expand, setExpand] = useState(false)
37
+
38
+ useMergeCustomerCart()
39
+
40
+ const [setGuestEmailOnCart] = useMutation(SetGuestEmailOnCartDocument)
41
+ const { data: cartData } = useCartQuery(CartEmailDocument)
42
+ const { mode, form, submit } = useFormIsEmailAvailable({ email: cartData?.cart?.email })
43
+
44
+ const { formState, muiRegister, required, watch, error, getValues } = form
45
+
46
+ useFormCompose({ form, step, submit, key: 'EmailForm' })
47
+
48
+ useEffect(() => {
49
+ if (!cartData?.cart?.id) return
50
+
51
+ // Customer isn't logged in, but we do have a valid email
52
+ if (mode === 'signin' || mode === 'signup') {
53
+ const [email] = getValues(['email'])
54
+
55
+ if (cartData.cart.email === email) return
56
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
57
+ setGuestEmailOnCart({ variables: { email, cartId: cartData.cart.id } })
58
+ }
59
+ }, [mode, getValues, cartData?.cart?.id, setGuestEmailOnCart, cartData?.cart?.email])
60
+
61
+ let endAdornment: React.ReactNode = null
62
+
63
+ if (mode === 'signin') {
64
+ endAdornment = (
65
+ <Button color='secondary' style={{ whiteSpace: 'nowrap' }} onClick={() => setExpand(!expand)}>
66
+ {expand ? 'Close' : 'Sign In'}
67
+ </Button>
68
+ )
69
+ }
70
+ if (mode === 'signup') {
71
+ endAdornment = (
72
+ <Button color='secondary' style={{ whiteSpace: 'nowrap' }} onClick={() => setExpand(!expand)}>
73
+ {expand ? 'Close' : 'Sign Up'}
74
+ </Button>
75
+ )
76
+ }
77
+ if (formState.isSubmitting) endAdornment = <CircularProgress />
78
+
79
+ return (
80
+ <FormDiv contained>
81
+ <AnimatePresence initial={false}>
82
+ <AnimatedRow key='emailform'>
83
+ <form noValidate onSubmit={submit}>
84
+ <FormRow>
85
+ <TextField
86
+ variant='outlined'
87
+ type='email'
88
+ error={formState.isSubmitted && !!formState.errors.email}
89
+ helperText={formState.isSubmitted && formState.errors.email?.message}
90
+ label='Email'
91
+ required={required.email}
92
+ {...muiRegister('email', {
93
+ required: required.email,
94
+ pattern: { value: emailPattern, message: '' },
95
+ })}
96
+ InputProps={{
97
+ autoComplete: 'email',
98
+ endAdornment,
99
+ readOnly: mode === 'signedin' || mode === 'session-expired',
100
+ }}
101
+ />
102
+ </FormRow>
103
+ <ApolloCartErrorAlert error={error} />
104
+ </form>
105
+ </AnimatedRow>
106
+
107
+ {((mode === 'signin' && expand) || mode === 'session-expired') && (
108
+ <AnimatedRow key='signin-form-inline'>
109
+ <SignInFormInline email={watch('email')} />
110
+ </AnimatedRow>
111
+ )}
112
+
113
+ {mode === 'signup' && expand && (
114
+ <AnimatedRow key='inline-signup'>
115
+ <SignUpFormInline
116
+ helperList={
117
+ <EmailHelperList key='signup-helper-list' classes={{ root: classes.helperList }} />
118
+ }
119
+ key='signup-form-inline'
120
+ email={watch('email')}
121
+ />
122
+ </AnimatedRow>
123
+ )}
124
+
125
+ {mode === 'session-expired' && (
126
+ <FormRow>
127
+ <Alert severity='error'>You must sign in to continue</Alert>
128
+ </FormRow>
129
+ )}
130
+ {mode !== 'session-expired' && ((mode !== 'signup' && expand) || !expand) && (
131
+ <AnimatedRow key='email-helperlist'>
132
+ <EmailHelperList />
133
+ </AnimatedRow>
134
+ )}
135
+ </AnimatePresence>
136
+ </FormDiv>
137
+ )
138
+ }
@@ -0,0 +1,13 @@
1
+ /* eslint-disable */
2
+ import * as Types from '@graphcommerce/graphql';
3
+
4
+ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
5
+
6
+ export const SetGuestEmailOnCartDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SetGuestEmailOnCart"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"cartId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"email"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"setGuestEmailOnCart"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"cart_id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"cartId"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"email"},"value":{"kind":"Variable","name":{"kind":"Name","value":"email"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"cart"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"__typename"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"email"}}]}}]}}]}}]} as unknown as DocumentNode<SetGuestEmailOnCartMutation, SetGuestEmailOnCartMutationVariables>;
7
+ export type SetGuestEmailOnCartMutationVariables = Types.Exact<{
8
+ cartId: Types.Scalars['String'];
9
+ email: Types.Scalars['String'];
10
+ }>;
11
+
12
+
13
+ export type SetGuestEmailOnCartMutation = { setGuestEmailOnCart?: Types.Maybe<{ cart: { __typename: 'Cart', id: string, email?: Types.Maybe<string> } }> };
@@ -0,0 +1,10 @@
1
+ mutation SetGuestEmailOnCart($cartId: String!, $email: String!) {
2
+ setGuestEmailOnCart(input: { cart_id: $cartId, email: $email }) {
3
+ cart {
4
+ __typename
5
+ id
6
+ email
7
+ ...GuestEmailChanged
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,32 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { makeStyles, Theme } from '@material-ui/core'
3
+ import { CustomerTokenDocument } from '@graphcommerce/magento-customer'
4
+ import { UseStyles } from '@graphcommerce/next-ui'
5
+ import clsx from 'clsx'
6
+
7
+ const useStyles = makeStyles(
8
+ (theme: Theme) => ({
9
+ root: {
10
+ ...theme.typography.body2,
11
+ paddingLeft: theme.spacings.xs,
12
+ },
13
+ }),
14
+ { name: 'EmailHelperList' },
15
+ )
16
+
17
+ type HelperListProps = UseStyles<typeof useStyles>
18
+
19
+ export default function EmailHelperList(props: HelperListProps) {
20
+ const { data: tokenData } = useQuery(CustomerTokenDocument)
21
+ const classes = useStyles(props)
22
+
23
+ if (!tokenData?.customerToken) return <></>
24
+
25
+ return (
26
+ <ul className={clsx(classes.root)}>
27
+ <li>E-mail address of existing customers will be recognized, sign in is optional.</li>
28
+ <li>Fill in password fields to create an account.</li>
29
+ <li>Leave passwords fields empty to order as guest.</li>
30
+ </ul>
31
+ )
32
+ }
package/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './Api/GuestEmailChanged.gql'
2
+ export * from './EmailForm/EmailForm'
3
+ export { default as EmailForm } from './EmailForm/EmailForm'
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@graphcommerce/magento-cart-email",
3
+ "version": "2.104.1",
4
+ "sideEffects": false,
5
+ "prettier": "@graphcommerce/prettier-config-pwa",
6
+ "browserslist": [
7
+ "extends @graphcommerce/browserslist-config-pwa"
8
+ ],
9
+ "eslintConfig": {
10
+ "extends": "@graphcommerce/eslint-config-pwa",
11
+ "parserOptions": {
12
+ "project": "./tsconfig.json"
13
+ }
14
+ },
15
+ "devDependencies": {
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"
21
+ },
22
+ "dependencies": {
23
+ "@apollo/client": "^3.3.21",
24
+ "@graphcommerce/graphql": "^2.103.1",
25
+ "@graphcommerce/image": "^2.104.1",
26
+ "@graphcommerce/magento-cart": "^3.0.1",
27
+ "@graphcommerce/magento-customer": "^3.0.1",
28
+ "@graphcommerce/magento-product": "^3.0.1",
29
+ "@graphcommerce/magento-store": "^3.0.1",
30
+ "@graphcommerce/next-ui": "^3.0.1",
31
+ "@graphcommerce/react-hook-form": "^2.102.1",
32
+ "@graphql-typed-document-node/core": "^3.1.0",
33
+ "@material-ui/core": "^4.12.3",
34
+ "@material-ui/lab": "^4.0.0-alpha.60",
35
+ "clsx": "^1.1.1",
36
+ "framer-motion": "^4.1.17",
37
+ "next": "^11.1.2",
38
+ "react": "^17.0.2",
39
+ "react-dom": "^17.0.2"
40
+ }
41
+ }