@graphcommerce/magento-cart-email 3.0.37 → 3.0.38

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,20 @@
1
1
  # Change Log
2
2
 
3
+ ## 3.0.38
4
+
5
+ ### Patch Changes
6
+
7
+ - [#1553](https://github.com/graphcommerce-org/graphcommerce/pull/1553) [`4ad45a2f3`](https://github.com/graphcommerce-org/graphcommerce/commit/4ad45a2f3389838c33da8c447f9647c1cd17aa91) Thanks [@NickdeK](https://github.com/NickdeK)! - Made the EmailForm much simpler, so it doesn't rerender as often by stripping out the registration flow inside that form
8
+
9
+ - Updated dependencies [[`1afc6a547`](https://github.com/graphcommerce-org/graphcommerce/commit/1afc6a5473d6e31f47b5d0188801803b31865290), [`03d01c06c`](https://github.com/graphcommerce-org/graphcommerce/commit/03d01c06c6dc13df8d38ab5b40bd100c567a9e8d), [`4a4579bb2`](https://github.com/graphcommerce-org/graphcommerce/commit/4a4579bb2f7da378f3fcc504405caf2560dc10f6), [`afcd8e4bf`](https://github.com/graphcommerce-org/graphcommerce/commit/afcd8e4bfb7010da4d5faeed85b61991ed7975f4), [`02e1988e5`](https://github.com/graphcommerce-org/graphcommerce/commit/02e1988e5f361c6f66ae30d3bbee38ef2ac062df), [`323fdee4b`](https://github.com/graphcommerce-org/graphcommerce/commit/323fdee4b15ae23e0e84dd0588cb2c6446dcfd50), [`d03f0860b`](https://github.com/graphcommerce-org/graphcommerce/commit/d03f0860b882db4f280d9467aef9d66e56c1c030), [`b68d0b44a`](https://github.com/graphcommerce-org/graphcommerce/commit/b68d0b44a87688c80fb0aa4a5c840f262ce48d2f)]:
10
+ - @graphcommerce/graphql@3.4.2
11
+ - @graphcommerce/magento-cart@4.6.0
12
+ - @graphcommerce/magento-customer@4.8.0
13
+ - @graphcommerce/react-hook-form@3.3.1
14
+ - @graphcommerce/next-ui@4.14.0
15
+ - @graphcommerce/magento-product@4.4.16
16
+ - @graphcommerce/magento-store@4.2.18
17
+
3
18
  ## 3.0.37
4
19
 
5
20
  ### Patch Changes
@@ -1,77 +1,58 @@
1
- import { useMutation } from '@graphcommerce/graphql'
1
+ import { useQuery } from '@graphcommerce/graphql'
2
2
  import {
3
3
  ApolloCartErrorAlert,
4
4
  useCartQuery,
5
- useMergeCustomerCart,
5
+ useFormGqlMutationCart,
6
6
  } from '@graphcommerce/magento-cart'
7
+ import { IsEmailAvailableDocument } from '@graphcommerce/magento-customer'
8
+ import { extendableComponent, FormRow } from '@graphcommerce/next-ui'
7
9
  import {
8
- SignInFormInline,
9
- SignUpFormInline,
10
- useFormIsEmailAvailable,
11
- } from '@graphcommerce/magento-customer'
12
- import { AnimatedRow, extendableComponent, FormDiv, FormRow } from '@graphcommerce/next-ui'
13
- import { emailPattern, useFormCompose, UseFormComposeOptions } from '@graphcommerce/react-hook-form'
10
+ emailPattern,
11
+ useFormAutoSubmit,
12
+ useFormCompose,
13
+ UseFormComposeOptions,
14
+ } from '@graphcommerce/react-hook-form'
14
15
  import { Trans } from '@lingui/react'
15
- import { CircularProgress, TextField, Typography, Alert, Button } from '@mui/material'
16
- import { AnimatePresence } from 'framer-motion'
16
+ import { TextField, Typography, Button, NoSsr, SxProps, Box, Theme } from '@mui/material'
17
17
  import PageLink from 'next/link'
18
- import React, { useEffect, useState } from 'react'
18
+ import React from 'react'
19
19
  import { CartEmailDocument } from './CartEmail.gql'
20
20
  import { SetGuestEmailOnCartDocument } from './SetGuestEmailOnCart.gql'
21
21
 
22
22
  export type EmailFormProps = Pick<UseFormComposeOptions, 'step'> & {
23
23
  children?: React.ReactNode
24
+ sx?: SxProps<Theme>
24
25
  }
25
26
 
26
27
  const name = 'EmailForm' as const
27
28
  const parts = ['root', 'formRow'] as const
28
29
  const { classes } = extendableComponent(name, parts)
29
30
 
30
- export function EmailForm(props: EmailFormProps) {
31
- const { step, children } = props
31
+ export const EmailForm = React.memo<EmailFormProps>((props) => {
32
+ const { step, sx } = props
32
33
 
33
- const [setGuestEmailOnCart] = useMutation(SetGuestEmailOnCartDocument)
34
- const { data: cartData } = useCartQuery(CartEmailDocument)
34
+ const cartEmail = useCartQuery(CartEmailDocument, { hydration: true })
35
35
 
36
- const { mode, form, submit } = useFormIsEmailAvailable({ email: cartData?.cart?.email })
36
+ const email = cartEmail.data?.cart?.email ?? ''
37
37
 
38
- const { formState, muiRegister, required, watch, error, getValues } = form
38
+ const form = useFormGqlMutationCart(SetGuestEmailOnCartDocument, {
39
+ mode: 'onChange',
40
+ defaultValues: { email },
41
+ })
39
42
 
40
- useFormCompose({ form, step, submit, key: 'EmailForm' })
41
-
42
- useEffect(() => {
43
- if (!cartData?.cart?.id) return
44
-
45
- // Customer isn't logged in, but we do have a valid email
46
- if (mode === 'signin' || mode === 'signup') {
47
- const [email] = getValues(['email'])
48
-
49
- if (cartData.cart.email === email) return
50
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
51
- setGuestEmailOnCart({ variables: { email, cartId: cartData.cart.id } })
52
- }
53
- }, [mode, getValues, cartData?.cart?.id, setGuestEmailOnCart, cartData?.cart?.email])
43
+ const isEmailAvailable = useQuery(IsEmailAvailableDocument, {
44
+ variables: { email },
45
+ skip: !email,
46
+ })
54
47
 
55
- let endAdornment: React.ReactNode = null
48
+ const { formState, muiRegister, required, error, handleSubmit } = form
49
+ const submit = handleSubmit(() => {})
56
50
 
57
- if (mode === 'signin') {
58
- endAdornment = (
59
- <PageLink href='/account/signin' passHref>
60
- <Button color='secondary' style={{ whiteSpace: 'nowrap' }}>
61
- <Trans id='Sign in' />
62
- </Button>
63
- </PageLink>
64
- )
65
- }
66
- if (formState.isSubmitting) endAdornment = <CircularProgress />
51
+ useFormCompose({ form, step, submit, key: 'EmailForm' })
52
+ useFormAutoSubmit({ form, submit })
67
53
 
68
54
  return (
69
- <form noValidate onSubmit={submit}>
70
- <FormRow>
71
- <Typography variant='h5' component='h2' gutterBottom>
72
- <Trans id='Personal details' />
73
- </Typography>
74
- </FormRow>
55
+ <Box component='form' noValidate onSubmit={submit} sx={sx}>
75
56
  <FormRow className={classes.formRow} sx={{ py: 0 }}>
76
57
  <TextField
77
58
  variant='outlined'
@@ -80,18 +61,28 @@ export function EmailForm(props: EmailFormProps) {
80
61
  helperText={formState.isSubmitted && formState.errors.email?.message}
81
62
  label={<Trans id='Email' />}
82
63
  required={required.email}
64
+ disabled={cartEmail.loading}
83
65
  {...muiRegister('email', {
84
66
  required: required.email,
85
67
  pattern: { value: emailPattern, message: '' },
86
68
  })}
87
69
  InputProps={{
88
70
  autoComplete: 'email',
89
- endAdornment,
90
- readOnly: mode === 'signedin' || mode === 'session-expired',
71
+ endAdornment: (
72
+ <NoSsr>
73
+ {isEmailAvailable.data?.isEmailAvailable && (
74
+ <PageLink href='/account/signin' passHref>
75
+ <Button color='secondary' style={{ whiteSpace: 'nowrap' }}>
76
+ <Trans id='Sign in' />
77
+ </Button>
78
+ </PageLink>
79
+ )}
80
+ </NoSsr>
81
+ ),
91
82
  }}
92
83
  />
93
84
  </FormRow>
94
85
  <ApolloCartErrorAlert error={error} />
95
- </form>
86
+ </Box>
96
87
  )
97
- }
88
+ })
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-cart-email",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "3.0.37",
5
+ "version": "3.0.38",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -18,14 +18,14 @@
18
18
  "@playwright/test": "^1.21.1"
19
19
  },
20
20
  "dependencies": {
21
- "@graphcommerce/graphql": "3.4.1",
21
+ "@graphcommerce/graphql": "3.4.2",
22
22
  "@graphcommerce/image": "3.1.7",
23
- "@graphcommerce/magento-cart": "4.5.2",
24
- "@graphcommerce/magento-customer": "4.7.2",
25
- "@graphcommerce/magento-product": "4.4.15",
26
- "@graphcommerce/magento-store": "4.2.17",
27
- "@graphcommerce/next-ui": "4.13.1",
28
- "@graphcommerce/react-hook-form": "3.3.0"
23
+ "@graphcommerce/magento-cart": "4.6.0",
24
+ "@graphcommerce/magento-customer": "4.8.0",
25
+ "@graphcommerce/magento-product": "4.4.16",
26
+ "@graphcommerce/magento-store": "4.2.18",
27
+ "@graphcommerce/next-ui": "4.14.0",
28
+ "@graphcommerce/react-hook-form": "3.3.1"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "@lingui/react": "^3.13.2",