@magento/peregrine 11.0.0-beta.1 → 12.0.0-alpha.3
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/magentoGqlCacheLink.js +59 -0
- package/lib/List/item.js +12 -9
- package/lib/List/list.js +10 -7
- package/lib/Price/price.js +0 -1
- package/lib/context/cart.js +9 -10
- package/lib/hooks/hook-wrappers/useInformedFieldStateWrapper.js +27 -0
- package/lib/hooks/useDelayedTransition.js +127 -0
- package/lib/hooks/useDetectScrollWidth.js +77 -0
- package/lib/hooks/useInternalLink.js +21 -0
- package/lib/hooks/useIntersectionObserver.js +7 -0
- package/lib/hooks/useIsInViewport.js +44 -0
- package/lib/store/actions/app/actions.js +2 -1
- package/lib/store/reducers/app.js +8 -1
- package/lib/talons/AccountInformationPage/useAccountInformationPage.js +0 -1
- package/lib/talons/Adapter/useAdapter.js +23 -3
- package/lib/talons/AddressBookPage/useAddressBookPage.js +0 -10
- package/lib/talons/Breadcrumbs/breadcrumbs.gql.js +11 -2
- package/lib/talons/Breadcrumbs/useBreadcrumbs.js +19 -5
- package/lib/talons/CartPage/GiftCards/giftCardFragments.gql.ee.js +14 -0
- package/lib/talons/CartPage/GiftCards/giftCardFragments.gql.js +8 -0
- package/lib/talons/CartPage/GiftCards/giftCardQueries.gql.ee.js +73 -0
- package/lib/talons/CartPage/GiftCards/useGiftCards.js +25 -16
- package/lib/talons/CartPage/PriceAdjustments/CouponCode/couponCode.gql.js +56 -0
- package/lib/talons/CartPage/PriceAdjustments/CouponCode/couponCodeFragments.gql.js +10 -0
- package/lib/talons/CartPage/PriceAdjustments/{useCouponCode.js → CouponCode/useCouponCode.js} +10 -6
- package/lib/talons/CartPage/{GiftOptions → PriceAdjustments/GiftOptions}/client-schema.graphql +0 -0
- package/lib/talons/CartPage/PriceAdjustments/GiftOptions/giftOptions.gql.js +21 -0
- package/lib/talons/CartPage/{GiftOptions → PriceAdjustments/GiftOptions}/useGiftOptions.js +5 -3
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/shippingMethods.gql.js +43 -0
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/shippingMethodsFragments.gql.js +60 -0
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingForm.js +8 -9
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingMethods.js +7 -5
- package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingRadios.js +1 -1
- package/lib/talons/CartPage/PriceSummary/priceSummary.gql.js +16 -0
- package/lib/talons/CartPage/PriceSummary/usePriceSummary.js +6 -5
- package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +78 -0
- package/lib/talons/CartPage/ProductListing/EditModal/productFormFragment.gql.js +47 -0
- package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +18 -8
- package/lib/talons/CartPage/ProductListing/product.gql.js +4 -3
- package/lib/talons/CartPage/ProductListing/productListing.gql.ce.js +13 -1
- package/lib/talons/CartPage/ProductListing/productListing.gql.ee.js +13 -1
- package/lib/talons/CartPage/ProductListing/productListingFragments.gql.js +52 -0
- package/lib/talons/CartPage/ProductListing/useProduct.js +22 -18
- package/lib/talons/CartPage/ProductListing/useProductListing.js +8 -13
- package/lib/talons/CartPage/ProductListing/useQuantity.js +2 -1
- package/lib/talons/CartPage/cartPage.gql.js +16 -0
- package/lib/talons/CartPage/cartPageFragments.gql.js +21 -0
- package/lib/talons/CartPage/useCartPage.js +7 -6
- package/lib/talons/CategoryList/categoryList.gql.js +11 -2
- package/lib/talons/CategoryList/useCategoryList.js +8 -1
- package/lib/talons/CategoryList/useCategoryTile.js +10 -4
- package/lib/talons/CategoryTree/categoryTree.gql.js +11 -2
- package/lib/talons/CategoryTree/useCategoryTree.js +12 -3
- package/lib/talons/CheckoutPage/AddressBook/addressBook.gql.js +34 -0
- package/lib/talons/CheckoutPage/AddressBook/addressBookFragments.gql.js +31 -0
- package/lib/talons/CheckoutPage/AddressBook/useAddressBook.js +16 -8
- package/lib/talons/CheckoutPage/PaymentInformation/braintreeSummary.gql.js +1 -1
- package/lib/talons/CheckoutPage/PaymentInformation/editModal.gql.js +16 -0
- package/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js +4 -8
- package/lib/talons/CheckoutPage/PaymentInformation/paymentMethods.gql.js +17 -0
- package/lib/talons/CheckoutPage/PaymentInformation/useBraintreeSummary.js +1 -1
- package/lib/talons/CheckoutPage/PaymentInformation/useEditModal.js +6 -5
- package/lib/talons/CheckoutPage/PaymentInformation/usePaymentInformation.js +22 -16
- package/lib/talons/CheckoutPage/PaymentInformation/usePaymentMethods.js +6 -3
- package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/customerForm.gql.js +55 -0
- package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js +44 -0
- package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/useCustomerForm.js +11 -14
- package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/useGuestForm.js +6 -7
- package/lib/talons/CheckoutPage/ShippingInformation/shippingInformation.gql.js +54 -0
- package/lib/talons/CheckoutPage/ShippingInformation/shippingInformationFragments.gql.js +25 -0
- package/lib/talons/CheckoutPage/ShippingInformation/useShippingInformation.js +11 -6
- package/lib/talons/CheckoutPage/ShippingMethod/shippingMethod.gql.js +64 -0
- package/lib/talons/CheckoutPage/ShippingMethod/shippingMethodFragments.gql.js +64 -0
- package/lib/talons/CheckoutPage/{useShippingMethod.js → ShippingMethod/useShippingMethod.js} +11 -8
- package/lib/talons/Cms/cmsPage.gql.js +2 -2
- package/lib/talons/Cms/useCmsPage.js +2 -2
- package/lib/talons/CommunicationsPage/useCommunicationsPage.js +1 -2
- package/lib/talons/CreateAccount/createAccount.gql.js +3 -0
- package/lib/talons/CreateAccount/useCreateAccount.js +2 -4
- package/lib/talons/CreateAccountPage/useCreateAccountPage.js +38 -9
- package/lib/talons/FilterModal/useFilterList.js +17 -3
- package/lib/talons/FilterModal/useFilterModal.js +4 -5
- package/lib/talons/FilterSidebar/useFilterSidebar.js +4 -5
- package/lib/talons/ForgotPasswordPage/useForgotPasswordPage.js +46 -0
- package/lib/talons/FormError/useFormError.js +10 -3
- package/lib/talons/Gallery/__fixtures__/apolloMocks.js +8 -6
- package/lib/talons/Gallery/addToCart.gql.js +17 -0
- package/lib/talons/Gallery/gallery.gql.ce.js +4 -3
- package/lib/talons/Gallery/gallery.gql.ee.js +4 -3
- package/lib/talons/Gallery/useAddToCartButton.js +81 -0
- package/lib/talons/Gallery/useGallery.js +4 -7
- package/lib/talons/Gallery/useGalleryItem.js +7 -1
- package/lib/talons/Header/useCartTrigger.js +14 -7
- package/lib/talons/Link/useLink.js +68 -0
- package/lib/talons/MagentoRoute/magentoRoute.gql.js +12 -3
- package/lib/talons/MagentoRoute/useMagentoRoute.js +115 -30
- package/lib/talons/MegaMenu/megaMenu.gql.js +10 -4
- package/lib/talons/MegaMenu/useMegaMenu.js +61 -11
- package/lib/talons/MegaMenu/useMegaMenuItem.js +61 -0
- package/lib/talons/MegaMenu/useSubMenu.js +20 -0
- package/lib/talons/MiniCart/ProductList/productListFragments.gql.js +0 -1
- package/lib/talons/MiniCart/miniCart.gql.js +4 -3
- package/lib/talons/MiniCart/useMiniCart.js +15 -12
- package/lib/talons/Navigation/useNavigation.js +6 -1
- package/lib/talons/OrderHistoryPage/orderRow.gql.js +0 -1
- package/lib/talons/OrderHistoryPage/useOrderHistoryPage.js +2 -14
- package/lib/talons/PageLoadingIndicator/usePageLoadingIndicator.js +52 -0
- package/lib/talons/Postcode/usePostcode.js +2 -1
- package/lib/talons/ProductFullDetail/useProductFullDetail.js +30 -5
- package/lib/talons/Region/useRegion.js +12 -10
- package/lib/talons/RootComponents/Category/categoryFragments.gql.js +5 -4
- package/lib/talons/RootComponents/Product/productDetailFragment.gql.js +7 -0
- package/lib/talons/SavedPaymentsPage/useSavedPaymentsPage.js +1 -11
- package/lib/talons/SearchBar/useAutocomplete.js +1 -1
- package/lib/talons/SearchBar/useSearchField.js +2 -1
- package/lib/talons/SearchBar/useSuggestedCategory.js +4 -6
- package/lib/talons/SearchPage/searchPage.gql.js +10 -9
- package/lib/talons/SignIn/signIn.gql.js +3 -0
- package/lib/talons/SignInPage/useSignInPage.js +63 -0
- package/lib/talons/Wishlist/AddToListButton/helpers/useSingleWishlist.js +2 -2
- package/lib/talons/Wishlist/AddToListButton/useAddToListButton.ee.js +2 -1
- package/lib/talons/WishlistPage/useActionMenu.js +39 -5
- package/lib/talons/WishlistPage/useWishlist.js +4 -4
- package/lib/talons/WishlistPage/useWishlistPage.js +3 -11
- package/lib/talons/WishlistPage/wishlist.gql.js +1 -1
- package/lib/talons/WishlistPage/wishlistConfig.gql.ce.js +14 -0
- package/lib/talons/WishlistPage/wishlistConfig.gql.ee.js +15 -0
- package/lib/targets/peregrine-declare.js +0 -4
- package/lib/util/deriveErrorMessage.js +12 -6
- package/lib/util/images.js +3 -2
- package/lib/util/isSupportedProductType.js +5 -0
- package/lib/util/magentoRouteData.js +9 -0
- package/package.json +8 -8
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { useQuery } from '@apollo/client';
|
|
3
|
+
import useInternalLink from '../../hooks/useInternalLink';
|
|
3
4
|
|
|
4
5
|
import mergeOperations from '../../util/shallowMerge';
|
|
5
6
|
|
|
@@ -28,14 +29,15 @@ const getPath = (path, suffix) => {
|
|
|
28
29
|
* currentCategory: string,
|
|
29
30
|
* currentCategoryPath: string,
|
|
30
31
|
* isLoading: boolean,
|
|
31
|
-
* normalizedData: array
|
|
32
|
+
* normalizedData: array,
|
|
33
|
+
* handleClick: function
|
|
32
34
|
* }}
|
|
33
35
|
*/
|
|
34
36
|
export const useBreadcrumbs = props => {
|
|
35
37
|
const { categoryId } = props;
|
|
36
38
|
|
|
37
39
|
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
38
|
-
const { getBreadcrumbsQuery } = operations;
|
|
40
|
+
const { getBreadcrumbsQuery, getStoreConfigQuery } = operations;
|
|
39
41
|
|
|
40
42
|
const { data, loading, error } = useQuery(getBreadcrumbsQuery, {
|
|
41
43
|
variables: { category_id: categoryId },
|
|
@@ -43,7 +45,15 @@ export const useBreadcrumbs = props => {
|
|
|
43
45
|
nextFetchPolicy: 'cache-first'
|
|
44
46
|
});
|
|
45
47
|
|
|
46
|
-
const
|
|
48
|
+
const { data: storeConfigData } = useQuery(getStoreConfigQuery, {
|
|
49
|
+
fetchPolicy: 'cache-and-network'
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const categoryUrlSuffix = useMemo(() => {
|
|
53
|
+
if (storeConfigData) {
|
|
54
|
+
return storeConfigData.storeConfig.category_url_suffix;
|
|
55
|
+
}
|
|
56
|
+
}, [storeConfigData]);
|
|
47
57
|
|
|
48
58
|
// When we have breadcrumb data sort and normalize it for easy rendering.
|
|
49
59
|
const normalizedData = useMemo(() => {
|
|
@@ -66,12 +76,16 @@ export const useBreadcrumbs = props => {
|
|
|
66
76
|
}
|
|
67
77
|
}, [categoryUrlSuffix, data, loading]);
|
|
68
78
|
|
|
79
|
+
const { setShimmerType } = useInternalLink('category');
|
|
80
|
+
|
|
69
81
|
return {
|
|
70
82
|
currentCategory: (data && data.category.name) || '',
|
|
71
83
|
currentCategoryPath:
|
|
72
|
-
(data && `${data.category.url_path}${categoryUrlSuffix}`) ||
|
|
84
|
+
(data && `${data.category.url_path}${categoryUrlSuffix || ''}`) ||
|
|
85
|
+
'#',
|
|
73
86
|
isLoading: loading,
|
|
74
87
|
hasError: !!error,
|
|
75
|
-
normalizedData: normalizedData || []
|
|
88
|
+
normalizedData: normalizedData || [],
|
|
89
|
+
handleClick: setShimmerType
|
|
76
90
|
};
|
|
77
91
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
import { CartPageFragment } from '../cartPageFragments.gql';
|
|
4
|
+
import { GiftCardFragment } from './giftCardFragments.gql';
|
|
5
|
+
|
|
6
|
+
const GET_APPLIED_GIFT_CARDS_QUERY = gql`
|
|
7
|
+
query getAppliedGiftCards($cartId: String!) {
|
|
8
|
+
cart(cart_id: $cartId) {
|
|
9
|
+
id
|
|
10
|
+
...GiftCardFragment
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
${GiftCardFragment}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
const GET_GIFT_CARD_BALANCE_QUERY = gql`
|
|
17
|
+
query getGiftCardBalance($giftCardCode: String!) {
|
|
18
|
+
giftCardAccount(input: { gift_card_code: $giftCardCode }) {
|
|
19
|
+
balance {
|
|
20
|
+
currency
|
|
21
|
+
value
|
|
22
|
+
}
|
|
23
|
+
code
|
|
24
|
+
expiration_date
|
|
25
|
+
id: code
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
const APPLY_GIFT_CARD_MUTATION = gql`
|
|
31
|
+
mutation applyGiftCardToCart($cartId: String!, $giftCardCode: String!) {
|
|
32
|
+
applyGiftCardToCart(
|
|
33
|
+
input: { cart_id: $cartId, gift_card_code: $giftCardCode }
|
|
34
|
+
) @connection(key: "applyGiftCardToCart") {
|
|
35
|
+
cart {
|
|
36
|
+
id
|
|
37
|
+
...CartPageFragment
|
|
38
|
+
# If this mutation causes "free" to become available we need to know.
|
|
39
|
+
available_payment_methods {
|
|
40
|
+
code
|
|
41
|
+
title
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
${CartPageFragment}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
const REMOVE_GIFT_CARD_MUTATION = gql`
|
|
50
|
+
mutation removeGiftCard($cartId: String!, $giftCardCode: String!) {
|
|
51
|
+
removeGiftCardFromCart(
|
|
52
|
+
input: { cart_id: $cartId, gift_card_code: $giftCardCode }
|
|
53
|
+
) @connection(key: "removeGiftCardFromCart") {
|
|
54
|
+
cart {
|
|
55
|
+
id
|
|
56
|
+
...CartPageFragment
|
|
57
|
+
# If this mutation causes "free" to become available we need to know.
|
|
58
|
+
available_payment_methods {
|
|
59
|
+
code
|
|
60
|
+
title
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
${CartPageFragment}
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
export default {
|
|
69
|
+
getAppliedGiftCardsQuery: GET_APPLIED_GIFT_CARDS_QUERY,
|
|
70
|
+
getGiftCardBalanceQuery: GET_GIFT_CARD_BALANCE_QUERY,
|
|
71
|
+
applyGiftCardMutation: APPLY_GIFT_CARD_MUTATION,
|
|
72
|
+
removeGiftCardMutation: REMOVE_GIFT_CARD_MUTATION
|
|
73
|
+
};
|
|
@@ -3,6 +3,8 @@ import { useFormApi } from 'informed';
|
|
|
3
3
|
import { useLazyQuery, useMutation, useQuery } from '@apollo/client';
|
|
4
4
|
|
|
5
5
|
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
6
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
7
|
+
import DEFAULT_OPERATIONS from './giftCardQueries.gql';
|
|
6
8
|
|
|
7
9
|
// To keep track of the most recent action taken.
|
|
8
10
|
const actions = {
|
|
@@ -34,11 +36,15 @@ const actions = {
|
|
|
34
36
|
* import { useGiftCards } from '@magento/peregrine/lib/talons/CartPage/GiftCards'
|
|
35
37
|
*/
|
|
36
38
|
export const useGiftCards = props => {
|
|
39
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
37
40
|
const {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
getAppliedGiftCardsQuery,
|
|
42
|
+
getGiftCardBalanceQuery,
|
|
43
|
+
applyGiftCardMutation,
|
|
44
|
+
removeGiftCardMutation
|
|
45
|
+
} = operations;
|
|
46
|
+
|
|
47
|
+
const { setIsCartUpdating } = props;
|
|
42
48
|
|
|
43
49
|
// We need the cartId for all of our queries and mutations.
|
|
44
50
|
const [{ cartId }] = useCartContext();
|
|
@@ -50,21 +56,24 @@ export const useGiftCards = props => {
|
|
|
50
56
|
*
|
|
51
57
|
* Immediately execute the cart query and set up the other graphql actions.
|
|
52
58
|
*/
|
|
53
|
-
const appliedCardsResult = useQuery(
|
|
59
|
+
const appliedCardsResult = useQuery(getAppliedGiftCardsQuery, {
|
|
54
60
|
fetchPolicy: 'cache-and-network',
|
|
55
61
|
nextFetchPolicy: 'cache-first',
|
|
56
62
|
skip: !cartId,
|
|
57
63
|
variables: { cartId }
|
|
58
64
|
});
|
|
59
65
|
|
|
60
|
-
const [checkCardBalance, balanceResult] = useLazyQuery(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
const [checkCardBalance, balanceResult] = useLazyQuery(
|
|
67
|
+
getGiftCardBalanceQuery,
|
|
68
|
+
{
|
|
69
|
+
// For security, always fetch this from the network and never cache the
|
|
70
|
+
// result.
|
|
71
|
+
fetchPolicy: 'no-cache'
|
|
72
|
+
}
|
|
73
|
+
);
|
|
65
74
|
|
|
66
|
-
const [applyCard, applyCardResult] = useMutation(
|
|
67
|
-
const [removeCard, removeCardResult] = useMutation(
|
|
75
|
+
const [applyCard, applyCardResult] = useMutation(applyGiftCardMutation);
|
|
76
|
+
const [removeCard, removeCardResult] = useMutation(removeGiftCardMutation);
|
|
68
77
|
|
|
69
78
|
/*
|
|
70
79
|
* useState hooks.
|
|
@@ -177,8 +186,8 @@ export const useGiftCards = props => {
|
|
|
177
186
|
*
|
|
178
187
|
* @typedef {Object} GiftCardsMutations
|
|
179
188
|
*
|
|
180
|
-
* @property {GraphQLAST}
|
|
181
|
-
* @property {GraphQLAST}
|
|
189
|
+
* @property {GraphQLAST} applyGiftCardMutation The mutation used to apply a gift card to the cart.
|
|
190
|
+
* @property {GraphQLAST} removeGiftCardMutation The mutation used to remove a gift card from the cart.
|
|
182
191
|
*
|
|
183
192
|
* @see [`giftCardQueries.ee.js`]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/CartPage/GiftCards/giftCardQueries.js}
|
|
184
193
|
* for queries used in Venia
|
|
@@ -189,8 +198,8 @@ export const useGiftCards = props => {
|
|
|
189
198
|
*
|
|
190
199
|
* @typedef {Object} GiftCardsQueries
|
|
191
200
|
*
|
|
192
|
-
* @property {GraphQLAST}
|
|
193
|
-
* @property {GraphQLAST}
|
|
201
|
+
* @property {GraphQLAST} getAppliedGiftCardsQuery The query used to get the gift cards currently applied to the cart.
|
|
202
|
+
* @property {GraphQLAST} getGiftCardBalanceQuery The query used to get the gift cards currently applied to the cart.
|
|
194
203
|
*
|
|
195
204
|
* @see [`giftCardQueries.ee.js`]{@link https://github.com/magento/pwa-studio/blob/develop/packages/venia-ui/lib/components/CartPage/GiftCards/giftCardQueries.js}
|
|
196
205
|
* for queries used in Venia
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { CartPageFragment } from '../../cartPageFragments.gql';
|
|
3
|
+
import { AppliedCouponsFragment } from './couponCodeFragments.gql';
|
|
4
|
+
|
|
5
|
+
const GET_APPLIED_COUPONS = gql`
|
|
6
|
+
query getAppliedCoupons($cartId: String!) {
|
|
7
|
+
cart(cart_id: $cartId) {
|
|
8
|
+
id
|
|
9
|
+
...AppliedCouponsFragment
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
${AppliedCouponsFragment}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
const APPLY_COUPON_MUTATION = gql`
|
|
16
|
+
mutation applyCouponToCart($cartId: String!, $couponCode: String!) {
|
|
17
|
+
applyCouponToCart(
|
|
18
|
+
input: { cart_id: $cartId, coupon_code: $couponCode }
|
|
19
|
+
) @connection(key: "applyCouponToCart") {
|
|
20
|
+
cart {
|
|
21
|
+
id
|
|
22
|
+
...CartPageFragment
|
|
23
|
+
# If this mutation causes "free" to become available we need to know.
|
|
24
|
+
available_payment_methods {
|
|
25
|
+
code
|
|
26
|
+
title
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
${CartPageFragment}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const REMOVE_COUPON_MUTATION = gql`
|
|
35
|
+
mutation removeCouponFromCart($cartId: String!) {
|
|
36
|
+
removeCouponFromCart(input: { cart_id: $cartId })
|
|
37
|
+
@connection(key: "removeCouponFromCart") {
|
|
38
|
+
cart {
|
|
39
|
+
id
|
|
40
|
+
...CartPageFragment
|
|
41
|
+
# If this mutation causes "free" to become available we need to know.
|
|
42
|
+
available_payment_methods {
|
|
43
|
+
code
|
|
44
|
+
title
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
${CartPageFragment}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
export default {
|
|
53
|
+
getAppliedCouponsQuery: GET_APPLIED_COUPONS,
|
|
54
|
+
applyCouponMutation: APPLY_COUPON_MUTATION,
|
|
55
|
+
removeCouponMutation: REMOVE_COUPON_MUTATION
|
|
56
|
+
};
|
package/lib/talons/CartPage/PriceAdjustments/{useCouponCode.js → CouponCode/useCouponCode.js}
RENAMED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useMutation, useQuery } from '@apollo/client';
|
|
3
3
|
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
5
|
+
import DEFAULT_OPERATIONS from './couponCode.gql';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* This talon contains the logic for a coupon code form component.
|
|
@@ -21,14 +23,16 @@ import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
|
21
23
|
* @return {CouponCodeTalonProps}
|
|
22
24
|
*
|
|
23
25
|
* @example <caption>Importing into your project</caption>
|
|
24
|
-
* import { useCouponCode } from '@magento/peregrine/lib/talons/CartPage/PriceAdjustments/useCouponCode';
|
|
26
|
+
* import { useCouponCode } from '@magento/peregrine/lib/talons/CartPage/PriceAdjustments/CouponCode/useCouponCode';
|
|
25
27
|
*/
|
|
26
28
|
export const useCouponCode = props => {
|
|
29
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
27
30
|
const {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
} =
|
|
31
|
+
getAppliedCouponsQuery,
|
|
32
|
+
applyCouponMutation,
|
|
33
|
+
removeCouponMutation
|
|
34
|
+
} = operations;
|
|
35
|
+
const { setIsCartUpdating } = props;
|
|
32
36
|
|
|
33
37
|
const [{ cartId }] = useCartContext();
|
|
34
38
|
const { data, error: fetchError } = useQuery(getAppliedCouponsQuery, {
|
package/lib/talons/CartPage/{GiftOptions → PriceAdjustments/GiftOptions}/client-schema.graphql
RENAMED
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Local query. GQL support is not available as of today.
|
|
5
|
+
*
|
|
6
|
+
* Once available, we can change the query to match the schema.
|
|
7
|
+
*/
|
|
8
|
+
const GET_GIFT_OPTIONS = gql`
|
|
9
|
+
query getGiftOptions($cartId: String!) {
|
|
10
|
+
cart(cart_id: $cartId) @client {
|
|
11
|
+
id
|
|
12
|
+
include_gift_receipt
|
|
13
|
+
include_printed_card
|
|
14
|
+
local_gift_message
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
getGiftOptionsQuery: GET_GIFT_OPTIONS
|
|
21
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useCallback, useRef, useState } from 'react';
|
|
2
2
|
import { useApolloClient, useQuery } from '@apollo/client';
|
|
3
3
|
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
5
|
+
import DEFAULT_OPERATIONS from './giftOptions.gql';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* This talon contains the logic for a gift options component.
|
|
@@ -22,9 +24,9 @@ import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
|
22
24
|
* @example <caption>Importing into your project</caption>
|
|
23
25
|
* import { useGiftOptions } from '@magento/peregrine/lib/talons/CartPage/GiftOptions/useGiftOptions';
|
|
24
26
|
*/
|
|
25
|
-
const useGiftOptions = props => {
|
|
26
|
-
const
|
|
27
|
-
const { getGiftOptionsQuery } =
|
|
27
|
+
const useGiftOptions = (props = {}) => {
|
|
28
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
29
|
+
const { getGiftOptionsQuery } = operations;
|
|
28
30
|
|
|
29
31
|
const [{ cartId }] = useCartContext();
|
|
30
32
|
const { cache } = useApolloClient();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { ShippingInformationFragment } from '@magento/peregrine/lib/talons/CheckoutPage/ShippingInformation/shippingInformationFragments.gql.js';
|
|
3
|
+
import { CartPageFragment } from '../../cartPageFragments.gql';
|
|
4
|
+
import { ShippingMethodsCartFragment } from './shippingMethodsFragments.gql';
|
|
5
|
+
|
|
6
|
+
const GET_SHIPPING_METHODS = gql`
|
|
7
|
+
query GetShippingMethods($cartId: String!) {
|
|
8
|
+
cart(cart_id: $cartId) {
|
|
9
|
+
id
|
|
10
|
+
...ShippingMethodsCartFragment
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
${ShippingMethodsCartFragment}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
const SET_SHIPPING_ADDRESS_MUTATION = gql`
|
|
17
|
+
mutation SetShippingAddressForEstimate(
|
|
18
|
+
$cartId: String!
|
|
19
|
+
$address: CartAddressInput!
|
|
20
|
+
) {
|
|
21
|
+
setShippingAddressesOnCart(
|
|
22
|
+
input: {
|
|
23
|
+
cart_id: $cartId
|
|
24
|
+
shipping_addresses: [{ address: $address }]
|
|
25
|
+
}
|
|
26
|
+
) @connection(key: "setShippingAddressesOnCart") {
|
|
27
|
+
cart {
|
|
28
|
+
id
|
|
29
|
+
...CartPageFragment
|
|
30
|
+
...ShippingMethodsCartFragment
|
|
31
|
+
...ShippingInformationFragment
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
${CartPageFragment}
|
|
36
|
+
${ShippingMethodsCartFragment}
|
|
37
|
+
${ShippingInformationFragment}
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
export default {
|
|
41
|
+
getShippingMethodsQuery: GET_SHIPPING_METHODS,
|
|
42
|
+
setShippingAddressMutation: SET_SHIPPING_ADDRESS_MUTATION
|
|
43
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WARNING: This fragment can cause slowdowns on the network request because it
|
|
5
|
+
* causes the backend to make remote queries to carriers for real-time data.
|
|
6
|
+
* It is intentionally not included in the CartPageFragment. Make sure you are
|
|
7
|
+
* conscious about the side effects when including it in queries and mutations.
|
|
8
|
+
*/
|
|
9
|
+
export const AvailableShippingMethodsCartFragment = gql`
|
|
10
|
+
fragment AvailableShippingMethodsCartFragment on Cart {
|
|
11
|
+
id
|
|
12
|
+
shipping_addresses {
|
|
13
|
+
available_shipping_methods {
|
|
14
|
+
amount {
|
|
15
|
+
currency
|
|
16
|
+
value
|
|
17
|
+
}
|
|
18
|
+
available
|
|
19
|
+
carrier_code
|
|
20
|
+
carrier_title
|
|
21
|
+
method_code
|
|
22
|
+
method_title
|
|
23
|
+
}
|
|
24
|
+
street
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
export const SelectedShippingMethodCartFragment = gql`
|
|
30
|
+
fragment SelectedShippingMethodCartFragment on Cart {
|
|
31
|
+
id
|
|
32
|
+
shipping_addresses {
|
|
33
|
+
selected_shipping_method {
|
|
34
|
+
carrier_code
|
|
35
|
+
method_code
|
|
36
|
+
}
|
|
37
|
+
street
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
export const ShippingMethodsCartFragment = gql`
|
|
43
|
+
fragment ShippingMethodsCartFragment on Cart {
|
|
44
|
+
id
|
|
45
|
+
...AvailableShippingMethodsCartFragment
|
|
46
|
+
...SelectedShippingMethodCartFragment
|
|
47
|
+
shipping_addresses {
|
|
48
|
+
country {
|
|
49
|
+
code
|
|
50
|
+
}
|
|
51
|
+
postcode
|
|
52
|
+
region {
|
|
53
|
+
code
|
|
54
|
+
}
|
|
55
|
+
street
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
${AvailableShippingMethodsCartFragment}
|
|
59
|
+
${SelectedShippingMethodCartFragment}
|
|
60
|
+
`;
|
|
@@ -2,6 +2,8 @@ import { useCallback, useEffect, useMemo } from 'react';
|
|
|
2
2
|
import { useApolloClient, useMutation } from '@apollo/client';
|
|
3
3
|
|
|
4
4
|
import { useCartContext } from '../../../../context/cart';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import DEFAULT_OPERATIONS from './shippingMethods.gql';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* GraphQL currently requires a complete address before it will return
|
|
@@ -43,12 +45,9 @@ export const MOCKED_ADDRESS = {
|
|
|
43
45
|
* import { useShippingForm } from '@magento/peregrine/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingForm';
|
|
44
46
|
*/
|
|
45
47
|
export const useShippingForm = props => {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
mutations: { setShippingAddressMutation },
|
|
50
|
-
queries: { shippingMethodsQuery }
|
|
51
|
-
} = props;
|
|
48
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
49
|
+
const { setShippingAddressMutation, getShippingMethodsQuery } = operations;
|
|
50
|
+
const { selectedValues, setIsCartUpdating } = props;
|
|
52
51
|
|
|
53
52
|
const [{ cartId }] = useCartContext();
|
|
54
53
|
const apolloClient = useApolloClient();
|
|
@@ -81,7 +80,7 @@ export const useShippingForm = props => {
|
|
|
81
80
|
zip => {
|
|
82
81
|
if (zip !== selectedValues.zip) {
|
|
83
82
|
const data = apolloClient.readQuery({
|
|
84
|
-
query:
|
|
83
|
+
query: getShippingMethodsQuery,
|
|
85
84
|
variables: {
|
|
86
85
|
cartId
|
|
87
86
|
}
|
|
@@ -97,7 +96,7 @@ export const useShippingForm = props => {
|
|
|
97
96
|
} = primaryAddress;
|
|
98
97
|
if (availableMethods.length) {
|
|
99
98
|
apolloClient.writeQuery({
|
|
100
|
-
query:
|
|
99
|
+
query: getShippingMethodsQuery,
|
|
101
100
|
data: {
|
|
102
101
|
cart: {
|
|
103
102
|
...cart,
|
|
@@ -115,7 +114,7 @@ export const useShippingForm = props => {
|
|
|
115
114
|
}
|
|
116
115
|
}
|
|
117
116
|
},
|
|
118
|
-
[apolloClient, cartId, selectedValues.zip,
|
|
117
|
+
[apolloClient, cartId, selectedValues.zip, getShippingMethodsQuery]
|
|
119
118
|
);
|
|
120
119
|
|
|
121
120
|
const handleOnSubmit = useCallback(
|
|
@@ -2,6 +2,8 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
2
2
|
import { useQuery } from '@apollo/client';
|
|
3
3
|
|
|
4
4
|
import { useCartContext } from '../../../../context/cart';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import DEFAULT_OPERATIONS from './shippingMethods.gql';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Contains logic for a shipping method selector component.
|
|
@@ -21,10 +23,10 @@ import { useCartContext } from '../../../../context/cart';
|
|
|
21
23
|
* @example <caption>Importing into your project</caption>
|
|
22
24
|
* import { useShippingMethods } from '@magento/peregrine/lib/talons/CartPage/PriceAdjustments/ShippingMethods/useShippingMethods';
|
|
23
25
|
*/
|
|
24
|
-
export const useShippingMethods = props => {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
export const useShippingMethods = (props = {}) => {
|
|
27
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
28
|
+
const { getShippingMethodsQuery } = operations;
|
|
29
|
+
|
|
28
30
|
const [{ cartId }] = useCartContext();
|
|
29
31
|
const { data } = useQuery(getShippingMethodsQuery, {
|
|
30
32
|
fetchPolicy: 'cache-and-network',
|
|
@@ -118,7 +120,7 @@ export const useShippingMethods = props => {
|
|
|
118
120
|
* Can be used as a boolean value since having no shipping methods would return 0.
|
|
119
121
|
* @property {boolean} isShowingForm True if the form should be shown. False otherwise.
|
|
120
122
|
* @property {SelectShippingFields} selectedShippingFields Values for the select input fields on the shipping form
|
|
121
|
-
* @property {String} selectedShippingMethod A serialized string of <carrier-code
|
|
123
|
+
* @property {String} selectedShippingMethod A serialized string of <inlineCode>${carrier-code}\|${method-code}</inlineCode>, eg. <inlineCode>usps\|priority</inlineCode>.
|
|
122
124
|
* @property {Array<Object>} shippingMethods A list of available shipping methods based on the primary shipping address
|
|
123
125
|
* @property {function} showForm A function that sets the `isShowingForm` value to true.
|
|
124
126
|
*/
|
|
@@ -17,7 +17,7 @@ import { useCartContext } from '../../../../context/cart';
|
|
|
17
17
|
*
|
|
18
18
|
* @param {Object} props
|
|
19
19
|
* @param {function} props.setIsCartUpdating Function for setting the updating state of the shopping cart
|
|
20
|
-
* @param {String} props.selectedShippingMethod A serialized string of <carrier-code
|
|
20
|
+
* @param {String} props.selectedShippingMethod A serialized string of <inlineCode>${carrier-code}\|${method-code}</inlineCode>, eg. <inlineCode>usps\|priority</inlineCode>.
|
|
21
21
|
* @param {Array<Object>} props.shippingMethods An array of available shipping methods
|
|
22
22
|
* @param {ShippingRadiosMutations} props.mutations GraphQL mutations for a shipping radio selector component.
|
|
23
23
|
*
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { PriceSummaryFragment } from './priceSummaryFragments.gql';
|
|
3
|
+
|
|
4
|
+
const GET_PRICE_SUMMARY = gql`
|
|
5
|
+
query getPriceSummary($cartId: String!) {
|
|
6
|
+
cart(cart_id: $cartId) {
|
|
7
|
+
id
|
|
8
|
+
...PriceSummaryFragment
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
${PriceSummaryFragment}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
getPriceSummaryQuery: GET_PRICE_SUMMARY
|
|
16
|
+
};
|
|
@@ -2,6 +2,8 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import { useHistory, useRouteMatch } from 'react-router-dom';
|
|
3
3
|
import { useQuery } from '@apollo/client';
|
|
4
4
|
import { useCartContext } from '@magento/peregrine/lib/context/cart';
|
|
5
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
6
|
+
import DEFAULT_OPERATIONS from './priceSummary.gql';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* @ignore
|
|
@@ -42,10 +44,9 @@ const flattenData = data => {
|
|
|
42
44
|
* @example <caption>Importing into your project</caption>
|
|
43
45
|
* import { usePriceSummary } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary';
|
|
44
46
|
*/
|
|
45
|
-
export const usePriceSummary = props => {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
} = props;
|
|
47
|
+
export const usePriceSummary = (props = {}) => {
|
|
48
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
49
|
+
const { getPriceSummaryQuery } = operations;
|
|
49
50
|
|
|
50
51
|
const [{ cartId }] = useCartContext();
|
|
51
52
|
const history = useHistory();
|
|
@@ -53,7 +54,7 @@ export const usePriceSummary = props => {
|
|
|
53
54
|
const match = useRouteMatch('/checkout');
|
|
54
55
|
const isCheckout = !!match;
|
|
55
56
|
|
|
56
|
-
const { error, loading, data } = useQuery(
|
|
57
|
+
const { error, loading, data } = useQuery(getPriceSummaryQuery, {
|
|
57
58
|
fetchPolicy: 'cache-and-network',
|
|
58
59
|
nextFetchPolicy: 'cache-first',
|
|
59
60
|
skip: !cartId,
|