@magento/peregrine 14.3.1 → 14.4.1-alpha.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.
- package/lib/Apollo/links/index.js +3 -0
- package/lib/store/actions/user/asyncActions.js +2 -2
- package/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js +1 -0
- package/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js +7 -1
- package/lib/talons/CreateAccount/createAccount.gql.js +1 -0
- package/lib/talons/CreateAccount/useCreateAccount.js +6 -2
- package/lib/talons/MagentoRoute/useMagentoRoute.js +30 -9
- package/lib/talons/ProductFullDetail/useProductFullDetail.js +2 -2
- package/lib/talons/SignIn/signIn.gql.js +1 -0
- package/lib/talons/SignIn/useSignIn.js +32 -10
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHttpLink } from '@apollo/client';
|
|
2
2
|
|
|
3
|
+
import createAuthLink from '@magento/peregrine/lib/Apollo/links/authLink';
|
|
3
4
|
import createErrorLink from '@magento/peregrine/lib/Apollo/links/errorLink';
|
|
4
5
|
import createGqlCacheLink from '@magento/peregrine/lib/Apollo/links/gqlCacheLink';
|
|
5
6
|
import createMutationQueueLink from '@magento/peregrine/lib/Apollo/links/mutationQueueLink';
|
|
@@ -31,6 +32,7 @@ export const customFetchToShrinkQuery = (uri, options) => {
|
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
const getLinks = apiBase => {
|
|
35
|
+
const authLink = createAuthLink();
|
|
34
36
|
const storeLink = createStoreLink();
|
|
35
37
|
const errorLink = createErrorLink();
|
|
36
38
|
const retryLink = createRetryLink();
|
|
@@ -52,6 +54,7 @@ const getLinks = apiBase => {
|
|
|
52
54
|
const links = new Map()
|
|
53
55
|
.set('MUTATION_QUEUE', mutationQueueLink)
|
|
54
56
|
.set('RETRY', retryLink)
|
|
57
|
+
.set('AUTH', authLink)
|
|
55
58
|
.set('GQL_CACHE', gqlCacheLink)
|
|
56
59
|
.set('STORE', storeLink)
|
|
57
60
|
.set('ERROR', errorLink)
|
|
@@ -63,13 +63,13 @@ export const resetPassword = ({ email }) =>
|
|
|
63
63
|
dispatch(actions.resetPassword.receive());
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
export const setToken = token =>
|
|
66
|
+
export const setToken = (token, customer_token_lifetime = 3600) =>
|
|
67
67
|
async function thunk(...args) {
|
|
68
68
|
const [dispatch] = args;
|
|
69
69
|
|
|
70
70
|
// Store token in local storage.
|
|
71
71
|
// TODO: Get correct token expire time from API
|
|
72
|
-
storage.setItem('signin_token', token,
|
|
72
|
+
storage.setItem('signin_token', token, customer_token_lifetime);
|
|
73
73
|
|
|
74
74
|
// Persist in store
|
|
75
75
|
dispatch(actions.setToken(token));
|
|
@@ -117,7 +117,13 @@ export const useCreateAccount = props => {
|
|
|
117
117
|
...recaptchaDataForSignIn
|
|
118
118
|
});
|
|
119
119
|
const token = signInResponse.data.generateCustomerToken.token;
|
|
120
|
-
|
|
120
|
+
const customerTokenLifetime =
|
|
121
|
+
signInResponse.data.generateCustomerToken
|
|
122
|
+
.customer_token_lifetime;
|
|
123
|
+
|
|
124
|
+
await (customerTokenLifetime
|
|
125
|
+
? setToken(token, customerTokenLifetime)
|
|
126
|
+
: setToken(token));
|
|
121
127
|
|
|
122
128
|
// Clear guest cart from redux.
|
|
123
129
|
await removeCart();
|
|
@@ -136,8 +136,12 @@ export const useCreateAccount = props => {
|
|
|
136
136
|
...recaptchaDataForSignIn
|
|
137
137
|
});
|
|
138
138
|
const token = signInResponse.data.generateCustomerToken.token;
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const customerTokenLifetime =
|
|
140
|
+
signInResponse.data.generateCustomerToken
|
|
141
|
+
.customer_token_lifetime;
|
|
142
|
+
await (customerTokenLifetime
|
|
143
|
+
? setToken(token, customerTokenLifetime)
|
|
144
|
+
: setToken(token));
|
|
141
145
|
// Clear all cart/customer data from cache and redux.
|
|
142
146
|
await apolloClient.clearCacheData(apolloClient, 'cart');
|
|
143
147
|
await apolloClient.clearCacheData(apolloClient, 'customer');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef } from 'react';
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { useHistory, useLocation } from 'react-router-dom';
|
|
3
3
|
import { useLazyQuery } from '@apollo/client';
|
|
4
4
|
import { useRootComponents } from '../../context/rootComponents';
|
|
@@ -44,9 +44,11 @@ export const useMagentoRoute = (props = {}) => {
|
|
|
44
44
|
const component = componentMap.get(pathname);
|
|
45
45
|
|
|
46
46
|
const [runQuery, queryResult] = useLazyQuery(resolveUrlQuery);
|
|
47
|
+
|
|
47
48
|
// destructure the query result
|
|
48
49
|
const { data, error, loading } = queryResult;
|
|
49
|
-
const
|
|
50
|
+
const [getRouteData, setRouteData] = useState(data);
|
|
51
|
+
const { route } = getRouteData || {};
|
|
50
52
|
|
|
51
53
|
// redirect to external url
|
|
52
54
|
useEffect(() => {
|
|
@@ -59,15 +61,34 @@ export const useMagentoRoute = (props = {}) => {
|
|
|
59
61
|
}, [route]);
|
|
60
62
|
|
|
61
63
|
useEffect(() => {
|
|
64
|
+
let isMounted = true; // Track whether the component is still mounted
|
|
65
|
+
const runInitialQuery = async () => {
|
|
66
|
+
try {
|
|
67
|
+
const { data } = await runQuery({
|
|
68
|
+
fetchPolicy: 'cache-and-network',
|
|
69
|
+
nextFetchPolicy: 'cache-first',
|
|
70
|
+
variables: { url: pathname }
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
if (isMounted) {
|
|
74
|
+
setRouteData(data);
|
|
75
|
+
fetchedPathname.current = pathname;
|
|
76
|
+
}
|
|
77
|
+
} catch (error) {
|
|
78
|
+
if (isMounted) {
|
|
79
|
+
console.error('Error running initial query:', error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
62
83
|
if (initialized.current || !getInlinedPageData()) {
|
|
63
|
-
|
|
64
|
-
fetchPolicy: 'cache-and-network',
|
|
65
|
-
nextFetchPolicy: 'cache-first',
|
|
66
|
-
variables: { url: pathname }
|
|
67
|
-
});
|
|
68
|
-
fetchedPathname.current = pathname;
|
|
84
|
+
runInitialQuery();
|
|
69
85
|
}
|
|
70
|
-
|
|
86
|
+
// Cleanup function
|
|
87
|
+
return () => {
|
|
88
|
+
isMounted = false; // Mark as unmounted
|
|
89
|
+
};
|
|
90
|
+
}, [initialized, pathname, runQuery]);
|
|
91
|
+
// eslint-disable-line react-hooks/exhaustive-deps
|
|
71
92
|
|
|
72
93
|
useEffect(() => {
|
|
73
94
|
if (component) {
|
|
@@ -144,8 +144,8 @@ const getBreadcrumbCategoryId = categories => {
|
|
|
144
144
|
const breadcrumbSet = new Set();
|
|
145
145
|
categories.forEach(({ breadcrumbs }) => {
|
|
146
146
|
// breadcrumbs can be `null`...
|
|
147
|
-
(breadcrumbs || []).forEach(({
|
|
148
|
-
breadcrumbSet.add(
|
|
147
|
+
(breadcrumbs || []).forEach(({ category_uid }) =>
|
|
148
|
+
breadcrumbSet.add(category_uid)
|
|
149
149
|
);
|
|
150
150
|
});
|
|
151
151
|
|
|
@@ -31,30 +31,35 @@ export const useSignIn = props => {
|
|
|
31
31
|
const apolloClient = useApolloClient();
|
|
32
32
|
const [isSigningIn, setIsSigningIn] = useState(false);
|
|
33
33
|
|
|
34
|
+
const cartContext = useCartContext();
|
|
34
35
|
const [
|
|
35
36
|
{ cartId },
|
|
36
37
|
{ createCart, removeCart, getCartDetails }
|
|
37
|
-
] =
|
|
38
|
+
] = cartContext;
|
|
38
39
|
|
|
40
|
+
const userContext = useUserContext();
|
|
39
41
|
const [
|
|
40
42
|
{ isGettingDetails, getDetailsError },
|
|
41
43
|
{ getUserDetails, setToken }
|
|
42
|
-
] =
|
|
44
|
+
] = userContext;
|
|
43
45
|
|
|
44
|
-
const
|
|
46
|
+
const eventingContext = useEventingContext();
|
|
47
|
+
const [, { dispatch }] = eventingContext;
|
|
45
48
|
|
|
46
|
-
const
|
|
49
|
+
const signInMutationResult = useMutation(signInMutation, {
|
|
47
50
|
fetchPolicy: 'no-cache'
|
|
48
51
|
});
|
|
52
|
+
const [signIn, { error: signInError }] = signInMutationResult;
|
|
49
53
|
|
|
54
|
+
const googleReCaptcha = useGoogleReCaptcha({
|
|
55
|
+
currentForm: 'CUSTOMER_LOGIN',
|
|
56
|
+
formAction: 'signIn'
|
|
57
|
+
});
|
|
50
58
|
const {
|
|
51
59
|
generateReCaptchaData,
|
|
52
60
|
recaptchaLoading,
|
|
53
61
|
recaptchaWidgetProps
|
|
54
|
-
} =
|
|
55
|
-
currentForm: 'CUSTOMER_LOGIN',
|
|
56
|
-
formAction: 'signIn'
|
|
57
|
-
});
|
|
62
|
+
} = googleReCaptcha;
|
|
58
63
|
|
|
59
64
|
const [fetchCartId] = useMutation(createCartMutation);
|
|
60
65
|
const [mergeCarts] = useMutation(mergeCartsMutation);
|
|
@@ -86,7 +91,13 @@ export const useSignIn = props => {
|
|
|
86
91
|
});
|
|
87
92
|
|
|
88
93
|
const token = signInResponse.data.generateCustomerToken.token;
|
|
89
|
-
|
|
94
|
+
const customerTokenLifetime =
|
|
95
|
+
signInResponse.data.generateCustomerToken
|
|
96
|
+
.customer_token_lifetime;
|
|
97
|
+
|
|
98
|
+
await (customerTokenLifetime
|
|
99
|
+
? setToken(token, customerTokenLifetime)
|
|
100
|
+
: setToken(token));
|
|
90
101
|
|
|
91
102
|
// Clear all cart/customer data from cache and redux.
|
|
92
103
|
await apolloClient.clearCacheData(apolloClient, 'cart');
|
|
@@ -216,6 +227,17 @@ export const useSignIn = props => {
|
|
|
216
227
|
handleSubmit,
|
|
217
228
|
isBusy: isGettingDetails || isSigningIn || recaptchaLoading,
|
|
218
229
|
setFormApi,
|
|
219
|
-
recaptchaWidgetProps
|
|
230
|
+
recaptchaWidgetProps,
|
|
231
|
+
userContext,
|
|
232
|
+
cartContext,
|
|
233
|
+
eventingContext,
|
|
234
|
+
signInMutationResult,
|
|
235
|
+
googleReCaptcha,
|
|
236
|
+
isSigningIn,
|
|
237
|
+
setIsSigningIn,
|
|
238
|
+
fetchCartId,
|
|
239
|
+
mergeCarts,
|
|
240
|
+
fetchUserDetails,
|
|
241
|
+
fetchCartDetails
|
|
220
242
|
};
|
|
221
243
|
};
|