@magento/peregrine 12.1.0-beta.1 → 12.2.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.
Files changed (110) hide show
  1. package/lib/Apollo/clearCartDataFromCache.js +11 -12
  2. package/lib/Apollo/clearCustomerDataFromCache.js +15 -8
  3. package/lib/Apollo/policies/index.js +35 -3
  4. package/lib/Toasts/useToasts.js +5 -0
  5. package/lib/hooks/useCustomerWishlistSkus/customerWishlist.gql.ce.js +3 -3
  6. package/lib/store/actions/cart/asyncActions.js +1 -2
  7. package/lib/store/actions/user/asyncActions.js +2 -4
  8. package/lib/store/reducers/catalog.js +7 -7
  9. package/lib/store/reducers/user.js +1 -3
  10. package/lib/talons/Adapter/useAdapter.js +80 -11
  11. package/lib/talons/AddToCartDialog/addToCartDialog.gql.js +2 -2
  12. package/lib/talons/AddressBookPage/addressBookPage.gql.js +3 -9
  13. package/lib/talons/Breadcrumbs/breadcrumbs.gql.js +16 -12
  14. package/lib/talons/Breadcrumbs/useBreadcrumbs.js +6 -4
  15. package/lib/talons/CartPage/GiftCards/giftCardQueries.gql.ee.js +2 -2
  16. package/lib/talons/CartPage/PriceAdjustments/CouponCode/couponCode.gql.js +2 -3
  17. package/lib/talons/CartPage/PriceAdjustments/ShippingMethods/shippingMethods.gql.js +1 -1
  18. package/lib/talons/CartPage/PriceSummary/priceSummaryFragments.gql.js +2 -1
  19. package/lib/talons/CartPage/ProductListing/EditModal/productForm.gql.js +3 -3
  20. package/lib/talons/CartPage/ProductListing/EditModal/productFormFragment.gql.js +6 -3
  21. package/lib/talons/CartPage/ProductListing/EditModal/useProductForm.js +1 -0
  22. package/lib/talons/CartPage/ProductListing/product.gql.js +2 -1
  23. package/lib/talons/CartPage/ProductListing/productListing.gql.ce.js +2 -1
  24. package/lib/talons/CartPage/ProductListing/productListing.gql.ee.js +2 -1
  25. package/lib/talons/CartPage/ProductListing/productListingFragments.gql.js +14 -5
  26. package/lib/talons/CartPage/ProductListing/useProduct.js +8 -1
  27. package/lib/talons/CartPage/ProductListing/useProductListing.js +4 -2
  28. package/lib/talons/CartPage/useCartPage.js +4 -3
  29. package/lib/talons/CategoryList/categoryList.gql.js +25 -17
  30. package/lib/talons/CategoryList/useCategoryList.js +6 -1
  31. package/lib/talons/CategoryList/useCategoryTile.js +2 -0
  32. package/lib/talons/CategoryTree/categoryTree.gql.js +18 -12
  33. package/lib/talons/CategoryTree/useCategoryBranch.js +1 -1
  34. package/lib/talons/CategoryTree/useCategoryTree.js +5 -5
  35. package/lib/talons/CheckoutPage/AddressBook/addressBook.gql.js +1 -1
  36. package/lib/talons/CheckoutPage/BillingAddress/billingAddress.gql.js +1 -1
  37. package/lib/talons/CheckoutPage/ItemsReview/__fixtures__/cartItems.js +12 -12
  38. package/lib/talons/CheckoutPage/ItemsReview/itemsReview.gql.js +2 -1
  39. package/lib/talons/CheckoutPage/ItemsReview/itemsReviewFragments.gql.js +11 -5
  40. package/lib/talons/CheckoutPage/OrderConfirmationPage/createAccount.gql.js +12 -6
  41. package/lib/talons/CheckoutPage/PaymentInformation/creditCard.gql.js +2 -2
  42. package/lib/talons/CheckoutPage/PaymentInformation/paymentInformation.gql.js +2 -2
  43. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/customerForm.gql.js +3 -5
  44. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/guestForm.gql.js +12 -4
  45. package/lib/talons/CheckoutPage/ShippingInformation/AddressForm/useGuestForm.js +45 -5
  46. package/lib/talons/CheckoutPage/ShippingInformation/shippingInformation.gql.js +2 -2
  47. package/lib/talons/CheckoutPage/ShippingMethod/shippingMethod.gql.js +1 -1
  48. package/lib/talons/CheckoutPage/checkoutPage.gql.js +2 -2
  49. package/lib/talons/CheckoutPage/checkoutPageFragments.gql.js +4 -2
  50. package/lib/talons/CheckoutPage/useCheckoutPage.js +5 -2
  51. package/lib/talons/Cms/cmsPage.gql.js +0 -4
  52. package/lib/talons/Cms/useCmsPage.js +6 -23
  53. package/lib/talons/CommunicationsPage/communicationsPage.gql.js +2 -2
  54. package/lib/talons/ContactPage/contactUs.gql.js +48 -0
  55. package/lib/talons/ContactPage/index.js +2 -0
  56. package/lib/talons/ContactPage/useContactLink.js +27 -0
  57. package/lib/talons/ContactPage/useContactPage.js +85 -0
  58. package/lib/talons/CreateAccount/createAccount.gql.js +15 -8
  59. package/lib/talons/CreateAccount/useCreateAccount.js +2 -4
  60. package/lib/talons/Footer/footer.gql.js +2 -1
  61. package/lib/talons/FormError/useFormError.js +9 -7
  62. package/lib/talons/Gallery/__fixtures__/apolloMocks.js +2 -2
  63. package/lib/talons/Gallery/gallery.gql.ce.js +2 -1
  64. package/lib/talons/Gallery/gallery.gql.ee.js +2 -1
  65. package/lib/talons/Gallery/useAddToCartButton.js +12 -11
  66. package/lib/talons/Header/storeSwitcher.gql.js +21 -9
  67. package/lib/talons/Header/useCartTrigger.js +3 -3
  68. package/lib/talons/Header/useStoreSwitcher.js +10 -8
  69. package/lib/talons/MagentoRoute/magentoRoute.gql.js +4 -2
  70. package/lib/talons/MagentoRoute/useMagentoRoute.js +39 -33
  71. package/lib/talons/MegaMenu/megaMenu.gql.js +10 -5
  72. package/lib/talons/MegaMenu/useMegaMenu.js +3 -5
  73. package/lib/talons/MegaMenu/useMegaMenuItem.js +5 -0
  74. package/lib/talons/MiniCart/ProductList/productListFragments.gql.js +10 -5
  75. package/lib/talons/MiniCart/miniCart.gql.js +2 -1
  76. package/lib/talons/MiniCart/useMiniCart.js +8 -7
  77. package/lib/talons/Navigation/navigation.gql.js +4 -3
  78. package/lib/talons/Navigation/useNavigation.js +1 -1
  79. package/lib/talons/Newsletter/newsletter.gql.js +14 -1
  80. package/lib/talons/Newsletter/useNewsletter.js +31 -12
  81. package/lib/talons/OrderHistoryPage/orderHistoryContext.gql.js +2 -1
  82. package/lib/talons/OrderHistoryPage/orderHistoryPage.gql.js +1 -1
  83. package/lib/talons/OrderHistoryPage/orderRow.gql.js +7 -3
  84. package/lib/talons/ProductFullDetail/CustomAttributes/AttributeType/useAttributeType.js +26 -0
  85. package/lib/talons/ProductFullDetail/productFullDetail.gql.ce.js +4 -3
  86. package/lib/talons/ProductFullDetail/productFullDetail.gql.ee.js +2 -1
  87. package/lib/talons/ProductFullDetail/useProductFullDetail.js +28 -2
  88. package/lib/talons/RootComponents/Category/category.gql.js +7 -4
  89. package/lib/talons/RootComponents/Category/categoryContent.gql.js +26 -7
  90. package/lib/talons/RootComponents/Category/categoryFragments.gql.js +4 -2
  91. package/lib/talons/RootComponents/Category/useCategory.js +8 -6
  92. package/lib/talons/RootComponents/Category/useCategoryContent.js +30 -3
  93. package/lib/talons/RootComponents/Category/useNoProductsFound.js +0 -1
  94. package/lib/talons/RootComponents/Product/product.gql.js +2 -1
  95. package/lib/talons/RootComponents/Product/productDetailFragment.gql.js +66 -10
  96. package/lib/talons/SearchPage/searchPage.gql.js +17 -2
  97. package/lib/talons/SearchPage/useSearchPage.js +25 -0
  98. package/lib/talons/SignIn/signIn.gql.js +4 -3
  99. package/lib/talons/SignIn/useSignIn.js +2 -4
  100. package/lib/talons/Wishlist/WishlistDialog/wishlistDialog.gql.js +3 -2
  101. package/lib/talons/WishlistPage/createWishlist.gql.js +2 -1
  102. package/lib/talons/WishlistPage/useWishlistItem.js +2 -2
  103. package/lib/talons/WishlistPage/wishlist.gql.js +2 -2
  104. package/lib/talons/WishlistPage/wishlistConfig.gql.ce.js +2 -1
  105. package/lib/talons/WishlistPage/wishlistConfig.gql.ee.js +2 -1
  106. package/lib/talons/WishlistPage/wishlistItemFragments.gql.js +5 -2
  107. package/lib/talons/WishlistPage/wishlistPage.gql.js +1 -1
  108. package/package.json +6 -6
  109. package/lib/Apollo/clearStore.js +0 -26
  110. package/lib/Apollo/deleteCacheEntry.js +0 -87
