@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,5 @@
|
|
|
1
1
|
import { useEffect, useMemo } from 'react';
|
|
2
|
-
import { useLazyQuery } from '@apollo/client';
|
|
2
|
+
import { useLazyQuery, useQuery } from '@apollo/client';
|
|
3
3
|
|
|
4
4
|
import mergeOperations from '../../util/shallowMerge';
|
|
5
5
|
|
|
@@ -28,7 +28,7 @@ export const useCategoryTree = props => {
|
|
|
28
28
|
const { categoryId, updateCategories } = props;
|
|
29
29
|
|
|
30
30
|
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
31
|
-
const { getNavigationMenuQuery } = operations;
|
|
31
|
+
const { getNavigationMenuQuery, getCategoryUrlSuffixQuery } = operations;
|
|
32
32
|
|
|
33
33
|
const [runQuery, queryResult] = useLazyQuery(getNavigationMenuQuery, {
|
|
34
34
|
fetchPolicy: 'cache-and-network',
|
|
@@ -36,6 +36,15 @@ export const useCategoryTree = props => {
|
|
|
36
36
|
});
|
|
37
37
|
const { data } = queryResult;
|
|
38
38
|
|
|
39
|
+
const { data: categoryUrlData } = useQuery(getCategoryUrlSuffixQuery, {
|
|
40
|
+
fetchPolicy: 'cache-and-network'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const categoryUrlSuffix = useMemo(() => {
|
|
44
|
+
if (categoryUrlData) {
|
|
45
|
+
return categoryUrlData.storeConfig.category_url_suffix;
|
|
46
|
+
}
|
|
47
|
+
}, [categoryUrlData]);
|
|
39
48
|
// fetch categories
|
|
40
49
|
useEffect(() => {
|
|
41
50
|
if (categoryId != null) {
|
|
@@ -79,5 +88,5 @@ export const useCategoryTree = props => {
|
|
|
79
88
|
return childCategories;
|
|
80
89
|
}, [children, rootCategory]);
|
|
81
90
|
|
|
82
|
-
return { childCategories, data };
|
|
91
|
+
return { childCategories, data, categoryUrlSuffix };
|
|
83
92
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
import { SET_CUSTOMER_ADDRESS_ON_CART } from '../ShippingInformation/shippingInformation.gql';
|
|
4
|
+
import { CustomerAddressFragment } from './addressBookFragments.gql';
|
|
5
|
+
import { ShippingInformationFragment } from '../ShippingInformation/shippingInformationFragments.gql';
|
|
6
|
+
|
|
7
|
+
export const GET_CUSTOMER_ADDRESSES = gql`
|
|
8
|
+
query GetCustomerAddresses {
|
|
9
|
+
customer {
|
|
10
|
+
id
|
|
11
|
+
addresses {
|
|
12
|
+
id
|
|
13
|
+
...CustomerAddressFragment
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
${CustomerAddressFragment}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export const GET_CUSTOMER_CART_ADDRESS = gql`
|
|
21
|
+
query GetCustomerCartAddress {
|
|
22
|
+
customerCart {
|
|
23
|
+
id
|
|
24
|
+
...ShippingInformationFragment
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
${ShippingInformationFragment}
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
setCustomerAddressOnCartMutation: SET_CUSTOMER_ADDRESS_ON_CART,
|
|
32
|
+
getCustomerAddressesQuery: GET_CUSTOMER_ADDRESSES,
|
|
33
|
+
getCustomerCartAddressQuery: GET_CUSTOMER_CART_ADDRESS
|
|
34
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const CustomerAddressFragment = gql`
|
|
4
|
+
fragment CustomerAddressFragment on CustomerAddress {
|
|
5
|
+
id
|
|
6
|
+
city
|
|
7
|
+
country_code
|
|
8
|
+
default_shipping
|
|
9
|
+
firstname
|
|
10
|
+
lastname
|
|
11
|
+
postcode
|
|
12
|
+
region {
|
|
13
|
+
region
|
|
14
|
+
region_code
|
|
15
|
+
region_id
|
|
16
|
+
}
|
|
17
|
+
street
|
|
18
|
+
telephone
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const AddressBookFragment = gql`
|
|
23
|
+
fragment AddressBookFragment on Customer {
|
|
24
|
+
id
|
|
25
|
+
addresses {
|
|
26
|
+
id
|
|
27
|
+
...CustomerAddressFragment
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
${CustomerAddressFragment}
|
|
31
|
+
`;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState, useRef, useMemo } from 'react';
|
|
2
2
|
import { useMutation, useQuery } from '@apollo/client';
|
|
3
|
+
import DEFAULT_OPERATIONS from './addressBook.gql';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
3
5
|
|
|
4
6
|
import { useAppContext } from '../../../context/app';
|
|
5
7
|
import { useCartContext } from '../../../context/cart';
|
|
@@ -7,12 +9,14 @@ import { useUserContext } from '../../../context/user';
|
|
|
7
9
|
import { deriveErrorMessage } from '../../../util/deriveErrorMessage';
|
|
8
10
|
|
|
9
11
|
export const useAddressBook = props => {
|
|
12
|
+
const { toggleActiveContent, onSuccess } = props;
|
|
13
|
+
|
|
14
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
10
15
|
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} = props;
|
|
16
|
+
setCustomerAddressOnCartMutation,
|
|
17
|
+
getCustomerAddressesQuery,
|
|
18
|
+
getCustomerCartAddressQuery
|
|
19
|
+
} = operations;
|
|
16
20
|
|
|
17
21
|
const [, { toggleDrawer }] = useAppContext();
|
|
18
22
|
const [{ cartId }] = useCartContext();
|
|
@@ -62,9 +66,13 @@ export const useAddressBook = props => {
|
|
|
62
66
|
customerCartAddressLoading ||
|
|
63
67
|
setCustomerAddressOnCartLoading;
|
|
64
68
|
|
|
65
|
-
const customerAddresses =
|
|
66
|
-
(
|
|
67
|
-
|
|
69
|
+
const customerAddresses = useMemo(
|
|
70
|
+
() =>
|
|
71
|
+
(customerAddressesData &&
|
|
72
|
+
customerAddressesData.customer.addresses) ||
|
|
73
|
+
[],
|
|
74
|
+
[customerAddressesData]
|
|
75
|
+
);
|
|
68
76
|
|
|
69
77
|
useEffect(() => {
|
|
70
78
|
if (customerAddresses.length !== addressCount.current) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const GET_SELECTED_PAYMENT_METHOD = gql`
|
|
4
|
+
query getSelectedPaymentMethod($cartId: String!) {
|
|
5
|
+
cart(cart_id: $cartId) {
|
|
6
|
+
id
|
|
7
|
+
selected_payment_method {
|
|
8
|
+
code
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
getSelectedPaymentMethodQuery: GET_SELECTED_PAYMENT_METHOD
|
|
16
|
+
};
|
|
@@ -120,12 +120,8 @@ export const SET_FREE_PAYMENT_METHOD_ON_CART = gql`
|
|
|
120
120
|
`;
|
|
121
121
|
|
|
122
122
|
export default {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
mutations: {
|
|
128
|
-
setBillingAddressMutation: SET_BILLING_ADDRESS,
|
|
129
|
-
setFreePaymentMethodMutation: SET_FREE_PAYMENT_METHOD_ON_CART
|
|
130
|
-
}
|
|
123
|
+
getPaymentNonceQuery: GET_PAYMENT_NONCE,
|
|
124
|
+
getPaymentInformationQuery: GET_PAYMENT_INFORMATION,
|
|
125
|
+
setBillingAddressMutation: SET_BILLING_ADDRESS,
|
|
126
|
+
setFreePaymentMethodMutation: SET_FREE_PAYMENT_METHOD_ON_CART
|
|
131
127
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const GET_PAYMENT_METHODS = gql`
|
|
4
|
+
query getPaymentMethods($cartId: String!) {
|
|
5
|
+
cart(cart_id: $cartId) {
|
|
6
|
+
id
|
|
7
|
+
available_payment_methods {
|
|
8
|
+
code
|
|
9
|
+
title
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
getPaymentMethodsQuery: GET_PAYMENT_METHODS
|
|
17
|
+
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useState, useCallback } from 'react';
|
|
2
2
|
import { useQuery } from '@apollo/client';
|
|
3
|
+
import DEFAULT_OPERATIONS from './editModal.gql';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
3
5
|
|
|
4
6
|
import { useCartContext } from '../../../context/cart';
|
|
5
7
|
|
|
@@ -7,7 +9,7 @@ import { useCartContext } from '../../../context/cart';
|
|
|
7
9
|
* Talon to handle checkout page's payment information edit modal.
|
|
8
10
|
*
|
|
9
11
|
* @param {Function} props.onClose callback to be called when the modal's close or cancel button is clicked.
|
|
10
|
-
* @param {DocumentNode} props.
|
|
12
|
+
* @param {DocumentNode} props.operations.getSelectedPaymentMethodQuery query to fetch the payment method that was used in the payment information checkout step
|
|
11
13
|
*
|
|
12
14
|
* @returns {
|
|
13
15
|
* selectedPaymentMethod: String,
|
|
@@ -22,11 +24,10 @@ import { useCartContext } from '../../../context/cart';
|
|
|
22
24
|
* }
|
|
23
25
|
*/
|
|
24
26
|
export const useEditModal = props => {
|
|
25
|
-
const {
|
|
26
|
-
onClose,
|
|
27
|
-
queries: { getSelectedPaymentMethodQuery }
|
|
28
|
-
} = props;
|
|
27
|
+
const { onClose } = props;
|
|
29
28
|
|
|
29
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
30
|
+
const { getSelectedPaymentMethodQuery } = operations;
|
|
30
31
|
/**
|
|
31
32
|
* Definitions
|
|
32
33
|
*/
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { useCallback, useState, useEffect } from 'react';
|
|
1
|
+
import { useCallback, useState, useEffect, useMemo } from 'react';
|
|
2
2
|
import { useQuery, useApolloClient, useMutation } from '@apollo/client';
|
|
3
|
+
import DEFAULT_OPERATIONS from './paymentInformation.gql';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
3
5
|
|
|
4
6
|
import { useCartContext } from '../../../context/cart';
|
|
5
7
|
import CheckoutError from '../CheckoutError';
|
|
@@ -9,31 +11,31 @@ import { CHECKOUT_STEP } from '../useCheckoutPage';
|
|
|
9
11
|
*
|
|
10
12
|
* @param {Function} props.onSave callback to be called when user clicks review order button
|
|
11
13
|
* @param {Object} props.checkoutError an instance of the `CheckoutError` error that has been generated using the error from the place order mutation
|
|
12
|
-
* @param {DocumentNode} props.queries.getPaymentNonceQuery query to fetch and/or clear payment nonce from cache
|
|
13
14
|
* @param {Boolean} props.shouldSubmit property telling us to proceed to next step
|
|
14
15
|
* @param {Function} props.resetShouldSubmit callback to reset the review order button flag
|
|
15
|
-
* @param {DocumentNode} props.
|
|
16
|
-
* @param {DocumentNode} props.
|
|
17
|
-
* @param {DocumentNode} props.mutation
|
|
16
|
+
* @param {DocumentNode} props.operations.getPaymentNonceQuery query to fetch and/or clear payment nonce from cache
|
|
17
|
+
* @param {DocumentNode} props.operations.getPaymentInformationQuery query to fetch data to render this component
|
|
18
|
+
* @param {DocumentNode} props.operations.setBillingAddressMutation mutation to set billing address on Cart
|
|
19
|
+
* @param {DocumentNode} props.operations.setFreePaymentMethodMutation mutation to set free payment method on Cart
|
|
18
20
|
*
|
|
19
21
|
* @returns {PaymentInformationTalonProps}
|
|
20
22
|
*/
|
|
21
23
|
export const usePaymentInformation = props => {
|
|
22
24
|
const {
|
|
23
|
-
mutations,
|
|
24
25
|
onSave,
|
|
25
26
|
checkoutError,
|
|
26
|
-
queries,
|
|
27
27
|
resetShouldSubmit,
|
|
28
28
|
setCheckoutStep,
|
|
29
29
|
shouldSubmit
|
|
30
30
|
} = props;
|
|
31
|
-
const {
|
|
32
|
-
setFreePaymentMethodMutation,
|
|
33
|
-
setBillingAddressMutation
|
|
34
|
-
} = mutations;
|
|
35
|
-
const { getPaymentInformation, getPaymentNonceQuery } = queries;
|
|
36
31
|
|
|
32
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
33
|
+
const {
|
|
34
|
+
getPaymentInformationQuery,
|
|
35
|
+
getPaymentNonceQuery,
|
|
36
|
+
setBillingAddressMutation,
|
|
37
|
+
setFreePaymentMethodMutation
|
|
38
|
+
} = operations;
|
|
37
39
|
/**
|
|
38
40
|
* Definitions
|
|
39
41
|
*/
|
|
@@ -73,7 +75,7 @@ export const usePaymentInformation = props => {
|
|
|
73
75
|
const {
|
|
74
76
|
data: paymentInformationData,
|
|
75
77
|
loading: paymentInformationLoading
|
|
76
|
-
} = useQuery(
|
|
78
|
+
} = useQuery(getPaymentInformationQuery, {
|
|
77
79
|
fetchPolicy: 'cache-and-network',
|
|
78
80
|
nextFetchPolicy: 'cache-first',
|
|
79
81
|
skip: !cartId,
|
|
@@ -109,9 +111,13 @@ export const usePaymentInformation = props => {
|
|
|
109
111
|
* Effects
|
|
110
112
|
*/
|
|
111
113
|
|
|
112
|
-
const availablePaymentMethods =
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
const availablePaymentMethods = useMemo(
|
|
115
|
+
() =>
|
|
116
|
+
paymentInformationData
|
|
117
|
+
? paymentInformationData.cart.available_payment_methods
|
|
118
|
+
: [],
|
|
119
|
+
[paymentInformationData]
|
|
120
|
+
);
|
|
115
121
|
|
|
116
122
|
const selectedPaymentMethod =
|
|
117
123
|
(paymentInformationData &&
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { useQuery } from '@apollo/client';
|
|
2
|
-
import
|
|
2
|
+
import useFieldState from '@magento/peregrine/lib/hooks/hook-wrappers/useInformedFieldStateWrapper';
|
|
3
|
+
import DEFAULT_OPERATIONS from './paymentMethods.gql';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
3
5
|
|
|
4
6
|
import { useCartContext } from '../../../context/cart';
|
|
5
7
|
|
|
6
8
|
export const usePaymentMethods = props => {
|
|
7
|
-
const
|
|
8
|
-
const { getPaymentMethodsQuery } =
|
|
9
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
10
|
+
const { getPaymentMethodsQuery } = operations;
|
|
11
|
+
|
|
9
12
|
const [{ cartId }] = useCartContext();
|
|
10
13
|
|
|
11
14
|
const { data, loading } = useQuery(getPaymentMethodsQuery, {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
import { GET_CUSTOMER_ADDRESSES } from '../../AddressBook/addressBook.gql';
|
|
4
|
+
import { CustomerAddressFragment } from '../../AddressBook/addressBookFragments.gql';
|
|
5
|
+
import { GET_DEFAULT_SHIPPING } from '../shippingInformation.gql';
|
|
6
|
+
|
|
7
|
+
export const CREATE_CUSTOMER_ADDRESS_MUTATION = gql`
|
|
8
|
+
mutation CreateCustomerAddress($address: CustomerAddressInput!) {
|
|
9
|
+
createCustomerAddress(input: $address)
|
|
10
|
+
@connection(key: "createCustomerAddress") {
|
|
11
|
+
id
|
|
12
|
+
...CustomerAddressFragment
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
${CustomerAddressFragment}
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* We would normally use the CustomerAddressFragment here for the response
|
|
20
|
+
* but due to GraphQL returning null region data, we return minimal data and
|
|
21
|
+
* rely on refetching after performing this mutation to get accurate data.
|
|
22
|
+
*
|
|
23
|
+
* Fragment will be added back after MC-33948 is resolved.
|
|
24
|
+
*/
|
|
25
|
+
export const UPDATE_CUSTOMER_ADDRESS_MUTATION = gql`
|
|
26
|
+
mutation UpdateCustomerAddress(
|
|
27
|
+
$addressId: Int!
|
|
28
|
+
$address: CustomerAddressInput!
|
|
29
|
+
) {
|
|
30
|
+
updateCustomerAddress(id: $addressId, input: $address)
|
|
31
|
+
@connection(key: "updateCustomerAddress") {
|
|
32
|
+
id
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
export const GET_CUSTOMER_QUERY = gql`
|
|
38
|
+
query GetCustomer {
|
|
39
|
+
customer {
|
|
40
|
+
id
|
|
41
|
+
default_shipping
|
|
42
|
+
email
|
|
43
|
+
firstname
|
|
44
|
+
lastname
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
export default {
|
|
50
|
+
createCustomerAddressMutation: CREATE_CUSTOMER_ADDRESS_MUTATION,
|
|
51
|
+
updateCustomerAddressMutation: UPDATE_CUSTOMER_ADDRESS_MUTATION,
|
|
52
|
+
getCustomerQuery: GET_CUSTOMER_QUERY,
|
|
53
|
+
getCustomerAddressesQuery: GET_CUSTOMER_ADDRESSES,
|
|
54
|
+
getDefaultShippingQuery: GET_DEFAULT_SHIPPING
|
|
55
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { PriceSummaryFragment } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql';
|
|
3
|
+
|
|
4
|
+
import { ShippingInformationFragment } from '../shippingInformationFragments.gql';
|
|
5
|
+
import { ShippingMethodsCheckoutFragment } from '../../ShippingMethod/shippingMethodFragments.gql';
|
|
6
|
+
import { AvailablePaymentMethodsFragment } from '../../PaymentInformation/paymentInformation.gql';
|
|
7
|
+
|
|
8
|
+
export const SET_GUEST_SHIPPING_MUTATION = gql`
|
|
9
|
+
mutation SetGuestShipping(
|
|
10
|
+
$cartId: String!
|
|
11
|
+
$email: String!
|
|
12
|
+
$address: CartAddressInput!
|
|
13
|
+
) {
|
|
14
|
+
setGuestEmailOnCart(input: { cart_id: $cartId, email: $email })
|
|
15
|
+
@connection(key: "setGuestEmailOnCart") {
|
|
16
|
+
cart {
|
|
17
|
+
id
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
setShippingAddressesOnCart(
|
|
22
|
+
input: {
|
|
23
|
+
cart_id: $cartId
|
|
24
|
+
shipping_addresses: [{ address: $address }]
|
|
25
|
+
}
|
|
26
|
+
) @connection(key: "setShippingAddressesOnCart") {
|
|
27
|
+
cart {
|
|
28
|
+
id
|
|
29
|
+
...ShippingInformationFragment
|
|
30
|
+
...ShippingMethodsCheckoutFragment
|
|
31
|
+
...PriceSummaryFragment
|
|
32
|
+
...AvailablePaymentMethodsFragment
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
${ShippingInformationFragment}
|
|
37
|
+
${ShippingMethodsCheckoutFragment}
|
|
38
|
+
${PriceSummaryFragment}
|
|
39
|
+
${AvailablePaymentMethodsFragment}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
export default {
|
|
43
|
+
setGuestShippingMutation: SET_GUEST_SHIPPING_MUTATION
|
|
44
|
+
};
|
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { useCallback, useMemo } from 'react';
|
|
2
2
|
import { useMutation, useQuery } from '@apollo/client';
|
|
3
|
+
import DEFAULT_OPERATIONS from './customerForm.gql';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
3
5
|
|
|
4
6
|
export const useCustomerForm = props => {
|
|
7
|
+
const { afterSubmit, onCancel, onSuccess, shippingData } = props;
|
|
8
|
+
|
|
9
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
5
10
|
const {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
onSuccess,
|
|
13
|
-
queries: {
|
|
14
|
-
getCustomerQuery,
|
|
15
|
-
getCustomerAddressesQuery,
|
|
16
|
-
getDefaultShippingQuery
|
|
17
|
-
},
|
|
18
|
-
shippingData
|
|
19
|
-
} = props;
|
|
11
|
+
createCustomerAddressMutation,
|
|
12
|
+
updateCustomerAddressMutation,
|
|
13
|
+
getCustomerQuery,
|
|
14
|
+
getCustomerAddressesQuery,
|
|
15
|
+
getDefaultShippingQuery
|
|
16
|
+
} = operations;
|
|
20
17
|
|
|
21
18
|
const [
|
|
22
19
|
createCustomerAddress,
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { useCallback, useMemo } from 'react';
|
|
2
2
|
import { useMutation } from '@apollo/client';
|
|
3
|
+
import DEFAULT_OPERATIONS from './guestForm.gql';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
3
5
|
|
|
4
6
|
import { useCartContext } from '../../../../context/cart';
|
|
5
7
|
|
|
6
8
|
export const useGuestForm = props => {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
onSuccess,
|
|
12
|
-
shippingData
|
|
13
|
-
} = props;
|
|
9
|
+
const { afterSubmit, onCancel, onSuccess, shippingData } = props;
|
|
10
|
+
|
|
11
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
12
|
+
const { setGuestShippingMutation } = operations;
|
|
14
13
|
|
|
15
14
|
const [{ cartId }] = useCartContext();
|
|
16
15
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
import { PriceSummaryFragment } from '../../CartPage/PriceSummary/priceSummaryFragments.gql';
|
|
3
|
+
|
|
4
|
+
import { ShippingInformationFragment } from './shippingInformationFragments.gql';
|
|
5
|
+
import { ShippingMethodsCheckoutFragment } from '../ShippingMethod/shippingMethodFragments.gql';
|
|
6
|
+
import { AvailablePaymentMethodsFragment } from '../PaymentInformation/paymentInformation.gql';
|
|
7
|
+
|
|
8
|
+
export const GET_SHIPPING_INFORMATION = gql`
|
|
9
|
+
query GetShippingInformation($cartId: String!) {
|
|
10
|
+
cart(cart_id: $cartId) {
|
|
11
|
+
id
|
|
12
|
+
...ShippingInformationFragment
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
${ShippingInformationFragment}
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export const GET_DEFAULT_SHIPPING = gql`
|
|
19
|
+
query GetDefaultShipping {
|
|
20
|
+
customer {
|
|
21
|
+
id
|
|
22
|
+
default_shipping
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
export const SET_CUSTOMER_ADDRESS_ON_CART = gql`
|
|
28
|
+
mutation SetCustomerAddressOnCart($cartId: String!, $addressId: Int!) {
|
|
29
|
+
setShippingAddressesOnCart(
|
|
30
|
+
input: {
|
|
31
|
+
cart_id: $cartId
|
|
32
|
+
shipping_addresses: [{ customer_address_id: $addressId }]
|
|
33
|
+
}
|
|
34
|
+
) @connection(key: "setShippingAddressesOnCart") {
|
|
35
|
+
cart {
|
|
36
|
+
id
|
|
37
|
+
...ShippingInformationFragment
|
|
38
|
+
...ShippingMethodsCheckoutFragment
|
|
39
|
+
...PriceSummaryFragment
|
|
40
|
+
...AvailablePaymentMethodsFragment
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
${ShippingInformationFragment}
|
|
45
|
+
${ShippingMethodsCheckoutFragment}
|
|
46
|
+
${PriceSummaryFragment}
|
|
47
|
+
${AvailablePaymentMethodsFragment}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
export default {
|
|
51
|
+
setDefaultAddressOnCartMutation: SET_CUSTOMER_ADDRESS_ON_CART,
|
|
52
|
+
getDefaultShippingQuery: GET_DEFAULT_SHIPPING,
|
|
53
|
+
getShippingInformationQuery: GET_SHIPPING_INFORMATION
|
|
54
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { gql } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
export const ShippingInformationFragment = gql`
|
|
4
|
+
fragment ShippingInformationFragment on Cart {
|
|
5
|
+
id
|
|
6
|
+
email
|
|
7
|
+
shipping_addresses {
|
|
8
|
+
city
|
|
9
|
+
country {
|
|
10
|
+
code
|
|
11
|
+
label
|
|
12
|
+
}
|
|
13
|
+
firstname
|
|
14
|
+
lastname
|
|
15
|
+
postcode
|
|
16
|
+
region {
|
|
17
|
+
code
|
|
18
|
+
label
|
|
19
|
+
region_id
|
|
20
|
+
}
|
|
21
|
+
street
|
|
22
|
+
telephone
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useMemo, useState, useRef } from 'react';
|
|
2
2
|
import { useMutation, useQuery } from '@apollo/client';
|
|
3
|
+
import DEFAULT_OPERATIONS from './shippingInformation.gql';
|
|
4
|
+
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
|
|
3
5
|
|
|
4
6
|
import { useAppContext } from '../../../context/app';
|
|
5
7
|
import { useCartContext } from '../../../context/cart';
|
|
@@ -7,12 +9,9 @@ import { useUserContext } from '../../../context/user';
|
|
|
7
9
|
import { MOCKED_ADDRESS } from '../../CartPage/PriceAdjustments/ShippingMethods/useShippingForm';
|
|
8
10
|
|
|
9
11
|
export const useShippingInformation = props => {
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
queries: { getDefaultShippingQuery, getShippingInformationQuery },
|
|
14
|
-
toggleActiveContent
|
|
15
|
-
} = props;
|
|
12
|
+
const { onSave, toggleActiveContent } = props;
|
|
13
|
+
|
|
14
|
+
const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
|
|
16
15
|
|
|
17
16
|
const [, { toggleDrawer }] = useAppContext();
|
|
18
17
|
const [{ cartId }] = useCartContext();
|
|
@@ -21,6 +20,12 @@ export const useShippingInformation = props => {
|
|
|
21
20
|
const [hasUpdate, setHasUpdate] = useState(false);
|
|
22
21
|
const hasLoadedData = useRef(false);
|
|
23
22
|
|
|
23
|
+
const {
|
|
24
|
+
setDefaultAddressOnCartMutation,
|
|
25
|
+
getDefaultShippingQuery,
|
|
26
|
+
getShippingInformationQuery
|
|
27
|
+
} = operations;
|
|
28
|
+
|
|
24
29
|
const {
|
|
25
30
|
data: shippingInformationData,
|
|
26
31
|
loading: getShippingInformationLoading
|