@shopgate/pwa-common-commerce 7.30.0-alpha.6 → 7.30.0-alpha.8
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/cart/action-creators/addCouponsToCart.js +9 -2
- package/cart/action-creators/addProductsToCart.js +9 -2
- package/cart/action-creators/deleteCouponsFromCart.js +9 -2
- package/cart/action-creators/deleteProductsFromCart.js +9 -2
- package/cart/action-creators/errorAddCouponsToCart.js +10 -2
- package/cart/action-creators/errorAddProductsToCart.js +10 -2
- package/cart/action-creators/errorCart.js +8 -2
- package/cart/action-creators/errorDeleteCouponsFromCart.js +10 -2
- package/cart/action-creators/errorDeleteProductsFromCart.js +10 -2
- package/cart/action-creators/errorUpdateProductsInCart.js +10 -2
- package/cart/action-creators/receiveCart.js +9 -2
- package/cart/action-creators/requestCart.js +8 -2
- package/cart/action-creators/setCartProductPendingCount.js +9 -2
- package/cart/action-creators/setCouponFieldError.js +9 -2
- package/cart/action-creators/setCouponFieldValue.js +9 -2
- package/cart/action-creators/setFulfillmentSlot.js +9 -2
- package/cart/action-creators/successAddCouponsToCart.js +10 -2
- package/cart/action-creators/successAddProductsToCart.js +8 -2
- package/cart/action-creators/successDeleteCouponsFromCart.js +8 -2
- package/cart/action-creators/successDeleteProductsFromCart.js +8 -2
- package/cart/action-creators/successUpdateProductsInCart.js +8 -2
- package/cart/action-creators/updateProductsInCart.js +9 -2
- package/cart/actions/addCouponsToCart.js +52 -8
- package/cart/actions/addProductsToCart.js +80 -11
- package/cart/actions/deleteCouponsFromCart.js +39 -6
- package/cart/actions/deleteProductsFromCart.js +38 -6
- package/cart/actions/fetchCart.js +52 -8
- package/cart/actions/updateProductsInCart.js +44 -6
- package/cart/constants/PipelineErrors.js +6 -1
- package/cart/constants/Pipelines.js +6 -1
- package/cart/constants/Portals.js +85 -1
- package/cart/constants/index.js +39 -2
- package/cart/helpers/config.js +47 -2
- package/cart/helpers/createPipelineErrorList.js +30 -4
- package/cart/helpers/fulfillmentSlots.js +37 -4
- package/cart/helpers/index.js +14 -3
- package/cart/helpers/quantity.js +23 -4
- package/cart/helpers/shipping.js +57 -2
- package/cart/helpers/tax.js +26 -2
- package/cart/index.js +25 -5
- package/cart/mock.js +130 -1
- package/cart/reducers/couponField.js +30 -2
- package/cart/reducers/data.js +98 -6
- package/cart/reducers/index.js +7 -1
- package/cart/selectors/index.js +181 -31
- package/cart/selectors/spec.js +189 -2
- package/cart/streams/index.js +176 -29
- package/cart/subscriptions/index.js +307 -30
- package/category/action-creators/errorCategory.js +10 -2
- package/category/action-creators/errorCategoryChildren.js +9 -2
- package/category/action-creators/errorRootCategories.js +8 -2
- package/category/action-creators/receiveCategory.js +12 -2
- package/category/action-creators/receiveCategoryChildren.js +10 -2
- package/category/action-creators/receiveRootCategories.js +9 -2
- package/category/action-creators/requestCategory.js +9 -2
- package/category/action-creators/requestCategoryChildren.js +9 -2
- package/category/action-creators/requestRootCategories.js +8 -2
- package/category/actions/fetchCategory.js +47 -5
- package/category/actions/fetchCategoryChildren.js +30 -2
- package/category/actions/fetchCategoryOrRootCategories.js +16 -2
- package/category/actions/fetchCategoryProducts.js +36 -2
- package/category/actions/fetchRootCategories.js +31 -2
- package/category/actions/getCategory.js +10 -2
- package/category/constants/Pipelines.js +3 -1
- package/category/constants/Portals.js +56 -3
- package/category/constants/index.js +17 -2
- package/category/helpers/index.js +27 -3
- package/category/index.js +19 -5
- package/category/mock.js +176 -1
- package/category/reducers/categoriesById.js +65 -3
- package/category/reducers/childrenByCategoryId.js +55 -4
- package/category/reducers/helpers/handleCategoryCollection.js +24 -3
- package/category/reducers/helpers/handleReceivedCategories.js +3 -1
- package/category/reducers/index.js +12 -2
- package/category/reducers/rootCategories.js +31 -2
- package/category/selectors/index.js +115 -16
- package/category/streams/index.js +82 -4
- package/category/subscriptions/index.js +96 -3
- package/checkout/action-creators/successCheckout.js +9 -2
- package/checkout/actions/fetchCheckoutUrl.js +28 -3
- package/checkout/constants/Pipelines.js +1 -1
- package/checkout/constants/index.js +3 -2
- package/checkout/index.js +11 -4
- package/checkout/selectors/index.js +7 -2
- package/checkout/streams/index.js +8 -2
- package/checkout/subscriptions/index.js +35 -6
- package/favorites/action-creators/index.js +206 -24
- package/favorites/actions/addFavorites.js +41 -3
- package/favorites/actions/addFavoritesList.js +27 -2
- package/favorites/actions/fetchFavoriteIds.js +49 -5
- package/favorites/actions/fetchFavorites.js +60 -5
- package/favorites/actions/fetchFavoritesList.js +47 -3
- package/favorites/actions/fetchFavoritesListsWithItems.js +32 -3
- package/favorites/actions/getFavorites.js +6 -2
- package/favorites/actions/removeFavorites.js +32 -3
- package/favorites/actions/removeFavoritesList.js +24 -2
- package/favorites/actions/toggleFavorites.js +68 -10
- package/favorites/actions/updateFavorites.js +39 -3
- package/favorites/actions/updateFavoritesList.js +26 -2
- package/favorites/constants/Pipelines.js +9 -1
- package/favorites/constants/Portals.js +32 -4
- package/favorites/constants/index.js +37 -5
- package/favorites/index.js +14 -4
- package/favorites/mock.js +89 -4
- package/favorites/reducers/index.js +7 -1
- package/favorites/reducers/lists.js +74 -2
- package/favorites/reducers/products.js +231 -24
- package/favorites/selectors/index.js +188 -24
- package/favorites/streams/index.js +135 -23
- package/favorites/streams/spec.js +517 -8
- package/favorites/subscriptions/index.js +260 -25
- package/favorites/subscriptions/spec.js +701 -28
- package/filter/action-creators/errorFilters.js +9 -2
- package/filter/action-creators/index.js +4 -1
- package/filter/action-creators/receiveFilters.js +10 -2
- package/filter/action-creators/requestFilters.js +9 -2
- package/filter/action-creators/updateFilters.js +8 -2
- package/filter/actions/fetchFilters.js +46 -3
- package/filter/actions/getFilters.js +6 -2
- package/filter/actions/helpers/buildFilterParams.js +34 -2
- package/filter/actions/helpers/buildRequestFilters.js +35 -2
- package/filter/actions/helpers/processFilters.js +10 -2
- package/filter/actions/helpers/processParams.js +26 -2
- package/filter/constants/Pipelines.js +1 -1
- package/filter/constants/Portals.js +39 -3
- package/filter/constants/index.js +8 -1
- package/filter/index.js +12 -4
- package/filter/reducers/helpers/enrichFilters.js +11 -3
- package/filter/reducers/index.js +5 -1
- package/filter/reducers/resultsByHash.js +43 -3
- package/filter/selectors/index.js +47 -6
- package/filter/streams/index.js +30 -1
- package/filter/subscriptions/index.js +34 -2
- package/market/constants/Portals.js +22 -4
- package/market/constants/index.js +2 -1
- package/market/helpers/showReturnPolicy.js +3 -1
- package/market/helpers/showTaxDisclaimer.js +3 -1
- package/market/index.js +6 -2
- package/orders/constants.js +2 -1
- package/package.json +3 -3
- package/product/action-creators/deleteProductsByIds.js +10 -2
- package/product/action-creators/errorProduct.js +10 -2
- package/product/action-creators/errorProductDescription.js +10 -2
- package/product/action-creators/errorProductImages.js +10 -2
- package/product/action-creators/errorProductMedia.js +10 -2
- package/product/action-creators/errorProductOptions.js +10 -2
- package/product/action-creators/errorProductProperties.js +10 -2
- package/product/action-creators/errorProductRelations.js +9 -2
- package/product/action-creators/errorProductShipping.js +10 -2
- package/product/action-creators/errorProductVariants.js +10 -2
- package/product/action-creators/errorProducts.js +9 -2
- package/product/action-creators/expireProductById.js +10 -2
- package/product/action-creators/expireProductData.js +11 -2
- package/product/action-creators/expireProductsByHash.js +9 -2
- package/product/action-creators/productNotAvailable.js +10 -2
- package/product/action-creators/provideProduct.js +9 -2
- package/product/action-creators/receiveProduct.js +10 -2
- package/product/action-creators/receiveProductCached.js +9 -2
- package/product/action-creators/receiveProductDescription.js +10 -2
- package/product/action-creators/receiveProductImages.js +10 -2
- package/product/action-creators/receiveProductMedia.js +10 -2
- package/product/action-creators/receiveProductOptions.js +10 -2
- package/product/action-creators/receiveProductProperties.js +10 -2
- package/product/action-creators/receiveProductRelations.js +12 -2
- package/product/action-creators/receiveProductShipping.js +10 -2
- package/product/action-creators/receiveProductVariants.js +10 -2
- package/product/action-creators/receiveProducts.js +16 -2
- package/product/action-creators/receiveProductsCached.js +9 -2
- package/product/action-creators/refreshExpiredPDPData.js +8 -2
- package/product/action-creators/requestProduct.js +10 -2
- package/product/action-creators/requestProductDescription.js +9 -2
- package/product/action-creators/requestProductImages.js +9 -2
- package/product/action-creators/requestProductMedia.js +9 -2
- package/product/action-creators/requestProductOptions.js +9 -2
- package/product/action-creators/requestProductProperties.js +9 -2
- package/product/action-creators/requestProductRelations.js +10 -2
- package/product/action-creators/requestProductShipping.js +9 -2
- package/product/action-creators/requestProductVariants.js +9 -2
- package/product/action-creators/requestProducts.js +9 -2
- package/product/action-creators/setProductId.js +9 -2
- package/product/action-creators/setProductQuantity.js +9 -2
- package/product/action-creators/setProductVariantId.js +9 -2
- package/product/actions/changeSortOrder.js +21 -2
- package/product/actions/fetchHighlightProducts.js +18 -2
- package/product/actions/fetchLiveshoppingProducts.js +14 -2
- package/product/actions/fetchProduct.js +52 -3
- package/product/actions/fetchProductDescription.js +30 -2
- package/product/actions/fetchProductImages.js +31 -2
- package/product/actions/fetchProductMedia.js +35 -2
- package/product/actions/fetchProductOptions.js +31 -2
- package/product/actions/fetchProductProperties.js +30 -2
- package/product/actions/fetchProductRelations.js +63 -2
- package/product/actions/fetchProductShipping.js +31 -2
- package/product/actions/fetchProductVariants.js +31 -2
- package/product/actions/fetchProducts.js +189 -17
- package/product/actions/fetchProductsById.js +68 -8
- package/product/actions/fetchProductsByQuery.js +102 -18
- package/product/actions/getHighlightProducts.js +6 -2
- package/product/actions/getLiveshoppingProducts.js +6 -2
- package/product/actions/getProduct.js +6 -2
- package/product/actions/getProductDescription.js +6 -2
- package/product/actions/getProductImages.js +6 -2
- package/product/actions/getProductOptions.js +6 -2
- package/product/actions/getProductProperties.js +6 -2
- package/product/actions/getProductRelations.js +6 -2
- package/product/actions/getProductShipping.js +6 -2
- package/product/actions/getProductVariants.js +6 -2
- package/product/actions/getProducts.js +6 -2
- package/product/actions/getProductsById.js +6 -2
- package/product/actions/getProductsByQuery.js +6 -2
- package/product/actions/processProductFlags.js +35 -3
- package/product/actions/updateMetadata.js +17 -2
- package/product/collections/ProductImageFormats.js +48 -8
- package/product/collections/index.js +1 -1
- package/product/constants/Pipelines.js +12 -1
- package/product/constants/Portals.js +200 -33
- package/product/constants/index.js +90 -18
- package/product/helpers/index.js +61 -8
- package/product/index.js +36 -6
- package/product/mock.js +1002 -2
- package/product/reducers/descriptionsByProductId.js +54 -5
- package/product/reducers/helpers/formatOptions.js +17 -2
- package/product/reducers/helpers/handleProductCollection.js +19 -2
- package/product/reducers/imagesByProductId.js +51 -4
- package/product/reducers/index.js +23 -1
- package/product/reducers/mediaByProductId.js +55 -3
- package/product/reducers/optionsByProductId.js +41 -2
- package/product/reducers/productRelationsByHash.js +43 -2
- package/product/reducers/productsById.js +122 -7
- package/product/reducers/propertiesByProductId.js +48 -2
- package/product/reducers/resultsByHash.js +125 -9
- package/product/reducers/shippingByProductId.js +37 -2
- package/product/reducers/variantsByProductId.js +56 -2
- package/product/selectors/options.js +90 -13
- package/product/selectors/page.js +62 -13
- package/product/selectors/price.js +81 -18
- package/product/selectors/product.js +549 -59
- package/product/selectors/product.mock.js +327 -12
- package/product/selectors/relations.js +35 -5
- package/product/selectors/variants.js +91 -15
- package/product/streams/index.js +167 -13
- package/product/subscriptions/index.js +210 -4
- package/reviews/action-creators/errorProductReviews.js +9 -2
- package/reviews/action-creators/errorReviews.js +9 -2
- package/reviews/action-creators/errorSubmitReview.js +9 -2
- package/reviews/action-creators/errorUserReview.js +9 -2
- package/reviews/action-creators/flushUserReview.js +8 -2
- package/reviews/action-creators/receiveProductReviews.js +11 -2
- package/reviews/action-creators/receiveReviews.js +12 -2
- package/reviews/action-creators/receiveSubmitReview.js +9 -2
- package/reviews/action-creators/receiveUserReview.js +10 -2
- package/reviews/action-creators/requestProductReviews.js +10 -2
- package/reviews/action-creators/requestReviews.js +9 -2
- package/reviews/action-creators/requestSubmitReview.js +9 -2
- package/reviews/action-creators/requestUserReview.js +9 -2
- package/reviews/action-creators/resetSubmittedReview.js +9 -2
- package/reviews/action-creators/spec.js +40 -1
- package/reviews/actions/fetchProductReviews.js +37 -2
- package/reviews/actions/fetchReviews.js +38 -2
- package/reviews/actions/fetchUserReview.js +31 -2
- package/reviews/actions/flushUserReview.js +5 -1
- package/reviews/actions/getProductReviews.js +6 -2
- package/reviews/actions/getUserReview.js +6 -2
- package/reviews/actions/spec.js +241 -4
- package/reviews/actions/submitReview.js +63 -3
- package/reviews/constants/Pipelines.js +4 -1
- package/reviews/constants/Portals.js +4 -1
- package/reviews/constants/index.js +26 -7
- package/reviews/index.js +15 -4
- package/reviews/mock.js +172 -11
- package/reviews/reducers/index.js +11 -1
- package/reviews/reducers/mock.js +14 -2
- package/reviews/reducers/reviewsByHash.js +52 -6
- package/reviews/reducers/reviewsById.js +27 -2
- package/reviews/reducers/reviewsByProductId.js +47 -2
- package/reviews/reducers/spec.js +211 -2
- package/reviews/reducers/userReviewsByProductId.js +68 -2
- package/reviews/selectors/index.js +123 -19
- package/reviews/selectors/mock.js +100 -1
- package/reviews/selectors/spec.js +100 -1
- package/reviews/streams/index.js +37 -5
- package/reviews/streams/spec.js +25 -1
- package/reviews/subscriptions/index.js +27 -2
- package/scanner/action-creators/errorHandleScanner.js +11 -2
- package/scanner/action-creators/scannerFinished.js +11 -2
- package/scanner/action-creators/startScanner.js +8 -2
- package/scanner/action-creators/successHandleScanner.js +11 -2
- package/scanner/actions/handleBarCode.js +22 -2
- package/scanner/actions/handleNoResults.js +23 -2
- package/scanner/actions/handleQrCode.js +116 -6
- package/scanner/actions/handleSearch.js +33 -2
- package/scanner/constants/Portals.js +22 -1
- package/scanner/constants/index.js +17 -1
- package/scanner/helpers/index.js +115 -5
- package/scanner/index.js +19 -5
- package/scanner/streams/index.js +36 -1
- package/scanner/subscriptions/index.js +78 -8
- package/search/action-creators/errorSearchResults.js +10 -2
- package/search/action-creators/receiveSearchResults.js +11 -2
- package/search/action-creators/receiveSearchSuggestions.js +10 -2
- package/search/action-creators/requestSearchResults.js +10 -2
- package/search/action-creators/requestSearchSuggestions.js +9 -2
- package/search/actions/fetchSearchResults.js +66 -8
- package/search/actions/fetchSearchSuggestions.js +36 -2
- package/search/constants/Pipelines.js +1 -1
- package/search/constants/Portals.js +9 -2
- package/search/constants/index.js +10 -2
- package/search/helpers/index.js +5 -2
- package/search/helpers/removeHighlightingPlaceholders.js +4 -1
- package/search/helpers/spec.js +19 -1
- package/search/index.js +17 -5
- package/search/reducers/index.js +38 -2
- package/search/selectors/index.js +23 -4
- package/search/streams/index.js +51 -3
- package/search/subscriptions/index.js +132 -5
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import{ADD_PRODUCT_TO_FAVORITES,REMOVE_PRODUCT_FROM_FAVORITES,CANCEL_REQUEST_SYNC_FAVORITES,ERROR_FETCH_FAVORITES,RECEIVE_FAVORITES,REQUEST_FAVORITES,REQUEST_ADD_FAVORITES,SUCCESS_ADD_FAVORITES,ERROR_ADD_FAVORITES,REQUEST_REMOVE_FAVORITES,SUCCESS_REMOVE_FAVORITES,ERROR_REMOVE_FAVORITES,ERROR_FAVORITES,IDLE_SYNC_FAVORITES,REQUEST_FLUSH_FAVORITES_BUFFER,OPEN_FAVORITE_LIST_CHOOSER,CLOSE_FAVORITE_LIST_CHOOSER,REQUEST_UPDATE_FAVORITES,SUCCESS_UPDATE_FAVORITES,ERROR_UPDATE_FAVORITES,UPDATE_PRODUCT_IN_FAVORITES,OPEN_FAVORITE_COMMENT_DIALOG,CLOSE_FAVORITE_COMMENT_DIALOG}from"../constants";
|
|
1
|
+
import { ADD_PRODUCT_TO_FAVORITES, REMOVE_PRODUCT_FROM_FAVORITES, CANCEL_REQUEST_SYNC_FAVORITES, ERROR_FETCH_FAVORITES, RECEIVE_FAVORITES, REQUEST_FAVORITES, REQUEST_ADD_FAVORITES, SUCCESS_ADD_FAVORITES, ERROR_ADD_FAVORITES, REQUEST_REMOVE_FAVORITES, SUCCESS_REMOVE_FAVORITES, ERROR_REMOVE_FAVORITES, ERROR_FAVORITES, IDLE_SYNC_FAVORITES, REQUEST_FLUSH_FAVORITES_BUFFER, OPEN_FAVORITE_LIST_CHOOSER, CLOSE_FAVORITE_LIST_CHOOSER, REQUEST_UPDATE_FAVORITES, SUCCESS_UPDATE_FAVORITES, ERROR_UPDATE_FAVORITES, UPDATE_PRODUCT_IN_FAVORITES, OPEN_FAVORITE_COMMENT_DIALOG, CLOSE_FAVORITE_COMMENT_DIALOG } from "../constants";
|
|
2
|
+
import { makeGetFavorites } from "../selectors";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* First action to add one product to favorites.
|
|
3
6
|
* @param {number} productId Id of the product to add.
|
|
4
7
|
* @param {string} listId List identifier.
|
|
@@ -6,30 +9,71 @@ import{ADD_PRODUCT_TO_FAVORITES,REMOVE_PRODUCT_FROM_FAVORITES,CANCEL_REQUEST_SYN
|
|
|
6
9
|
* @param {string} notes New favorites notes to set
|
|
7
10
|
* @param {boolean} showToast Whether to show a confirmation toast after product was added
|
|
8
11
|
* @returns {Object}
|
|
9
|
-
*/
|
|
12
|
+
*/
|
|
13
|
+
export const addProductToFavorites = (productId, listId, quantity, notes, showToast = true) => ({
|
|
14
|
+
type: ADD_PRODUCT_TO_FAVORITES,
|
|
15
|
+
productId,
|
|
16
|
+
listId,
|
|
17
|
+
quantity,
|
|
18
|
+
notes,
|
|
19
|
+
showToast
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
10
23
|
* First action to update a product in favorites.
|
|
11
24
|
* @param {number} productId Id of the product to add.
|
|
12
25
|
* @param {string} listId List identifier.
|
|
13
26
|
* @param {number} quantity The quantity of the product.
|
|
14
27
|
* @param {string} notes Notes about the product.
|
|
15
28
|
* @returns {Object}
|
|
16
|
-
*/
|
|
29
|
+
*/
|
|
30
|
+
export const updateProductInFavorites = (productId, listId, quantity, notes) => ({
|
|
31
|
+
type: UPDATE_PRODUCT_IN_FAVORITES,
|
|
32
|
+
productId,
|
|
33
|
+
listId,
|
|
34
|
+
notes,
|
|
35
|
+
quantity
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
/**
|
|
17
39
|
* First action to remove one product to favorites.
|
|
18
40
|
* @param {number} productId Id of the product to remove.
|
|
19
41
|
* @param {boolean} withRelatives States, whether to remove all relative products or not.
|
|
20
42
|
* @param {string} listId List identifier.
|
|
21
43
|
* @returns {Object}
|
|
22
|
-
*/
|
|
44
|
+
*/
|
|
45
|
+
export const removeProductFromFavorites = (productId, withRelatives, listId) => ({
|
|
46
|
+
type: REMOVE_PRODUCT_FROM_FAVORITES,
|
|
47
|
+
productId,
|
|
48
|
+
withRelatives,
|
|
49
|
+
listId
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
23
53
|
* Error on fetch favorites action.
|
|
24
54
|
* @param {Error} error Error.
|
|
25
55
|
* @param {string} listId List identifier.
|
|
26
56
|
* @returns {Object}
|
|
27
|
-
*/
|
|
57
|
+
*/
|
|
58
|
+
export const errorFetchFavorites = (error, listId) => ({
|
|
59
|
+
type: ERROR_FETCH_FAVORITES,
|
|
60
|
+
error,
|
|
61
|
+
listId
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
/**
|
|
28
65
|
* Error on favorites action.
|
|
29
66
|
* @param {string} productId Product identifier.
|
|
30
67
|
* @param {Error} error Error.
|
|
31
68
|
* @returns {Object}
|
|
32
|
-
*/
|
|
69
|
+
*/
|
|
70
|
+
export const errorFavorites = (productId, error) => ({
|
|
71
|
+
type: ERROR_FAVORITES,
|
|
72
|
+
productId,
|
|
73
|
+
error
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/**
|
|
33
77
|
* Request add favorites action. This action just updates the redux store.
|
|
34
78
|
* @param {string} productId Product identifier.
|
|
35
79
|
* @param {string} listId List identifier.
|
|
@@ -37,47 +81,120 @@ import{ADD_PRODUCT_TO_FAVORITES,REMOVE_PRODUCT_FROM_FAVORITES,CANCEL_REQUEST_SYN
|
|
|
37
81
|
* @param {string} notes New favorites notes to set
|
|
38
82
|
* @param {boolean} showToast Whether to show a confirmation toast after product was added
|
|
39
83
|
* @returns {Object}
|
|
40
|
-
*/
|
|
84
|
+
*/
|
|
85
|
+
export const requestAddFavorites = (productId, listId, quantity, notes, showToast = true) => ({
|
|
86
|
+
type: REQUEST_ADD_FAVORITES,
|
|
87
|
+
productId,
|
|
88
|
+
listId,
|
|
89
|
+
quantity,
|
|
90
|
+
notes,
|
|
91
|
+
showToast
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
/**
|
|
41
95
|
* Action to be triggered upon successful addFavorites pipeline call.
|
|
42
96
|
* @param {string} productId Product identifier.
|
|
43
97
|
* @param {string} listId List identifier.
|
|
44
98
|
* @param {boolean} showToast Whether to show a confirmation toast after product was added
|
|
45
99
|
* @returns {Object}
|
|
46
|
-
*/
|
|
100
|
+
*/
|
|
101
|
+
export const successAddFavorites = (productId, listId, showToast = true) => ({
|
|
102
|
+
type: SUCCESS_ADD_FAVORITES,
|
|
103
|
+
productId,
|
|
104
|
+
listId,
|
|
105
|
+
showToast
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/**
|
|
47
109
|
* Action to be triggered upon a failed addFavorites pipeline call.
|
|
48
110
|
* @param {string} productId Product identifier.
|
|
49
111
|
* @param {Error} error The error that occurred.
|
|
50
112
|
* @param {string} listId List identifier.
|
|
51
113
|
* @returns {Object}
|
|
52
|
-
*/
|
|
114
|
+
*/
|
|
115
|
+
export const errorAddFavorites = (productId, error, listId) => ({
|
|
116
|
+
type: ERROR_ADD_FAVORITES,
|
|
117
|
+
productId,
|
|
118
|
+
listId,
|
|
119
|
+
error
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
53
123
|
* Request update favorites action. This action just updates the redux store.
|
|
54
124
|
* @param {string} productId Product identifier.
|
|
55
125
|
* @param {string} listId List identifier.
|
|
56
126
|
* @param {number} quantity The quantity of the product
|
|
57
127
|
* @param {string} notes Notes about the product
|
|
58
128
|
* @returns {Object}
|
|
59
|
-
*/
|
|
129
|
+
*/
|
|
130
|
+
export const requestUpdateFavorites = (productId, listId, quantity, notes) => ({
|
|
131
|
+
type: REQUEST_UPDATE_FAVORITES,
|
|
132
|
+
productId,
|
|
133
|
+
listId,
|
|
134
|
+
notes,
|
|
135
|
+
quantity
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
/**
|
|
60
139
|
* Action to be triggered upon successful updateFavorites pipeline call.
|
|
61
140
|
* @param {string} productId Product identifier.
|
|
62
141
|
* @param {string} listId List identifier.
|
|
63
142
|
* @returns {Object}
|
|
64
|
-
*/
|
|
143
|
+
*/
|
|
144
|
+
export const successUpdateFavorites = (productId, listId) => ({
|
|
145
|
+
type: SUCCESS_UPDATE_FAVORITES,
|
|
146
|
+
productId,
|
|
147
|
+
listId
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
/**
|
|
65
151
|
* Action to be triggered upon failed updateFavorites pipeline call.
|
|
66
152
|
* @param {string} productId Product identifier.
|
|
67
153
|
* @param {string} listId List identifier.
|
|
68
154
|
* @param {Error} error The error that occurred.
|
|
69
155
|
* @returns {Object}
|
|
70
|
-
*/
|
|
156
|
+
*/
|
|
157
|
+
export const errorUpdateFavorites = (productId, listId, error) => ({
|
|
158
|
+
type: ERROR_UPDATE_FAVORITES,
|
|
159
|
+
productId,
|
|
160
|
+
listId,
|
|
161
|
+
error
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
/**
|
|
71
165
|
* Request remove favorites action. This action just updates the redux store.
|
|
72
166
|
* @param {string} productId Product identifier.
|
|
73
167
|
* @param {string} listId List identifier.
|
|
74
168
|
* @returns {Object}
|
|
75
|
-
*/
|
|
169
|
+
*/
|
|
170
|
+
export const requestRemoveFavorites = (productId, listId) => (dispatch, getState) => {
|
|
171
|
+
const getFavorites = makeGetFavorites(() => listId);
|
|
172
|
+
const favorites = getFavorites(getState());
|
|
173
|
+
const matchingFavorite = favorites.find(({
|
|
174
|
+
productId: itemProductId
|
|
175
|
+
}) => itemProductId === productId) || {};
|
|
176
|
+
return dispatch({
|
|
177
|
+
type: REQUEST_REMOVE_FAVORITES,
|
|
178
|
+
productId,
|
|
179
|
+
listId,
|
|
180
|
+
quantity: matchingFavorite.quantity || 1,
|
|
181
|
+
notes: matchingFavorite.notes || ''
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
76
186
|
* Action to be triggered upon successful removeFavorites (deleteFavorites) pipeline call.
|
|
77
187
|
* @param {string} productId Product identifier.
|
|
78
188
|
* @param {number} takenListId List id
|
|
79
189
|
* @returns {Object}
|
|
80
|
-
*/
|
|
190
|
+
*/
|
|
191
|
+
export const successRemoveFavorites = (productId, takenListId) => ({
|
|
192
|
+
type: SUCCESS_REMOVE_FAVORITES,
|
|
193
|
+
productId,
|
|
194
|
+
listId: takenListId
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
/**
|
|
81
198
|
* Action to be triggered upon a failed removeFavorites (deleteFavorites) pipeline call.
|
|
82
199
|
* @param {string} productId Product identifier.
|
|
83
200
|
* @param {string} takenListId List id
|
|
@@ -85,43 +202,108 @@ import{ADD_PRODUCT_TO_FAVORITES,REMOVE_PRODUCT_FROM_FAVORITES,CANCEL_REQUEST_SYN
|
|
|
85
202
|
* @param {number} quantity Quantity of the favorite
|
|
86
203
|
* @param {string} notes Notes of the favorite
|
|
87
204
|
* @returns {Object}
|
|
88
|
-
*/
|
|
205
|
+
*/
|
|
206
|
+
export const errorRemoveFavorites = (productId, takenListId, error, quantity, notes) => ({
|
|
207
|
+
type: ERROR_REMOVE_FAVORITES,
|
|
208
|
+
productId,
|
|
209
|
+
listId: takenListId,
|
|
210
|
+
error,
|
|
211
|
+
quantity,
|
|
212
|
+
notes
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
/**
|
|
89
216
|
* Return the flush favorites buffer Now action object
|
|
90
217
|
* @param {string} listId The Id of the wishlist.
|
|
91
218
|
* @return {Object}
|
|
92
|
-
*/
|
|
219
|
+
*/
|
|
220
|
+
export const requestFlushFavoritesBuffer = listId => ({
|
|
221
|
+
type: REQUEST_FLUSH_FAVORITES_BUFFER,
|
|
222
|
+
listId
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
/**
|
|
93
226
|
* Idle sync action.
|
|
94
227
|
* @param {string} listId The Id of the wishlist.
|
|
95
228
|
* @returns {Object}
|
|
96
|
-
*/
|
|
229
|
+
*/
|
|
230
|
+
export const idleSyncFavorites = listId => ({
|
|
231
|
+
type: IDLE_SYNC_FAVORITES,
|
|
232
|
+
listId
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
/**
|
|
97
236
|
* Action to cancel one or multiple request to add or to remove favorites.
|
|
98
237
|
* @param {number} [count=1] Optional count of sync requests.
|
|
99
238
|
* @param {string} listId The Id of the wishlist.
|
|
100
239
|
* @returns {Object}
|
|
101
|
-
*/
|
|
240
|
+
*/
|
|
241
|
+
export const cancelRequestSyncFavorites = (count = 1, listId) => ({
|
|
242
|
+
type: CANCEL_REQUEST_SYNC_FAVORITES,
|
|
243
|
+
count,
|
|
244
|
+
listId
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
/**
|
|
102
248
|
* Receive favorites action.
|
|
103
249
|
* @param {Array} items Wishlist items.
|
|
104
250
|
* @param {number} requestTimestamp Time when request was initiated (ms).
|
|
105
251
|
* @param {string} listId The Id of the wishlist.
|
|
106
252
|
* @returns {Object}
|
|
107
|
-
*/
|
|
253
|
+
*/
|
|
254
|
+
export const receiveFavorites = (items, requestTimestamp, listId = null) => ({
|
|
255
|
+
type: RECEIVE_FAVORITES,
|
|
256
|
+
items,
|
|
257
|
+
requestTimestamp,
|
|
258
|
+
listId
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
/**
|
|
108
262
|
* Request favorites action.
|
|
109
263
|
* @param {string} listId The Id of the wishlist.
|
|
110
264
|
* @returns {Object}
|
|
111
|
-
*/
|
|
265
|
+
*/
|
|
266
|
+
export const requestFavorites = (listId = null) => ({
|
|
267
|
+
type: REQUEST_FAVORITES,
|
|
268
|
+
listId
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
/**
|
|
112
272
|
* Opens the favorite list chooser.
|
|
113
273
|
* @param {string} productId The Id of the product.
|
|
114
274
|
* @param {boolean} withRelatives States, whether to remove all relative products or not.
|
|
115
275
|
* @returns {Object}
|
|
116
|
-
*/
|
|
276
|
+
*/
|
|
277
|
+
export const openFavoritesListChooser = (productId, withRelatives = false) => ({
|
|
278
|
+
type: OPEN_FAVORITE_LIST_CHOOSER,
|
|
279
|
+
productId,
|
|
280
|
+
withRelatives
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
/**
|
|
117
284
|
* Opens the favorite list chooser.
|
|
118
285
|
* @returns {Object}
|
|
119
|
-
*/
|
|
286
|
+
*/
|
|
287
|
+
export const closeFavoritesListChooser = () => ({
|
|
288
|
+
type: CLOSE_FAVORITE_LIST_CHOOSER
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
/**
|
|
120
292
|
* Opens the favorite comment sheet
|
|
121
293
|
* @param {string} productId The id of the product.
|
|
122
294
|
* @param {string} listId The id of the list.
|
|
123
295
|
* @returns {Object}
|
|
124
|
-
*/
|
|
296
|
+
*/
|
|
297
|
+
export const openFavoritesCommentDialog = (productId, listId) => ({
|
|
298
|
+
type: OPEN_FAVORITE_COMMENT_DIALOG,
|
|
299
|
+
productId,
|
|
300
|
+
listId
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
/**
|
|
125
304
|
* Closes the favorite comment sheet
|
|
126
305
|
* @returns {Object}
|
|
127
|
-
*/
|
|
306
|
+
*/
|
|
307
|
+
export const closeFavoritesCommentDialog = () => ({
|
|
308
|
+
type: CLOSE_FAVORITE_COMMENT_DIALOG
|
|
309
|
+
});
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
2
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
3
|
+
import { getWishlistItemNotesEnabled, getWishlistItemQuantityEnabled } from '@shopgate/engage/core/selectors';
|
|
4
|
+
import { SHOPGATE_USER_ADD_FAVORITES } from "../constants/Pipelines";
|
|
5
|
+
import { successAddFavorites, errorAddFavorites } from "../action-creators";
|
|
6
|
+
import { getHasMultipleFavoritesListsSupport, getFavoritesDefaultList } from "../selectors";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Adds a single product to the favorite list using the `addFavorites` pipeline.
|
|
3
10
|
* @param {string} productId Id of the product to be added.
|
|
4
11
|
* @param {string} listId Id of the list to be added.
|
|
@@ -6,5 +13,36 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function _extends(){
|
|
|
6
13
|
* @param {string} notes New favorites notes to set
|
|
7
14
|
* @param {boolean} showToast Whether to show a confirmation toast after product was added
|
|
8
15
|
* @returns {Function} A redux thunk.
|
|
9
|
-
*/
|
|
10
|
-
|
|
16
|
+
*/
|
|
17
|
+
function addFavorites(productId, listId = null, quantity, notes, showToast = true) {
|
|
18
|
+
return async (dispatch, getState) => {
|
|
19
|
+
const state = getState();
|
|
20
|
+
const hasMultiSupport = getHasMultipleFavoritesListsSupport(state);
|
|
21
|
+
const quantityEnabled = getWishlistItemQuantityEnabled(state);
|
|
22
|
+
const notesEnabled = getWishlistItemNotesEnabled(state);
|
|
23
|
+
|
|
24
|
+
// Fallback for deprecated calls without list id.
|
|
25
|
+
const defaultList = getFavoritesDefaultList(state);
|
|
26
|
+
const takenListId = listId || defaultList.id;
|
|
27
|
+
const request = new PipelineRequest(SHOPGATE_USER_ADD_FAVORITES).setInput({
|
|
28
|
+
productId,
|
|
29
|
+
...(hasMultiSupport ? {
|
|
30
|
+
favoritesListId: takenListId
|
|
31
|
+
} : null),
|
|
32
|
+
...(quantityEnabled && quantity !== null ? {
|
|
33
|
+
quantity
|
|
34
|
+
} : null),
|
|
35
|
+
...(notesEnabled && notes !== null ? {
|
|
36
|
+
notes
|
|
37
|
+
} : null)
|
|
38
|
+
}).setRetries(0).dispatch();
|
|
39
|
+
try {
|
|
40
|
+
await request;
|
|
41
|
+
dispatch(successAddFavorites(productId, takenListId, showToast));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
dispatch(errorAddFavorites(productId, error, takenListId));
|
|
44
|
+
}
|
|
45
|
+
return request;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export default mutable(addFavorites);
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
2
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
3
|
+
import { SHOPGATE_USER_ADD_FAVORITES_LIST } from "../constants/Pipelines";
|
|
4
|
+
import { SUCCESS_ADD_FAVORITES_LIST } from "../constants";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* Adds a new favorite list.
|
|
3
8
|
* @param {string} name Name of the wishlist.
|
|
4
9
|
* @returns {Function} A redux thunk.
|
|
5
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
function addFavoritesList(name) {
|
|
12
|
+
return async dispatch => {
|
|
13
|
+
const request = new PipelineRequest(SHOPGATE_USER_ADD_FAVORITES_LIST).setInput({
|
|
14
|
+
name
|
|
15
|
+
}).setRetries(0).dispatch();
|
|
16
|
+
try {
|
|
17
|
+
const {
|
|
18
|
+
id
|
|
19
|
+
} = await request;
|
|
20
|
+
dispatch({
|
|
21
|
+
type: SUCCESS_ADD_FAVORITES_LIST,
|
|
22
|
+
listId: id,
|
|
23
|
+
name
|
|
24
|
+
});
|
|
25
|
+
} catch (_) {
|
|
26
|
+
// Fail silently
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export default mutable(addFavoritesList);
|
|
@@ -1,9 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { EFAVORITE, EUNKNOWN } from '@shopgate/pwa-core/constants/Pipeline';
|
|
3
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
4
|
+
import { SHOPGATE_USER_GET_FAVORITE_IDS } from "../constants/Pipelines";
|
|
5
|
+
import { receiveFavorites, requestFavorites, errorFetchFavorites } from "../action-creators";
|
|
6
|
+
import { getHasMultipleFavoritesListsSupport, makeGetFavoritesProductsByList } from "../selectors";
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Fetch favorite IDs of a favorites list action.
|
|
3
10
|
* @param {boolean} ignoreCache Ignores cache when true
|
|
4
11
|
* @param {string} [favoritesListId] The ID of the favorites list
|
|
5
12
|
* @returns {Function} A redux thunk.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
*/
|
|
14
|
+
function fetchFavoriteIds(ignoreCache = false, favoritesListId = 'DEFAULT') {
|
|
15
|
+
return (dispatch, getState) => {
|
|
16
|
+
const hasMultiSupport = getHasMultipleFavoritesListsSupport(getState());
|
|
17
|
+
const getFavoritesProductsByList = makeGetFavoritesProductsByList(() => favoritesListId);
|
|
18
|
+
const data = getFavoritesProductsByList(getState());
|
|
19
|
+
if (!ignoreCache && !shouldFetchData(data)) {
|
|
20
|
+
return Promise.resolve(data);
|
|
21
|
+
}
|
|
22
|
+
const timestamp = Date.now();
|
|
23
|
+
dispatch(requestFavorites(favoritesListId));
|
|
24
|
+
return new PipelineRequest(SHOPGATE_USER_GET_FAVORITE_IDS).setInput({
|
|
25
|
+
...(hasMultiSupport ? {
|
|
26
|
+
favoritesListId
|
|
27
|
+
} : null)
|
|
28
|
+
}).setErrorBlacklist([EFAVORITE, EUNKNOWN]).dispatch().then(({
|
|
29
|
+
productIds
|
|
30
|
+
}) => {
|
|
31
|
+
/**
|
|
32
|
+
* Sanitize the pipeline return value to archive compatibility with the reducers for the
|
|
33
|
+
* fetchFavorites pipeline.
|
|
34
|
+
*/
|
|
35
|
+
const items = productIds.map(productId => ({
|
|
36
|
+
product: {
|
|
37
|
+
id: productId
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
const sanitizedResponse = {
|
|
41
|
+
items,
|
|
42
|
+
itemCount: items.length
|
|
43
|
+
};
|
|
44
|
+
dispatch(receiveFavorites(sanitizedResponse.items, timestamp, favoritesListId));
|
|
45
|
+
return sanitizedResponse;
|
|
46
|
+
}).catch(err => {
|
|
47
|
+
dispatch(errorFetchFavorites(err, favoritesListId));
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @mixes {MutableFunction} */
|
|
53
|
+
export default mutable(fetchFavoriteIds);
|
|
@@ -1,9 +1,64 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { EFAVORITE, EUNKNOWN, EBIGAPI, ELIMIT } from '@shopgate/pwa-core/constants/Pipeline';
|
|
3
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
4
|
+
import { hasNewServices } from '@shopgate/engage/core/helpers';
|
|
5
|
+
import { SHOPGATE_USER_GET_FAVORITES } from "../constants/Pipelines";
|
|
6
|
+
import { receiveFavorites, requestFavorites, errorFetchFavorites } from "../action-creators";
|
|
7
|
+
import { getHasMultipleFavoritesListsSupport, makeGetFavoritesProductsByList, getFavoritesDefaultList } from "../selectors";
|
|
8
|
+
import receiveProducts from "../../product/action-creators/receiveProducts";
|
|
9
|
+
|
|
10
|
+
/**
|
|
2
11
|
* Fetch favorites action.
|
|
3
12
|
* @param {boolean} ignoreCache Ignores cache when true
|
|
4
13
|
* @param {string} listId The id of the list that needs to be fetched.
|
|
5
14
|
* @returns {Function} A redux thunk.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
*/
|
|
16
|
+
function fetchFavorites(ignoreCache = false, listId = undefined) {
|
|
17
|
+
return async (dispatch, getState) => {
|
|
18
|
+
// Fallback for deprecated calls without list id.
|
|
19
|
+
const defaultList = getFavoritesDefaultList(getState());
|
|
20
|
+
const takenListId = listId || defaultList.code;
|
|
21
|
+
const hasMultiSupport = getHasMultipleFavoritesListsSupport(getState());
|
|
22
|
+
const getFavoritesProductsByList = makeGetFavoritesProductsByList(() => takenListId);
|
|
23
|
+
const data = getFavoritesProductsByList(getState());
|
|
24
|
+
if (!ignoreCache && !shouldFetchData(data)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const timestamp = Date.now();
|
|
28
|
+
dispatch(requestFavorites(takenListId));
|
|
29
|
+
|
|
30
|
+
// v2 of the getFavorites pipeline doesn't exist right now within the old services
|
|
31
|
+
const pipelineVersion = hasNewServices() ? 2 : 1;
|
|
32
|
+
const request = new PipelineRequest(SHOPGATE_USER_GET_FAVORITES).setVersion(pipelineVersion).setInput({
|
|
33
|
+
...(hasMultiSupport ? {
|
|
34
|
+
favoritesListId: takenListId
|
|
35
|
+
} : null)
|
|
36
|
+
}).setErrorBlacklist([EFAVORITE, EUNKNOWN, EBIGAPI, ELIMIT]).dispatch();
|
|
37
|
+
try {
|
|
38
|
+
const result = await request;
|
|
39
|
+
if (pipelineVersion === 1) {
|
|
40
|
+
// Convert response data based on the pipeline version
|
|
41
|
+
result.items = (result?.products || []).map(product => ({
|
|
42
|
+
product,
|
|
43
|
+
note: null,
|
|
44
|
+
quantity: 1
|
|
45
|
+
}));
|
|
46
|
+
delete result.products;
|
|
47
|
+
}
|
|
48
|
+
dispatch(receiveProducts({
|
|
49
|
+
products: result.items.map(({
|
|
50
|
+
product
|
|
51
|
+
}) => product),
|
|
52
|
+
fetchInventory: false
|
|
53
|
+
}));
|
|
54
|
+
dispatch(receiveFavorites(result.items, timestamp, takenListId));
|
|
55
|
+
return result;
|
|
56
|
+
} catch (err) {
|
|
57
|
+
dispatch(errorFetchFavorites(err, takenListId));
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** @mixes {MutableFunction} */
|
|
64
|
+
export default mutable(fetchFavorites);
|
|
@@ -1,9 +1,53 @@
|
|
|
1
|
-
import
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { shouldFetchData, mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
3
|
+
import { getFavoritesListState, getHasMultipleFavoritesListsSupport } from "../selectors";
|
|
4
|
+
import { SHOPGATE_USER_GET_FAVORITES_LIST } from "../constants/Pipelines";
|
|
5
|
+
import { RECEIVE_FAVORITES_LISTS } from "../constants";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* Fetch favorites list action.
|
|
3
9
|
* @param {boolean} ignoreCache Ignores cache when true
|
|
4
10
|
* @returns {Function} A redux thunk.
|
|
5
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
function fetchFavoritesLists(ignoreCache = false) {
|
|
13
|
+
return async (dispatch, getState) => {
|
|
14
|
+
const state = getState();
|
|
15
|
+
const hasMultiSupport = getHasMultipleFavoritesListsSupport(state);
|
|
16
|
+
if (!hasMultiSupport) {
|
|
17
|
+
/**
|
|
6
18
|
* If the doesn't have support for multiple favorite lists, we just mock the pipeline response
|
|
7
19
|
* and don't dispatch the request. So we can keep backwards compatibility with older
|
|
8
20
|
* extensions that don't support the pipeline.
|
|
9
|
-
*/
|
|
21
|
+
*/
|
|
22
|
+
const favoritesLists = [{
|
|
23
|
+
id: 'DEFAULT',
|
|
24
|
+
name: ''
|
|
25
|
+
}];
|
|
26
|
+
dispatch({
|
|
27
|
+
type: RECEIVE_FAVORITES_LISTS,
|
|
28
|
+
favoritesLists
|
|
29
|
+
});
|
|
30
|
+
return favoritesLists;
|
|
31
|
+
}
|
|
32
|
+
const data = getFavoritesListState(state);
|
|
33
|
+
if (!ignoreCache && !shouldFetchData(data)) {
|
|
34
|
+
return data?.lists || [];
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const {
|
|
38
|
+
favoritesLists
|
|
39
|
+
} = await new PipelineRequest(SHOPGATE_USER_GET_FAVORITES_LIST).dispatch();
|
|
40
|
+
dispatch({
|
|
41
|
+
type: RECEIVE_FAVORITES_LISTS,
|
|
42
|
+
favoritesLists
|
|
43
|
+
});
|
|
44
|
+
return favoritesLists;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
// Fail silently
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @mixes {MutableFunction} */
|
|
53
|
+
export default mutable(fetchFavoritesLists);
|