@magento/peregrine 12.6.0-beta.2 → 13.0.0-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/hooks/useDelayedTransition.js +1 -3
- package/lib/hooks/useGoogleReCaptcha/useGoogleReCaptcha.js +1 -1
- package/lib/hooks/useInternalLink.js +1 -1
- package/lib/hooks/useIntersectionObserver.js +1 -1
- package/lib/hooks/useIsInViewport.js +1 -1
- package/lib/hooks/useScript.js +1 -1
- package/lib/talons/Breadcrumbs/useBreadcrumbs.js +1 -1
- package/lib/talons/CartPage/PriceSummary/usePriceSummary.js +10 -0
- package/lib/talons/CategoryList/useCategoryTile.js +1 -1
- package/lib/talons/CheckoutPage/OrderConfirmationPage/useCreateAccount.js +10 -0
- package/lib/talons/CheckoutPage/useCheckoutPage.js +20 -0
- package/lib/talons/ContactPage/index.js +2 -2
- package/lib/talons/ContactPage/useContactLink.js +1 -1
- package/lib/talons/ContactPage/useContactPage.js +1 -1
- package/lib/talons/Gallery/useAddToCartButton.js +6 -1
- package/lib/talons/Gallery/useGalleryItem.js +1 -1
- package/lib/talons/Header/useAccountTrigger.js +5 -2
- package/lib/talons/Link/useLink.js +2 -4
- package/lib/talons/MegaMenu/useMegaMenu.js +1 -1
- package/lib/talons/Navigation/useNavigation.js +1 -1
- package/lib/talons/OrderHistoryPage/orderRow.gql.js +2 -0
- package/lib/talons/PageLoadingIndicator/usePageLoadingIndicator.js +1 -1
- package/lib/talons/SearchPage/useSearchPage.js +4 -3
- package/lib/talons/SignIn/useSignIn.js +9 -0
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ import { getRootComponent } from '../talons/MagentoRoute/helpers';
|
|
|
14
14
|
|
|
15
15
|
const DELAY_MESSAGE_PREFIX = 'DELAY:';
|
|
16
16
|
|
|
17
|
-
const useDelayedTransition = () => {
|
|
17
|
+
export const useDelayedTransition = () => {
|
|
18
18
|
const { pathname } = useLocation();
|
|
19
19
|
const history = useHistory();
|
|
20
20
|
const client = useApolloClient();
|
|
@@ -123,5 +123,3 @@ const useDelayedTransition = () => {
|
|
|
123
123
|
};
|
|
124
124
|
}, [client, resolveUrlQuery, setComponentMap, setPageLoading]);
|
|
125
125
|
};
|
|
126
|
-
|
|
127
|
-
export default useDelayedTransition;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react';
|
|
2
2
|
import { useQuery } from '@apollo/client';
|
|
3
3
|
|
|
4
|
-
import useScript from '@magento/peregrine/lib/hooks/useScript';
|
|
4
|
+
import { useScript } from '@magento/peregrine/lib/hooks/useScript';
|
|
5
5
|
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
6
|
|
|
7
7
|
import defaultOperations from './googleReCaptchaConfig.gql';
|
|
@@ -3,7 +3,7 @@ import { useAppContext } from '../context/app';
|
|
|
3
3
|
|
|
4
4
|
export const SHIMMER_TYPE_SUFFIX = '_SHIMMER';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export const useInternalLink = rootType => {
|
|
7
7
|
const [, appApi] = useAppContext();
|
|
8
8
|
const { actions: appActions } = appApi;
|
|
9
9
|
const { setNextRootComponent } = appActions;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
|
|
3
|
-
import useIntersectionObserver from '@magento/peregrine/lib/hooks/useIntersectionObserver';
|
|
3
|
+
import { useIntersectionObserver } from '@magento/peregrine/lib/hooks/useIntersectionObserver';
|
|
4
4
|
|
|
5
5
|
export const useIsInViewport = props => {
|
|
6
6
|
const { elementRef, renderOnce = true } = props;
|
package/lib/hooks/useScript.js
CHANGED
|
@@ -8,7 +8,7 @@ import { useState, useEffect } from 'react';
|
|
|
8
8
|
*
|
|
9
9
|
* @returns {string} - returns one of the possible status: "idle", "loading", "ready" or "error"
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export const useScript = src => {
|
|
12
12
|
// Keep track of script status ("idle", "loading", "ready", "error")
|
|
13
13
|
const [status, setStatus] = useState(src ? 'loading' : 'idle');
|
|
14
14
|
useEffect(
|
|
@@ -68,8 +68,17 @@ export const usePriceSummary = (props = {}) => {
|
|
|
68
68
|
history.push('/checkout');
|
|
69
69
|
}, [history]);
|
|
70
70
|
|
|
71
|
+
const handleEnterKeyPress = useCallback(() => {
|
|
72
|
+
event => {
|
|
73
|
+
if (event.key === 'Enter') {
|
|
74
|
+
handleProceedToCheckout();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}, [handleProceedToCheckout]);
|
|
78
|
+
|
|
71
79
|
return {
|
|
72
80
|
handleProceedToCheckout,
|
|
81
|
+
handleEnterKeyPress,
|
|
73
82
|
hasError: !!error,
|
|
74
83
|
hasItems: data && !!data.cart.items.length,
|
|
75
84
|
isCheckout,
|
|
@@ -111,6 +120,7 @@ export const usePriceSummary = (props = {}) => {
|
|
|
111
120
|
* @typedef {Object} PriceSummaryTalonProps
|
|
112
121
|
*
|
|
113
122
|
* @property {function} handleProceedToCheckout Callback function which navigates the browser to the checkout
|
|
123
|
+
* * @property {function} handleEnterKeyPress Callback function which navigates the browser to the checkout at the press of enter key
|
|
114
124
|
* @property {boolean} hasError True if a GraphQL query returns an error. False otherwise.
|
|
115
125
|
* @property {boolean} hasItems True if the cart has any items. False otherwise.
|
|
116
126
|
* @property {boolean} isLoading True while the GraphQL query is still in flight. False otherwise.
|
|
@@ -24,6 +24,7 @@ import { useEventingContext } from '../../../context/eventing';
|
|
|
24
24
|
* @returns {{
|
|
25
25
|
* errors: Map,
|
|
26
26
|
* handleSubmit: function,
|
|
27
|
+
* handleEnterKeyPress: function,
|
|
27
28
|
* isDisabled: boolean,
|
|
28
29
|
* initialValues: object,
|
|
29
30
|
* recaptchaWidgetProps: { containerElement: function, shouldRender: boolean }
|
|
@@ -161,6 +162,14 @@ export const useCreateAccount = props => {
|
|
|
161
162
|
]
|
|
162
163
|
);
|
|
163
164
|
|
|
165
|
+
const handleEnterKeyPress = useCallback(() => {
|
|
166
|
+
event => {
|
|
167
|
+
if (event.key === 'Enter') {
|
|
168
|
+
handleSubmit();
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}, [handleSubmit]);
|
|
172
|
+
|
|
164
173
|
const sanitizedInitialValues = useMemo(() => {
|
|
165
174
|
const { email, firstName, lastName, ...rest } = initialValues;
|
|
166
175
|
|
|
@@ -182,6 +191,7 @@ export const useCreateAccount = props => {
|
|
|
182
191
|
return {
|
|
183
192
|
errors,
|
|
184
193
|
handleSubmit,
|
|
194
|
+
handleEnterKeyPress,
|
|
185
195
|
isDisabled: isSubmitting || isGettingDetails || recaptchaLoading,
|
|
186
196
|
initialValues: sanitizedInitialValues,
|
|
187
197
|
recaptchaWidgetProps
|
|
@@ -40,6 +40,7 @@ export const CHECKOUT_STEP = {
|
|
|
40
40
|
* customer: Object,
|
|
41
41
|
* error: ApolloError,
|
|
42
42
|
* handlePlaceOrder: Function,
|
|
43
|
+
* handlePlaceOrderEnterKeyPress: Function,
|
|
43
44
|
* hasError: Boolean,
|
|
44
45
|
* isCartEmpty: Boolean,
|
|
45
46
|
* isGuestCheckout: Boolean,
|
|
@@ -60,6 +61,7 @@ export const CHECKOUT_STEP = {
|
|
|
60
61
|
* scrollShippingMethodIntoView: Function,
|
|
61
62
|
* resetReviewOrderButtonClicked: Function,
|
|
62
63
|
* handleReviewOrder: Function,
|
|
64
|
+
* handleReviewOrderEnterKeyPress: Function,
|
|
63
65
|
* reviewOrderButtonClicked: Boolean,
|
|
64
66
|
* toggleAddressBookContent: Function,
|
|
65
67
|
* toggleSignInContent: Function,
|
|
@@ -182,6 +184,14 @@ export const useCheckoutPage = (props = {}) => {
|
|
|
182
184
|
setReviewOrderButtonClicked(true);
|
|
183
185
|
}, []);
|
|
184
186
|
|
|
187
|
+
const handleReviewOrderEnterKeyPress = useCallback(() => {
|
|
188
|
+
event => {
|
|
189
|
+
if (event.key === 'Enter') {
|
|
190
|
+
handleReviewOrder();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}, [handleReviewOrder]);
|
|
194
|
+
|
|
185
195
|
const resetReviewOrderButtonClicked = useCallback(() => {
|
|
186
196
|
setReviewOrderButtonClicked(false);
|
|
187
197
|
}, []);
|
|
@@ -241,6 +251,14 @@ export const useCheckoutPage = (props = {}) => {
|
|
|
241
251
|
setIsPlacingOrder(true);
|
|
242
252
|
}, [cartId, getOrderDetails]);
|
|
243
253
|
|
|
254
|
+
const handlePlaceOrderEnterKeyPress = useCallback(() => {
|
|
255
|
+
event => {
|
|
256
|
+
if (event.key === 'Enter') {
|
|
257
|
+
handlePlaceOrder();
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}, [handlePlaceOrder]);
|
|
261
|
+
|
|
244
262
|
const [, { dispatch }] = useEventingContext();
|
|
245
263
|
|
|
246
264
|
// Go back to checkout if shopper logs in
|
|
@@ -377,6 +395,7 @@ export const useCheckoutPage = (props = {}) => {
|
|
|
377
395
|
error: checkoutError,
|
|
378
396
|
guestSignInUsername,
|
|
379
397
|
handlePlaceOrder,
|
|
398
|
+
handlePlaceOrderEnterKeyPress,
|
|
380
399
|
hasError: !!checkoutError,
|
|
381
400
|
isCartEmpty: !(checkoutData && checkoutData?.cart?.total_quantity),
|
|
382
401
|
isGuestCheckout: !isSignedIn,
|
|
@@ -401,6 +420,7 @@ export const useCheckoutPage = (props = {}) => {
|
|
|
401
420
|
scrollShippingMethodIntoView,
|
|
402
421
|
resetReviewOrderButtonClicked,
|
|
403
422
|
handleReviewOrder,
|
|
423
|
+
handleReviewOrderEnterKeyPress,
|
|
404
424
|
reviewOrderButtonClicked,
|
|
405
425
|
recaptchaWidgetProps,
|
|
406
426
|
toggleAddressBookContent,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { useContactPage } from './useContactPage';
|
|
2
|
+
export { useContactLink } from './useContactLink';
|
|
@@ -3,7 +3,7 @@ import { useQuery } from '@apollo/client';
|
|
|
3
3
|
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
4
4
|
import DEFAULT_OPERATIONS from './contactUs.gql';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export const useContactLink = (props = {}) => {
|
|
7
7
|
const { getStoreConfigQuery } = mergeOperations(
|
|
8
8
|
DEFAULT_OPERATIONS,
|
|
9
9
|
props.operations
|
|
@@ -3,7 +3,7 @@ import { useMutation, useQuery } from '@apollo/client';
|
|
|
3
3
|
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
4
4
|
import DEFAULT_OPERATIONS from './contactUs.gql';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export const useContactPage = props => {
|
|
7
7
|
const { cmsBlockIdentifiers = [], operations } = props;
|
|
8
8
|
const {
|
|
9
9
|
contactMutation,
|
|
@@ -4,6 +4,7 @@ import { useHistory } from 'react-router-dom';
|
|
|
4
4
|
|
|
5
5
|
import { useCartContext } from '../../context/cart';
|
|
6
6
|
import { useEventingContext } from '../../context/eventing';
|
|
7
|
+
import resourceUrl from '../../util/makeUrl';
|
|
7
8
|
import operations from './addToCart.gql';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -91,7 +92,11 @@ export const useAddToCartButton = props => {
|
|
|
91
92
|
|
|
92
93
|
setIsLoading(false);
|
|
93
94
|
} else if (productType === 'ConfigurableProduct') {
|
|
94
|
-
|
|
95
|
+
const productLink = resourceUrl(
|
|
96
|
+
`/${item.url_key}${urlSuffix || ''}`
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
history.push(productLink);
|
|
95
100
|
} else {
|
|
96
101
|
console.warn('Unsupported product type unable to handle.');
|
|
97
102
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isSupportedProductType as isSupported } from '@magento/peregrine/lib/util/isSupportedProductType';
|
|
2
2
|
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
|
|
3
3
|
import { useCallback, useEffect, useRef } from 'react';
|
|
4
|
-
import useIntersectionObserver from '@magento/peregrine/lib/hooks/useIntersectionObserver';
|
|
4
|
+
import { useIntersectionObserver } from '@magento/peregrine/lib/hooks/useIntersectionObserver';
|
|
5
5
|
|
|
6
6
|
export const useGalleryItem = (props = {}) => {
|
|
7
7
|
const [, { dispatch }] = useEventingContext();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useDropdown } from '@magento/peregrine/lib/hooks/useDropdown';
|
|
4
|
-
|
|
4
|
+
import { useUserContext } from '@magento/peregrine/lib/context/user';
|
|
5
5
|
/**
|
|
6
6
|
* The useAccountTrigger talon complements the AccountTrigger component.
|
|
7
7
|
*
|
|
@@ -25,11 +25,14 @@ export const useAccountTrigger = () => {
|
|
|
25
25
|
setAccountMenuIsOpen(isOpen => !isOpen);
|
|
26
26
|
}, [setAccountMenuIsOpen]);
|
|
27
27
|
|
|
28
|
+
const [{ isSignedIn: isUserSignedIn }] = useUserContext();
|
|
29
|
+
|
|
28
30
|
return {
|
|
29
31
|
accountMenuIsOpen,
|
|
30
32
|
accountMenuRef,
|
|
31
33
|
accountMenuTriggerRef,
|
|
32
34
|
setAccountMenuIsOpen,
|
|
33
|
-
handleTriggerClick
|
|
35
|
+
handleTriggerClick,
|
|
36
|
+
isUserSignedIn
|
|
34
37
|
};
|
|
35
38
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { useLazyQuery } from '@apollo/client';
|
|
3
|
-
import useIntersectionObserver from '../../hooks/useIntersectionObserver';
|
|
3
|
+
import { useIntersectionObserver } from '../../hooks/useIntersectionObserver';
|
|
4
4
|
import resourceUrl from '../../util/makeUrl';
|
|
5
5
|
import mergeOperations from '../../util/shallowMerge';
|
|
6
6
|
import DEFAULT_OPERATIONS from '../MagentoRoute/magentoRoute.gql';
|
|
7
7
|
|
|
8
|
-
const useLink = (props, passedOperations = {}) => {
|
|
8
|
+
export const useLink = (props, passedOperations = {}) => {
|
|
9
9
|
const { innerRef: originalRef, to } = props;
|
|
10
10
|
const shouldPrefetch = props.prefetchType || props.shouldPrefetch;
|
|
11
11
|
const operations = shouldPrefetch
|
|
@@ -65,5 +65,3 @@ const useLink = (props, passedOperations = {}) => {
|
|
|
65
65
|
ref: elementRef
|
|
66
66
|
};
|
|
67
67
|
};
|
|
68
|
-
|
|
69
|
-
export default useLink;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo, useState, useCallback, useEffect } from 'react';
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
|
-
import useInternalLink from '../../hooks/useInternalLink';
|
|
3
|
+
import { useInternalLink } from '../../hooks/useInternalLink';
|
|
4
4
|
|
|
5
5
|
import { useQuery } from '@apollo/client';
|
|
6
6
|
import { useEventListener } from '../../hooks/useEventListener';
|
|
@@ -6,7 +6,7 @@ import { useAppContext } from '../../context/app';
|
|
|
6
6
|
import { useCatalogContext } from '../../context/catalog';
|
|
7
7
|
import { useUserContext } from '../../context/user';
|
|
8
8
|
import { useAwaitQuery } from '../../hooks/useAwaitQuery';
|
|
9
|
-
import useInternalLink from '../../hooks/useInternalLink';
|
|
9
|
+
import { useInternalLink } from '../../hooks/useInternalLink';
|
|
10
10
|
|
|
11
11
|
import DEFAULT_OPERATIONS from './navigation.gql';
|
|
12
12
|
|
|
@@ -17,6 +17,7 @@ export const GET_PRODUCT_THUMBNAILS_BY_URL_KEY = gql`
|
|
|
17
17
|
items {
|
|
18
18
|
uid
|
|
19
19
|
sku
|
|
20
|
+
name
|
|
20
21
|
thumbnail {
|
|
21
22
|
label
|
|
22
23
|
url
|
|
@@ -29,6 +30,7 @@ export const GET_PRODUCT_THUMBNAILS_BY_URL_KEY = gql`
|
|
|
29
30
|
product {
|
|
30
31
|
sku
|
|
31
32
|
uid
|
|
33
|
+
name
|
|
32
34
|
thumbnail {
|
|
33
35
|
label
|
|
34
36
|
url
|
|
@@ -3,7 +3,7 @@ import { useAppContext } from '../../context/app';
|
|
|
3
3
|
|
|
4
4
|
const GROUP_LOADING_DELAY = 750;
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export const usePageLoadingIndicator = () => {
|
|
7
7
|
const [{ isPageLoading }] = useAppContext();
|
|
8
8
|
const doneTimeoutRef = useRef();
|
|
9
9
|
const [loadingState, setLoadingState] = useState('off');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
|
2
2
|
import { useLazyQuery, useQuery } from '@apollo/client';
|
|
3
3
|
import { useLocation } from 'react-router-dom';
|
|
4
|
-
|
|
4
|
+
import { useStoreSwitcher } from '@magento/peregrine/lib/talons/Header/useStoreSwitcher';
|
|
5
5
|
import mergeOperations from '../../util/shallowMerge';
|
|
6
6
|
import { useAppContext } from '../../context/app';
|
|
7
7
|
import { usePagination } from '../../hooks/usePagination';
|
|
@@ -22,7 +22,7 @@ import { useEventingContext } from '../../context/eventing';
|
|
|
22
22
|
export const useSearchPage = (props = {}) => {
|
|
23
23
|
const [, { dispatch }] = useEventingContext();
|
|
24
24
|
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
25
|
-
|
|
25
|
+
const { currentStoreName } = useStoreSwitcher();
|
|
26
26
|
const {
|
|
27
27
|
getFilterInputsQuery,
|
|
28
28
|
getPageSize,
|
|
@@ -286,6 +286,7 @@ export const useSearchPage = (props = {}) => {
|
|
|
286
286
|
pageControl,
|
|
287
287
|
searchCategory,
|
|
288
288
|
searchTerm: inputText,
|
|
289
|
-
sortProps
|
|
289
|
+
sortProps,
|
|
290
|
+
currentStoreName
|
|
290
291
|
};
|
|
291
292
|
};
|
|
@@ -165,6 +165,14 @@ export const useSignIn = props => {
|
|
|
165
165
|
showCreateAccount();
|
|
166
166
|
}, [setDefaultUsername, showCreateAccount]);
|
|
167
167
|
|
|
168
|
+
const handleEnterKeyPress = useCallback(() => {
|
|
169
|
+
event => {
|
|
170
|
+
if (event.key === 'Enter') {
|
|
171
|
+
handleCreateAccount();
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}, [handleCreateAccount]);
|
|
175
|
+
|
|
168
176
|
const errors = useMemo(
|
|
169
177
|
() =>
|
|
170
178
|
new Map([
|
|
@@ -177,6 +185,7 @@ export const useSignIn = props => {
|
|
|
177
185
|
return {
|
|
178
186
|
errors,
|
|
179
187
|
handleCreateAccount,
|
|
188
|
+
handleEnterKeyPress,
|
|
180
189
|
handleForgotPassword,
|
|
181
190
|
handleSubmit,
|
|
182
191
|
isBusy: isGettingDetails || isSigningIn || recaptchaLoading,
|