@graphcommerce/magento-customer 3.0.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +294 -0
  2. package/components/AccountAddress/AccountAddress.gql.ts +4 -0
  3. package/components/AccountAddress/AccountAddress.graphql +6 -0
  4. package/components/AccountAddress/index.tsx +59 -0
  5. package/components/AccountAddresses/AccountAddresses.gql.ts +4 -0
  6. package/components/AccountAddresses/AccountAddresses.graphql +5 -0
  7. package/components/AccountAddresses/UpdateDefaultAddress.gql.ts +14 -0
  8. package/components/AccountAddresses/UpdateDefaultAddress.graphql +14 -0
  9. package/components/AccountAddresses/index.tsx +101 -0
  10. package/components/AddressFields/index.tsx +189 -0
  11. package/components/AddressMultiLine/index.tsx +68 -0
  12. package/components/AddressSingleLine/index.tsx +34 -0
  13. package/components/ApolloCustomerError/ApolloCustomerErrorAlert.tsx +21 -0
  14. package/components/ApolloCustomerError/ApolloCustomerErrorFullPage.tsx +46 -0
  15. package/components/ChangeNameForm/UpdateCustomerName.gql.ts +14 -0
  16. package/components/ChangeNameForm/UpdateCustomerName.graphql +9 -0
  17. package/components/ChangeNameForm/index.tsx +66 -0
  18. package/components/ChangePasswordForm/ChangePassword.gql.ts +13 -0
  19. package/components/ChangePasswordForm/ChangePassword.graphql +5 -0
  20. package/components/ChangePasswordForm/ChangePasswordForm.tsx +93 -0
  21. package/components/CreateCustomerAddressForm/CreateCustomerAddress.gql.ts +28 -0
  22. package/components/CreateCustomerAddressForm/CreateCustomerAddress.graphql +41 -0
  23. package/components/CreateCustomerAddressForm/CustomerAddress.gql.ts +4 -0
  24. package/components/CreateCustomerAddressForm/CustomerAddress.graphql +22 -0
  25. package/components/CreateCustomerAddressForm/CustomerAddressEdit.gql.ts +4 -0
  26. package/components/CreateCustomerAddressForm/CustomerAddressEdit.graphql +4 -0
  27. package/components/CreateCustomerAddressForm/index.tsx +98 -0
  28. package/components/CustomerFab/index.tsx +55 -0
  29. package/components/CustomerMenuFabItem/index.tsx +68 -0
  30. package/components/DeleteCustomerAddressForm/DeleteCustomerAddressForm.gql.ts +12 -0
  31. package/components/DeleteCustomerAddressForm/DeleteCustomerAddressForm.graphql +3 -0
  32. package/components/DeleteCustomerAddressForm/index.tsx +46 -0
  33. package/components/EditAddressForm/UpdateCustomerAddress.gql.ts +29 -0
  34. package/components/EditAddressForm/UpdateCustomerAddress.graphql +43 -0
  35. package/components/EditAddressForm/index.tsx +127 -0
  36. package/components/ForgotPasswordForm/ForgotPassword.gql.ts +12 -0
  37. package/components/ForgotPasswordForm/ForgotPassword.graphql +3 -0
  38. package/components/ForgotPasswordForm/ForgotPasswordForm.tsx +73 -0
  39. package/components/InlineAccount/InlineAccount.gql.ts +12 -0
  40. package/components/InlineAccount/InlineAccount.graphql +10 -0
  41. package/components/InlineAccount/index.tsx +149 -0
  42. package/components/NameFields/index.tsx +89 -0
  43. package/components/ResetPasswordForm/ResetPassword.gql.ts +14 -0
  44. package/components/ResetPasswordForm/ResetPassword.graphql +3 -0
  45. package/components/ResetPasswordForm/index.tsx +98 -0
  46. package/components/SignInForm/SignIn.gql.ts +13 -0
  47. package/components/SignInForm/SignIn.graphql +5 -0
  48. package/components/SignInForm/SignInForm.tsx +96 -0
  49. package/components/SignInForm/SignInFormInline.tsx +68 -0
  50. package/components/SignOutForm/SignOutForm.gql.ts +10 -0
  51. package/components/SignOutForm/SignOutForm.graphql +5 -0
  52. package/components/SignOutForm/index.tsx +30 -0
  53. package/components/SignUpForm/SignUp.gql.ts +22 -0
  54. package/components/SignUpForm/SignUp.graphql +36 -0
  55. package/components/SignUpForm/SignUpForm.tsx +90 -0
  56. package/components/SignUpForm/SignUpFormInline.tsx +113 -0
  57. package/components/UpdateCustomerEmailForm/UpdateCustomerEmail.gql.ts +13 -0
  58. package/components/UpdateCustomerEmailForm/UpdateCustomerEmail.graphql +7 -0
  59. package/components/UpdateCustomerEmailForm/index.tsx +133 -0
  60. package/components/UpdateDefaultAddressForm/index.tsx +91 -0
  61. package/components/index.ts +29 -0
  62. package/hooks/Customer.gql.ts +10 -0
  63. package/hooks/Customer.graphql +5 -0
  64. package/hooks/CustomerInfo.gql.ts +4 -0
  65. package/hooks/CustomerInfo.graphql +20 -0
  66. package/hooks/CustomerToken.gql.ts +10 -0
  67. package/hooks/CustomerToken.graphql +8 -0
  68. package/hooks/CustomerToken.graphqls +8 -0
  69. package/hooks/IsEmailAvailable.gql.ts +12 -0
  70. package/hooks/IsEmailAvailable.graphql +5 -0
  71. package/hooks/index.ts +7 -0
  72. package/hooks/useExtractCustomerErrors.tsx +42 -0
  73. package/hooks/useFormIsEmailAvailable.tsx +69 -0
  74. package/index.ts +4 -0
  75. package/next-env.d.ts +4 -0
  76. package/package.json +41 -0
  77. package/tsconfig.json +5 -0
  78. package/typePolicies.ts +91 -0
