@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,41 @@
1
+ mutation CreateCustomerAddress(
2
+ $prefix: String!
3
+ $firstname: String!
4
+ $middlename: String
5
+ $lastname: String!
6
+ $suffix: String
7
+ $telephone: String!
8
+ $street: String!
9
+ $houseNumber: String!
10
+ $addition: String
11
+ $city: String!
12
+ $postcode: String!
13
+ $region: CustomerAddressRegionInput!
14
+ $company: String
15
+ $countryCode: CountryCodeEnum!
16
+ $vatId: String
17
+ $defaultBilling: Boolean = false
18
+ $defaultShipping: Boolean = false
19
+ ) {
20
+ createCustomerAddress(
21
+ input: {
22
+ prefix: $prefix
23
+ firstname: $firstname
24
+ middlename: $middlename
25
+ lastname: $lastname
26
+ telephone: $telephone
27
+ suffix: $suffix
28
+ street: [$street, $houseNumber, $addition]
29
+ city: $city
30
+ postcode: $postcode
31
+ region: $region
32
+ company: $company
33
+ country_code: $countryCode
34
+ vat_id: $vatId
35
+ default_billing: $defaultBilling
36
+ default_shipping: $defaultShipping
37
+ }
38
+ ) {
39
+ id
40
+ }
41
+ }
@@ -0,0 +1,4 @@
1
+ /* eslint-disable */
2
+ import * as Types from '@graphcommerce/graphql';
3
+
4
+ export type CustomerAddressFragment = { 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,22 @@
1
+ fragment CustomerAddress on CustomerAddress {
2
+ id
3
+
4
+ prefix
5
+ firstname
6
+ middlename
7
+ lastname
8
+ suffix
9
+ city
10
+ company
11
+ country_code
12
+ postcode
13
+ region {
14
+ region
15
+ region_code
16
+ region_id
17
+ }
18
+ street
19
+ telephone
20
+
21
+ vat_id
22
+ }
@@ -0,0 +1,4 @@
1
+ /* eslint-disable */
2
+ import * as Types from '@graphcommerce/graphql';
3
+
4
+ export type CustomerAddressEditFragment = { 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,4 @@
1
+ fragment CustomerAddressEdit on CustomerAddress {
2
+ id
3
+ ...CustomerAddress
4
+ }
@@ -0,0 +1,98 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { TextField } from '@material-ui/core'
3
+ import { CountryRegionsDocument } from '@graphcommerce/magento-store'
4
+ import {
5
+ Button,
6
+ Form,
7
+ FormActions,
8
+ FormDivider,
9
+ FormRow,
10
+ InputCheckmark,
11
+ } from '@graphcommerce/next-ui'
12
+ import { phonePattern, useFormGqlMutation } from '@graphcommerce/react-hook-form'
13
+ import { useRouter } from 'next/router'
14
+ import React from 'react'
15
+ import AddressFields from '../AddressFields'
16
+ import ApolloCustomerErrorAlert from '../ApolloCustomerError/ApolloCustomerErrorAlert'
17
+ import NameFields from '../NameFields'
18
+ import { CreateCustomerAddressDocument } from './CreateCustomerAddress.gql'
19
+
20
+ export default function CreateCustomerAddressForm() {
21
+ const countries = useQuery(CountryRegionsDocument).data?.countries
22
+ const router = useRouter()
23
+
24
+ const form = useFormGqlMutation(
25
+ CreateCustomerAddressDocument,
26
+ {
27
+ onBeforeSubmit: (formData) => {
28
+ const region = countries
29
+ ?.find((country) => country?.two_letter_abbreviation === formData.countryCode)
30
+ ?.available_regions?.find((r) => r?.id === formData.region)
31
+
32
+ return {
33
+ ...formData,
34
+ region:
35
+ (region && {
36
+ region: region.name,
37
+ region_code: region.code,
38
+ region_id: region.id,
39
+ }) ??
40
+ {},
41
+ }
42
+ },
43
+ onComplete: (e) => {
44
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
45
+ router.push(`/account/addresses/edit?addressId=${e.data?.createCustomerAddress?.id}`)
46
+ },
47
+ },
48
+ { errorPolicy: 'all' },
49
+ )
50
+
51
+ const { handleSubmit, formState, required, error, muiRegister, valid } = form
52
+ const submitHandler = handleSubmit((_, e) => {
53
+ if (!formState.errors) e?.target.reset()
54
+ })
55
+
56
+ return (
57
+ <>
58
+ <Form onSubmit={submitHandler} noValidate>
59
+ <NameFields form={form} prefix />
60
+ <AddressFields form={form} />
61
+
62
+ <FormRow>
63
+ <TextField
64
+ variant='outlined'
65
+ type='text'
66
+ error={!!formState.errors.telephone}
67
+ required={required.telephone}
68
+ label='Telephone'
69
+ {...muiRegister('telephone', {
70
+ required: required.telephone,
71
+ pattern: { value: phonePattern, message: 'Invalid phone number' },
72
+ })}
73
+ helperText={formState.isSubmitted && formState.errors.telephone?.message}
74
+ disabled={formState.isSubmitting}
75
+ InputProps={{ endAdornment: <InputCheckmark show={valid.telephone} /> }}
76
+ />
77
+ </FormRow>
78
+
79
+ <FormDivider />
80
+
81
+ <FormActions>
82
+ <Button
83
+ type='submit'
84
+ variant='contained'
85
+ color='primary'
86
+ size='large'
87
+ text='bold'
88
+ loading={formState.isSubmitting}
89
+ >
90
+ Save changes
91
+ </Button>
92
+ </FormActions>
93
+ </Form>
94
+
95
+ <ApolloCustomerErrorAlert error={error} />
96
+ </>
97
+ )
98
+ }
@@ -0,0 +1,55 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { Fab, makeStyles, NoSsr, Theme } from '@material-ui/core'
3
+ import {
4
+ iconPersonAlt,
5
+ StyledBadge,
6
+ SvgImage,
7
+ SvgImageSimple,
8
+ UseStyles,
9
+ } from '@graphcommerce/next-ui'
10
+ import PageLink from 'next/link'
11
+ import React from 'react'
12
+ import { CustomerTokenDocument, CustomerTokenQuery } from '../../hooks'
13
+
14
+ const useStyles = makeStyles((theme: Theme) => ({
15
+ colorError: {
16
+ backgroundColor: theme.palette.grey['500'],
17
+ },
18
+ }))
19
+
20
+ type CustomerFabContentProps = CustomerTokenQuery & {
21
+ icon?: React.ReactNode
22
+ authHref: string
23
+ guestHref: string
24
+ } & UseStyles<typeof useStyles>
25
+
26
+ function CustomerFabContent(props: CustomerFabContentProps) {
27
+ const { customerToken, icon, guestHref, authHref } = props
28
+ const classes = useStyles(props)
29
+ const requireAuth = Boolean(!customerToken || !customerToken.valid)
30
+
31
+ return (
32
+ <PageLink href={requireAuth ? guestHref : authHref} passHref>
33
+ <Fab style={{ boxShadow: 'none' }} aria-label='Open Menu' size='large'>
34
+ <StyledBadge
35
+ badgeContent={customerToken?.token ? 1 : 0}
36
+ color={customerToken?.valid ? 'primary' : 'error'}
37
+ variant='dot'
38
+ classes={{ colorError: classes.colorError }}
39
+ >
40
+ {icon ?? <SvgImageSimple src={iconPersonAlt} alt='Account' size='large' />}
41
+ </StyledBadge>
42
+ </Fab>
43
+ </PageLink>
44
+ )
45
+ }
46
+
47
+ export default function CustomerFab(props: CustomerFabContentProps) {
48
+ const { data } = useQuery(CustomerTokenDocument)
49
+
50
+ return (
51
+ <NoSsr fallback={<CustomerFabContent {...props} />}>
52
+ <CustomerFabContent customerToken={data?.customerToken} {...props} />
53
+ </NoSsr>
54
+ )
55
+ }
@@ -0,0 +1,68 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { makeStyles, NoSsr, Theme } from '@material-ui/core'
3
+ import {
4
+ MenuFabSecondaryItem,
5
+ StyledBadge,
6
+ UseStyles,
7
+ iconPersonAlt,
8
+ SvgImageSimple,
9
+ } from '@graphcommerce/next-ui'
10
+ import React from 'react'
11
+ import { CustomerTokenDocument, CustomerTokenQuery } from '../../hooks'
12
+
13
+ const useStyles = makeStyles((theme: Theme) => ({
14
+ colorError: {
15
+ backgroundColor: theme.palette.grey['500'],
16
+ },
17
+ badge: {
18
+ top: 3,
19
+ right: 3,
20
+ padding: 3,
21
+ [theme.breakpoints.up('md')]: {
22
+ top: 5,
23
+ right: 7,
24
+ padding: 4,
25
+ },
26
+ },
27
+ }))
28
+
29
+ type CustomerMenuFabItemProps = CustomerTokenQuery & {
30
+ icon?: React.ReactNode
31
+ children: React.ReactNode
32
+ authHref: string
33
+ guestHref: string
34
+ } & UseStyles<typeof useStyles>
35
+
36
+ function CustomerMenuFabItemContent(props: CustomerMenuFabItemProps) {
37
+ const { customerToken, icon, children, guestHref, authHref } = props
38
+ const classes = useStyles(props)
39
+ const requireAuth = Boolean(!customerToken || !customerToken.valid)
40
+
41
+ return (
42
+ <MenuFabSecondaryItem
43
+ icon={
44
+ <StyledBadge
45
+ badgeContent={customerToken?.token ? 1 : 0}
46
+ color={customerToken?.valid ? 'primary' : 'error'}
47
+ variant='dot'
48
+ classes={{ colorError: classes.colorError, badge: classes.badge }}
49
+ >
50
+ {icon ?? <SvgImageSimple src={iconPersonAlt} alt='Account' />}
51
+ </StyledBadge>
52
+ }
53
+ href={requireAuth ? guestHref : authHref}
54
+ >
55
+ {children}
56
+ </MenuFabSecondaryItem>
57
+ )
58
+ }
59
+
60
+ export default function CustomerMenuFabItem(props: CustomerMenuFabItemProps) {
61
+ const { data } = useQuery(CustomerTokenDocument)
62
+
63
+ return (
64
+ <NoSsr fallback={<CustomerMenuFabItemContent {...props} />}>
65
+ <CustomerMenuFabItemContent customerToken={data?.customerToken} {...props} />
66
+ </NoSsr>
67
+ )
68
+ }
@@ -0,0 +1,12 @@
1
+ /* eslint-disable */
2
+ import * as Types from '@graphcommerce/graphql';
3
+
4
+ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
5
+
6
+ export const DeleteCustomerAddressFormDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteCustomerAddressForm"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteCustomerAddress"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}]}}]} as unknown as DocumentNode<DeleteCustomerAddressFormMutation, DeleteCustomerAddressFormMutationVariables>;
7
+ export type DeleteCustomerAddressFormMutationVariables = Types.Exact<{
8
+ id: Types.Scalars['Int'];
9
+ }>;
10
+
11
+
12
+ export type DeleteCustomerAddressFormMutation = { deleteCustomerAddress?: Types.Maybe<boolean> };
@@ -0,0 +1,3 @@
1
+ mutation DeleteCustomerAddressForm($id: Int!) {
2
+ deleteCustomerAddress(id: $id)
3
+ }
@@ -0,0 +1,46 @@
1
+ import { Button, makeStyles, Theme } from '@material-ui/core'
2
+ import { useFormGqlMutation } from '@graphcommerce/react-hook-form'
3
+ import { useRouter } from 'next/router'
4
+ import React from 'react'
5
+ import ApolloCustomerErrorAlert from '../ApolloCustomerError/ApolloCustomerErrorAlert'
6
+ import { DeleteCustomerAddressFormDocument } from './DeleteCustomerAddressForm.gql'
7
+
8
+ export type DeleteCustomerAddressFormProps = {
9
+ addressId?: number
10
+ }
11
+
12
+ const useStyles = makeStyles((theme: Theme) => ({
13
+ button: {
14
+ display: 'block',
15
+ color: theme.palette.primary.contrastText,
16
+ },
17
+ }))
18
+
19
+ export default function DeleteCustomerAddressForm(props: DeleteCustomerAddressFormProps) {
20
+ const { addressId } = props
21
+ const router = useRouter()
22
+ const classes = useStyles()
23
+ const { handleSubmit, error } = useFormGqlMutation(
24
+ DeleteCustomerAddressFormDocument,
25
+ {
26
+ defaultValues: {
27
+ id: addressId,
28
+ },
29
+ onComplete: () => {
30
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
31
+ router.push({ pathname: '/account/addresses', query: 'confirm_delete' })
32
+ },
33
+ },
34
+ { errorPolicy: 'all' },
35
+ )
36
+ const submitHandler = handleSubmit(() => {})
37
+
38
+ return (
39
+ <form onSubmit={submitHandler} noValidate>
40
+ <Button type='submit' variant='text' color='inherit' className={classes.button}>
41
+ Delete this address
42
+ </Button>
43
+ <ApolloCustomerErrorAlert error={error} />
44
+ </form>
45
+ )
46
+ }
@@ -0,0 +1,29 @@
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 UpdateCustomerAddressDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateCustomerAddress"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}},{"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":"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":"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":"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":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"postcode"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"region"}},"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":"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"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"defaultShipping"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateCustomerAddress"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}},{"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<UpdateCustomerAddressMutation, UpdateCustomerAddressMutationVariables>;
7
+ export type UpdateCustomerAddressMutationVariables = Types.Exact<{
8
+ id: Types.Scalars['Int'];
9
+ prefix?: Types.Maybe<Types.Scalars['String']>;
10
+ firstname?: Types.Maybe<Types.Scalars['String']>;
11
+ middlename?: Types.Maybe<Types.Scalars['String']>;
12
+ lastname?: Types.Maybe<Types.Scalars['String']>;
13
+ suffix?: Types.Maybe<Types.Scalars['String']>;
14
+ telephone?: Types.Maybe<Types.Scalars['String']>;
15
+ street: Types.Scalars['String'];
16
+ houseNumber: Types.Scalars['String'];
17
+ addition?: Types.Maybe<Types.Scalars['String']>;
18
+ city?: Types.Maybe<Types.Scalars['String']>;
19
+ postcode?: Types.Maybe<Types.Scalars['String']>;
20
+ region?: Types.Maybe<Types.CustomerAddressRegionInput>;
21
+ company?: Types.Maybe<Types.Scalars['String']>;
22
+ countryCode?: Types.Maybe<Types.CountryCodeEnum>;
23
+ vatId?: Types.Maybe<Types.Scalars['String']>;
24
+ defaultBilling?: Types.Maybe<Types.Scalars['Boolean']>;
25
+ defaultShipping?: Types.Maybe<Types.Scalars['Boolean']>;
26
+ }>;
27
+
28
+
29
+ export type UpdateCustomerAddressMutation = { updateCustomerAddress?: Types.Maybe<{ id?: Types.Maybe<number> }> };
@@ -0,0 +1,43 @@
1
+ mutation UpdateCustomerAddress(
2
+ $id: Int!
3
+ $prefix: String
4
+ $firstname: String
5
+ $middlename: String
6
+ $lastname: String
7
+ $suffix: String
8
+ $telephone: String
9
+ $street: String!
10
+ $houseNumber: String!
11
+ $addition: String
12
+ $city: String
13
+ $postcode: String
14
+ $region: CustomerAddressRegionInput
15
+ $company: String
16
+ $countryCode: CountryCodeEnum
17
+ $vatId: String
18
+ $defaultBilling: Boolean
19
+ $defaultShipping: Boolean
20
+ ) {
21
+ updateCustomerAddress(
22
+ id: $id
23
+ input: {
24
+ prefix: $prefix
25
+ firstname: $firstname
26
+ middlename: $middlename
27
+ lastname: $lastname
28
+ telephone: $telephone
29
+ suffix: $suffix
30
+ street: [$street, $houseNumber, $addition]
31
+ city: $city
32
+ postcode: $postcode
33
+ region: $region
34
+ company: $company
35
+ country_code: $countryCode
36
+ vat_id: $vatId
37
+ default_billing: $defaultBilling
38
+ default_shipping: $defaultShipping
39
+ }
40
+ ) {
41
+ id
42
+ }
43
+ }
@@ -0,0 +1,127 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { makeStyles, TextField } from '@material-ui/core'
3
+ import { CountryRegionsDocument } from '@graphcommerce/magento-store'
4
+ import {
5
+ Button,
6
+ Form,
7
+ FormActions,
8
+ FormDivider,
9
+ FormRow,
10
+ InputCheckmark,
11
+ } from '@graphcommerce/next-ui'
12
+ import { phonePattern, useFormGqlMutation } from '@graphcommerce/react-hook-form'
13
+ import { useRouter } from 'next/router'
14
+ import React from 'react'
15
+ import { AccountAddressFragment } from '../AccountAddress/AccountAddress.gql'
16
+ import AddressFields from '../AddressFields'
17
+ import ApolloCustomerErrorAlert from '../ApolloCustomerError/ApolloCustomerErrorAlert'
18
+ import NameFields from '../NameFields'
19
+ import { UpdateCustomerAddressDocument } from './UpdateCustomerAddress.gql'
20
+
21
+ const useStyles = makeStyles(
22
+ () => ({
23
+ editActions: {
24
+ paddingBottom: 0,
25
+ },
26
+ }),
27
+ { name: 'EditAddressForm' },
28
+ )
29
+
30
+ type EditAddressFormProps = { address?: AccountAddressFragment }
31
+
32
+ export default function EditAddressForm(props: EditAddressFormProps) {
33
+ const countries = useQuery(CountryRegionsDocument).data?.countries
34
+ const { address } = props
35
+ const classes = useStyles()
36
+ const router = useRouter()
37
+
38
+ const form = useFormGqlMutation(
39
+ UpdateCustomerAddressDocument,
40
+ {
41
+ defaultValues: {
42
+ id: address?.id ?? undefined,
43
+ firstname: address?.firstname,
44
+ lastname: address?.lastname,
45
+ street: address?.street?.[0] ?? undefined,
46
+ postcode: address?.postcode,
47
+ city: address?.city,
48
+ countryCode: address?.country_code,
49
+ telephone: address?.telephone,
50
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
51
+ // @ts-ignore
52
+ houseNumber: address?.street?.[1],
53
+ addition: address?.street?.[2],
54
+ },
55
+ onBeforeSubmit: (formData) => {
56
+ const region = countries
57
+ ?.find((country) => country?.two_letter_abbreviation === formData.countryCode)
58
+ ?.available_regions?.find((r) => r?.id === formData.region)
59
+ const regionData = {
60
+ region:
61
+ (region && {
62
+ region: region.name,
63
+ region_code: region.code,
64
+ region_id: region.id,
65
+ }) ??
66
+ null,
67
+ }
68
+
69
+ return {
70
+ ...formData,
71
+ ...regionData,
72
+ }
73
+ },
74
+ onComplete: () => {
75
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
76
+ router.push('/account/addresses')
77
+ },
78
+ },
79
+ { errorPolicy: 'all' },
80
+ )
81
+
82
+ const { handleSubmit, formState, required, error, muiRegister, valid } = form
83
+ const submitHandler = handleSubmit(() => {})
84
+
85
+ return (
86
+ <>
87
+ <Form onSubmit={submitHandler} noValidate>
88
+ <NameFields form={form} prefix />
89
+ <AddressFields form={form} />
90
+
91
+ <FormRow>
92
+ <TextField
93
+ variant='outlined'
94
+ type='text'
95
+ error={!!formState.errors.telephone}
96
+ required={required.telephone}
97
+ label='Telephone'
98
+ {...muiRegister('telephone', {
99
+ required: required.telephone,
100
+ pattern: { value: phonePattern, message: 'Invalid phone number' },
101
+ })}
102
+ helperText={formState.isSubmitted && formState.errors.telephone?.message}
103
+ disabled={formState.isSubmitting}
104
+ InputProps={{ endAdornment: <InputCheckmark show={valid.telephone} /> }}
105
+ />
106
+ </FormRow>
107
+
108
+ <FormDivider />
109
+
110
+ <FormActions classes={{ root: classes.editActions }}>
111
+ <Button
112
+ type='submit'
113
+ variant='contained'
114
+ color='primary'
115
+ size='large'
116
+ text='bold'
117
+ loading={formState.isSubmitting}
118
+ >
119
+ Save changes
120
+ </Button>
121
+ </FormActions>
122
+ </Form>
123
+
124
+ <ApolloCustomerErrorAlert error={error} />
125
+ </>
126
+ )
127
+ }
@@ -0,0 +1,12 @@
1
+ /* eslint-disable */
2
+ import * as Types from '@graphcommerce/graphql';
3
+
4
+ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core';
5
+
6
+ export const ForgotPasswordDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"ForgotPassword"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"email"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"requestPasswordResetEmail"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"email"},"value":{"kind":"Variable","name":{"kind":"Name","value":"email"}}}]}]}}]} as unknown as DocumentNode<ForgotPasswordMutation, ForgotPasswordMutationVariables>;
7
+ export type ForgotPasswordMutationVariables = Types.Exact<{
8
+ email: Types.Scalars['String'];
9
+ }>;
10
+
11
+
12
+ export type ForgotPasswordMutation = { requestPasswordResetEmail?: Types.Maybe<boolean> };
@@ -0,0 +1,3 @@
1
+ mutation ForgotPassword($email: String!) {
2
+ requestPasswordResetEmail(email: $email)
3
+ }