@graphcommerce/magento-customer 4.1.4 → 4.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,45 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1368](https://github.com/graphcommerce-org/graphcommerce/pull/1368) [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a) Thanks [@paales](https://github.com/paales)! - Add a feature to set CUSTOMER_REQUIRE_EMAIL_CONFIRMATION in the env
8
+
9
+ ### Patch Changes
10
+
11
+ - [#1369](https://github.com/graphcommerce-org/graphcommerce/pull/1369) [`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9) Thanks [@paales](https://github.com/paales)! - Upgraded dependencies
12
+
13
+ * [#1362](https://github.com/graphcommerce-org/graphcommerce/pull/1362) [`6213f0b0f`](https://github.com/graphcommerce-org/graphcommerce/commit/6213f0b0f5f53d622b993d9f7ea96cbbeb5bd670) Thanks [@timhofman](https://github.com/timhofman)! - persistence layer not purged at logout
14
+
15
+ * Updated dependencies [[`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a), [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a), [`ae6449502`](https://github.com/graphcommerce-org/graphcommerce/commit/ae64495024a455bbe5188588604368c1542840c9), [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a), [`892018809`](https://github.com/graphcommerce-org/graphcommerce/commit/8920188093d0422ec50580e408dc28ac5f93e46a)]:
16
+ - @graphcommerce/graphql@3.0.6
17
+ - @graphcommerce/next-ui@4.5.0
18
+ - @graphcommerce/ecommerce-ui@1.0.4
19
+ - @graphcommerce/image@3.1.2
20
+ - @graphcommerce/magento-graphql@3.0.5
21
+ - @graphcommerce/magento-store@4.1.4
22
+ - @graphcommerce/react-hook-form@3.0.6
23
+
24
+ ## 4.1.6
25
+
26
+ ### Patch Changes
27
+
28
+ - [#1353](https://github.com/graphcommerce-org/graphcommerce/pull/1353) [`0e5ee7ba8`](https://github.com/graphcommerce-org/graphcommerce/commit/0e5ee7ba89698e5e711001e846ed182528060cba) Thanks [@paales](https://github.com/paales)! - Eslint: enable rules that were previously disabled and make fixes
29
+
30
+ - Updated dependencies [[`49a2d6617`](https://github.com/graphcommerce-org/graphcommerce/commit/49a2d661712e1787fba46c6195f7b559189e23d9), [`f67da3cfb`](https://github.com/graphcommerce-org/graphcommerce/commit/f67da3cfbe2dcf5ea23519d088c5aa0074029182), [`218766869`](https://github.com/graphcommerce-org/graphcommerce/commit/218766869f7468c067a590857c942f3819f8add4), [`0e5ee7ba8`](https://github.com/graphcommerce-org/graphcommerce/commit/0e5ee7ba89698e5e711001e846ed182528060cba), [`829b8690b`](https://github.com/graphcommerce-org/graphcommerce/commit/829b8690bc5d0a46e596299e4120e9837a9f179c)]:
31
+ - @graphcommerce/next-ui@4.4.0
32
+
33
+ ## 4.1.5
34
+
35
+ ### Patch Changes
36
+
37
+ - [#1322](https://github.com/graphcommerce-org/graphcommerce/pull/1322) [`3b4d46de2`](https://github.com/graphcommerce-org/graphcommerce/commit/3b4d46de2555db9eed733c8fac574bc809d75da4) Thanks [@paales](https://github.com/paales)! - CustomerMenuFabItem badge was rendered with the wrong size
38
+
39
+ - Updated dependencies [[`5266388ea`](https://github.com/graphcommerce-org/graphcommerce/commit/5266388eaffda41592623ef7a3ddbbe03c8e0dad), [`9b35403d9`](https://github.com/graphcommerce-org/graphcommerce/commit/9b35403d9dbb2606ac7cf3bb641a0f9cc3d8a2ba), [`0298a0de1`](https://github.com/graphcommerce-org/graphcommerce/commit/0298a0de1d13e543c4124a6a099297b4e27e2b05), [`815132ea4`](https://github.com/graphcommerce-org/graphcommerce/commit/815132ea43937b4b84b59ec9974ac593cb4eb456), [`3326742a0`](https://github.com/graphcommerce-org/graphcommerce/commit/3326742a0dceb45f0cac4741ca09dc4d4f09ad90), [`7a3799bfc`](https://github.com/graphcommerce-org/graphcommerce/commit/7a3799bfc107f26aa9991a91db5f228e3476f4aa), [`9a77f88ed`](https://github.com/graphcommerce-org/graphcommerce/commit/9a77f88ed26cbecdae9a135c3cb234a5b7ecf4df), [`0eeaad304`](https://github.com/graphcommerce-org/graphcommerce/commit/0eeaad30461b1d5b486438f0287fa76d49429044), [`bc5213547`](https://github.com/graphcommerce-org/graphcommerce/commit/bc52135471479c83d989449dad24798112e898f4), [`3f1912f55`](https://github.com/graphcommerce-org/graphcommerce/commit/3f1912f553318d5888f8af2b841918ef4ae96a84), [`b6c68cda8`](https://github.com/graphcommerce-org/graphcommerce/commit/b6c68cda8836a1d0c78ef351899cec9ec1037385)]:
40
+ - @graphcommerce/next-ui@4.3.0
41
+ - @graphcommerce/magento-store@4.1.3
42
+
3
43
  ## 4.1.4
4
44
 
5
45
  ### Patch Changes
@@ -0,0 +1,7 @@
1
+ import { ApolloErrorSnackbar, ApolloErrorSnackbarProps } from '@graphcommerce/ecommerce-ui'
2
+
3
+ type ApolloCustomerErrorSnackbarProps = ApolloErrorSnackbarProps
4
+
5
+ export function ApolloCustomerErrorSnackbar(props: ApolloCustomerErrorSnackbarProps) {
6
+ return <ApolloErrorSnackbar {...props} />
7
+ }
@@ -31,7 +31,7 @@ function CustomerFabContent(props: CustomerFabContentProps) {
31
31
  <PageLink href={requireAuth ? guestHref : authHref} passHref>
32
32
  <Fab
33
33
  color='inherit'
34
- data-test-id='customer-fab'
34
+ id='account'
35
35
  aria-label={t`Account`}
36
36
  size='large'
37
37
  className={classes.root}
@@ -1,11 +1,6 @@
1
1
  import { useQuery } from '@graphcommerce/graphql'
2
- import {
3
- MenuFabSecondaryItem,
4
- DesktopHeaderBadge,
5
- iconPerson,
6
- IconSvg,
7
- } from '@graphcommerce/next-ui'
8
- import { NoSsr, SxProps, Theme } from '@mui/material'
2
+ import { MenuFabSecondaryItem, iconPerson, IconSvg } from '@graphcommerce/next-ui'
3
+ import { Badge, NoSsr, SxProps, Theme } from '@mui/material'
9
4
  import React from 'react'
10
5
  import { CustomerTokenDocument, CustomerTokenQuery } from '../../hooks'
11
6
 
@@ -25,14 +20,14 @@ function CustomerMenuFabItemContent(props: CustomerMenuFabItemProps) {
25
20
  <MenuFabSecondaryItem
26
21
  sx={sx}
27
22
  icon={
28
- <DesktopHeaderBadge
23
+ <Badge
29
24
  badgeContent={customerToken?.token ? 1 : 0}
30
25
  color={customerToken?.valid ? 'primary' : 'error'}
31
26
  variant='dot'
32
27
  overlap='circular'
33
28
  >
34
29
  {icon ?? <IconSvg src={iconPerson} size='medium' />}
35
- </DesktopHeaderBadge>
30
+ </Badge>
36
31
  }
37
32
  href={requireAuth ? guestHref : authHref}
38
33
  >
@@ -27,7 +27,7 @@ export function ForgotPasswordForm(props: { sx?: SxProps<Theme> }) {
27
27
  marginBottom: theme.spacings.sm,
28
28
  })}
29
29
  >
30
- <Trans>We've send a password reset link to your email address!</Trans>
30
+ <Trans>Weve send a password reset link to your email address!</Trans>
31
31
  </Alert>
32
32
  )
33
33
  }
@@ -3,16 +3,20 @@ import { useRouter } from 'next/router'
3
3
  import React from 'react'
4
4
  import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
5
5
  import { SignOutFormDocument } from './SignOutForm.gql'
6
+ import { useApolloClient } from '@graphcommerce/graphql'
6
7
 
7
8
  type SignOutFormProps = { button: (props: { formState: FormState<unknown> }) => React.ReactNode }
8
9
 
9
10
  export function SignOutForm(props: SignOutFormProps) {
10
11
  const { button } = props
11
12
  const router = useRouter()
13
+ const client = useApolloClient()
14
+
12
15
  const { handleSubmit, formState, error } = useFormGqlMutation(
13
16
  SignOutFormDocument,
14
17
  {
15
18
  onComplete: () => {
19
+ client.clearStore()
16
20
  // eslint-disable-next-line @typescript-eslint/no-floating-promises
17
21
  router.push('/')
18
22
  },
@@ -11,25 +11,7 @@ mutation SignUp(
11
11
  $isSubscribed: Boolean = false
12
12
  $dateOfBirth: String
13
13
  ) {
14
- createCustomer(
15
- input: {
16
- email: $email
17
- password: $password
18
- prefix: $prefix
19
- firstname: $firstname
20
- middlename: $middlename
21
- lastname: $lastname
22
- suffix: $suffix
23
- taxvat: $taxvat
24
- gender: $gender
25
- is_subscribed: $isSubscribed
26
- date_of_birth: $dateOfBirth
27
- }
28
- ) {
29
- customer {
30
- ...CustomerInfo
31
- }
32
- }
14
+ ...CreateCustomerMutationFragment
33
15
  generateCustomerToken(email: $email, password: $password) {
34
16
  token
35
17
  }
@@ -0,0 +1,15 @@
1
+ mutation SignUpConfirm(
2
+ $email: String!
3
+ $password: String!
4
+ $prefix: String!
5
+ $firstname: String!
6
+ $middlename: String
7
+ $lastname: String!
8
+ $suffix: String
9
+ $taxvat: String
10
+ $gender: Int
11
+ $isSubscribed: Boolean = false
12
+ $dateOfBirth: String
13
+ ) {
14
+ ...CreateCustomerMutationFragment
15
+ }
@@ -1,22 +1,30 @@
1
+ import { useQuery } from '@graphcommerce/graphql'
1
2
  import { graphqlErrorByCategory } from '@graphcommerce/magento-graphql'
3
+ import { StoreConfigDocument } from '@graphcommerce/magento-store'
2
4
  import { Button, FormActions, FormRow } from '@graphcommerce/next-ui'
3
5
  import { useFormGqlMutation, useFormPersist } from '@graphcommerce/react-hook-form'
4
6
  import { t, Trans } from '@lingui/macro'
5
- import { FormControlLabel, Switch, TextField } from '@mui/material'
6
- import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
7
+ import { Alert, FormControlLabel, Switch, TextField } from '@mui/material'
8
+ import { ApolloCustomerErrorSnackbar } from '../ApolloCustomerError/ApolloCustomerErrorSnackbar'
7
9
  import { NameFields } from '../NameFields/NameFields'
8
10
  import { SignUpDocument, SignUpMutation, SignUpMutationVariables } from './SignUp.gql'
11
+ import { SignUpConfirmDocument } from './SignUpConfirm.gql'
9
12
 
10
- type SignUpFormProps = {
11
- email?: string
12
- }
13
+ type SignUpFormProps = { email: string }
14
+
15
+ const requireEmailValidation = process.env.CUSTOMER_REQUIRE_EMAIL_CONFIRMATION === '1'
13
16
 
14
17
  export function SignUpForm(props: SignUpFormProps) {
15
18
  const { email } = props
19
+
20
+ const storeConfig = useQuery(StoreConfigDocument).data?.storeConfig
21
+
22
+ const Mutation = requireEmailValidation ? SignUpConfirmDocument : SignUpDocument
23
+
16
24
  const form = useFormGqlMutation<
17
25
  SignUpMutation,
18
26
  SignUpMutationVariables & { confirmPassword?: string }
19
- >(SignUpDocument, { defaultValues: { email } }, { errorPolicy: 'all' })
27
+ >(Mutation, { defaultValues: { email } }, { errorPolicy: 'all' })
20
28
 
21
29
  const { muiRegister, handleSubmit, required, watch, formState, error } = form
22
30
  const [remainingError, inputError] = graphqlErrorByCategory({ category: 'graphql-input', error })
@@ -26,6 +34,14 @@ export function SignUpForm(props: SignUpFormProps) {
26
34
 
27
35
  useFormPersist({ form, name: 'SignUp', exclude: ['password', 'confirmPassword'] })
28
36
 
37
+ if (requireEmailValidation && form.formState.isSubmitSuccessful) {
38
+ return (
39
+ <Alert>
40
+ <Trans>Please check your inbox to validate your email ({email})</Trans>
41
+ </Alert>
42
+ )
43
+ }
44
+
29
45
  return (
30
46
  <form onSubmit={submitHandler} noValidate>
31
47
  <FormRow>
@@ -39,7 +55,10 @@ export function SignUpForm(props: SignUpFormProps) {
39
55
  required={required.password}
40
56
  {...muiRegister('password', {
41
57
  required: required.password,
42
- minLength: { value: 8, message: t`Password must have at least 8 characters` },
58
+ minLength: {
59
+ value: Number(storeConfig?.minimum_password_length ?? 8),
60
+ message: t`Password must have at least 8 characters`,
61
+ },
43
62
  })}
44
63
  helperText={formState.errors.password?.message || inputError?.message}
45
64
  disabled={formState.isSubmitting}
@@ -69,12 +88,12 @@ export function SignUpForm(props: SignUpFormProps) {
69
88
  label={<Trans>Subscribe to newsletter</Trans>}
70
89
  />
71
90
 
72
- <ApolloCustomerErrorAlert error={remainingError} />
91
+ <ApolloCustomerErrorSnackbar error={remainingError} />
73
92
 
74
93
  <FormActions>
75
94
  <Button
76
95
  type='submit'
77
- data-test-id='create-account'
96
+ id='create-account'
78
97
  variant='contained'
79
98
  color='primary'
80
99
  size='large'
@@ -1,6 +1,8 @@
1
+ import { useQuery } from '@graphcommerce/graphql'
2
+ import { StoreConfigDocument } from '@graphcommerce/magento-store'
1
3
  import { Button, extendableComponent, Form, FormRow } from '@graphcommerce/next-ui'
2
4
  import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
3
- import { Trans } from '@lingui/macro'
5
+ import { t, Trans } from '@lingui/macro'
4
6
  import { Box, TextField } from '@mui/material'
5
7
  import React, { PropsWithChildren } from 'react'
6
8
  import { SignUpMutationVariables, SignUpMutation, SignUpDocument } from './SignUp.gql'
@@ -42,6 +44,10 @@ export function SignUpFormInline({
42
44
  const submitHandler = handleSubmit(onSubmitted)
43
45
  const watchPassword = watch('password')
44
46
 
47
+ const minPasswordLength = Number(
48
+ useQuery(StoreConfigDocument).data?.storeConfig?.minimum_password_length ?? 8,
49
+ )
50
+
45
51
  return (
46
52
  <Form onSubmit={submitHandler} noValidate className={classes.form} sx={{ padding: 0 }}>
47
53
  <FormRow key='inline-signup' className={classes.row} sx={{ padding: 0 }}>
@@ -54,7 +60,13 @@ export function SignUpFormInline({
54
60
  autoComplete='new-password'
55
61
  id='new-password'
56
62
  required={required.password}
57
- {...muiRegister('password', { required: required.password })}
63
+ {...muiRegister('password', {
64
+ required: required.password,
65
+ minLength: {
66
+ value: minPasswordLength,
67
+ message: t`Password must have at least 8 characters`,
68
+ },
69
+ })}
58
70
  helperText={error?.message}
59
71
  disabled={formState.isSubmitting}
60
72
  />
@@ -0,0 +1,21 @@
1
+ fragment CreateCustomerMutationFragment on Mutation {
2
+ createCustomer(
3
+ input: {
4
+ email: $email
5
+ password: $password
6
+ prefix: $prefix
7
+ firstname: $firstname
8
+ middlename: $middlename
9
+ lastname: $lastname
10
+ suffix: $suffix
11
+ taxvat: $taxvat
12
+ gender: $gender
13
+ is_subscribed: $isSubscribed
14
+ date_of_birth: $dateOfBirth
15
+ }
16
+ ) {
17
+ customer {
18
+ ...CustomerInfo
19
+ }
20
+ }
21
+ }
@@ -5,6 +5,7 @@ export * from './AddressMultiLine/AddressMultiLine'
5
5
  export * from './AddressSingleLine/AddressSingleLine'
6
6
  export * from './ApolloCustomerError/ApolloCustomerErrorAlert'
7
7
  export * from './ApolloCustomerError/ApolloCustomerErrorFullPage'
8
+ export * from './ApolloCustomerError/ApolloCustomerErrorSnackbar'
8
9
  export * from './ChangeNameForm/ChangeNameForm'
9
10
  export * from './ChangePasswordForm/ChangePassword.gql'
10
11
  export * from './ChangePasswordForm/ChangePasswordForm'
@@ -0,0 +1,5 @@
1
+ fragment CustomerStoreConfig on StoreConfig @inject(into: ["StoreConfigFragment"]) {
2
+ autocomplete_on_storefront
3
+ minimum_password_length
4
+ required_character_classes_number
5
+ }
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.1.4",
5
+ "version": "4.2.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,19 +12,19 @@
12
12
  }
13
13
  },
14
14
  "devDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^4.0.5",
16
- "@graphcommerce/prettier-config-pwa": "^4.0.3",
15
+ "@graphcommerce/eslint-config-pwa": "^4.1.3",
16
+ "@graphcommerce/prettier-config-pwa": "^4.0.5",
17
17
  "@graphcommerce/typescript-config-pwa": "^4.0.2",
18
- "@playwright/test": "^1.19.2"
18
+ "@playwright/test": "^1.20.1"
19
19
  },
20
20
  "dependencies": {
21
- "@graphcommerce/ecommerce-ui": "^1.0.3",
22
- "@graphcommerce/graphql": "^3.0.4",
23
- "@graphcommerce/image": "^3.1.1",
24
- "@graphcommerce/magento-graphql": "^3.0.4",
25
- "@graphcommerce/magento-store": "^4.1.2",
26
- "@graphcommerce/next-ui": "^4.2.4",
27
- "@graphcommerce/react-hook-form": "^3.0.4"
21
+ "@graphcommerce/ecommerce-ui": "^1.0.4",
22
+ "@graphcommerce/graphql": "^3.0.6",
23
+ "@graphcommerce/image": "^3.1.2",
24
+ "@graphcommerce/magento-graphql": "^3.0.5",
25
+ "@graphcommerce/magento-store": "^4.1.4",
26
+ "@graphcommerce/next-ui": "^4.5.0",
27
+ "@graphcommerce/react-hook-form": "^3.0.6"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "@lingui/macro": "^3.13.2",
package/typePolicies.ts CHANGED
@@ -1,15 +1,13 @@
1
- import { FieldPolicy , CustomerToken, MigrateCache, Mutation, TypedTypePolicies } from '@graphcommerce/graphql'
1
+ import {
2
+ FieldPolicy,
3
+ CustomerToken,
4
+ MigrateCache,
5
+ Mutation,
6
+ TypedTypePolicies,
7
+ } from '@graphcommerce/graphql'
2
8
  import { CustomerTokenDocument } from './hooks/CustomerToken.gql'
3
9
  import { IsEmailAvailableDocument } from './hooks/IsEmailAvailable.gql'
4
10
 
5
- const revokeCustomerToken: FieldPolicy<Mutation['revokeCustomerToken']> = {
6
- merge(_existing, incoming, options) {
7
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
8
- options.cache.reset()
9
- return incoming
10
- },
11
- }
12
-
13
11
  const TOKEN_EXPIRATION_MS = 60 * 60 * 1000
14
12
 
15
13
  const valid: FieldPolicy<CustomerToken['valid']> = {
@@ -74,7 +72,7 @@ const createCustomer: FieldPolicy<Mutation['createCustomer']> = {
74
72
 
75
73
  export const customerTypePolicies: TypedTypePolicies = {
76
74
  // Query: { fields: { customer } },
77
- Mutation: { fields: { generateCustomerToken, revokeCustomerToken, createCustomer } },
75
+ Mutation: { fields: { generateCustomerToken, createCustomer } },
78
76
  CustomerToken: { fields: { valid } },
79
77
  }
80
78