@graphcommerce/magento-customer 6.0.2-canary.8 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/components/AddressFields/AddressFields.tsx +48 -38
- package/components/OrderCard/OrderCard.tsx +8 -7
- package/components/SignInForm/SignInForm.tsx +7 -4
- package/hooks/useCustomerQuery.ts +3 -11
- package/hooks/useCustomerSession.ts +4 -30
- package/hooks/useGuestQuery.ts +2 -2
- package/package.json +13 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,67 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 6.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1869](https://github.com/graphcommerce-org/graphcommerce/pull/1869) [`82111fa35`](https://github.com/graphcommerce-org/graphcommerce/commit/82111fa351b68a76ff053ebb7e0261ee507a826d) - Faster page rendering on all pages that use Apollo Client: Revert to classical useEffect strategy for Apollo cache persist restore and remove custom hydration strategies from the cart/customer.
|
|
8
|
+
|
|
9
|
+
This comes with a caviat: When using `<Suspense>` to defer rendering you might run into hydration errors. In the case where the Suspense boundaries are used to improve performance, you are required to remove those. We have a follow-up [PR](https://github.com/graphcommerce-org/graphcommerce/pull/1878) in the works that allows getting the hydration performance improvement, but not have the hydration errors. ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1866](https://github.com/graphcommerce-org/graphcommerce/pull/1866) [`eafe3a17d`](https://github.com/graphcommerce-org/graphcommerce/commit/eafe3a17d6c6b4a9ca524361498ffa382d44c63f) - useOrderCardItemImages was triggered when there were no urlKeys present, causing unnessary requests to be made to the backend. ([@Giovanni-Schroevers](https://github.com/Giovanni-Schroevers))
|
|
14
|
+
|
|
15
|
+
- [#1889](https://github.com/graphcommerce-org/graphcommerce/pull/1889) [`38bf4b6bc`](https://github.com/graphcommerce-org/graphcommerce/commit/38bf4b6bc6e705d9d124d50b775ba3f440599482) - put the country field first, so the address fields will not be changed afterwards when postcode service is active. ([@carlocarels90](https://github.com/carlocarels90))
|
|
16
|
+
|
|
17
|
+
- [#1899](https://github.com/graphcommerce-org/graphcommerce/pull/1899) [`3de184ee2`](https://github.com/graphcommerce-org/graphcommerce/commit/3de184ee28d48d8f1c1c092f264ac6b86fdf3ec6) - Make order states translatable ([@carlocarels90](https://github.com/carlocarels90))
|
|
18
|
+
|
|
19
|
+
- [#1896](https://github.com/graphcommerce-org/graphcommerce/pull/1896) [`4f846293f`](https://github.com/graphcommerce-org/graphcommerce/commit/4f846293f3b020dc7bae885fe4ccd1cbd0cb10d7) - When a customer would log in the current guest information would be lost ([@paales](https://github.com/paales))
|
|
20
|
+
|
|
21
|
+
## 6.0.2-canary.22
|
|
22
|
+
|
|
23
|
+
## 6.0.2-canary.21
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- [#1899](https://github.com/graphcommerce-org/graphcommerce/pull/1899) [`3de184ee2`](https://github.com/graphcommerce-org/graphcommerce/commit/3de184ee28d48d8f1c1c092f264ac6b86fdf3ec6) - Make order states translatable ([@carlocarels90](https://github.com/carlocarels90))
|
|
28
|
+
|
|
29
|
+
## 6.0.2-canary.20
|
|
30
|
+
|
|
31
|
+
## 6.0.2-canary.19
|
|
32
|
+
|
|
33
|
+
## 6.0.2-canary.18
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- [#1889](https://github.com/graphcommerce-org/graphcommerce/pull/1889) [`38bf4b6bc`](https://github.com/graphcommerce-org/graphcommerce/commit/38bf4b6bc6e705d9d124d50b775ba3f440599482) - put the country field first, so the address fields will not be changed afterwards when postcode service is active. ([@carlocarels90](https://github.com/carlocarels90))
|
|
38
|
+
|
|
39
|
+
## 6.0.2-canary.17
|
|
40
|
+
|
|
41
|
+
## 6.0.2-canary.16
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- [#1896](https://github.com/graphcommerce-org/graphcommerce/pull/1896) [`4f846293f`](https://github.com/graphcommerce-org/graphcommerce/commit/4f846293f3b020dc7bae885fe4ccd1cbd0cb10d7) - When a customer would log in the current guest information would be lost ([@paales](https://github.com/paales))
|
|
46
|
+
|
|
47
|
+
## 6.0.2-canary.15
|
|
48
|
+
|
|
49
|
+
## 6.0.2-canary.14
|
|
50
|
+
|
|
51
|
+
## 6.0.2-canary.13
|
|
52
|
+
|
|
53
|
+
### Patch Changes
|
|
54
|
+
|
|
55
|
+
- [#1869](https://github.com/graphcommerce-org/graphcommerce/pull/1869) [`82111fa35`](https://github.com/graphcommerce-org/graphcommerce/commit/82111fa351b68a76ff053ebb7e0261ee507a826d) - Revert to classical useEffect strategy for Apollo cache persist restore and remove custom hydration strategies from the cart. ([@paales](https://github.com/paales))
|
|
56
|
+
|
|
57
|
+
## 6.0.2-canary.12
|
|
58
|
+
|
|
59
|
+
## 6.0.2-canary.11
|
|
60
|
+
|
|
61
|
+
## 6.0.2-canary.10
|
|
62
|
+
|
|
63
|
+
## 6.0.2-canary.9
|
|
64
|
+
|
|
3
65
|
## 6.0.2-canary.8
|
|
4
66
|
|
|
5
67
|
## 6.0.2-canary.7
|
|
@@ -22,10 +22,14 @@ export type AddressFieldValues = {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
export type AddressFieldsProps = {
|
|
25
|
+
export type AddressFieldsProps = {
|
|
26
|
+
form: UseFormReturn<any>
|
|
27
|
+
readOnly?: boolean
|
|
28
|
+
countryFirst?: boolean
|
|
29
|
+
}
|
|
26
30
|
|
|
27
31
|
export function AddressFields(props: AddressFieldsProps) {
|
|
28
|
-
const { form, readOnly } = props
|
|
32
|
+
const { form, readOnly, countryFirst } = props
|
|
29
33
|
|
|
30
34
|
const countryQuery = useQuery(CountryRegionsDocument, { fetchPolicy: 'cache-and-network' })
|
|
31
35
|
const countries = countryQuery.data?.countries ?? countryQuery.previousData?.countries
|
|
@@ -54,8 +58,49 @@ export function AddressFields(props: AddressFieldsProps) {
|
|
|
54
58
|
return availableRegions?.sort(compare)
|
|
55
59
|
}, [country, countryList])
|
|
56
60
|
|
|
61
|
+
const countryFields = (
|
|
62
|
+
<FormRow>
|
|
63
|
+
<SelectElement
|
|
64
|
+
control={control}
|
|
65
|
+
name='countryCode'
|
|
66
|
+
SelectProps={{ autoWidth: true }}
|
|
67
|
+
variant='outlined'
|
|
68
|
+
label={<Trans id='Country' />}
|
|
69
|
+
required={required.countryCode}
|
|
70
|
+
InputProps={{
|
|
71
|
+
readOnly,
|
|
72
|
+
endAdornment: <InputCheckmark show={valid.countryCode} select />,
|
|
73
|
+
}}
|
|
74
|
+
options={filterNonNullableKeys(countryList, [
|
|
75
|
+
'two_letter_abbreviation',
|
|
76
|
+
'full_name_locale',
|
|
77
|
+
]).map(({ two_letter_abbreviation: id, full_name_locale: label }) => ({ id, label }))}
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
{regionList.length > 0 && (
|
|
81
|
+
<SelectElement
|
|
82
|
+
control={control}
|
|
83
|
+
name='regionId'
|
|
84
|
+
// SelectProps={{ native: true, displayEmpty: true }}
|
|
85
|
+
variant='outlined'
|
|
86
|
+
label={<Trans id='Region' />}
|
|
87
|
+
required
|
|
88
|
+
InputProps={{
|
|
89
|
+
readOnly,
|
|
90
|
+
endAdornment: <InputCheckmark show={valid.regionId} select />,
|
|
91
|
+
}}
|
|
92
|
+
options={filterNonNullableKeys(regionList, ['id', 'name']).map(({ id, name: label }) => ({
|
|
93
|
+
id,
|
|
94
|
+
label,
|
|
95
|
+
}))}
|
|
96
|
+
/>
|
|
97
|
+
)}
|
|
98
|
+
</FormRow>
|
|
99
|
+
)
|
|
100
|
+
|
|
57
101
|
return (
|
|
58
102
|
<>
|
|
103
|
+
{countryFirst && countryFields}
|
|
59
104
|
<FormRow>
|
|
60
105
|
<TextFieldElement
|
|
61
106
|
variant='outlined'
|
|
@@ -129,42 +174,7 @@ export function AddressFields(props: AddressFieldsProps) {
|
|
|
129
174
|
}}
|
|
130
175
|
/>
|
|
131
176
|
</FormRow>
|
|
132
|
-
|
|
133
|
-
<SelectElement
|
|
134
|
-
control={control}
|
|
135
|
-
name='countryCode'
|
|
136
|
-
SelectProps={{ autoWidth: true }}
|
|
137
|
-
variant='outlined'
|
|
138
|
-
label={<Trans id='Country' />}
|
|
139
|
-
required={required.countryCode}
|
|
140
|
-
InputProps={{
|
|
141
|
-
readOnly,
|
|
142
|
-
endAdornment: <InputCheckmark show={valid.countryCode} select />,
|
|
143
|
-
}}
|
|
144
|
-
options={filterNonNullableKeys(countryList, [
|
|
145
|
-
'two_letter_abbreviation',
|
|
146
|
-
'full_name_locale',
|
|
147
|
-
]).map(({ two_letter_abbreviation: id, full_name_locale: label }) => ({ id, label }))}
|
|
148
|
-
/>
|
|
149
|
-
|
|
150
|
-
{regionList.length > 0 && (
|
|
151
|
-
<SelectElement
|
|
152
|
-
control={control}
|
|
153
|
-
name='regionId'
|
|
154
|
-
// SelectProps={{ native: true, displayEmpty: true }}
|
|
155
|
-
variant='outlined'
|
|
156
|
-
label={<Trans id='Region' />}
|
|
157
|
-
required
|
|
158
|
-
InputProps={{
|
|
159
|
-
readOnly,
|
|
160
|
-
endAdornment: <InputCheckmark show={valid.regionId} select />,
|
|
161
|
-
}}
|
|
162
|
-
options={filterNonNullableKeys(regionList, ['id', 'name']).map(
|
|
163
|
-
({ id, name: label }) => ({ id, label }),
|
|
164
|
-
)}
|
|
165
|
-
/>
|
|
166
|
-
)}
|
|
167
|
-
</FormRow>
|
|
177
|
+
{!countryFirst && countryFields}
|
|
168
178
|
</>
|
|
169
179
|
)
|
|
170
180
|
}
|
|
@@ -6,6 +6,7 @@ import { OrderCardItemImage } from '../OrderCardItemImage/OrderCardItemImage'
|
|
|
6
6
|
import { OrderStateLabel } from '../OrderStateLabel/OrderStateLabel'
|
|
7
7
|
import { TrackingLink } from '../TrackingLink/TrackingLink'
|
|
8
8
|
import { OrderCardFragment } from './OrderCard.gql'
|
|
9
|
+
import { Trans } from '@lingui/react'
|
|
9
10
|
|
|
10
11
|
type OrderCardProps = Partial<OrderCardFragment> & {
|
|
11
12
|
loading?: boolean
|
|
@@ -101,13 +102,13 @@ export function OrderCard(props: OrderCardProps) {
|
|
|
101
102
|
<OrderStateLabel
|
|
102
103
|
items={items}
|
|
103
104
|
renderer={{
|
|
104
|
-
Ordered: () => <
|
|
105
|
-
Invoiced: () => <
|
|
106
|
-
Shipped: () => <
|
|
107
|
-
Refunded: () => <
|
|
108
|
-
Canceled: () => <
|
|
109
|
-
Returned: () => <
|
|
110
|
-
Partial: () => <
|
|
105
|
+
Ordered: () => <Trans id='Your order is being processed' />,
|
|
106
|
+
Invoiced: () => <Trans id='Your order has been invoiced' />,
|
|
107
|
+
Shipped: () => <Trans id='Your order is on its way!' />,
|
|
108
|
+
Refunded: () => <Trans id='Your order has been refunded' />,
|
|
109
|
+
Canceled: () => <Trans id='Your order has been canceled' />,
|
|
110
|
+
Returned: () => <Trans id='Your order has been returned' />,
|
|
111
|
+
Partial: () => <Trans id='Your order has been partially processed' />,
|
|
111
112
|
}}
|
|
112
113
|
/>
|
|
113
114
|
</OrderRow>
|
|
@@ -19,10 +19,13 @@ export function SignInForm(props: SignInFormProps) {
|
|
|
19
19
|
{
|
|
20
20
|
defaultValues: { email },
|
|
21
21
|
onBeforeSubmit: async (values) => {
|
|
22
|
-
const oldEmail = client.cache.readQuery({ query: CustomerDocument })
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
const oldEmail = client.cache.readQuery({ query: CustomerDocument })?.customer?.email
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* We are logging in because the session expired, but we're logging in with a different
|
|
26
|
+
* email address, we need to reset the store.
|
|
27
|
+
*/
|
|
28
|
+
if (oldEmail && oldEmail !== email) await client.resetStore()
|
|
26
29
|
return { ...values, email }
|
|
27
30
|
},
|
|
28
31
|
},
|
|
@@ -10,16 +10,8 @@ import { useCustomerSession } from './useCustomerSession'
|
|
|
10
10
|
/** Will only execute when the customer is signed in. */
|
|
11
11
|
export function useCustomerQuery<Q, V extends OperationVariables>(
|
|
12
12
|
document: TypedDocumentNode<Q, V>,
|
|
13
|
-
options: QueryHookOptions<Q, V>
|
|
13
|
+
options: QueryHookOptions<Q, V> = {},
|
|
14
14
|
): QueryResult<Q, V> {
|
|
15
|
-
const {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const result = useQuery(document, {
|
|
19
|
-
...queryOptions,
|
|
20
|
-
ssr: false,
|
|
21
|
-
skip: !loggedIn,
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
return result
|
|
15
|
+
const { loggedIn } = useCustomerSession()
|
|
16
|
+
return useQuery(document, { ...options, ssr: false, skip: !loggedIn })
|
|
25
17
|
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils'
|
|
2
1
|
import { QueryResult, useQuery } from '@graphcommerce/graphql'
|
|
3
|
-
import { startTransition, useState } from 'react'
|
|
4
2
|
import {
|
|
5
3
|
CustomerTokenDocument,
|
|
6
4
|
CustomerTokenQuery,
|
|
7
5
|
CustomerTokenQueryVariables,
|
|
8
6
|
} from './CustomerToken.gql'
|
|
9
7
|
|
|
10
|
-
export type UseCustomerSessionOptions =
|
|
8
|
+
export type UseCustomerSessionOptions = Record<string, unknown>
|
|
11
9
|
|
|
12
10
|
export type UseCustomerSessionReturn =
|
|
13
11
|
| {
|
|
@@ -16,33 +14,9 @@ export type UseCustomerSessionReturn =
|
|
|
16
14
|
query: QueryResult<CustomerTokenQuery, CustomerTokenQueryVariables>
|
|
17
15
|
} & Partial<Omit<NonNullable<CustomerTokenQuery['customerToken']>, '__typename'>>
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
* How can we determine we're not actually hydrating? Classically you could just use some global
|
|
24
|
-
* state to track this because when the initial render is done, we're not hydrating anymore.
|
|
25
|
-
*
|
|
26
|
-
* However, <Suspense/> can be used to defer the rendering to a later moment. This means that the
|
|
27
|
-
* useCustomerSession hook is called later and we're still in the hydration phase for this
|
|
28
|
-
* component while other components are rendering for the second time.
|
|
29
|
-
*/
|
|
30
|
-
const { hydration = false } = options
|
|
31
|
-
const [hydrating, setHydrating] = useState(!hydration)
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* After the initital render we are definitely sure we're not hydrating anymore so we can flip the
|
|
35
|
-
* switch and rerender.
|
|
36
|
-
*/
|
|
37
|
-
useIsomorphicLayoutEffect(() => {
|
|
38
|
-
if (!hydrating) return
|
|
39
|
-
startTransition(() => setHydrating(false))
|
|
40
|
-
}, [hydrating])
|
|
41
|
-
|
|
42
|
-
const skip = hydrating
|
|
43
|
-
|
|
44
|
-
const query = useQuery(CustomerTokenDocument, { skip })
|
|
45
|
-
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
18
|
+
export function useCustomerSession(_: UseCustomerSessionOptions = {}) {
|
|
19
|
+
const query = useQuery(CustomerTokenDocument)
|
|
46
20
|
const token = query.data?.customerToken
|
|
47
21
|
|
|
48
22
|
return {
|
package/hooks/useGuestQuery.ts
CHANGED
|
@@ -9,8 +9,8 @@ import { useCustomerSession } from './useCustomerSession'
|
|
|
9
9
|
/** Will only execute when the customer is not signed in. */
|
|
10
10
|
export function useGuestQuery<Q, V extends OperationVariables>(
|
|
11
11
|
document: TypedDocumentNode<Q, V>,
|
|
12
|
-
queryOptions: QueryHookOptions<Q, V>
|
|
12
|
+
queryOptions: QueryHookOptions<Q, V> = {},
|
|
13
13
|
) {
|
|
14
|
-
const { token } = useCustomerSession(
|
|
14
|
+
const { token } = useCustomerSession()
|
|
15
15
|
return useQuery(document, { ...queryOptions, ssr: false, skip: !!token })
|
|
16
16
|
}
|
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": "6.0
|
|
5
|
+
"version": "6.1.0",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,20 +12,20 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
|
-
"@graphcommerce/eslint-config-pwa": "6.0
|
|
16
|
-
"@graphcommerce/prettier-config-pwa": "6.0
|
|
17
|
-
"@graphcommerce/typescript-config-pwa": "6.0
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "6.1.0",
|
|
16
|
+
"@graphcommerce/prettier-config-pwa": "6.1.0",
|
|
17
|
+
"@graphcommerce/typescript-config-pwa": "6.1.0"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@graphcommerce/ecommerce-ui": "6.0
|
|
21
|
-
"@graphcommerce/framer-utils": "6.0
|
|
22
|
-
"@graphcommerce/graphql": "6.0
|
|
23
|
-
"@graphcommerce/graphql-mesh": "6.0
|
|
24
|
-
"@graphcommerce/image": "6.0
|
|
25
|
-
"@graphcommerce/magento-graphql": "6.0
|
|
26
|
-
"@graphcommerce/magento-store": "6.0
|
|
27
|
-
"@graphcommerce/next-ui": "6.0
|
|
28
|
-
"@graphcommerce/react-hook-form": "6.0
|
|
20
|
+
"@graphcommerce/ecommerce-ui": "6.1.0",
|
|
21
|
+
"@graphcommerce/framer-utils": "6.1.0",
|
|
22
|
+
"@graphcommerce/graphql": "6.1.0",
|
|
23
|
+
"@graphcommerce/graphql-mesh": "6.1.0",
|
|
24
|
+
"@graphcommerce/image": "6.1.0",
|
|
25
|
+
"@graphcommerce/magento-graphql": "6.1.0",
|
|
26
|
+
"@graphcommerce/magento-store": "6.1.0",
|
|
27
|
+
"@graphcommerce/next-ui": "6.1.0",
|
|
28
|
+
"@graphcommerce/react-hook-form": "6.1.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@lingui/react": "^3.13.2",
|