@graphcommerce/magento-customer 4.10.4 → 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 CHANGED
@@ -1,5 +1,14 @@
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
+
3
12
  ## 4.10.4
4
13
 
5
14
  ### 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, formState, required, muiRegister, valid } = form
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
- const regions = availableRegions?.sort(compare)
52
- return regions
52
+ return availableRegions?.sort(compare)
53
53
  }, [country, countryList])
54
54
 
55
55
  return (
56
56
  <>
57
57
  <FormRow>
58
- <TextField
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
- <TextField
73
- variant='outlined'
74
- type='text'
75
- error={!!formState.errors.houseNumber}
76
- label={<Trans id='Housenumber' />}
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
- helperText={formState.isSubmitted && formState.errors.houseNumber?.message}
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
- <TextField
90
+ <TextFieldElement
91
+ control={control}
92
+ name='addition'
93
93
  variant='outlined'
94
94
  type='text'
95
- error={!!formState.errors.addition}
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
- <TextField
105
+ <TextFieldElement
106
+ control={control}
107
+ name='postcode'
109
108
  variant='outlined'
110
109
  type='text'
111
- error={!!formState.errors.postcode}
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
- <TextField
117
+ <TextFieldElement
118
+ control={control}
119
+ name='city'
122
120
  variant='outlined'
123
121
  type='text'
124
- error={!!formState.errors.city}
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
- <TextField
137
- select
138
- SelectProps={{ native: true, displayEmpty: true }}
139
- {...muiRegister('countryCode', { required: required.countryCode })}
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={!!required?.countryCode}
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
- {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
152
- <option value='' />
153
- {countryList.map((c) => {
154
- if (!c?.two_letter_abbreviation) return null
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
- <TextField
165
- select
166
- SelectProps={{ native: true, displayEmpty: true }}
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
- {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */}
183
- <option value='' />
184
- {regionList.map((r) => {
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
  </>
@@ -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
- <TextField
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
- <TextField
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
  </>
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.4",
5
+ "version": "4.10.5",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -19,7 +19,7 @@
19
19
  "type-fest": "^2.12.2"
20
20
  },
21
21
  "dependencies": {
22
- "@graphcommerce/ecommerce-ui": "1.2.3",
22
+ "@graphcommerce/ecommerce-ui": "1.3.0",
23
23
  "@graphcommerce/framer-utils": "3.2.0",
24
24
  "@graphcommerce/graphql": "3.4.8",
25
25
  "@graphcommerce/graphql-mesh": "4.1.9",