@graphcommerce/magento-customer 4.10.2 → 4.10.5
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 +28 -0
- package/components/AddressFields/AddressFields.tsx +49 -78
- package/components/CustomerMenuFabItem/CustomerMenuFabItem.tsx +0 -1
- package/components/EditAddressForm/EditAddressForm.tsx +0 -1
- package/components/NameFields/NameFields.tsx +9 -10
- package/hooks/useCustomerQuery.ts +3 -21
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 4.10.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1579](https://github.com/graphcommerce-org/graphcommerce/pull/1579) [`e8639ec5f`](https://github.com/graphcommerce-org/graphcommerce/commit/e8639ec5f6759504211d70a966f5c348c6b3a7f6) Thanks [@paales](https://github.com/paales)! - New FormComponents added which combines react-hook-form and mui's form components for easier form handling
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`e8639ec5f`](https://github.com/graphcommerce-org/graphcommerce/commit/e8639ec5f6759504211d70a966f5c348c6b3a7f6)]:
|
|
10
|
+
- @graphcommerce/ecommerce-ui@1.3.0
|
|
11
|
+
|
|
12
|
+
## 4.10.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [[`9b84a68a1`](https://github.com/graphcommerce-org/graphcommerce/commit/9b84a68a1e7311a79eb687c7dcee905d3000facf)]:
|
|
17
|
+
- @graphcommerce/next-ui@4.23.1
|
|
18
|
+
- @graphcommerce/ecommerce-ui@1.2.3
|
|
19
|
+
- @graphcommerce/magento-store@4.2.32
|
|
20
|
+
|
|
21
|
+
## 4.10.3
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [[`396b5de5d`](https://github.com/graphcommerce-org/graphcommerce/commit/396b5de5d50c7b8f59bf636807e7a4b50f14e0b2)]:
|
|
26
|
+
- @graphcommerce/graphql@3.4.8
|
|
27
|
+
- @graphcommerce/magento-graphql@3.1.8
|
|
28
|
+
- @graphcommerce/ecommerce-ui@1.2.2
|
|
29
|
+
- @graphcommerce/magento-store@4.2.31
|
|
30
|
+
|
|
3
31
|
## 4.10.2
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { SelectElement, TextFieldElement } from '@graphcommerce/ecommerce-ui'
|
|
1
2
|
import { useQuery } from '@graphcommerce/graphql'
|
|
2
3
|
import { CountryRegionsDocument } from '@graphcommerce/magento-store'
|
|
3
|
-
import { FormRow, InputCheckmark } from '@graphcommerce/next-ui'
|
|
4
|
+
import { filterNonNullableKeys, FormRow, InputCheckmark } from '@graphcommerce/next-ui'
|
|
4
5
|
import {
|
|
5
6
|
assertFormGqlOperation,
|
|
6
7
|
houseNumberPattern,
|
|
@@ -8,7 +9,6 @@ import {
|
|
|
8
9
|
} from '@graphcommerce/react-hook-form'
|
|
9
10
|
import { i18n } from '@lingui/core'
|
|
10
11
|
import { Trans } from '@lingui/react'
|
|
11
|
-
import { TextField } from '@mui/material'
|
|
12
12
|
import React, { useMemo } from 'react'
|
|
13
13
|
|
|
14
14
|
type AddressFieldValues = {
|
|
@@ -26,9 +26,10 @@ type AddressFieldsProps = { form: UseFormReturn<any>; readOnly?: boolean }
|
|
|
26
26
|
|
|
27
27
|
export function AddressFields(props: AddressFieldsProps) {
|
|
28
28
|
const { form, readOnly } = props
|
|
29
|
+
|
|
29
30
|
const countries = useQuery(CountryRegionsDocument).data?.countries
|
|
30
31
|
assertFormGqlOperation<AddressFieldValues>(form)
|
|
31
|
-
const { watch,
|
|
32
|
+
const { watch, required, valid, control } = form
|
|
32
33
|
|
|
33
34
|
const country = watch('countryCode')
|
|
34
35
|
|
|
@@ -48,56 +49,52 @@ export function AddressFields(props: AddressFieldsProps) {
|
|
|
48
49
|
const compare: (a: Region, b: Region) => number = (a, b) =>
|
|
49
50
|
(a?.name ?? '')?.localeCompare(b?.name ?? '')
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
return regions
|
|
52
|
+
return availableRegions?.sort(compare)
|
|
53
53
|
}, [country, countryList])
|
|
54
54
|
|
|
55
55
|
return (
|
|
56
56
|
<>
|
|
57
57
|
<FormRow>
|
|
58
|
-
<
|
|
58
|
+
<TextFieldElement
|
|
59
59
|
variant='outlined'
|
|
60
|
+
control={control}
|
|
61
|
+
required={required.street}
|
|
62
|
+
name='street'
|
|
60
63
|
type='text'
|
|
61
|
-
error={!!formState.errors.street}
|
|
62
64
|
label={<Trans id='Street' />}
|
|
63
65
|
autoComplete='address-line1'
|
|
64
|
-
required={!!required?.street}
|
|
65
|
-
{...muiRegister('street', { required: required?.street })}
|
|
66
|
-
helperText={formState.isSubmitted && formState.errors.street?.message}
|
|
67
66
|
InputProps={{
|
|
68
67
|
readOnly,
|
|
69
68
|
endAdornment: <InputCheckmark show={valid.street} />,
|
|
70
69
|
}}
|
|
71
70
|
/>
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
autoComplete='address-line2'
|
|
78
|
-
required={!!required?.houseNumber}
|
|
79
|
-
{...muiRegister('houseNumber', {
|
|
80
|
-
required: required?.houseNumber,
|
|
71
|
+
<TextFieldElement
|
|
72
|
+
control={control}
|
|
73
|
+
name='houseNumber'
|
|
74
|
+
required={required.houseNumber}
|
|
75
|
+
validation={{
|
|
81
76
|
pattern: {
|
|
82
77
|
value: houseNumberPattern,
|
|
83
78
|
message: i18n._(/* i18n */ 'Please provide a valid house number'),
|
|
84
79
|
},
|
|
85
|
-
}
|
|
86
|
-
|
|
80
|
+
}}
|
|
81
|
+
variant='outlined'
|
|
82
|
+
type='text'
|
|
83
|
+
label={<Trans id='Housenumber' />}
|
|
84
|
+
autoComplete='address-line2'
|
|
87
85
|
InputProps={{
|
|
88
86
|
readOnly,
|
|
89
87
|
endAdornment: <InputCheckmark show={valid.houseNumber} />,
|
|
90
88
|
}}
|
|
91
89
|
/>
|
|
92
|
-
<
|
|
90
|
+
<TextFieldElement
|
|
91
|
+
control={control}
|
|
92
|
+
name='addition'
|
|
93
93
|
variant='outlined'
|
|
94
94
|
type='text'
|
|
95
|
-
|
|
96
|
-
required={!!required?.addition}
|
|
95
|
+
required={required.addition}
|
|
97
96
|
label={<Trans id='Addition' />}
|
|
98
97
|
autoComplete='address-line3'
|
|
99
|
-
{...muiRegister('addition', { required: required?.addition })}
|
|
100
|
-
helperText={formState.isSubmitted && formState.errors.addition?.message}
|
|
101
98
|
InputProps={{
|
|
102
99
|
readOnly,
|
|
103
100
|
endAdornment: <InputCheckmark show={valid.addition} />,
|
|
@@ -105,27 +102,25 @@ export function AddressFields(props: AddressFieldsProps) {
|
|
|
105
102
|
/>
|
|
106
103
|
</FormRow>
|
|
107
104
|
<FormRow>
|
|
108
|
-
<
|
|
105
|
+
<TextFieldElement
|
|
106
|
+
control={control}
|
|
107
|
+
name='postcode'
|
|
109
108
|
variant='outlined'
|
|
110
109
|
type='text'
|
|
111
|
-
|
|
112
|
-
required={!!required?.postcode}
|
|
110
|
+
required={required.postcode}
|
|
113
111
|
label={<Trans id='Postcode' />}
|
|
114
|
-
{...muiRegister('postcode', { required: required?.postcode })}
|
|
115
|
-
helperText={formState.isSubmitted && formState.errors.postcode?.message}
|
|
116
112
|
InputProps={{
|
|
117
113
|
readOnly,
|
|
118
114
|
endAdornment: <InputCheckmark show={valid.postcode} />,
|
|
119
115
|
}}
|
|
120
116
|
/>
|
|
121
|
-
<
|
|
117
|
+
<TextFieldElement
|
|
118
|
+
control={control}
|
|
119
|
+
name='city'
|
|
122
120
|
variant='outlined'
|
|
123
121
|
type='text'
|
|
124
|
-
|
|
125
|
-
required={!!required?.city}
|
|
122
|
+
required={required.city}
|
|
126
123
|
label={<Trans id='City' />}
|
|
127
|
-
{...muiRegister('city', { required: required?.city })}
|
|
128
|
-
helperText={formState.isSubmitted && formState.errors.city?.message}
|
|
129
124
|
InputProps={{
|
|
130
125
|
readOnly,
|
|
131
126
|
endAdornment: <InputCheckmark show={valid.city} />,
|
|
@@ -133,63 +128,39 @@ export function AddressFields(props: AddressFieldsProps) {
|
|
|
133
128
|
/>
|
|
134
129
|
</FormRow>
|
|
135
130
|
<FormRow>
|
|
136
|
-
<
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
{
|
|
131
|
+
<SelectElement
|
|
132
|
+
control={control}
|
|
133
|
+
name='countryCode'
|
|
134
|
+
SelectProps={{ autoWidth: true }}
|
|
140
135
|
variant='outlined'
|
|
141
|
-
error={!!formState.errors.countryCode}
|
|
142
136
|
label={<Trans id='Country' />}
|
|
143
|
-
required={
|
|
144
|
-
helperText={formState.errors.countryCode?.message}
|
|
145
|
-
// onBlur={onBlur}
|
|
137
|
+
required={required.countryCode}
|
|
146
138
|
InputProps={{
|
|
147
139
|
readOnly,
|
|
148
140
|
endAdornment: <InputCheckmark show={valid.countryCode} select />,
|
|
149
141
|
}}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return (
|
|
156
|
-
<option key={c.two_letter_abbreviation} value={c.two_letter_abbreviation}>
|
|
157
|
-
{c.full_name_locale}
|
|
158
|
-
</option>
|
|
159
|
-
)
|
|
160
|
-
})}
|
|
161
|
-
</TextField>
|
|
142
|
+
options={filterNonNullableKeys(countryList, [
|
|
143
|
+
'two_letter_abbreviation',
|
|
144
|
+
'full_name_locale',
|
|
145
|
+
]).map(({ two_letter_abbreviation: id, full_name_locale: label }) => ({ id, label }))}
|
|
146
|
+
/>
|
|
162
147
|
|
|
163
148
|
{regionList.length > 0 && (
|
|
164
|
-
<
|
|
165
|
-
|
|
166
|
-
|
|
149
|
+
<SelectElement
|
|
150
|
+
control={control}
|
|
151
|
+
name='regionId'
|
|
152
|
+
// SelectProps={{ native: true, displayEmpty: true }}
|
|
167
153
|
variant='outlined'
|
|
168
|
-
error={!!formState.errors.regionId}
|
|
169
154
|
label={<Trans id='Region' />}
|
|
170
|
-
{...muiRegister('regionId', {
|
|
171
|
-
required: true,
|
|
172
|
-
shouldUnregister: true,
|
|
173
|
-
valueAsNumber: true,
|
|
174
|
-
})}
|
|
175
155
|
required
|
|
176
|
-
helperText={formState.errors.regionId?.message}
|
|
177
156
|
InputProps={{
|
|
178
157
|
readOnly,
|
|
179
158
|
endAdornment: <InputCheckmark show={valid.regionId} select />,
|
|
180
159
|
}}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
if (!r?.id) return null
|
|
186
|
-
return (
|
|
187
|
-
<option key={r.id} value={r.id}>
|
|
188
|
-
{r.name}
|
|
189
|
-
</option>
|
|
190
|
-
)
|
|
191
|
-
})}
|
|
192
|
-
</TextField>
|
|
160
|
+
options={filterNonNullableKeys(regionList, ['id', 'name']).map(
|
|
161
|
+
({ id, name: label }) => ({ id, label }),
|
|
162
|
+
)}
|
|
163
|
+
/>
|
|
193
164
|
)}
|
|
194
165
|
</FormRow>
|
|
195
166
|
</>
|
|
@@ -13,7 +13,6 @@ import { phonePattern, useFormGqlMutation } from '@graphcommerce/react-hook-form
|
|
|
13
13
|
import { i18n } from '@lingui/core'
|
|
14
14
|
import { Trans } from '@lingui/react'
|
|
15
15
|
import { SxProps, TextField, Theme } from '@mui/material'
|
|
16
|
-
import { useRouter } from 'next/router'
|
|
17
16
|
import { AccountAddressFragment } from '../AccountAddress/AccountAddress.gql'
|
|
18
17
|
import { AddressFields } from '../AddressFields/AddressFields'
|
|
19
18
|
import { ApolloCustomerErrorAlert } from '../ApolloCustomerError/ApolloCustomerErrorAlert'
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TextFieldElement } from '@graphcommerce/ecommerce-ui'
|
|
1
2
|
import { FormRow, InputCheckmark } from '@graphcommerce/next-ui'
|
|
2
3
|
import { assertFormGqlOperation, Controller, UseFormReturn } from '@graphcommerce/react-hook-form'
|
|
3
4
|
import { i18n } from '@lingui/core'
|
|
@@ -65,31 +66,29 @@ export function NameFields(props: NameFieldProps) {
|
|
|
65
66
|
)}
|
|
66
67
|
|
|
67
68
|
<FormRow>
|
|
68
|
-
<
|
|
69
|
+
<TextFieldElement
|
|
70
|
+
control={form.control}
|
|
71
|
+
name='firstname'
|
|
72
|
+
required={required.firstname}
|
|
69
73
|
variant='outlined'
|
|
70
74
|
type='text'
|
|
71
75
|
label={<Trans id='First Name' />}
|
|
72
|
-
required={!!required}
|
|
73
|
-
error={!!formState.errors.firstname}
|
|
74
|
-
helperText={formState.isSubmitted && formState.errors.firstname?.message}
|
|
75
76
|
InputProps={{
|
|
76
77
|
readOnly,
|
|
77
78
|
endAdornment: <InputCheckmark show={valid.firstname} />,
|
|
78
79
|
}}
|
|
79
|
-
{...muiRegister('firstname', { required: required?.firstname })}
|
|
80
80
|
/>
|
|
81
|
-
<
|
|
81
|
+
<TextFieldElement
|
|
82
|
+
control={form.control}
|
|
83
|
+
name='lastname'
|
|
84
|
+
required={required.lastname}
|
|
82
85
|
variant='outlined'
|
|
83
86
|
type='text'
|
|
84
|
-
error={!!formState.errors.lastname}
|
|
85
87
|
label={<Trans id='Last Name' />}
|
|
86
|
-
required={!!required?.lastname}
|
|
87
|
-
helperText={formState.isSubmitted && formState.errors.lastname?.message}
|
|
88
88
|
InputProps={{
|
|
89
89
|
readOnly,
|
|
90
90
|
endAdornment: <InputCheckmark show={valid.lastname} />,
|
|
91
91
|
}}
|
|
92
|
-
{...muiRegister('lastname', { required: required?.lastname })}
|
|
93
92
|
/>
|
|
94
93
|
</FormRow>
|
|
95
94
|
</>
|
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useQuery,
|
|
3
|
-
TypedDocumentNode,
|
|
4
|
-
QueryHookOptions,
|
|
5
|
-
QueryResult,
|
|
6
|
-
ApolloError,
|
|
7
|
-
} from '@graphcommerce/graphql'
|
|
8
|
-
import { GraphQLError } from 'graphql'
|
|
1
|
+
import { useQuery, TypedDocumentNode, QueryHookOptions, QueryResult } from '@graphcommerce/graphql'
|
|
9
2
|
import { useCustomerSession } from './useCustomerSession'
|
|
10
3
|
|
|
11
|
-
const notLoggedInError = new ApolloError({
|
|
12
|
-
graphQLErrors: [
|
|
13
|
-
new GraphQLError('Not authorized', {
|
|
14
|
-
extensions: { category: 'graphql-authorization' },
|
|
15
|
-
}),
|
|
16
|
-
],
|
|
17
|
-
})
|
|
18
|
-
|
|
19
4
|
/** Will only execute when the customer is signed in. */
|
|
20
5
|
export function useCustomerQuery<Q, V>(
|
|
21
6
|
document: TypedDocumentNode<Q, V>,
|
|
22
7
|
options: QueryHookOptions<Q, V> & { hydration?: boolean } = {},
|
|
23
8
|
): QueryResult<Q, V> {
|
|
24
9
|
const { hydration, ...queryOptions } = options
|
|
25
|
-
const { loggedIn
|
|
10
|
+
const { loggedIn } = useCustomerSession({ hydration })
|
|
26
11
|
|
|
27
12
|
const result = useQuery(document, {
|
|
28
13
|
...queryOptions,
|
|
@@ -30,8 +15,5 @@ export function useCustomerQuery<Q, V>(
|
|
|
30
15
|
skip: !loggedIn,
|
|
31
16
|
})
|
|
32
17
|
|
|
33
|
-
return
|
|
34
|
-
...result,
|
|
35
|
-
error: query.called && !loggedIn ? notLoggedInError : result.error,
|
|
36
|
-
}
|
|
18
|
+
return result
|
|
37
19
|
}
|
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.10.
|
|
5
|
+
"version": "4.10.5",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"type-fest": "^2.12.2"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@graphcommerce/ecommerce-ui": "1.
|
|
22
|
+
"@graphcommerce/ecommerce-ui": "1.3.0",
|
|
23
23
|
"@graphcommerce/framer-utils": "3.2.0",
|
|
24
|
-
"@graphcommerce/graphql": "3.4.
|
|
24
|
+
"@graphcommerce/graphql": "3.4.8",
|
|
25
25
|
"@graphcommerce/graphql-mesh": "4.1.9",
|
|
26
26
|
"@graphcommerce/image": "3.1.9",
|
|
27
|
-
"@graphcommerce/magento-graphql": "3.1.
|
|
28
|
-
"@graphcommerce/magento-store": "4.2.
|
|
29
|
-
"@graphcommerce/next-ui": "4.23.
|
|
27
|
+
"@graphcommerce/magento-graphql": "3.1.8",
|
|
28
|
+
"@graphcommerce/magento-store": "4.2.32",
|
|
29
|
+
"@graphcommerce/next-ui": "4.23.1",
|
|
30
30
|
"@graphcommerce/react-hook-form": "3.3.2"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|