@@ -0,0 +1,189 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { TextField } from '@material-ui/core'
3
+ import { CountryRegionsDocument } from '@graphcommerce/magento-store'
4
+ import { FormRow, InputCheckmark } from '@graphcommerce/next-ui'
5
+ import {
6
+ assertFormGqlOperation,
7
+ houseNumberPattern,
8
+ UseFormReturn,
9
+ } from '@graphcommerce/react-hook-form'
10
+ import React, { useMemo } from 'react'
11
+
12
+ type AddressFieldValues = {
13
+ street?: string
14
+ houseNumber?: string
15
+ addition?: string
16
+ countryCode?: string
17
+ regionId?: string
18
+ postcode?: string
19
+ city?: string
20
+ }
21
+
22
+ type AddressFieldsProps = { form: UseFormReturn<any>; readOnly?: boolean }
23
+
24
+ export default function AddressFields(props: AddressFieldsProps) {
25
+ const { form, readOnly } = props
26
+ const countries = useQuery(CountryRegionsDocument).data?.countries
27
+ assertFormGqlOperation<AddressFieldValues>(form)
28
+ const { watch, formState, required, muiRegister, valid } = form
29
+
30
+ const country = watch('countryCode')
31
+
32
+ const countryList = useMemo(() => {
33
+ const countriesWithLocale = (countries ?? [])?.filter((c) => c?.full_name_locale)
34
+ return countriesWithLocale.sort((a, b) =>
35
+ (a?.full_name_locale ?? '')?.localeCompare(b?.full_name_locale ?? ''),
36
+ )
37
+ }, [countries])
38
+
39
+ const regionList = useMemo(() => {
40
+ const availableRegions = Object.values(
41
+ countryList.find((c) => c?.two_letter_abbreviation === country)?.available_regions ?? {},
42
+ )
43
+ type Region = typeof availableRegions[0]
44
+
45
+ const compare: (a: Region, b: Region) => number = (a, b) =>
46
+ (a?.name ?? '')?.localeCompare(b?.name ?? '')
47
+
48
+ const regions = availableRegions?.sort(compare)
49
+ return regions
50
+ }, [country, countryList])
51
+
52
+ return (
53
+ <>
54
+ <FormRow>
55
+ <TextField
56
+ variant='outlined'
57
+ type='text'
58
+ error={!!formState.errors.street}
59
+ label='Street'
60
+ autoComplete='address-line1'
61
+ required={!!required?.street}
62
+ {...muiRegister('street', { required: required?.street })}
63
+ helperText={formState.isSubmitted && formState.errors.street?.message}
64
+ InputProps={{
65
+ readOnly,
66
+ endAdornment: <InputCheckmark show={valid.street} />,
67
+ }}
68
+ />
69
+ <TextField
70
+ variant='outlined'
71
+ type='text'
72
+ error={!!formState.errors.houseNumber}
73
+ label='Housenumber'
74
+ autoComplete='address-line2'
75
+ required={!!required?.houseNumber}
76
+ {...muiRegister('houseNumber', {
77
+ required: required?.houseNumber,
78
+ pattern: { value: houseNumberPattern, message: 'Please provide a valid house number' },
79
+ })}
80
+ helperText={formState.isSubmitted && formState.errors.houseNumber?.message}
81
+ InputProps={{
82
+ readOnly,
83
+ endAdornment: <InputCheckmark show={valid.houseNumber} />,
84
+ }}
85
+ />
86
+ <TextField
87
+ variant='outlined'
88
+ type='text'
89
+ error={!!formState.errors.addition}
90
+ required={!!required?.addition}
91
+ label='Addition'
92
+ autoComplete='address-line3'
93
+ {...muiRegister('addition', { required: required?.addition })}
94
+ helperText={formState.isSubmitted && formState.errors.addition?.message}
95
+ InputProps={{
96
+ readOnly,
97
+ endAdornment: <InputCheckmark show={valid.addition} />,
98
+ }}
99
+ />
100
+ </FormRow>
101
+ <FormRow>
102
+ <TextField
103
+ variant='outlined'
104
+ type='text'
105
+ error={!!formState.errors.postcode}
106
+ required={!!required?.postcode}
107
+ label='Postcode'
108
+ {...muiRegister('postcode', { required: required?.postcode })}
109
+ helperText={formState.isSubmitted && formState.errors.postcode?.message}
110
+ InputProps={{
111
+ readOnly,
112
+ endAdornment: <InputCheckmark show={valid.postcode} />,
113
+ }}
114
+ />
115
+ <TextField
116
+ variant='outlined'
117
+ type='text'
118
+ error={!!formState.errors.city}
119
+ required={!!required?.city}
120
+ label='City'
121
+ {...muiRegister('city', { required: required?.city })}
122
+ helperText={formState.isSubmitted && formState.errors.city?.message}
123
+ InputProps={{
124
+ readOnly,
125
+ endAdornment: <InputCheckmark show={valid.city} />,
126
+ }}
127
+ />
128
+ </FormRow>
129
+ <FormRow>
130
+ <TextField
131
+ select
132
+ SelectProps={{ native: true, displayEmpty: true }}
133
+ {...muiRegister('countryCode', { required: required.countryCode })}
134
+ variant='outlined'
135
+ error={!!formState.errors.countryCode}
136
+ label='Country'
137
+ required={!!required?.countryCode}
138
+ helperText={formState.errors.countryCode?.message}
139
+ // onBlur={onBlur}
140
+ InputProps={{
141
+ readOnly,
142
+ endAdornment: <InputCheckmark show={valid.countryCode} />,
143
+ }}
144
+ >
145
+ <option value='' />
146
+ {countryList.map((c) => {
147
+ if (!c?.two_letter_abbreviation) return null
148
+ return (
149
+ <option key={c.two_letter_abbreviation} value={c.two_letter_abbreviation}>
150
+ {c.full_name_locale}
151
+ </option>
152
+ )
153
+ })}
154
+ </TextField>
155
+
156
+ {regionList.length > 0 && (
157
+ <TextField
158
+ select
159
+ SelectProps={{ native: true, displayEmpty: true }}
160
+ variant='outlined'
161
+ error={!!formState.errors.regionId}
162
+ label='Region'
163
+ {...muiRegister('regionId', {
164
+ required: true,
165
+ shouldUnregister: true,
166
+ valueAsNumber: true,
167
+ })}
168
+ required
169
+ helperText={formState.errors.regionId?.message}
170
+ InputProps={{
171
+ readOnly,
172
+ endAdornment: <InputCheckmark show={valid.regionId} />,
173
+ }}
174
+ >
175
+ <option value='' />
176
+ {regionList.map((r) => {
177
+ if (!r?.id) return null
178
+ return (
179
+ <option key={r.id} value={r.id}>
180
+ {r.name}
181
+ </option>
182
+ )
183
+ })}
184
+ </TextField>
185
+ )}
186
+ </FormRow>
187
+ </>
188
+ )
189
+ }
@@ -0,0 +1,68 @@
1
+ import { makeStyles, Theme, Typography } from '@material-ui/core'
2
+ import { useFindCountry } from '@graphcommerce/magento-store'
3
+ import { UseStyles } from '@graphcommerce/next-ui'
4
+ import { CustomerAddressFragment } from '../CreateCustomerAddressForm/CustomerAddress.gql'
5
+
6
+ // exports.getEuMembers = function()
7
+ // {
8
+ // return ["BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "HR", "IT", "CY", "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", "SI", "SK", "FI", "SE"];
9
+ // };
10
+ // exports.isEuMember = function(code)
11
+ // {
12
+ // return exports.getEuMembers().indexOf(code.toUpperCase()) != -1;
13
+ // };
14
+
15
+ const useStyles = makeStyles(
16
+ (theme: Theme) => ({
17
+ title: {
18
+ // fontWeight: 'bold',
19
+ // paddingBottom: theme.spacings.xxs,
20
+ },
21
+ }),
22
+ {
23
+ name: 'AddressMultiLine',
24
+ },
25
+ )
26
+
27
+ type AddressMultiLineProps = CustomerAddressFragment & UseStyles<typeof useStyles>
28
+
29
+ export default function AddressMultiLine(props: AddressMultiLineProps) {
30
+ const {
31
+ company,
32
+ prefix,
33
+ firstname,
34
+ lastname,
35
+ middlename,
36
+ suffix,
37
+ street,
38
+ region,
39
+ city,
40
+ postcode,
41
+ country_code,
42
+ } = props
43
+ const countryName = useFindCountry(country_code)?.full_name_locale ?? country_code
44
+
45
+ const regionName = typeof region === 'string' ? region : region?.region
46
+ const classes = useStyles(props)
47
+
48
+ return (
49
+ <Typography variant='body1' component='div'>
50
+ <div className={classes.title}>
51
+ <div>{company}</div>
52
+ <div>
53
+ {prefix} {firstname} {middlename} {lastname} {suffix}
54
+ </div>
55
+ </div>
56
+ <div>
57
+ {street?.[0]} {street?.slice(1).join('')}
58
+ </div>
59
+ <div>
60
+ {postcode} {city}
61
+ </div>
62
+ <div>
63
+ {regionName && `${regionName}, `}
64
+ {countryName}
65
+ </div>
66
+ </Typography>
67
+ )
68
+ }
@@ -0,0 +1,34 @@
1
+ import { useFindCountry } from '@graphcommerce/magento-store'
2
+ import { CustomerAddressFragment } from '../CreateCustomerAddressForm/CustomerAddress.gql'
3
+
4
+ export default function AddressSingleLine(props: CustomerAddressFragment) {
5
+ const {
6
+ company,
7
+ prefix,
8
+ firstname,
9
+ lastname,
10
+ middlename,
11
+ suffix,
12
+ street,
13
+ region,
14
+ city,
15
+ postcode,
16
+ country_code,
17
+ } = props
18
+ const countryName = useFindCountry(country_code)?.full_name_locale
19
+ const regionName = typeof region === 'string' ? region : region?.region
20
+
21
+ // todo: detect correct format by locale
22
+ // for now, US format will be returned by default
23
+
24
+ let address = `$company ${prefix}, ${firstname}, $middlename ${lastname}, $suffix ${
25
+ street?.[0]
26
+ }, ${street?.slice(1).join(' ')}, ${postcode}, ${city}, ${regionName} $countryName`
27
+
28
+ address = address.replace('$company', company ? `${company},` : '')
29
+ address = address.replace('$middlename', middlename ? `${middlename},` : '')
30
+ address = address.replace('$suffix', suffix ? `${suffix},` : '')
31
+ address = address.replace('$countryName', countryName ? `${countryName},` : '')
32
+
33
+ return <>{address}</>
34
+ }
@@ -0,0 +1,21 @@
1
+ import { Link } from '@material-ui/core'
2
+ import { ApolloErrorAlert, ApolloErrorAlertProps } from '@graphcommerce/next-ui'
3
+ import NextLink from 'next/link'
4
+ import React from 'react'
5
+ import { useExtractCustomerErrors } from '../../hooks/useExtractCustomerErrors'
6
+
7
+ type MagentoErrorAlertProps = ApolloErrorAlertProps
8
+
9
+ export default function ApolloCustomerErrorAlert(props: MagentoErrorAlertProps) {
10
+ const { error, unauthorized } = useExtractCustomerErrors(props)
11
+
12
+ const action = unauthorized && (
13
+ <>
14
+ <NextLink href='/account/signin' passHref>
15
+ <Link>Sign Up / Sign In</Link>
16
+ </NextLink>
17
+ </>
18
+ )
19
+
20
+ return <ApolloErrorAlert error={error} graphqlErrorAlertProps={{ action }} />
21
+ }
@@ -0,0 +1,46 @@
1
+ import {
2
+ ApolloErrorFullPage,
3
+ ApolloErrorAlertProps,
4
+ Button,
5
+ SvgImage,
6
+ iconPersonAltBig,
7
+ } from '@graphcommerce/next-ui'
8
+ import PageLink from 'next/link'
9
+ import React from 'react'
10
+
11
+ import { useExtractCustomerErrors } from '../../hooks/useExtractCustomerErrors'
12
+
13
+ type ApolloCustomerErrorFullPageProps = {
14
+ signInHref: string
15
+ signUpHref: string
16
+ } & ApolloErrorAlertProps
17
+
18
+ export default function ApolloCustomerErrorFullPage(props: ApolloCustomerErrorFullPageProps) {
19
+ const { signInHref, signUpHref } = props
20
+ const { error, unauthorized } = useExtractCustomerErrors(props)
21
+
22
+ return (
23
+ <ApolloErrorFullPage
24
+ error={error}
25
+ icon={<SvgImage src={iconPersonAltBig} size={148} alt='person' />}
26
+ button={
27
+ unauthorized ? (
28
+ <PageLink href={signInHref} passHref>
29
+ <Button variant='contained' color='primary' text='bold' size='large'>
30
+ Login
31
+ </Button>
32
+ </PageLink>
33
+ ) : undefined
34
+ }
35
+ altButton={
36
+ unauthorized ? (
37
+ <PageLink href={signUpHref} passHref>
38
+ <Button variant='text' color='primary'>
39
+ Or create an account
40
+ </Button>
41
+ </PageLink>
42
+ ) : undefined
43
+ }
44
+ />
45
+ )
46
+ }
@@ -0,0 +1,14 @@
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 UpdateCustomerNameDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateCustomerName"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"prefix"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"firstname"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"lastname"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateCustomer"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"prefix"},"value":{"kind":"Variable","name":{"kind":"Name","value":"prefix"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"firstname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"firstname"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"lastname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"lastname"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"customer"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"prefix"}},{"kind":"Field","name":{"kind":"Name","value":"firstname"}},{"kind":"Field","name":{"kind":"Name","value":"lastname"}}]}}]}}]}}]} as unknown as DocumentNode<UpdateCustomerNameMutation, UpdateCustomerNameMutationVariables>;
7
+ export type UpdateCustomerNameMutationVariables = Types.Exact<{
8
+ prefix?: Types.Maybe<Types.Scalars['String']>;
9
+ firstname: Types.Scalars['String'];
10
+ lastname: Types.Scalars['String'];
11
+ }>;
12
+
13
+
14
+ export type UpdateCustomerNameMutation = { updateCustomer?: Types.Maybe<{ customer: { prefix?: Types.Maybe<string>, firstname?: Types.Maybe<string>, lastname?: Types.Maybe<string> } }> };
@@ -0,0 +1,9 @@
1
+ mutation UpdateCustomerName($prefix: String, $firstname: String!, $lastname: String!) {
2
+ updateCustomer(input: { prefix: $prefix, firstname: $firstname, lastname: $lastname }) {
3
+ customer {
4
+ prefix
5
+ firstname
6
+ lastname
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,66 @@
1
+ import {
2
+ Button,
3
+ Form,
4
+ FormActions,
5
+ FormDivider,
6
+ MessageSnackbar,
7
+ SvgImage,
8
+ iconCheckmark,
9
+ } from '@graphcommerce/next-ui'
10
+ import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
11
+ import React from 'react'
12
+ import ApolloCustomerErrorAlert from '../ApolloCustomerError/ApolloCustomerErrorAlert'
13
+ import NameFields from '../NameFields'
14
+ import { UpdateCustomerNameDocument } from './UpdateCustomerName.gql'
15
+
16
+ type ChangeNameFormProps = {
17
+ prefix?: string
18
+ firstname: string
19
+ lastname: string
20
+ }
21
+
22
+ export default function ChangeNameForm(props: ChangeNameFormProps) {
23
+ const { prefix, firstname, lastname } = props
24
+ const form = useFormGqlMutation(
25
+ UpdateCustomerNameDocument,
26
+ {
27
+ defaultValues: {
28
+ prefix: prefix ?? '',
29
+ firstname: firstname ?? '',
30
+ lastname: lastname ?? '',
31
+ },
32
+ },
33
+ { errorPolicy: 'all' },
34
+ )
35
+
36
+ const { handleSubmit, error, formState } = form
37
+ const submit = handleSubmit(() => {})
38
+
39
+ return (
40
+ <>
41
+ <Form onSubmit={submit} noValidate>
42
+ <NameFields form={form} prefix />
43
+ <FormDivider />
44
+ <FormActions>
45
+ <Button
46
+ type='submit'
47
+ text='bold'
48
+ color='primary'
49
+ variant='contained'
50
+ size='large'
51
+ loading={formState.isSubmitting}
52
+ >
53
+ Save changes
54
+ </Button>
55
+ </FormActions>
56
+ <ApolloCustomerErrorAlert error={error} />
57
+ </Form>
58
+ <MessageSnackbar open={formState.isSubmitSuccessful && !error} variant='pill' color='default'>
59
+ <>
60
+ <SvgImage src={iconCheckmark} size='small' loading='eager' alt='checkmark' />
61
+ Changes saved
62
+ </>
63
+ </MessageSnackbar>
64
+ </>
65
+ )
66
+ }
@@ -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 ChangePasswordDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"ChangePassword"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"currentPassword"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"newPassword"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"changeCustomerPassword"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"currentPassword"},"value":{"kind":"Variable","name":{"kind":"Name","value":"currentPassword"}}},{"kind":"Argument","name":{"kind":"Name","value":"newPassword"},"value":{"kind":"Variable","name":{"kind":"Name","value":"newPassword"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"default_billing"}},{"kind":"Field","name":{"kind":"Name","value":"default_shipping"}},{"kind":"Field","name":{"kind":"Name","value":"addresses"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"prefix"}},{"kind":"Field","name":{"kind":"Name","value":"firstname"}},{"kind":"Field","name":{"kind":"Name","value":"middlename"}},{"kind":"Field","name":{"kind":"Name","value":"lastname"}},{"kind":"Field","name":{"kind":"Name","value":"suffix"}},{"kind":"Field","name":{"kind":"Name","value":"city"}},{"kind":"Field","name":{"kind":"Name","value":"company"}},{"kind":"Field","name":{"kind":"Name","value":"country_code"}},{"kind":"Field","name":{"kind":"Name","value":"postcode"}},{"kind":"Field","name":{"kind":"Name","value":"region"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"region"}},{"kind":"Field","name":{"kind":"Name","value":"region_code"}},{"kind":"Field","name":{"kind":"Name","value":"region_id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"street"}},{"kind":"Field","name":{"kind":"Name","value":"telephone"}},{"kind":"Field","name":{"kind":"Name","value":"vat_id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"email"}},{"kind":"Field","name":{"kind":"Name","value":"prefix"}},{"kind":"Field","name":{"kind":"Name","value":"firstname"}},{"kind":"Field","name":{"kind":"Name","value":"middlename"}},{"kind":"Field","name":{"kind":"Name","value":"lastname"}},{"kind":"Field","name":{"kind":"Name","value":"suffix"}},{"kind":"Field","name":{"kind":"Name","value":"gender"}},{"kind":"Field","name":{"kind":"Name","value":"is_subscribed"}},{"kind":"Field","name":{"kind":"Name","value":"date_of_birth"}},{"kind":"Field","name":{"kind":"Name","value":"taxvat"}}]}}]}}]} as unknown as DocumentNode<ChangePasswordMutation, ChangePasswordMutationVariables>;
7
+ export type ChangePasswordMutationVariables = Types.Exact<{
8
+ currentPassword: Types.Scalars['String'];
9
+ newPassword: Types.Scalars['String'];
10
+ }>;
11
+
12
+
13
+ export type ChangePasswordMutation = { changeCustomerPassword?: Types.Maybe<{ default_billing?: Types.Maybe<string>, default_shipping?: Types.Maybe<string>, email?: Types.Maybe<string>, prefix?: Types.Maybe<string>, firstname?: Types.Maybe<string>, middlename?: Types.Maybe<string>, lastname?: Types.Maybe<string>, suffix?: Types.Maybe<string>, gender?: Types.Maybe<number>, is_subscribed?: Types.Maybe<boolean>, date_of_birth?: Types.Maybe<string>, taxvat?: Types.Maybe<string>, addresses?: Types.Maybe<Array<Types.Maybe<{ id?: Types.Maybe<number>, prefix?: Types.Maybe<string>, firstname?: Types.Maybe<string>, middlename?: Types.Maybe<string>, lastname?: Types.Maybe<string>, suffix?: Types.Maybe<string>, city?: Types.Maybe<string>, company?: Types.Maybe<string>, country_code?: Types.Maybe<Types.CountryCodeEnum>, postcode?: Types.Maybe<string>, street?: Types.Maybe<Array<Types.Maybe<string>>>, telephone?: Types.Maybe<string>, vat_id?: Types.Maybe<string>, region?: Types.Maybe<{ region?: Types.Maybe<string>, region_code?: Types.Maybe<string>, region_id?: Types.Maybe<number> }> }>>> }> };
@@ -0,0 +1,5 @@
1
+ mutation ChangePassword($currentPassword: String!, $newPassword: String!) {
2
+ changeCustomerPassword(currentPassword: $currentPassword, newPassword: $newPassword) {
3
+ ...CustomerInfo
4
+ }
5
+ }
@@ -0,0 +1,93 @@
1
+ import { TextField } from '@material-ui/core'
2
+ import {
3
+ Button,
4
+ Form,
5
+ FormActions,
6
+ FormRow,
7
+ MessageSnackbar,
8
+ FormDivider,
9
+ } from '@graphcommerce/next-ui'
10
+ import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
11
+ import React from 'react'
12
+
13
+ import ApolloCustomerErrorAlert from '../ApolloCustomerError/ApolloCustomerErrorAlert'
14
+ import {
15
+ ChangePasswordDocument,
16
+ ChangePasswordMutation,
17
+ ChangePasswordMutationVariables,
18
+ } from './ChangePassword.gql'
19
+
20
+ export default function ChangePasswordForm() {
21
+ const form = useFormGqlMutation<
22
+ ChangePasswordMutation,
23
+ ChangePasswordMutationVariables & { confirmPassword?: string }
24
+ >(ChangePasswordDocument)
25
+ const { muiRegister, handleSubmit, required, watch, data, formState, error } = form
26
+ const submitHandler = handleSubmit(() => {})
27
+ const pass = watch('newPassword')
28
+
29
+ return (
30
+ <Form onSubmit={submitHandler} noValidate>
31
+ <FormRow>
32
+ <TextField
33
+ variant='outlined'
34
+ type='password'
35
+ error={!!formState.errors.currentPassword}
36
+ label='Current Password'
37
+ required={required.currentPassword}
38
+ {...muiRegister('currentPassword', { required: required.currentPassword })}
39
+ helperText={formState.errors.currentPassword?.message}
40
+ disabled={formState.isSubmitting}
41
+ />
42
+ </FormRow>
43
+
44
+ <FormRow>
45
+ <TextField
46
+ variant='outlined'
47
+ type='password'
48
+ error={!!formState.errors.newPassword}
49
+ label='New Password'
50
+ required={required.newPassword}
51
+ {...muiRegister('newPassword', { required: required.newPassword })}
52
+ helperText={formState.errors.newPassword?.message}
53
+ disabled={formState.isSubmitting}
54
+ />
55
+
56
+ <TextField
57
+ variant='outlined'
58
+ type='password'
59
+ error={!!formState.errors.confirmPassword}
60
+ label='Confirm Password'
61
+ required
62
+ {...muiRegister('confirmPassword', {
63
+ required: true,
64
+ validate: (value) => value === pass || "Passwords don't match",
65
+ })}
66
+ helperText={formState.errors.confirmPassword?.message}
67
+ disabled={formState.isSubmitting}
68
+ />
69
+ </FormRow>
70
+
71
+ <ApolloCustomerErrorAlert error={error} />
72
+
73
+ <FormDivider />
74
+
75
+ <FormActions>
76
+ <Button
77
+ type='submit'
78
+ loading={formState.isSubmitting}
79
+ color='primary'
80
+ variant='contained'
81
+ size='large'
82
+ text='bold'
83
+ >
84
+ Save new password
85
+ </Button>
86
+ </FormActions>
87
+
88
+ <MessageSnackbar sticky open={Boolean(formState.isSubmitSuccessful && data)}>
89
+ <>Password changed</>
90
+ </MessageSnackbar>
91
+ </Form>
92
+ )
93
+ }
@@ -0,0 +1,28 @@
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 CreateCustomerAddressDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateCustomerAddress"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"prefix"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"firstname"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"middlename"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"lastname"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"suffix"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"telephone"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"street"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"houseNumber"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"addition"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"city"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"postcode"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"region"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CustomerAddressRegionInput"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"company"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"countryCode"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CountryCodeEnum"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"vatId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"defaultBilling"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}},"defaultValue":{"kind":"BooleanValue","value":false}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"defaultShipping"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}},"defaultValue":{"kind":"BooleanValue","value":false}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createCustomerAddress"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"prefix"},"value":{"kind":"Variable","name":{"kind":"Name","value":"prefix"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"firstname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"firstname"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"middlename"},"value":{"kind":"Variable","name":{"kind":"Name","value":"middlename"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"lastname"},"value":{"kind":"Variable","name":{"kind":"Name","value":"lastname"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"telephone"},"value":{"kind":"Variable","name":{"kind":"Name","value":"telephone"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"suffix"},"value":{"kind":"Variable","name":{"kind":"Name","value":"suffix"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"street"},"value":{"kind":"ListValue","values":[{"kind":"Variable","name":{"kind":"Name","value":"street"}},{"kind":"Variable","name":{"kind":"Name","value":"houseNumber"}},{"kind":"Variable","name":{"kind":"Name","value":"addition"}}]}},{"kind":"ObjectField","name":{"kind":"Name","value":"city"},"value":{"kind":"Variable","name":{"kind":"Name","value":"city"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"postcode"},"value":{"kind":"Variable","name":{"kind":"Name","value":"postcode"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"region"},"value":{"kind":"Variable","name":{"kind":"Name","value":"region"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"company"},"value":{"kind":"Variable","name":{"kind":"Name","value":"company"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"country_code"},"value":{"kind":"Variable","name":{"kind":"Name","value":"countryCode"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"vat_id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"vatId"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"default_billing"},"value":{"kind":"Variable","name":{"kind":"Name","value":"defaultBilling"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"default_shipping"},"value":{"kind":"Variable","name":{"kind":"Name","value":"defaultShipping"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode<CreateCustomerAddressMutation, CreateCustomerAddressMutationVariables>;
7
+ export type CreateCustomerAddressMutationVariables = Types.Exact<{
8
+ prefix: Types.Scalars['String'];
9
+ firstname: Types.Scalars['String'];
10
+ middlename?: Types.Maybe<Types.Scalars['String']>;
11
+ lastname: Types.Scalars['String'];
12
+ suffix?: Types.Maybe<Types.Scalars['String']>;
13
+ telephone: Types.Scalars['String'];
14
+ street: Types.Scalars['String'];
15
+ houseNumber: Types.Scalars['String'];
16
+ addition?: Types.Maybe<Types.Scalars['String']>;
17
+ city: Types.Scalars['String'];
18
+ postcode: Types.Scalars['String'];
19
+ region: Types.CustomerAddressRegionInput;
20
+ company?: Types.Maybe<Types.Scalars['String']>;
21
+ countryCode: Types.CountryCodeEnum;
22
+ vatId?: Types.Maybe<Types.Scalars['String']>;
23
+ defaultBilling?: Types.Maybe<Types.Scalars['Boolean']>;
24
+ defaultShipping?: Types.Maybe<Types.Scalars['Boolean']>;
25
+ }>;
26
+
27
+
28
+ export type CreateCustomerAddressMutation = { createCustomerAddress?: Types.Maybe<{ id?: Types.Maybe<number> }> };