@@ -9,7 +9,7 @@ import operations from './addToCart.gql';
9
9
  * @param {String} props.item.uid - uid of item
10
10
  * @param {String} props.item.name - name of item
11
11
  * @param {String} props.item.stock_status - stock status of item
12
- * @param {String} props.item.type_id - product type
12
+ * @param {String} props.item.__typename - product type
13
13
  * @param {String} props.item.url_key - item url key
14
14
  * @param {String} props.item.sku - item sku
15
15
  *
@@ -21,20 +21,20 @@ import operations from './addToCart.gql';
21
21
  *
22
22
  */
23
23
  const UNSUPPORTED_PRODUCT_TYPES = [
24
- 'virtual',
25
- 'bundle',
26
- 'grouped',
27
- 'downloadable'
24
+ 'VirtualProduct',
25
+ 'BundleProduct',
26
+ 'GroupedProduct',
27
+ 'DownloadableProduct'
28
28
  ];
29
29
 
30
30
  export const useAddToCartButton = props => {
31
- const { item } = props;
31
+ const { item, urlSuffix } = props;
32
32
 
33
33
  const [isLoading, setIsLoading] = useState(false);
34
34
 
35
35
  const isInStock = item.stock_status === 'IN_STOCK';
36
36
 
37
- const productType = item.type_id;
37
+ const productType = item.__typename;
38
38
  const isUnsupportedProductType = UNSUPPORTED_PRODUCT_TYPES.includes(
39
39
  productType
40
40
  );
@@ -48,7 +48,7 @@ export const useAddToCartButton = props => {
48
48
 
49
49
  const handleAddToCart = useCallback(async () => {
50
50
  try {
51
- if (productType === 'simple') {
51
+ if (productType === 'SimpleProduct') {
52
52
  setIsLoading(true);
53
53
 
54
54
  await addToCart({
@@ -68,8 +68,8 @@ export const useAddToCartButton = props => {
68
68
  });
69
69
 
70
70
  setIsLoading(false);
71
- } else if (productType === 'configurable') {
72
- history.push(`${item.url_key}.html`);
71
+ } else if (productType === 'ConfigurableProduct') {
72
+ history.push(`${item.url_key}${urlSuffix || ''}`);
73
73
  } else {
74
74
  console.warn('Unsupported product type unable to handle.');
75
75
  }
@@ -84,7 +84,8 @@ export const useAddToCartButton = props => {
84
84
  item.url_key,
85
85
  productType,
86
86
  item.uid,
87
- item.name
87
+ item.name,
88
+ urlSuffix
88
89
  ]);
89
90
 
90
91
  return {
@@ -2,34 +2,46 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_STORE_CONFIG_DATA = gql`
4
4
  query getStoreConfigData {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
- code
7
+ store_code
8
8
  store_name
9
9
  store_group_name
10
10
  }
11
11
  }
12
12
  `;
13
13
 
14
- export const GET_URL_RESOLVER_DATA = gql`
15
- query getUrlResolverData($url: String!) {
16
- urlResolver(url: $url) {
17
- id
14
+ export const GET_ROUTE_DATA = gql`
15
+ query getRouteData($url: String!) {
16
+ route(url: $url) {
18
17
  type
18
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
19
+ ... on CmsPage {
20
+ identifier
21
+ }
22
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
23
+ ... on ProductInterface {
24
+ uid
25
+ __typename
26
+ }
27
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
28
+ ... on CategoryInterface {
29
+ uid
30
+ }
19
31
  }
20
32
  }
21
33
  `;
22
34
 
23
35
  export const GET_AVAILABLE_STORES_DATA = gql`
24
36
  query getAvailableStoresData {
37
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
25
38
  availableStores {
26
39
  category_url_suffix
27
- code
28
40
  default_display_currency_code
29
- id
30
41
  locale
31
42
  product_url_suffix
32
43
  secure_base_media_url
44
+ store_code
33
45
  store_group_code
34
46
  store_group_name
35
47
  store_name
@@ -40,6 +52,6 @@ export const GET_AVAILABLE_STORES_DATA = gql`
40
52
 
41
53
  export default {
42
54
  getStoreConfigData: GET_STORE_CONFIG_DATA,
43
- getUrlResolverData: GET_URL_RESOLVER_DATA,
55
+ getRouteData: GET_ROUTE_DATA,
44
56
  getAvailableStoresData: GET_AVAILABLE_STORES_DATA
45
57
  };
@@ -45,14 +45,14 @@ export const useCartTrigger = props => {
45
45
 
46
46
  const { data } = useQuery(getItemCountQuery, {
47
47
  fetchPolicy: 'cache-and-network',
48
- nextFetchPolicy: 'cache-first',
49
48
  variables: {
50
49
  cartId
51
50
  },
52
- skip: !cartId
51
+ skip: !cartId,
52
+ errorPolicy: 'all'
53
53
  });
54
54
 
55
- const itemCount = data ? data.cart.total_quantity : 0;
55
+ const itemCount = data?.cart?.total_quantity || 0;
56
56
 
57
57
  const handleTriggerClick = useCallback(() => {
58
58
  // Open the mini cart.
@@ -9,16 +9,17 @@ import DEFAULT_OPERATIONS from './storeSwitcher.gql';
9
9
  const storage = new BrowserPersistence();
10
10
 
11
11
  const mapAvailableOptions = (config, stores) => {
12
- const { code: configCode } = config;
12
+ const { store_code: configCode } = config;
13
13
 
14
14
  return stores.reduce((map, store) => {
15
15
  const {
16
16
  category_url_suffix,
17
- code,
17
+ store_code: code,
18
18
  default_display_currency_code: currency,
19
19
  locale,
20
20
  product_url_suffix,
21
21
  secure_base_media_url,
22
+ store_code: storeCode,
22
23
  store_group_code: storeGroupCode,
23
24
  store_group_name: storeGroupName,
24
25
  store_name: storeName,
@@ -35,6 +36,7 @@ const mapAvailableOptions = (config, stores) => {
35
36
  product_url_suffix,
36
37
  secure_base_media_url,
37
38
  sortOrder,
39
+ storeCode,
38
40
  storeGroupCode,
39
41
  storeGroupName,
40
42
  storeName
@@ -62,7 +64,7 @@ export const useStoreSwitcher = (props = {}) => {
62
64
  const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
63
65
  const {
64
66
  getStoreConfigData,
65
- getUrlResolverData,
67
+ getRouteData,
66
68
  getAvailableStoresData
67
69
  } = operations;
68
70
  const { pathname } = useLocation();
@@ -78,7 +80,7 @@ export const useStoreSwitcher = (props = {}) => {
78
80
  nextFetchPolicy: 'cache-first'
79
81
  });
80
82
 
81
- const { data: urlResolverData } = useQuery(getUrlResolverData, {
83
+ const { data: routeData } = useQuery(getRouteData, {
82
84
  fetchPolicy: 'cache-first',
83
85
  variables: { url: pathname }
84
86
  });
@@ -102,15 +104,15 @@ export const useStoreSwitcher = (props = {}) => {
102
104
 
103
105
  const currentStoreCode = useMemo(() => {
104
106
  if (storeConfigData) {
105
- return storeConfigData.storeConfig.code;
107
+ return storeConfigData.storeConfig.store_code;
106
108
  }
107
109
  }, [storeConfigData]);
108
110
 
109
111
  const pageType = useMemo(() => {
110
- if (urlResolverData && urlResolverData.urlResolver) {
111
- return urlResolverData.urlResolver.type;
112
+ if (routeData && routeData.route) {
113
+ return routeData.route.type;
112
114
  }
113
- }, [urlResolverData]);
115
+ }, [routeData]);
114
116
 
115
117
  // availableStores => mapped options or empty map if undefined.
116
118
  const availableStores = useMemo(() => {
@@ -9,12 +9,14 @@ export const RESOLVE_URL = gql`
9
9
  ... on CmsPage {
10
10
  identifier
11
11
  }
12
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
12
13
  ... on ProductInterface {
13
- id
14
+ uid
14
15
  __typename
15
16
  }
17
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
16
18
  ... on CategoryInterface {
17
- id
19
+ uid
18
20
  }
19
21
  }
20
22
  }
@@ -28,7 +28,6 @@ export const useMagentoRoute = (props = {}) => {
28
28
 
29
29
  const initialized = useRef(false);
30
30
  const fetchedPathname = useRef(null);
31
- const fetching = useRef(false);
32
31
 
33
32
  const [appState, appApi] = useAppContext();
34
33
  const { actions: appActions } = appApi;
@@ -44,31 +43,13 @@ export const useMagentoRoute = (props = {}) => {
44
43
 
45
44
  const component = componentMap.get(pathname);
46
45
 
47
- const [runQuery, queryResult] = useLazyQuery(resolveUrlQuery, {
48
- onCompleted: async ({ route }) => {
49
- fetching.current = false;
50
- if (!component) {
51
- const { type, ...routeData } = route || {};
52
- try {
53
- const rootComponent = await getRootComponent(type);
54
- setComponent(pathname, {
55
- component: rootComponent,
56
- ...getComponentData(routeData),
57
- type
58
- });
59
- } catch (error) {
60
- setComponent(pathname, error);
61
- }
62
- }
63
- },
64
- onError: () => {
65
- fetching.current = false;
66
- }
67
- });
46
+ const [runQuery, queryResult] = useLazyQuery(resolveUrlQuery);
47
+ // destructure the query result
48
+ const { data, error, loading } = queryResult;
49
+ const { route } = data || {};
68
50
 
69
51
  useEffect(() => {
70
52
  if (initialized.current || !getInlinedPageData()) {
71
- fetching.current = true;
72
53
  runQuery({
73
54
  fetchPolicy: 'cache-and-network',
74
55
  nextFetchPolicy: 'cache-first',
@@ -78,13 +59,42 @@ export const useMagentoRoute = (props = {}) => {
78
59
  }
79
60
  }, [initialized, pathname]); // eslint-disable-line react-hooks/exhaustive-deps
80
61
 
81
- // destructure the query result
82
- const { data, error } = queryResult;
83
- const { route } = data || {};
84
- const { id, redirect_code, relative_url, type } = route || {};
62
+ useEffect(() => {
63
+ if (component) {
64
+ return;
65
+ }
66
+
67
+ (async () => {
68
+ const { type, ...routeData } = route || {};
69
+ const { id, identifier, uid } = routeData || {};
70
+ const isEmpty = !id && !identifier && !uid;
71
+
72
+ if (!type || isEmpty) {
73
+ return;
74
+ }
75
+
76
+ try {
77
+ const rootComponent = await getRootComponent(type);
78
+ setComponent(pathname, {
79
+ component: rootComponent,
80
+ ...getComponentData(routeData),
81
+ type
82
+ });
83
+ } catch (error) {
84
+ if (process.env.NODE_ENV !== 'production') {
85
+ console.error(error);
86
+ }
87
+
88
+ setComponent(pathname, error);
89
+ }
90
+ })();
91
+ }, [route]); // eslint-disable-line react-hooks/exhaustive-deps
92
+
93
+ const { id, identifier, uid, redirect_code, relative_url, type } =
94
+ route || {};
85
95
 
86
96
  // evaluate both results and determine the response type
87
- const empty = !route || !type || id < 1;
97
+ const empty = !route || !type || (!id && !identifier && !uid);
88
98
  const redirect = isRedirect(redirect_code);
89
99
  const fetchError = component instanceof Error && component;
90
100
  const routeError = fetchError || error;
@@ -107,11 +117,7 @@ export const useMagentoRoute = (props = {}) => {
107
117
  ? relative_url
108
118
  : '/' + relative_url
109
119
  };
110
- } else if (
111
- empty &&
112
- fetchedPathname.current === pathname &&
113
- !fetching.current
114
- ) {
120
+ } else if (empty && fetchedPathname.current === pathname && !loading) {
115
121
  // NOT FOUND
116
122
  routeData = { isNotFound: true };
117
123
  } else if (nextRootComponent) {
@@ -1,8 +1,9 @@
1
1
  import { gql } from '@apollo/client';
2
2
  export const GET_STORE_CONFIG_DATA = gql`
3
3
  query GetStoreConfigForMegaMenu {
4
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
4
5
  storeConfig {
5
- id
6
+ store_code
6
7
  category_url_suffix
7
8
  }
8
9
  }
@@ -10,23 +11,27 @@ export const GET_STORE_CONFIG_DATA = gql`
10
11
 
11
12
  export const GET_MEGA_MENU = gql`
12
13
  query getMegaMenu {
14
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
13
15
  categoryList {
14
- id
16
+ uid
15
17
  name
18
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
16
19
  children {
17
- id
20
+ uid
18
21
  include_in_menu
19
22
  name
20
23
  position
21
24
  url_path
25
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
22
26
  children {
23
- id
27
+ uid
24
28
  include_in_menu
25
29
  name
26
30
  position
27
31
  url_path
32
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
28
33
  children {
29
- id
34
+ uid
30
35
  include_in_menu
31
36
  name
32
37
  position
@@ -86,7 +86,7 @@ export const useMegaMenu = (props = {}) => {
86
86
  const megaMenuCategory = Object.assign({}, category);
87
87
 
88
88
  if (!isRoot) {
89
- megaMenuCategory.path = [...path, category.id];
89
+ megaMenuCategory.path = [...path, category.uid];
90
90
  }
91
91
 
92
92
  megaMenuCategory.isActive = isActive(megaMenuCategory);
@@ -131,8 +131,6 @@ export const useMegaMenu = (props = {}) => {
131
131
  }
132
132
  };
133
133
 
134
- useEventListener(globalThis, 'mousedown', handleClickOutside);
135
- useEventListener(globalThis, 'mouseout', handleClickOutside);
136
134
  useEventListener(globalThis, 'keydown', handleClickOutside);
137
135
 
138
136
  const handleSubMenuFocus = useCallback(() => {
@@ -179,7 +177,7 @@ export const useMegaMenu = (props = {}) => {
179
177
  * @property {MegaMenuCategory} megaMenuData - The Object with categories contains only categories
180
178
  * with the include_in_menu = 1 flag. The categories are sorted
181
179
  * based on the field position.
182
- * @property {int} activeCategoryId returns the currently selected category id.
180
+ * @property {String} activeCategoryId returns the currently selected category uid.
183
181
  * @property {String} categoryUrlSuffix store's category url suffix to construct category URL
184
182
  * @property {Function} handleClickOutside function to handle mouse/key events.
185
183
  * @property {Boolean} subMenuState maintaining sub-menu open/close state
@@ -192,7 +190,7 @@ export const useMegaMenu = (props = {}) => {
192
190
  * Object type returned by the {@link useMegaMenu} talon.
193
191
  * @typedef {Object} MegaMenuCategory
194
192
  *
195
- * @property {int} id - id of the category
193
+ * @property {String} uid - uid of the category
196
194
  * @property {int} include_in_menu - describes if category should be included in menu
197
195
  * @property {String} name - name of the category
198
196
  * @property {int} position - value used for sorting
@@ -6,6 +6,10 @@ export const useMegaMenuItem = props => {
6
6
  const [isFocused, setIsFocused] = useState(false);
7
7
  const isActive = category.id === activeCategoryId;
8
8
 
9
+ const handleMenuItemFocus = useCallback(() => {
10
+ setIsFocused(true);
11
+ }, [setIsFocused]);
12
+
9
13
  const handleCloseSubMenu = useCallback(() => {
10
14
  setIsFocused(false);
11
15
  }, [setIsFocused]);
@@ -54,6 +58,7 @@ export const useMegaMenuItem = props => {
54
58
  return {
55
59
  isFocused,
56
60
  isActive,
61
+ handleMenuItemFocus,
57
62
  handleCloseSubMenu,
58
63
  isMenuActive,
59
64
  handleKeyDown
@@ -3,24 +3,27 @@ import { gql } from '@apollo/client';
3
3
  export const ProductListFragment = gql`
4
4
  fragment ProductListFragment on Cart {
5
5
  id
6
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
6
7
  items {
7
- id
8
8
  uid
9
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
9
10
  product {
10
- id
11
+ uid
11
12
  name
12
13
  url_key
13
14
  thumbnail {
14
15
  url
15
16
  }
16
17
  stock_status
18
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
17
19
  ... on ConfigurableProduct {
18
20
  variants {
19
21
  attributes {
20
22
  uid
21
23
  }
24
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
22
25
  product {
23
- id
26
+ uid
24
27
  thumbnail {
25
28
  url
26
29
  }
@@ -35,11 +38,13 @@ export const ProductListFragment = gql`
35
38
  }
36
39
  }
37
40
  quantity
41
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
38
42
  ... on ConfigurableCartItem {
43
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
39
44
  configurable_options {
40
- id
45
+ configurable_product_option_uid
41
46
  option_label
42
- value_id
47
+ configurable_product_option_value_uid
43
48
  value_label
44
49
  }
45
50
  }
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_STORE_CONFIG_DATA = gql`
4
4
  query getStoreConfigForMiniCart {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  product_url_suffix
8
9
  configurable_thumbnail_source
9
10
  }
@@ -45,7 +45,8 @@ export const useMiniCart = props => {
45
45
  fetchPolicy: 'cache-and-network',
46
46
  nextFetchPolicy: 'cache-first',
47
47
  variables: { cartId },
48
- skip: !cartId
48
+ skip: !cartId,
49
+ errorPolicy: 'all'
49
50
  }
50
51
  );
51
52
 
@@ -75,20 +76,20 @@ export const useMiniCart = props => {
75
76
  ] = useMutation(removeItemMutation);
76
77
 
77
78
  const totalQuantity = useMemo(() => {
78
- if (!miniCartLoading && miniCartData) {
79
- return miniCartData.cart.total_quantity;
79
+ if (!miniCartLoading) {
80
+ return miniCartData?.cart?.total_quantity;
80
81
  }
81
82
  }, [miniCartData, miniCartLoading]);
82
83
 
83
84
  const subTotal = useMemo(() => {
84
- if (!miniCartLoading && miniCartData) {
85
- return miniCartData.cart.prices.subtotal_excluding_tax;
85
+ if (!miniCartLoading) {
86
+ return miniCartData?.cart?.prices?.subtotal_excluding_tax;
86
87
  }
87
88
  }, [miniCartData, miniCartLoading]);
88
89
 
89
90
  const productList = useMemo(() => {
90
- if (!miniCartLoading && miniCartData) {
91
- return miniCartData.cart.items;
91
+ if (!miniCartLoading) {
92
+ return miniCartData?.cart?.items;
92
93
  }
93
94
  }, [miniCartData, miniCartLoading]);
94
95
 
@@ -2,8 +2,8 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  export const GET_CUSTOMER = gql`
4
4
  query GetCustomerForLeftNav {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  customer {
6
- id
7
7
  email
8
8
  firstname
9
9
  lastname
@@ -14,9 +14,10 @@ export const GET_CUSTOMER = gql`
14
14
 
15
15
  const GET_ROOT_CATEGORY_ID = gql`
16
16
  query getRootCategoryId {
17
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
17
18
  storeConfig {
18
- id
19
- root_category_id
19
+ store_code
20
+ root_category_uid
20
21
  }
21
22
  }
22
23
  `;
@@ -38,7 +38,7 @@ export const useNavigation = (props = {}) => {
38
38
 
39
39
  const rootCategoryId = useMemo(() => {
40
40
  if (getRootCategoryData) {
41
- return getRootCategoryData.storeConfig.root_category_id;
41
+ return getRootCategoryData.storeConfig.root_category_uid;
42
42
  }
43
43
  }, [getRootCategoryData]);
44
44
 
@@ -1,4 +1,5 @@
1
1
  import { gql } from '@apollo/client';
2
+
2
3
  export const SUBSCRIBE_TO_NEWSLETTER = gql`
3
4
  mutation SubscribeToNewsletter($email: String!) {
4
5
  subscribeEmailToNewsletter(email: $email) {
@@ -6,6 +7,18 @@ export const SUBSCRIBE_TO_NEWSLETTER = gql`
6
7
  }
7
8
  }
8
9
  `;
10
+
11
+ export const GET_STORE_CONFIG_DATA = gql`
12
+ query GetStoreConfigForNewsletter {
13
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
14
+ storeConfig {
15
+ store_code
16
+ newsletter_enabled
17
+ }
18
+ }
19
+ `;
20
+
9
21
  export default {
10
- subscribeMutation: SUBSCRIBE_TO_NEWSLETTER
22
+ subscribeMutation: SUBSCRIBE_TO_NEWSLETTER,
23
+ getStoreConfigQuery: GET_STORE_CONFIG_DATA
11
24
  };
@@ -1,25 +1,42 @@
1
- import { useCallback, useRef, useState, useMemo } from 'react';
2
- import { useMutation } from '@apollo/client';
1
+ import { useCallback, useRef, useMemo, useState } from 'react';
2
+ import { useMutation, useQuery } from '@apollo/client';
3
3
  import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
4
4
  import DEFAULT_OPERATIONS from './newsletter.gql';
5
5
 
6
6
  export const useNewsletter = (props = {}) => {
7
- const { subscribeMutation } = mergeOperations(
7
+ const { subscribeMutation, getStoreConfigQuery } = mergeOperations(
8
8
  DEFAULT_OPERATIONS,
9
9
  props.operations
10
10
  );
11
- const [subscribing, setSubscribing] = useState(false);
12
- const [subscribeNewsLetter, { error: newsLetterError, data }] = useMutation(
13
- subscribeMutation,
11
+
12
+ const formApiRef = useRef(null);
13
+
14
+ const [newsLetterError, setNewsLetterError] = useState(null);
15
+
16
+ const clearErrors = () => setNewsLetterError(null);
17
+
18
+ const [
19
+ subscribeNewsLetter,
20
+ { data, loading: subscribeLoading }
21
+ ] = useMutation(subscribeMutation, {
22
+ fetchPolicy: 'no-cache',
23
+ onError: setNewsLetterError
24
+ });
25
+
26
+ const { data: storeConfigData, loading: configLoading } = useQuery(
27
+ getStoreConfigQuery,
14
28
  {
15
- fetchPolicy: 'no-cache'
29
+ fetchPolicy: 'cache-and-network'
16
30
  }
17
31
  );
18
- const formApiRef = useRef(null);
32
+
33
+ const isEnabled = useMemo(() => {
34
+ return !!storeConfigData?.storeConfig?.newsletter_enabled;
35
+ }, [storeConfigData]);
36
+
19
37
  const setFormApi = useCallback(api => (formApiRef.current = api), []);
20
38
  const handleSubmit = useCallback(
21
39
  async ({ email }) => {
22
- setSubscribing(true);
23
40
  try {
24
41
  await subscribeNewsLetter({
25
42
  variables: { email }
@@ -32,7 +49,6 @@ export const useNewsletter = (props = {}) => {
32
49
  console.error(error);
33
50
  }
34
51
  }
35
- setSubscribing(false);
36
52
  },
37
53
  [subscribeNewsLetter]
38
54
  );
@@ -42,10 +58,13 @@ export const useNewsletter = (props = {}) => {
42
58
  );
43
59
 
44
60
  return {
61
+ isEnabled,
45
62
  errors,
46
63
  handleSubmit,
47
- isBusy: subscribing,
64
+ isBusy: subscribeLoading,
65
+ isLoading: configLoading,
48
66
  setFormApi,
49
- newsLetterResponse: data && data.subscribeEmailToNewsletter
67
+ newsLetterResponse: data && data.subscribeEmailToNewsletter,
68
+ clearErrors
50
69
  };
51
70
  };
@@ -2,8 +2,9 @@ import { gql } from '@apollo/client';
2
2
 
3
3
  const GET_PRODUCT_URL_SUFFIX = gql`
4
4
  query GetProductURLSuffix {
5
+ # eslint-disable-next-line @graphql-eslint/require-id-when-available
5
6
  storeConfig {
6
- id
7
+ store_code
7
8
  product_url_suffix
8
9
  }
9
10
  }