@graphcommerce/magento-customer 4.2.10 → 4.3.0

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 (34) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/components/AccountAddress/AccountAddress.tsx +2 -2
  3. package/components/AccountAddresses/AccountAddresses.tsx +5 -5
  4. package/components/AddressFields/AddressFields.tsx +13 -9
  5. package/components/ApolloCustomerError/ApolloCustomerErrorAlert.tsx +2 -2
  6. package/components/ApolloCustomerError/ApolloCustomerErrorFullPage.tsx +3 -3
  7. package/components/ChangeNameForm/ChangeNameForm.tsx +3 -3
  8. package/components/ChangePasswordForm/ChangePasswordForm.tsx +8 -7
  9. package/components/CreateCustomerAddressForm/CreateCustomerAddressForm.tsx +5 -4
  10. package/components/CreateCustomerAddressForm/CustomerAddress.graphql +1 -0
  11. package/components/CustomerFab/CustomerFab.tsx +4 -4
  12. package/components/DeleteCustomerAddressForm/DeleteCustomerAddressForm.tsx +2 -2
  13. package/components/EditAddressForm/EditAddressForm.tsx +15 -10
  14. package/components/EditAddressForm/UpdateCustomerAddress.graphql +1 -0
  15. package/components/ForgotPasswordForm/ForgotPasswordForm.tsx +6 -5
  16. package/components/NameFields/NameFields.tsx +10 -5
  17. package/components/ResetPasswordForm/ResetPasswordForm.tsx +5 -5
  18. package/components/SignInForm/SignIn.graphql +1 -1
  19. package/components/SignInForm/SignInForm.tsx +11 -5
  20. package/components/SignInForm/SignInFormInline.tsx +4 -4
  21. package/components/SignUpForm/SignUpForm.tsx +10 -8
  22. package/components/SignUpForm/SignUpFormInline.tsx +4 -3
  23. package/components/UpdateCustomerEmailForm/UpdateCustomerEmailForm.tsx +8 -7
  24. package/components/UpdateDefaultAddressForm/UpdateDefaultAddressForm.tsx +3 -3
  25. package/components/index.ts +1 -0
  26. package/hooks/CustomerToken.graphql +2 -3
  27. package/hooks/CustomerTokenFragment.graphql +4 -0
  28. package/hooks/index.ts +2 -0
  29. package/hooks/useCustomerQuery.ts +11 -0
  30. package/hooks/useCustomerSession.ts +23 -0
  31. package/hooks/useExtractCustomerErrors.tsx +2 -2
  32. package/hooks/useFormIsEmailAvailable.tsx +7 -8
  33. package/package.json +11 -10
  34. package/typePolicies.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,82 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1463](https://github.com/graphcommerce-org/graphcommerce/pull/1463) [`7159d3ab3`](https://github.com/graphcommerce-org/graphcommerce/commit/7159d3ab31e937c9c921023c46e80db5813e789c) Thanks [@paales](https://github.com/paales)! - Make the CustomerToken injectable
8
+
9
+ * [#1466](https://github.com/graphcommerce-org/graphcommerce/pull/1466) [`ed2b67a06`](https://github.com/graphcommerce-org/graphcommerce/commit/ed2b67a0618d9db97e79ed2a8226e0ae12403943) Thanks [@FrankHarland](https://github.com/FrankHarland)! - Added a new useCustomerSession hook to allow for more fine grained control over loading data for customers.
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1466](https://github.com/graphcommerce-org/graphcommerce/pull/1466) [`00f6167ff`](https://github.com/graphcommerce-org/graphcommerce/commit/00f6167ff4096bf7432f3d8e8e739ecbf6ab0dd2) Thanks [@FrankHarland](https://github.com/FrankHarland)! - Signing in requested client fields which weren't available on the server
14
+
15
+ * [#1465](https://github.com/graphcommerce-org/graphcommerce/pull/1465) [`32370574b`](https://github.com/graphcommerce-org/graphcommerce/commit/32370574bef6345b857ae911049ca27a64bc7e08) Thanks [@paales](https://github.com/paales)! - make sure the createCustomerV2 also marks the currenly registered email as known and also check the network if an email exists
16
+
17
+ - [#1461](https://github.com/graphcommerce-org/graphcommerce/pull/1461) [`4c146c682`](https://github.com/graphcommerce-org/graphcommerce/commit/4c146c68242e6edc616807fb73173cc959c26034) Thanks [@mikekeehnen](https://github.com/mikekeehnen)! - User is now able to change their email after the email check. Before the submit, the emailaddress gets checked from the props
18
+
19
+ - Updated dependencies [[`0363b9671`](https://github.com/graphcommerce-org/graphcommerce/commit/0363b9671db7c2932321d97faf6f1eb385238397), [`3ac90b57c`](https://github.com/graphcommerce-org/graphcommerce/commit/3ac90b57c68b96f9d81771d6664ed9435a28fc1d)]:
20
+ - @graphcommerce/next-ui@4.8.0
21
+ - @graphcommerce/ecommerce-ui@1.0.12
22
+ - @graphcommerce/magento-store@4.2.4
23
+
24
+ ## 4.2.12
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [[`c30893857`](https://github.com/graphcommerce-org/graphcommerce/commit/c3089385791291e812a48c2691a39a2325ee0439)]:
29
+ - @graphcommerce/magento-store@4.2.3
30
+
31
+ ## 4.2.11
32
+
33
+ ### Patch Changes
34
+
35
+ - [#1451](https://github.com/graphcommerce-org/graphcommerce/pull/1451) [`f698ff85d`](https://github.com/graphcommerce-org/graphcommerce/commit/f698ff85df6bb0922288471bb3c81856091b8061) Thanks [@paales](https://github.com/paales)! - Removed all occurences of @lingui/macro and moved to @lingui/macro / @lingui/core in preparation to move to swc.
36
+
37
+ Since we've removed @lingui/macro, all occurences need to be replaced with @lingui/core and @lingui/react.
38
+
39
+ All occurences of `<Trans>` and `t` need to be replaced:
40
+
41
+ ```tsx
42
+ import { Trans, t } from '@lingui/macro'
43
+
44
+ function MyComponent() {
45
+ const foo = 'bar'
46
+ return (
47
+ <div aria-label={t`Account ${foo}`}>
48
+ <Trans>My Translation {foo}</Trans>
49
+ </div>
50
+ )
51
+ }
52
+ ```
53
+
54
+ Needs to be replaced with:
55
+
56
+ ```tsx
57
+ import { Trans } from '@lingui/react'
58
+ import { i18n } from '@lingui/core'
59
+
60
+ function MyComponent() {
61
+ const foo = 'bar'
62
+ return (
63
+ <div aria-label={i18n._(/* i18n */ `Account {foo}`, { foo })}>
64
+ <Trans key='My Translation {foo}' values={{ foo }}></Trans>
65
+ </div>
66
+ )
67
+ }
68
+ ```
69
+
70
+ [More examples for Trans](https://lingui.js.org/ref/macro.html#examples-of-jsx-macros) and [more examples for `t`](https://lingui.js.org/ref/macro.html#examples-of-js-macros)
71
+
72
+ - Updated dependencies [[`50188e378`](https://github.com/graphcommerce-org/graphcommerce/commit/50188e378b4c77561ebc600958ea11cd114fa61a), [`f698ff85d`](https://github.com/graphcommerce-org/graphcommerce/commit/f698ff85df6bb0922288471bb3c81856091b8061)]:
73
+ - @graphcommerce/react-hook-form@3.1.3
74
+ - @graphcommerce/ecommerce-ui@1.0.11
75
+ - @graphcommerce/magento-store@4.2.2
76
+ - @graphcommerce/next-ui@4.7.2
77
+ - @graphcommerce/graphql@3.1.3
78
+ - @graphcommerce/magento-graphql@3.0.12
79
+
3
80
  ## 4.2.10
4
81
 
5
82
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import { extendableComponent } from '@graphcommerce/next-ui'
2
- import { Trans } from '@lingui/macro'
2
+ import { Trans } from '@lingui/react'
3
3
  import { Box, Link, SxProps, Theme } from '@mui/material'
4
4
  import PageLink from 'next/link'
5
5
  import { AddressMultiLine } from '../AddressMultiLine/AddressMultiLine'
@@ -48,7 +48,7 @@ export function AccountAddress(props: AccountAddressProps) {
48
48
  >
49
49
  <PageLink href={`/account/addresses/edit?addressId=${id}`} passHref>
50
50
  <Link color='primary' underline='hover'>
51
- <Trans>Edit</Trans>
51
+ <Trans id='Edit' />
52
52
  </Link>
53
53
  </PageLink>
54
54
  <DeleteCustomerAddressForm addressId={id ?? undefined} />
@@ -5,7 +5,7 @@ import {
5
5
  IconSvg,
6
6
  extendableComponent,
7
7
  } from '@graphcommerce/next-ui'
8
- import { Trans } from '@lingui/macro'
8
+ import { Trans } from '@lingui/react'
9
9
  import { Skeleton, Button, Box, Theme, SxProps } from '@mui/material'
10
10
  import Link from 'next/link'
11
11
  import { AccountAddress } from '../AccountAddress/AccountAddress'
@@ -46,7 +46,7 @@ export function AccountAddresses(props: AccountAddressesProps) {
46
46
  margin: `${theme.spacings.md} auto`,
47
47
  })}
48
48
  >
49
- <Trans>Add new address</Trans>
49
+ <Trans id='Add new address' />
50
50
  </Button>
51
51
  </SectionContainer>
52
52
  )
@@ -56,12 +56,12 @@ export function AccountAddresses(props: AccountAddressesProps) {
56
56
  <>
57
57
  {((addresses && addresses.length === 0) || !addresses) && (
58
58
  <FullPageMessage
59
- title={<Trans>You have no addresses saved yet</Trans>}
59
+ title={<Trans id='You have no addresses saved yet' />}
60
60
  icon={<IconSvg src={iconHome} size='xxl' />}
61
61
  button={
62
62
  <Link href='/account/addresses/add' passHref>
63
63
  <Button size='large' variant='contained' color='primary'>
64
- <Trans>Add new address</Trans>
64
+ <Trans id='Add new address' />
65
65
  </Button>
66
66
  </Link>
67
67
  }
@@ -91,7 +91,7 @@ export function AccountAddresses(props: AccountAddressesProps) {
91
91
  margin: `${theme.spacings.md} auto`,
92
92
  })}
93
93
  >
94
- <Trans>Add new address</Trans>
94
+ <Trans id='Add new address' />
95
95
  </Button>
96
96
  </Link>
97
97
  </SectionContainer>
@@ -6,7 +6,8 @@ import {
6
6
  houseNumberPattern,
7
7
  UseFormReturn,
8
8
  } from '@graphcommerce/react-hook-form'
9
- import { t, Trans } from '@lingui/macro'
9
+ import { i18n } from '@lingui/core'
10
+ import { Trans } from '@lingui/react'
10
11
  import { TextField } from '@mui/material'
11
12
  import React, { useMemo } from 'react'
12
13
 
@@ -58,7 +59,7 @@ export function AddressFields(props: AddressFieldsProps) {
58
59
  variant='outlined'
59
60
  type='text'
60
61
  error={!!formState.errors.street}
61
- label={<Trans>Street</Trans>}
62
+ label={<Trans id='Street' />}
62
63
  autoComplete='address-line1'
63
64
  required={!!required?.street}
64
65
  {...muiRegister('street', { required: required?.street })}
@@ -72,12 +73,15 @@ export function AddressFields(props: AddressFieldsProps) {
72
73
  variant='outlined'
73
74
  type='text'
74
75
  error={!!formState.errors.houseNumber}
75
- label={<Trans>Housenumber</Trans>}
76
+ label={<Trans id='Housenumber' />}
76
77
  autoComplete='address-line2'
77
78
  required={!!required?.houseNumber}
78
79
  {...muiRegister('houseNumber', {
79
80
  required: required?.houseNumber,
80
- pattern: { value: houseNumberPattern, message: t`Please provide a valid house number` },
81
+ pattern: {
82
+ value: houseNumberPattern,
83
+ message: i18n._(/* i18n */ `Please provide a valid house number`),
84
+ },
81
85
  })}
82
86
  helperText={formState.isSubmitted && formState.errors.houseNumber?.message}
83
87
  InputProps={{
@@ -90,7 +94,7 @@ export function AddressFields(props: AddressFieldsProps) {
90
94
  type='text'
91
95
  error={!!formState.errors.addition}
92
96
  required={!!required?.addition}
93
- label={<Trans>Addition</Trans>}
97
+ label={<Trans id='Addition' />}
94
98
  autoComplete='address-line3'
95
99
  {...muiRegister('addition', { required: required?.addition })}
96
100
  helperText={formState.isSubmitted && formState.errors.addition?.message}
@@ -106,7 +110,7 @@ export function AddressFields(props: AddressFieldsProps) {
106
110
  type='text'
107
111
  error={!!formState.errors.postcode}
108
112
  required={!!required?.postcode}
109
- label={<Trans>Postcode</Trans>}
113
+ label={<Trans id='Postcode' />}
110
114
  {...muiRegister('postcode', { required: required?.postcode })}
111
115
  helperText={formState.isSubmitted && formState.errors.postcode?.message}
112
116
  InputProps={{
@@ -119,7 +123,7 @@ export function AddressFields(props: AddressFieldsProps) {
119
123
  type='text'
120
124
  error={!!formState.errors.city}
121
125
  required={!!required?.city}
122
- label={<Trans>City</Trans>}
126
+ label={<Trans id='City' />}
123
127
  {...muiRegister('city', { required: required?.city })}
124
128
  helperText={formState.isSubmitted && formState.errors.city?.message}
125
129
  InputProps={{
@@ -135,7 +139,7 @@ export function AddressFields(props: AddressFieldsProps) {
135
139
  {...muiRegister('countryCode', { required: required.countryCode })}
136
140
  variant='outlined'
137
141
  error={!!formState.errors.countryCode}
138
- label={<Trans>Country</Trans>}
142
+ label={<Trans id='Country' />}
139
143
  required={!!required?.countryCode}
140
144
  helperText={formState.errors.countryCode?.message}
141
145
  // onBlur={onBlur}
@@ -162,7 +166,7 @@ export function AddressFields(props: AddressFieldsProps) {
162
166
  SelectProps={{ native: true, displayEmpty: true }}
163
167
  variant='outlined'
164
168
  error={!!formState.errors.regionId}
165
- label={<Trans>Region</Trans>}
169
+ label={<Trans id='Region' />}
166
170
  {...muiRegister('regionId', {
167
171
  required: true,
168
172
  shouldUnregister: true,
@@ -1,5 +1,5 @@
1
1
  import { ApolloErrorAlert, ApolloErrorAlertProps } from '@graphcommerce/ecommerce-ui'
2
- import { Trans } from '@lingui/macro'
2
+ import { Trans } from '@lingui/react'
3
3
  import { Link } from '@mui/material'
4
4
  import NextLink from 'next/link'
5
5
  import { useExtractCustomerErrors } from '../../hooks/useExtractCustomerErrors'
@@ -12,7 +12,7 @@ export function ApolloCustomerErrorAlert(props: MagentoErrorAlertProps) {
12
12
  const action = unauthorized && (
13
13
  <NextLink href='/account/signin' passHref>
14
14
  <Link underline='hover'>
15
- <Trans>Create Account</Trans> / <Trans>Sign in</Trans>
15
+ <Trans id='Create Account' /> / <Trans id='Sign in' />
16
16
  </Link>
17
17
  </NextLink>
18
18
  )
@@ -1,6 +1,6 @@
1
1
  import { ApolloErrorFullPage, ApolloErrorAlertProps } from '@graphcommerce/ecommerce-ui'
2
2
  import { iconPerson, IconSvg } from '@graphcommerce/next-ui'
3
- import { Trans } from '@lingui/macro'
3
+ import { Trans } from '@lingui/react'
4
4
  import { Button } from '@mui/material'
5
5
  import PageLink from 'next/link'
6
6
  import { useExtractCustomerErrors } from '../../hooks/useExtractCustomerErrors'
@@ -22,7 +22,7 @@ export function ApolloCustomerErrorFullPage(props: ApolloCustomerErrorFullPagePr
22
22
  unauthorized ? (
23
23
  <PageLink href={signInHref} passHref>
24
24
  <Button variant='contained' color='primary' size='large'>
25
- <Trans>Log in</Trans>
25
+ <Trans id='Log in' />
26
26
  </Button>
27
27
  </PageLink>
28
28
  ) : undefined
@@ -31,7 +31,7 @@ export function ApolloCustomerErrorFullPage(props: ApolloCustomerErrorFullPagePr
31
31
  unauthorized ? (
32
32
  <PageLink href={signUpHref} passHref>
33
33
  <Button variant='text' color='primary'>
34
- <Trans>Or create an account</Trans>
34
+ <Trans id='Or create an account' />
35
35
  </Button>
36
36
  </PageLink>
37
37
  ) : undefined
@@ -1,6 +1,6 @@
1
1
  import { Form, FormActions, FormDivider, MessageSnackbar, Button } from '@graphcommerce/next-ui'
2
2
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
3
- import { Trans } from '@lingui/macro'
3
+ import { Trans } from '@lingui/react'
4
4
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
5
5
  import { NameFields } from '../NameFields/NameFields'
6
6
  import { UpdateCustomerNameDocument } from './UpdateCustomerName.gql'
@@ -41,13 +41,13 @@ export function ChangeNameForm(props: ChangeNameFormProps) {
41
41
  size='large'
42
42
  loading={formState.isSubmitting}
43
43
  >
44
- <Trans>Save changes</Trans>
44
+ <Trans id='Save changes' />
45
45
  </Button>
46
46
  </FormActions>
47
47
  <ApolloCustomerErrorAlert error={error} />
48
48
  </Form>
49
49
  <MessageSnackbar open={formState.isSubmitSuccessful && !error} variant='pill'>
50
- <Trans>Successfully saved changes</Trans>
50
+ <Trans id='Successfully saved changes' />
51
51
  </MessageSnackbar>
52
52
  </>
53
53
  )
@@ -7,7 +7,8 @@ import {
7
7
  Button,
8
8
  } from '@graphcommerce/next-ui'
9
9
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
10
- import { Trans, t } from '@lingui/macro'
10
+ import { i18n } from '@lingui/core'
11
+ import { Trans } from '@lingui/react'
11
12
  import { TextField } from '@mui/material'
12
13
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
13
14
  import {
@@ -32,7 +33,7 @@ export function ChangePasswordForm() {
32
33
  variant='outlined'
33
34
  type='password'
34
35
  error={!!formState.errors.currentPassword}
35
- label={<Trans>Current Password</Trans>}
36
+ label={<Trans id='Current Password' />}
36
37
  required={required.currentPassword}
37
38
  {...muiRegister('currentPassword', { required: required.currentPassword })}
38
39
  helperText={formState.errors.currentPassword?.message}
@@ -45,7 +46,7 @@ export function ChangePasswordForm() {
45
46
  variant='outlined'
46
47
  type='password'
47
48
  error={!!formState.errors.newPassword}
48
- label={<Trans>New password</Trans>}
49
+ label={<Trans id='New password' />}
49
50
  required={required.newPassword}
50
51
  {...muiRegister('newPassword', { required: required.newPassword })}
51
52
  helperText={formState.errors.newPassword?.message}
@@ -56,11 +57,11 @@ export function ChangePasswordForm() {
56
57
  variant='outlined'
57
58
  type='password'
58
59
  error={!!formState.errors.confirmPassword}
59
- label={<Trans>Confirm password</Trans>}
60
+ label={<Trans id='Confirm password' />}
60
61
  required
61
62
  {...muiRegister('confirmPassword', {
62
63
  required: true,
63
- validate: (value) => value === pass || t`Passwords don't match`,
64
+ validate: (value) => value === pass || i18n._(/* i18n */ `Passwords don't match`),
64
65
  })}
65
66
  helperText={formState.errors.confirmPassword?.message}
66
67
  disabled={formState.isSubmitting}
@@ -79,12 +80,12 @@ export function ChangePasswordForm() {
79
80
  variant='contained'
80
81
  size='large'
81
82
  >
82
- <Trans>Save new password</Trans>
83
+ <Trans id='Save new password' />
83
84
  </Button>
84
85
  </FormActions>
85
86
 
86
87
  <MessageSnackbar sticky open={Boolean(formState.isSubmitSuccessful && data)}>
87
- <Trans>Successfully changed password</Trans>
88
+ <Trans id='Successfully changed password' />
88
89
  </MessageSnackbar>
89
90
  </Form>
90
91
  )
@@ -9,7 +9,8 @@ import {
9
9
  Button,
10
10
  } from '@graphcommerce/next-ui'
11
11
  import { phonePattern, useFormGqlMutation } from '@graphcommerce/react-hook-form'
12
- import { Trans, t } from '@lingui/macro'
12
+ import { i18n } from '@lingui/core'
13
+ import { Trans } from '@lingui/react'
13
14
  import { TextField } from '@mui/material'
14
15
  import { useRouter } from 'next/router'
15
16
  import { AddressFields } from '../AddressFields/AddressFields'
@@ -65,10 +66,10 @@ export function CreateCustomerAddressForm() {
65
66
  type='text'
66
67
  error={!!formState.errors.telephone}
67
68
  required={required.telephone}
68
- label={<Trans>Telephone</Trans>}
69
+ label={<Trans id='Telephone' />}
69
70
  {...muiRegister('telephone', {
70
71
  required: required.telephone,
71
- pattern: { value: phonePattern, message: t`Invalid phone number` },
72
+ pattern: { value: phonePattern, message: i18n._(/* i18n */ `Invalid phone number`) },
72
73
  })}
73
74
  helperText={formState.isSubmitted && formState.errors.telephone?.message}
74
75
  disabled={formState.isSubmitting}
@@ -86,7 +87,7 @@ export function CreateCustomerAddressForm() {
86
87
  size='large'
87
88
  loading={formState.isSubmitting}
88
89
  >
89
- <Trans>Save changes</Trans>
90
+ <Trans id='Save changes' />
90
91
  </Button>
91
92
  </FormActions>
92
93
  </Form>
@@ -19,4 +19,5 @@ fragment CustomerAddress on CustomerAddress {
19
19
  telephone
20
20
 
21
21
  vat_id
22
+ default_shipping
22
23
  }
@@ -5,11 +5,11 @@ import {
5
5
  IconSvg,
6
6
  extendableComponent,
7
7
  } from '@graphcommerce/next-ui'
8
- import { t } from '@lingui/macro'
8
+ import { i18n } from '@lingui/core'
9
9
  import { Fab, FabProps as FabPropsType, NoSsr, SxProps, Theme } from '@mui/material'
10
10
  import PageLink from 'next/link'
11
11
  import React from 'react'
12
- import { CustomerTokenDocument, CustomerTokenQuery } from '../../hooks'
12
+ import { CustomerTokenDocument, CustomerTokenQuery, useCustomerSession } from '../../hooks'
13
13
 
14
14
  type CustomerFabContentProps = CustomerTokenQuery & {
15
15
  icon?: React.ReactNode
@@ -25,14 +25,14 @@ const { classes } = extendableComponent(name, parts)
25
25
 
26
26
  function CustomerFabContent(props: CustomerFabContentProps) {
27
27
  const { customerToken, icon, guestHref, authHref, FabProps, sx } = props
28
- const requireAuth = Boolean(!customerToken || !customerToken.valid)
28
+ const { requireAuth } = useCustomerSession()
29
29
 
30
30
  return (
31
31
  <PageLink href={requireAuth ? guestHref : authHref} passHref>
32
32
  <Fab
33
33
  color='inherit'
34
34
  id='account'
35
- aria-label={t`Account`}
35
+ aria-label={i18n._(/* i18n */ `Account`)}
36
36
  size='large'
37
37
  className={classes.root}
38
38
  {...FabProps}
@@ -1,6 +1,6 @@
1
1
  import { ApolloErrorSnackbar } from '@graphcommerce/ecommerce-ui'
2
2
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
3
- import { Trans } from '@lingui/macro'
3
+ import { Trans } from '@lingui/react'
4
4
  import { Button } from '@mui/material'
5
5
  import { DeleteCustomerAddressFormDocument } from './DeleteCustomerAddressForm.gql'
6
6
 
@@ -20,7 +20,7 @@ export function DeleteCustomerAddressForm(props: DeleteCustomerAddressFormProps)
20
20
  return (
21
21
  <form onSubmit={submitHandler} noValidate>
22
22
  <Button type='submit' variant='text' color='primary'>
23
- <Trans>Delete this address</Trans>
23
+ <Trans id='Delete this address' />
24
24
  </Button>
25
25
  <ApolloErrorSnackbar error={error} />
26
26
  </form>
@@ -1,3 +1,4 @@
1
+ import { useGo, usePageContext } from '@graphcommerce/framer-next-pages'
1
2
  import { useQuery } from '@graphcommerce/graphql'
2
3
  import { CountryRegionsDocument } from '@graphcommerce/magento-store'
3
4
  import {
@@ -9,7 +10,8 @@ import {
9
10
  InputCheckmark,
10
11
  } from '@graphcommerce/next-ui'
11
12
  import { phonePattern, useFormGqlMutation } from '@graphcommerce/react-hook-form'
12
- import { t, Trans } from '@lingui/macro'
13
+ import { i18n } from '@lingui/core'
14
+ import { Trans } from '@lingui/react'
13
15
  import { SxProps, TextField, Theme } from '@mui/material'
14
16
  import { useRouter } from 'next/router'
15
17
  import { AccountAddressFragment } from '../AccountAddress/AccountAddress.gql'
@@ -18,12 +20,18 @@ import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerE
18
20
  import { NameFields } from '../NameFields/NameFields'
19
21
  import { UpdateCustomerAddressDocument } from './UpdateCustomerAddress.gql'
20
22
 
21
- type EditAddressFormProps = { address?: AccountAddressFragment; sx?: SxProps<Theme> }
23
+ type EditAddressFormProps = {
24
+ address?: AccountAddressFragment
25
+ sx?: SxProps<Theme>
26
+ onCompleteRoute?: string
27
+ }
22
28
 
23
29
  export function EditAddressForm(props: EditAddressFormProps) {
24
30
  const countries = useQuery(CountryRegionsDocument).data?.countries
25
31
  const { address, sx } = props
26
- const router = useRouter()
32
+
33
+ const { closeSteps } = usePageContext()
34
+ const onComplete = useGo(closeSteps * -1)
27
35
 
28
36
  const form = useFormGqlMutation(
29
37
  UpdateCustomerAddressDocument,
@@ -61,10 +69,7 @@ export function EditAddressForm(props: EditAddressFormProps) {
61
69
  ...regionData,
62
70
  }
63
71
  },
64
- onComplete: () => {
65
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
66
- router.push('/account/addresses')
67
- },
72
+ onComplete,
68
73
  },
69
74
  { errorPolicy: 'all' },
70
75
  )
@@ -84,10 +89,10 @@ export function EditAddressForm(props: EditAddressFormProps) {
84
89
  type='text'
85
90
  error={!!formState.errors.telephone}
86
91
  required={required.telephone}
87
- label={<Trans>Telephone</Trans>}
92
+ label={<Trans id='Telephone' />}
88
93
  {...muiRegister('telephone', {
89
94
  required: required.telephone,
90
- pattern: { value: phonePattern, message: t`Invalid phone number` },
95
+ pattern: { value: phonePattern, message: i18n._(/* i18n */ `Invalid phone number`) },
91
96
  })}
92
97
  helperText={formState.isSubmitted && formState.errors.telephone?.message}
93
98
  disabled={formState.isSubmitting}
@@ -105,7 +110,7 @@ export function EditAddressForm(props: EditAddressFormProps) {
105
110
  size='large'
106
111
  loading={formState.isSubmitting}
107
112
  >
108
- <Trans>Save changes</Trans>
113
+ <Trans id='Save changes' />
109
114
  </Button>
110
115
  </FormActions>
111
116
  </Form>
@@ -39,5 +39,6 @@ mutation UpdateCustomerAddress(
39
39
  }
40
40
  ) {
41
41
  id
42
+ ...CustomerAddress
42
43
  }
43
44
  }
@@ -1,6 +1,7 @@
1
1
  import { Button, Form, FormActions, FormRow } from '@graphcommerce/next-ui'
2
2
  import { emailPattern, useFormGqlMutation } from '@graphcommerce/react-hook-form'
3
- import { t, Trans } from '@lingui/macro'
3
+ import { i18n } from '@lingui/core'
4
+ import { Trans } from '@lingui/react'
4
5
  import { TextField, Alert, SxProps, Theme } from '@mui/material'
5
6
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
6
7
  import {
@@ -27,7 +28,7 @@ export function ForgotPasswordForm(props: { sx?: SxProps<Theme> }) {
27
28
  marginBottom: theme.spacings.sm,
28
29
  })}
29
30
  >
30
- <Trans>We’ve send a password reset link to your email address!</Trans>
31
+ <Trans id='We’ve send a password reset link to your email address!' />
31
32
  </Alert>
32
33
  )
33
34
  }
@@ -39,11 +40,11 @@ export function ForgotPasswordForm(props: { sx?: SxProps<Theme> }) {
39
40
  variant='outlined'
40
41
  type='text'
41
42
  error={!!formState.errors.email}
42
- label={<Trans>Email</Trans>}
43
+ label={<Trans id='Email' />}
43
44
  required={required.email}
44
45
  {...muiRegister('email', {
45
46
  required: required.email,
46
- pattern: { value: emailPattern, message: t`Invalid email address` },
47
+ pattern: { value: emailPattern, message: i18n._(/* i18n */ `Invalid email address`) },
47
48
  })}
48
49
  helperText={formState.errors.email?.message}
49
50
  disabled={formState.isSubmitting}
@@ -60,7 +61,7 @@ export function ForgotPasswordForm(props: { sx?: SxProps<Theme> }) {
60
61
  variant='contained'
61
62
  size='large'
62
63
  >
63
- <Trans>Send password reset email</Trans>
64
+ <Trans id='Send password reset email' />
64
65
  </Button>
65
66
  </FormActions>
66
67
  </Form>
@@ -1,6 +1,7 @@
1
1
  import { FormRow, InputCheckmark } from '@graphcommerce/next-ui'
2
2
  import { assertFormGqlOperation, Controller, UseFormReturn } from '@graphcommerce/react-hook-form'
3
- import { t, Trans } from '@lingui/macro'
3
+ import { i18n } from '@lingui/core'
4
+ import { Trans } from '@lingui/react'
4
5
  import { MenuItem, TextField } from '@mui/material'
5
6
  import React from 'react'
6
7
 
@@ -19,7 +20,11 @@ type NameFieldProps = {
19
20
  }
20
21
 
21
22
  export function NameFields(props: NameFieldProps) {
22
- const { prefix, form, readOnly, prefixes = [t`Mr`, t`Mrs`, t`Other`] } = props
23
+ const mr = i18n._(/* i18n */ `Mr`)
24
+ const mrs = i18n._(/* i18n */ `Mrs`)
25
+ const other = i18n._(/* i18n */ `Other`)
26
+
27
+ const { prefix, form, readOnly, prefixes = [mr, mrs, other] } = props
23
28
  assertFormGqlOperation<NameFieldValues>(form)
24
29
 
25
30
  const { control, formState, muiRegister, required, valid } = form
@@ -37,7 +42,7 @@ export function NameFields(props: NameFieldProps) {
37
42
  variant='outlined'
38
43
  select
39
44
  error={!!fieldState.error}
40
- label={<Trans>Prefix</Trans>}
45
+ label={<Trans id='Prefix' />}
41
46
  required={!!required?.prefix}
42
47
  helperText={fieldState.error?.message}
43
48
  onChange={(e) => onChange(e.target.value)}
@@ -63,7 +68,7 @@ export function NameFields(props: NameFieldProps) {
63
68
  <TextField
64
69
  variant='outlined'
65
70
  type='text'
66
- label={<Trans>First Name</Trans>}
71
+ label={<Trans id='First Name' />}
67
72
  required={!!required}
68
73
  error={!!formState.errors.firstname}
69
74
  helperText={formState.isSubmitted && formState.errors.firstname?.message}
@@ -77,7 +82,7 @@ export function NameFields(props: NameFieldProps) {
77
82
  variant='outlined'
78
83
  type='text'
79
84
  error={!!formState.errors.lastname}
80
- label={<Trans>Last Name</Trans>}
85
+ label={<Trans id='Last Name' />}
81
86
  required={!!required?.lastname}
82
87
  helperText={formState.isSubmitted && formState.errors.lastname?.message}
83
88
  InputProps={{
@@ -1,6 +1,6 @@
1
1
  import { Button, Form, FormActions, FormRow } from '@graphcommerce/next-ui'
2
2
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
3
- import { Trans } from '@lingui/macro'
3
+ import { Trans } from '@lingui/react'
4
4
  import { TextField } from '@mui/material'
5
5
  import { useRouter } from 'next/router'
6
6
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
@@ -44,7 +44,7 @@ export function ResetPasswordForm(props: ResetPasswordFormProps) {
44
44
  variant='outlined'
45
45
  type='email'
46
46
  error={!!formState.errors.email}
47
- label={<Trans>Email</Trans>}
47
+ label={<Trans id='Email' />}
48
48
  required={required.email}
49
49
  {...muiRegister('email', { required: required.email })}
50
50
  helperText={formState.errors.email?.message}
@@ -56,7 +56,7 @@ export function ResetPasswordForm(props: ResetPasswordFormProps) {
56
56
  variant='outlined'
57
57
  type='password'
58
58
  error={!!formState.errors.newPassword}
59
- label={<Trans>New password</Trans>}
59
+ label={<Trans id='New password' />}
60
60
  required={required.newPassword}
61
61
  {...muiRegister('newPassword', { required: required.newPassword })}
62
62
  helperText={formState.errors.newPassword?.message}
@@ -68,7 +68,7 @@ export function ResetPasswordForm(props: ResetPasswordFormProps) {
68
68
  variant='outlined'
69
69
  type='password'
70
70
  error={!!formState.errors.confirmPassword}
71
- label={<Trans>Confirm password</Trans>}
71
+ label={<Trans id='Confirm password' />}
72
72
  required
73
73
  {...muiRegister('confirmPassword', {
74
74
  required: true,
@@ -89,7 +89,7 @@ export function ResetPasswordForm(props: ResetPasswordFormProps) {
89
89
  variant='contained'
90
90
  size='large'
91
91
  >
92
- <Trans>Save new password</Trans>
92
+ <Trans id='Save new password' />
93
93
  </Button>
94
94
  </FormActions>
95
95
  </Form>
@@ -1,5 +1,5 @@
1
1
  mutation SignIn($email: String!, $password: String!) {
2
2
  generateCustomerToken(email: $email, password: $password) {
3
- token
3
+ ...CustomerTokenFragment
4
4
  }
5
5
  }
@@ -1,7 +1,7 @@
1
1
  import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql'
2
2
  import { Button, FormRow, FormActions } from '@graphcommerce/next-ui'
3
3
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
4
- import { Trans } from '@lingui/macro'
4
+ import { Trans } from '@lingui/react'
5
5
  import { Box, FormControl, Link, SxProps, TextField, Theme } from '@mui/material'
6
6
  import PageLink from 'next/link'
7
7
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
@@ -13,7 +13,13 @@ export function SignInForm(props: SignInFormProps) {
13
13
  const { email, sx } = props
14
14
  const form = useFormGqlMutation(
15
15
  SignInDocument,
16
- { defaultValues: { email } },
16
+ {
17
+ defaultValues: { email },
18
+ onBeforeSubmit: (values) => ({
19
+ ...values,
20
+ email,
21
+ }),
22
+ },
17
23
  { errorPolicy: 'all' },
18
24
  )
19
25
 
@@ -32,7 +38,7 @@ export function SignInForm(props: SignInFormProps) {
32
38
  variant='outlined'
33
39
  type='password'
34
40
  error={!!formState.errors.password || !!authError}
35
- label={<Trans>Password</Trans>}
41
+ label={<Trans id='Password' />}
36
42
  autoFocus
37
43
  autoComplete='current-password'
38
44
  id='current-password'
@@ -42,7 +48,7 @@ export function SignInForm(props: SignInFormProps) {
42
48
  endAdornment: (
43
49
  <PageLink href='/account/forgot-password' key='forgot-password' passHref>
44
50
  <Link underline='hover' sx={{ whiteSpace: 'nowrap' }}>
45
- <Trans>Forgot password?</Trans>
51
+ <Trans id='Forgot password?' />
46
52
  </Link>
47
53
  </PageLink>
48
54
  ),
@@ -63,7 +69,7 @@ export function SignInForm(props: SignInFormProps) {
63
69
  variant='contained'
64
70
  size='large'
65
71
  >
66
- <Trans>Log in</Trans>
72
+ <Trans id='Log in' />
67
73
  </Button>
68
74
  </FormControl>
69
75
  </FormActions>
@@ -1,6 +1,6 @@
1
1
  import { Button, extendableComponent } from '@graphcommerce/next-ui'
2
2
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
3
- import { Trans } from '@lingui/macro'
3
+ import { Trans } from '@lingui/react'
4
4
  import { Box, SxProps, TextField, Theme } from '@mui/material'
5
5
  import PageLink from 'next/link'
6
6
  import { PropsWithChildren } from 'react'
@@ -44,7 +44,7 @@ export function SignInFormInline(props: PropsWithChildren<InlineSignInFormProps>
44
44
  variant='outlined'
45
45
  type='password'
46
46
  error={!!formState.errors.password || !!error?.message}
47
- label={<Trans>Password</Trans>}
47
+ label={<Trans id='Password' />}
48
48
  autoFocus
49
49
  autoComplete='current-password'
50
50
  id='current-password'
@@ -61,14 +61,14 @@ export function SignInFormInline(props: PropsWithChildren<InlineSignInFormProps>
61
61
  className={classes.button}
62
62
  sx={{ minWidth: 'max-content' }}
63
63
  >
64
- <Trans>Forgot password?</Trans>
64
+ <Trans id='Forgot password?' />
65
65
  </Button>
66
66
  </PageLink>
67
67
  ),
68
68
  }}
69
69
  />
70
70
  <Button type='submit' loading={formState.isSubmitting} color='secondary' variant='pill'>
71
- <Trans>Sign in</Trans>
71
+ <Trans id='Sign in' />
72
72
  </Button>
73
73
  </Box>
74
74
  )
@@ -3,7 +3,8 @@ import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql'
3
3
  import { StoreConfigDocument } from '@graphcommerce/magento-store'
4
4
  import { Button, FormActions, FormRow } from '@graphcommerce/next-ui'
5
5
  import { useFormGqlMutation, useFormPersist } from '@graphcommerce/react-hook-form'
6
- import { t, Trans } from '@lingui/macro'
6
+ import { i18n } from '@lingui/core'
7
+ import { Trans } from '@lingui/react'
7
8
  import { Alert, FormControlLabel, Switch, TextField } from '@mui/material'
8
9
  import { ApolloCustomerErrorSnackbar } from '../ApolloCustomerError/ApolloCustomerErrorSnackbar'
9
10
  import { NameFields } from '../NameFields/NameFields'
@@ -37,7 +38,7 @@ export function SignUpForm(props: SignUpFormProps) {
37
38
  if (requireEmailValidation && form.formState.isSubmitSuccessful) {
38
39
  return (
39
40
  <Alert>
40
- <Trans>Please check your inbox to validate your email ({email})</Trans>
41
+ <Trans id='Please check your inbox to validate your email ({email})' values={{ email }} />
41
42
  </Alert>
42
43
  )
43
44
  }
@@ -49,7 +50,7 @@ export function SignUpForm(props: SignUpFormProps) {
49
50
  variant='outlined'
50
51
  type='password'
51
52
  error={!!formState.errors.password || !!inputError}
52
- label={<Trans>Password</Trans>}
53
+ label={<Trans id='Password' />}
53
54
  autoFocus
54
55
  autoComplete='new-password'
55
56
  required={required.password}
@@ -57,7 +58,7 @@ export function SignUpForm(props: SignUpFormProps) {
57
58
  required: required.password,
58
59
  minLength: {
59
60
  value: Number(storeConfig?.minimum_password_length ?? 8),
60
- message: t`Password must have at least 8 characters`,
61
+ message: i18n._(/* i18n */ `Password must have at least 8 characters`),
61
62
  },
62
63
  })}
63
64
  helperText={formState.errors.password?.message || inputError?.message}
@@ -67,12 +68,13 @@ export function SignUpForm(props: SignUpFormProps) {
67
68
  variant='outlined'
68
69
  type='password'
69
70
  error={!!formState.errors.confirmPassword}
70
- label={<Trans>Confirm password</Trans>}
71
+ label={<Trans id='Confirm password' />}
71
72
  autoComplete='new-password'
72
73
  required
73
74
  {...muiRegister('confirmPassword', {
74
75
  required: true,
75
- validate: (value) => value === watchPassword || t`Passwords don't match`,
76
+ validate: (value) =>
77
+ value === watchPassword || i18n._(/* i18n */ `Passwords don't match`),
76
78
  })}
77
79
  helperText={formState.errors.confirmPassword?.message}
78
80
  disabled={formState.isSubmitting}
@@ -85,7 +87,7 @@ export function SignUpForm(props: SignUpFormProps) {
85
87
  control={<Switch color='primary' />}
86
88
  {...muiRegister('isSubscribed', { required: required.isSubscribed })}
87
89
  disabled={formState.isSubmitting}
88
- label={<Trans>Subscribe to newsletter</Trans>}
90
+ label={<Trans id='Subscribe to newsletter' />}
89
91
  />
90
92
 
91
93
  <ApolloCustomerErrorSnackbar error={remainingError} />
@@ -99,7 +101,7 @@ export function SignUpForm(props: SignUpFormProps) {
99
101
  size='large'
100
102
  loading={formState.isSubmitting}
101
103
  >
102
- <Trans>Create Account</Trans>
104
+ <Trans id='Create Account' />
103
105
  </Button>
104
106
  </FormActions>
105
107
  </form>
@@ -2,7 +2,8 @@ import { useQuery } from '@graphcommerce/graphql'
2
2
  import { StoreConfigDocument } from '@graphcommerce/magento-store'
3
3
  import { Button, extendableComponent, Form, FormRow } from '@graphcommerce/next-ui'
4
4
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
5
- import { t, Trans } from '@lingui/macro'
5
+ import { i18n } from '@lingui/core'
6
+ import { Trans } from '@lingui/react'
6
7
  import { Box, TextField } from '@mui/material'
7
8
  import React, { PropsWithChildren } from 'react'
8
9
  import { SignUpMutationVariables, SignUpMutation, SignUpDocument } from './SignUp.gql'
@@ -55,7 +56,7 @@ export function SignUpFormInline({
55
56
  variant='outlined'
56
57
  type='password'
57
58
  error={!!formState.errors.password || !!error?.message}
58
- label={<Trans>Password</Trans>}
59
+ label={<Trans id='Password' />}
59
60
  autoFocus
60
61
  autoComplete='new-password'
61
62
  id='new-password'
@@ -64,7 +65,7 @@ export function SignUpFormInline({
64
65
  required: required.password,
65
66
  minLength: {
66
67
  value: minPasswordLength,
67
- message: t`Password must have at least 8 characters`,
68
+ message: i18n._(/* i18n */ `Password must have at least 8 characters`),
68
69
  },
69
70
  })}
70
71
  helperText={error?.message}
@@ -7,7 +7,8 @@ import {
7
7
  MessageSnackbar,
8
8
  } from '@graphcommerce/next-ui'
9
9
  import { emailPattern, useFormGqlMutation } from '@graphcommerce/react-hook-form'
10
- import { t, Trans } from '@lingui/macro'
10
+ import { i18n } from '@lingui/core'
11
+ import { Trans } from '@lingui/react'
11
12
  import { TextField } from '@mui/material'
12
13
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
13
14
  import {
@@ -70,7 +71,7 @@ export function UpdateCustomerEmailForm(props: UpdateCustomerEmailFormProps) {
70
71
  autoFocus
71
72
  error={formState.isSubmitted && !!formState.errors.email}
72
73
  helperText={formState.isSubmitted && formState.errors.email?.message}
73
- label={<Trans>New email</Trans>}
74
+ label={<Trans id='New email' />}
74
75
  required={required.email}
75
76
  {...muiRegister('email', {
76
77
  required: true,
@@ -85,11 +86,11 @@ export function UpdateCustomerEmailForm(props: UpdateCustomerEmailFormProps) {
85
86
  autoFocus
86
87
  error={formState.isSubmitted && !!formState.errors.confirmEmail}
87
88
  helperText={formState.isSubmitted && formState.errors.confirmEmail?.message}
88
- label={<Trans>Confirm new email</Trans>}
89
+ label={<Trans id='Confirm new email' />}
89
90
  required
90
91
  {...muiRegister('confirmEmail', {
91
92
  required: true,
92
- validate: (value) => value === watchNewEmail || t`Emails don't match`,
93
+ validate: (value) => value === watchNewEmail || i18n._(/* i18n */ `Emails don't match`),
93
94
  })}
94
95
  />
95
96
  </FormRow>
@@ -99,7 +100,7 @@ export function UpdateCustomerEmailForm(props: UpdateCustomerEmailFormProps) {
99
100
  variant='outlined'
100
101
  type='password'
101
102
  error={!!formState.errors.password}
102
- label={<Trans>Password</Trans>}
103
+ label={<Trans id='Password' />}
103
104
  autoComplete='password'
104
105
  required={required.password}
105
106
  {...muiRegister('password', {
@@ -119,13 +120,13 @@ export function UpdateCustomerEmailForm(props: UpdateCustomerEmailFormProps) {
119
120
  size='large'
120
121
  loading={formState.isSubmitting}
121
122
  >
122
- <Trans>Save changes</Trans>
123
+ <Trans id='Save changes' />
123
124
  </Button>
124
125
  </FormActions>
125
126
  <ApolloCustomerErrorAlert error={error} />
126
127
 
127
128
  <MessageSnackbar sticky open={formState.isSubmitSuccessful && !error}>
128
- <Trans>Successfully updated email</Trans>
129
+ <Trans id='Successfully updated email' />
129
130
  </MessageSnackbar>
130
131
  </Form>
131
132
  )
@@ -1,5 +1,5 @@
1
1
  import { Controller, useFormAutoSubmit, useFormGqlMutation } from '@graphcommerce/react-hook-form'
2
- import { Trans } from '@lingui/macro'
2
+ import { Trans } from '@lingui/react'
3
3
  import { FormControl, FormControlLabel, FormHelperText, Switch } from '@mui/material'
4
4
  import React, { useEffect, useMemo } from 'react'
5
5
  import { AccountAddressFragment } from '../AccountAddress/AccountAddress.gql'
@@ -46,7 +46,7 @@ export function UpdateDefaultAddressForm(props: UpdateDefaultAddressFormProps) {
46
46
  <FormControl error={!!formState.errors.defaultShipping}>
47
47
  <FormControlLabel
48
48
  control={<Switch color='primary' />}
49
- label={<Trans>Shipping address</Trans>}
49
+ label={<Trans id='Shipping address' />}
50
50
  checked={value}
51
51
  inputRef={ref}
52
52
  onBlur={onBlur}
@@ -67,7 +67,7 @@ export function UpdateDefaultAddressForm(props: UpdateDefaultAddressFormProps) {
67
67
  <FormControl error={!!formState.errors.defaultBilling}>
68
68
  <FormControlLabel
69
69
  control={<Switch color='primary' />}
70
- label={<Trans>Billing address</Trans>}
70
+ label={<Trans id='Billing address' />}
71
71
  checked={value}
72
72
  inputRef={ref}
73
73
  onBlur={onBlur}
@@ -1,4 +1,5 @@
1
1
  export * from './AccountAddress/AccountAddress'
2
+ export * from './AccountAddresses/AccountAddresses.gql'
2
3
  export * from './AccountAddresses/AccountAddresses'
3
4
  export * from './AddressFields/AddressFields'
4
5
  export * from './AddressMultiLine/AddressMultiLine'
@@ -1,8 +1,7 @@
1
1
  query CustomerToken {
2
2
  customerToken @client {
3
- __typename
4
- token
5
- valid
3
+ ...CustomerTokenFragment
6
4
  createdAt
5
+ valid
7
6
  }
8
7
  }
@@ -0,0 +1,4 @@
1
+ fragment CustomerTokenFragment on CustomerToken @injectable {
2
+ __typename
3
+ token
4
+ }
package/hooks/index.ts CHANGED
@@ -4,3 +4,5 @@ export * from './CustomerToken.gql'
4
4
  export * from './IsEmailAvailable.gql'
5
5
  export * from './useExtractCustomerErrors'
6
6
  export * from './useFormIsEmailAvailable'
7
+ export * from './useCustomerQuery'
8
+ export * from './useCustomerSession'
@@ -0,0 +1,11 @@
1
+ import { useQuery, TypedDocumentNode, QueryHookOptions } from '@graphcommerce/graphql'
2
+ import { useCustomerSession } from './useCustomerSession'
3
+
4
+ /** Will only execute when the customer is signed in. */
5
+ export function useCustomerQuery<Q, V>(
6
+ document: TypedDocumentNode<Q, V>,
7
+ queryOptions: QueryHookOptions<Q, V> = {},
8
+ ) {
9
+ const { token } = useCustomerSession()
10
+ return useQuery(document, { ...queryOptions, ssr: false, skip: !token })
11
+ }
@@ -0,0 +1,23 @@
1
+ import { useQuery } from '@graphcommerce/graphql'
2
+ import { CustomerTokenDocument } from './CustomerToken.gql'
3
+ import { CustomerTokenFragment } from './CustomerTokenFragment.gql'
4
+
5
+ export type UseCustomerTokenReturn =
6
+ | (CustomerTokenFragment & {
7
+ loggedIn: boolean
8
+ requireAuth: boolean
9
+ })
10
+ | (Partial<CustomerTokenFragment> & { loggedIn: false; requireAuth: true })
11
+
12
+ export function useCustomerSession(): UseCustomerTokenReturn {
13
+ const token = useQuery(CustomerTokenDocument, { ssr: false, fetchPolicy: 'cache-only' }).data
14
+ ?.customerToken
15
+
16
+ if (!token) return { loggedIn: false, requireAuth: true }
17
+
18
+ return {
19
+ ...token,
20
+ loggedIn: Boolean(token?.token && token.valid),
21
+ requireAuth: Boolean(!token || !token.valid),
22
+ }
23
+ }
@@ -1,6 +1,6 @@
1
1
  import { ApolloError, useApolloClient } from '@graphcommerce/graphql'
2
2
  import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql'
3
- import { t } from '@lingui/macro'
3
+ import { i18n } from '@lingui/core'
4
4
  import { useEffect } from 'react'
5
5
  import { CustomerTokenDocument } from './CustomerToken.gql'
6
6
 
@@ -12,7 +12,7 @@ export function useExtractCustomerErrors({ error }: UseExtractErrors) {
12
12
  category: 'graphql-authorization',
13
13
  error,
14
14
  extract: false,
15
- mask: t`You must sign in to continue`,
15
+ mask: i18n._(/* i18n */ `You must sign in to continue`),
16
16
  })
17
17
 
18
18
  useEffect(() => {
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
4
4
  import { CustomerDocument } from './Customer.gql'
5
5
  import { CustomerTokenDocument } from './CustomerToken.gql'
6
6
  import { IsEmailAvailableDocument } from './IsEmailAvailable.gql'
7
+ import { useCustomerQuery } from './useCustomerQuery'
7
8
 
8
9
  export type UseFormIsEmailAvailableProps = {
9
10
  email?: string | null
@@ -13,15 +14,13 @@ export type UseFormIsEmailAvailableProps = {
13
14
  export function useFormIsEmailAvailable(props: UseFormIsEmailAvailableProps) {
14
15
  const { email, onSubmitted } = props
15
16
  const { data: token } = useQuery(CustomerTokenDocument)
16
- const customerQuery = useQuery(CustomerDocument, {
17
- ssr: false,
18
- skip: typeof token === 'undefined',
19
- })
17
+ const customerQuery = useCustomerQuery(CustomerDocument)
20
18
 
21
- const form = useFormGqlQuery(IsEmailAvailableDocument, {
22
- mode: 'onChange',
23
- defaultValues: { email: email ?? '' },
24
- })
19
+ const form = useFormGqlQuery(
20
+ IsEmailAvailableDocument,
21
+ { mode: 'onChange', defaultValues: { email: email ?? '' } },
22
+ { fetchPolicy: 'cache-and-network' },
23
+ )
25
24
  const { formState, data, handleSubmit } = form
26
25
 
27
26
  const submit = handleSubmit(onSubmitted || (() => {}))
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-customer",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "4.2.10",
5
+ "version": "4.3.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,23 +12,24 @@
12
12
  }
13
13
  },
14
14
  "devDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^4.1.6",
15
+ "@graphcommerce/eslint-config-pwa": "^4.1.7",
16
16
  "@graphcommerce/prettier-config-pwa": "^4.0.6",
17
- "@graphcommerce/typescript-config-pwa": "^4.0.2",
17
+ "@graphcommerce/typescript-config-pwa": "^4.0.3",
18
18
  "@playwright/test": "^1.21.1"
19
19
  },
20
20
  "dependencies": {
21
- "@graphcommerce/ecommerce-ui": "1.0.10",
22
- "@graphcommerce/graphql": "3.1.2",
21
+ "@graphcommerce/ecommerce-ui": "1.0.12",
22
+ "@graphcommerce/graphql": "3.1.3",
23
23
  "@graphcommerce/graphql-mesh": "4.1.3",
24
24
  "@graphcommerce/image": "3.1.5",
25
- "@graphcommerce/magento-graphql": "3.0.11",
26
- "@graphcommerce/magento-store": "4.2.1",
27
- "@graphcommerce/next-ui": "4.7.1",
28
- "@graphcommerce/react-hook-form": "3.1.2"
25
+ "@graphcommerce/magento-graphql": "3.0.12",
26
+ "@graphcommerce/magento-store": "4.2.4",
27
+ "@graphcommerce/next-ui": "4.8.0",
28
+ "@graphcommerce/react-hook-form": "3.1.3"
29
29
  },
30
30
  "peerDependencies": {
31
- "@lingui/macro": "^3.13.2",
31
+ "@lingui/react": "^3.13.2",
32
+ "@lingui/core": "^3.13.2",
32
33
  "@mui/material": "5.5.3",
33
34
  "framer-motion": "^6.2.4",
34
35
  "next": "12.1.2",
package/typePolicies.ts CHANGED
@@ -67,7 +67,7 @@ const createCustomer: FieldPolicy<Mutation['createCustomer']> = {
67
67
 
68
68
  export const customerTypePolicies: StrictTypedTypePolicies = {
69
69
  // Query: { fields: { customer } },
70
- Mutation: { fields: { generateCustomerToken, createCustomer } },
70
+ Mutation: { fields: { generateCustomerToken, createCustomer, createCustomerV2: createCustomer } },
71
71
  CustomerToken: { fields: { valid } },
72
72
  }
73
73