@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,11 +1,40 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getUseGetFavoriteIdsPipeline } from "../selectors";
|
|
2
|
+
import fetchFavorites from "./fetchFavorites";
|
|
3
|
+
import fetchFavoriteIds from "./fetchFavoriteIds";
|
|
4
|
+
import fetchFavoritesList from "./fetchFavoritesList";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
*
|
|
3
8
|
* Combine fetch favorites list action and fetch favorites action.
|
|
4
9
|
* @param {boolean} ignoreCache Ignores cache when true
|
|
5
10
|
* @returns {Function} A redux thunk.
|
|
6
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
function fetchFavoritesListsWithItems(ignoreCache = false) {
|
|
13
|
+
return async (dispatch, getState) => {
|
|
14
|
+
const lists = (await dispatch(fetchFavoritesList(ignoreCache))) || [];
|
|
15
|
+
const useGetFavoriteIdsPipeline = getUseGetFavoriteIdsPipeline(getState());
|
|
16
|
+
const itemPromises = lists.map(list => {
|
|
17
|
+
/**
|
|
7
18
|
* In PWA6 the fetchFavoriteIds pipelines was used to retrieve the contents of the
|
|
8
19
|
* favorites list. Its response doesn't contain product objects, but only product ids.
|
|
9
20
|
* For compatibility reasons and simplification, the action returns an object that's similar
|
|
10
21
|
* to the fetchFavorites response, so that the existing reducers can be used.
|
|
11
|
-
*/
|
|
22
|
+
*/
|
|
23
|
+
if (useGetFavoriteIdsPipeline) {
|
|
24
|
+
return dispatch(fetchFavoriteIds(ignoreCache, list.id));
|
|
25
|
+
}
|
|
26
|
+
return dispatch(fetchFavorites(ignoreCache, list.id));
|
|
27
|
+
});
|
|
28
|
+
const wishlistItems = await Promise.all(itemPromises);
|
|
29
|
+
return lists.map(({
|
|
30
|
+
id,
|
|
31
|
+
name
|
|
32
|
+
}, index) => ({
|
|
33
|
+
id,
|
|
34
|
+
name,
|
|
35
|
+
itemCount: (wishlistItems[index] || {}).itemCount,
|
|
36
|
+
items: (wishlistItems[index] || {}).items
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export default fetchFavoritesListsWithItems;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import fetchFavorites from"./fetchFavorites"
|
|
1
|
+
import fetchFavorites from "./fetchFavorites";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Get favorites action.
|
|
3
5
|
* @param {boolean} ignoreCache Ignores cache when true
|
|
4
6
|
* @returns {Promise|undefined}
|
|
5
7
|
* @deprecated
|
|
6
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
const getFavorites = fetchFavorites;
|
|
10
|
+
export default getFavorites;
|
|
@@ -1,9 +1,38 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
2
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
3
|
+
import { SHOPGATE_USER_DELETE_FAVORITES } from "../constants/Pipelines";
|
|
4
|
+
import { successRemoveFavorites, errorRemoveFavorites } from "../action-creators";
|
|
5
|
+
import { getHasMultipleFavoritesListsSupport, getFavoritesDefaultList } from "../selectors";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* Removes a single product from the favorite list using the `deleteFavorites` pipeline.
|
|
3
9
|
* @param {string} productId Id of the product to be deleted.
|
|
4
10
|
* @param {string} listId Id of the list to be deleted.
|
|
5
11
|
* @param {number} quantity Quantity of the favorite
|
|
6
12
|
* @param {string} notes Notes of the favorite
|
|
7
13
|
* @returns {Function} A redux thunk.
|
|
8
|
-
*/
|
|
9
|
-
|
|
14
|
+
*/
|
|
15
|
+
function removeFavorites(productId, listId, quantity, notes) {
|
|
16
|
+
return async (dispatch, getState) => {
|
|
17
|
+
const state = getState();
|
|
18
|
+
const hasMultiSupport = getHasMultipleFavoritesListsSupport(state);
|
|
19
|
+
|
|
20
|
+
// Fallback for deprecated calls without list id.
|
|
21
|
+
const defaultList = getFavoritesDefaultList(state);
|
|
22
|
+
const takenListId = listId || defaultList.id;
|
|
23
|
+
const request = new PipelineRequest(SHOPGATE_USER_DELETE_FAVORITES).setInput({
|
|
24
|
+
productId,
|
|
25
|
+
...(hasMultiSupport ? {
|
|
26
|
+
favoritesListId: takenListId
|
|
27
|
+
} : null)
|
|
28
|
+
}).setRetries(0).dispatch();
|
|
29
|
+
try {
|
|
30
|
+
await request;
|
|
31
|
+
dispatch(successRemoveFavorites(productId, takenListId));
|
|
32
|
+
} catch (error) {
|
|
33
|
+
dispatch(errorRemoveFavorites(productId, takenListId, error, quantity, notes));
|
|
34
|
+
}
|
|
35
|
+
return request;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export default mutable(removeFavorites);
|
|
@@ -1,5 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
2
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
3
|
+
import { SHOPGATE_USER_REMOVE_FAVORITES_LIST } from "../constants/Pipelines";
|
|
4
|
+
import { SUCCESS_REMOVE_FAVORITES_LIST } from "../constants";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* Adds a new favorite list.
|
|
3
8
|
* @param {string} listId Id of the wishlist.
|
|
4
9
|
* @returns {Function} A redux thunk.
|
|
5
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
function removeFavoritesList(listId) {
|
|
12
|
+
return async dispatch => {
|
|
13
|
+
const request = new PipelineRequest(SHOPGATE_USER_REMOVE_FAVORITES_LIST).setInput({
|
|
14
|
+
id: listId
|
|
15
|
+
}).setRetries(0).dispatch();
|
|
16
|
+
try {
|
|
17
|
+
await request;
|
|
18
|
+
dispatch({
|
|
19
|
+
type: SUCCESS_REMOVE_FAVORITES_LIST,
|
|
20
|
+
listId
|
|
21
|
+
});
|
|
22
|
+
} catch (_) {
|
|
23
|
+
// Fail silently
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export default mutable(removeFavoritesList);
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
2
|
+
import { getWishlistItemQuantityEnabled, getLoadWishlistOnAppStartEnabled } from '@shopgate/engage/core/selectors/shopSettings';
|
|
3
|
+
import { getFavoritesDefaultList, getFavoritesLists, makeIsProductOnSpecificFavoriteList } from "../selectors";
|
|
4
|
+
import { addProductToFavorites, removeProductFromFavorites, requestFlushFavoritesBuffer, openFavoritesListChooser, updateProductInFavorites } from "../action-creators";
|
|
5
|
+
import fetchFavoritesListsWithItems from "./fetchFavoritesListsWithItems";
|
|
6
|
+
|
|
7
|
+
/**
|
|
2
8
|
* Adds a product to the favorite list (debounced and buffered).
|
|
3
9
|
* @mixes {MutableFunction}
|
|
4
10
|
* @param {string} productId Product identifier.
|
|
@@ -7,41 +13,93 @@ import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGenera
|
|
|
7
13
|
* @param {string} notes New favorites notes to set
|
|
8
14
|
* @param {boolean} showToast Whether to show a confirmation toast after product was added
|
|
9
15
|
* @return {Function}
|
|
10
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
export const addFavorite = mutable((productId, listId, quantity, notes, showToast = false) => (dispatch, getState) => {
|
|
18
|
+
const defaultList = getFavoritesDefaultList(getState());
|
|
19
|
+
dispatch(addProductToFavorites(productId, listId || defaultList.id, quantity, notes, showToast));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
/**
|
|
11
23
|
* Adds a product to the favorite list (debounced and buffered).
|
|
12
24
|
* @param {string} productId Product identifier.
|
|
13
25
|
* @return {Function}
|
|
14
26
|
* @deprecated Please use `addFavorite` instead.
|
|
15
|
-
*/
|
|
27
|
+
*/
|
|
28
|
+
export const addFavorites = addFavorite;
|
|
29
|
+
|
|
30
|
+
/**
|
|
16
31
|
* Removes a product and optionally its relatives from the favorite list (debounced and buffered).
|
|
17
32
|
* @mixes {MutableFunction}
|
|
18
33
|
* @param {string} productId Product identifier.
|
|
19
34
|
* @param {boolean} withRelatives When true relatives which are on list are also removed.
|
|
20
35
|
* @param {string} listId List identifier.
|
|
21
36
|
* @returns {Function}
|
|
22
|
-
*/
|
|
37
|
+
*/
|
|
38
|
+
export const removeFavorites = mutable((productId, withRelatives = false, listId) => (dispatch, getState) => {
|
|
39
|
+
const defaultList = getFavoritesDefaultList(getState());
|
|
40
|
+
dispatch(removeProductFromFavorites(productId, withRelatives, listId || defaultList.id));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
23
44
|
* Triggers a sync of favorites by immediately flushing buffered favorite update actions.
|
|
24
45
|
* @mixes {MutableFunction}
|
|
25
46
|
* @return {Function}
|
|
26
|
-
*/
|
|
47
|
+
*/
|
|
48
|
+
export const requestSync = mutable(listId => dispatch => {
|
|
49
|
+
dispatch(requestFlushFavoritesBuffer(listId));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
27
53
|
* Adds a product to the favorite list (debounced and buffered).
|
|
28
54
|
* @param {string} productId Product identifier.
|
|
29
55
|
* @param {string} listId List identifier.
|
|
30
56
|
* @param {boolean} withRelatives When true relatives which are on list are also removed.
|
|
31
57
|
* @return {Function}
|
|
32
|
-
*/
|
|
33
|
-
|
|
58
|
+
*/
|
|
59
|
+
export const toggleFavorite = mutable((productId, listId, withRelatives = false) => (dispatch, getState) => {
|
|
60
|
+
const state = getState();
|
|
61
|
+
// With quantity enabled the favorites button always adds (increases quantity)
|
|
62
|
+
const wishlistItemQuantityEnabled = getWishlistItemQuantityEnabled(state);
|
|
63
|
+
const loadWishlistOnAppStartEnabled = getLoadWishlistOnAppStartEnabled(state);
|
|
64
|
+
if (wishlistItemQuantityEnabled || !loadWishlistOnAppStartEnabled) {
|
|
65
|
+
dispatch(addFavorite(productId, listId, null, null, true));
|
|
66
|
+
} else {
|
|
67
|
+
const isOnList = makeIsProductOnSpecificFavoriteList(() => productId, () => listId)(state);
|
|
68
|
+
dispatch(!isOnList ? addFavorite(productId, listId) : removeFavorites(productId, withRelatives, listId));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
/**
|
|
34
73
|
* Updatest a product in the favorite list (debounced and buffered).
|
|
35
74
|
* @param {string} productId Product identifier.
|
|
36
75
|
* @param {string} listId List identifier.
|
|
37
76
|
* @param {number} quantity
|
|
38
77
|
* @param {string} notes
|
|
39
78
|
* @return {Function}
|
|
40
|
-
*/
|
|
79
|
+
*/
|
|
80
|
+
export const updateFavorite = mutable((productId, listId, quantity, notes) => (dispatch, getState) => {
|
|
81
|
+
const defaultList = getFavoritesDefaultList(getState());
|
|
82
|
+
dispatch(updateProductInFavorites(productId, listId || defaultList.id, quantity, notes));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
41
86
|
* Adds a product to a wishlist by opening a chooser if user has multiple lists.
|
|
42
87
|
* @mixes {MutableFunction}
|
|
43
88
|
* @param {string} productId Product identifier.
|
|
44
89
|
* @param {boolean} withRelatives When true relatives which are on list are also removed.
|
|
45
90
|
* @return {Function}
|
|
46
|
-
*/
|
|
47
|
-
|
|
91
|
+
*/
|
|
92
|
+
export const toggleFavoriteWithListChooser = mutable((productId, withRelatives = false) => async (dispatch, getState) => {
|
|
93
|
+
// Ensure favorites lists are fetched before.
|
|
94
|
+
// In some cases this fetch will NOT happen on app start
|
|
95
|
+
await dispatch(fetchFavoritesListsWithItems());
|
|
96
|
+
const state = getState();
|
|
97
|
+
const lists = getFavoritesLists(state);
|
|
98
|
+
|
|
99
|
+
// Only one list available therefore we just add/remove it the product there.
|
|
100
|
+
if (lists.length <= 1) {
|
|
101
|
+
dispatch(toggleFavorite(productId, lists[0].id, withRelatives));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
dispatch(openFavoritesListChooser(productId, withRelatives));
|
|
105
|
+
});
|
|
@@ -1,9 +1,45 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
2
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
3
|
+
import isNumber from 'lodash/isNumber';
|
|
4
|
+
import isString from 'lodash/isString';
|
|
5
|
+
import { SHOPGATE_USER_UPDATE_FAVORITES } from "../constants/Pipelines";
|
|
6
|
+
import { errorUpdateFavorites, successUpdateFavorites } from "../action-creators";
|
|
7
|
+
import { getHasMultipleFavoritesListsSupport, getFavoritesDefaultList } from "../selectors";
|
|
8
|
+
/**
|
|
2
9
|
* Updates a single product on the favorite list using the `updateFavorites` pipeline.
|
|
3
10
|
* @param {string} productId The id of the product.
|
|
4
11
|
* @param {string} listId Id of the list to be updated.
|
|
5
12
|
* @param {number} quantity New favorites quantity to set
|
|
6
13
|
* @param {string} notes ew favorites notes to set
|
|
7
14
|
* @returns {Function} A redux thunk.
|
|
8
|
-
*/
|
|
9
|
-
|
|
15
|
+
*/
|
|
16
|
+
function updateFavorites(productId, listId = null, quantity, notes) {
|
|
17
|
+
return async (dispatch, getState) => {
|
|
18
|
+
const state = getState();
|
|
19
|
+
const hasMultiSupport = getHasMultipleFavoritesListsSupport(state);
|
|
20
|
+
|
|
21
|
+
// Fallback for deprecated calls without list id.
|
|
22
|
+
const defaultList = getFavoritesDefaultList(state);
|
|
23
|
+
const takenListId = listId || defaultList.id;
|
|
24
|
+
const request = new PipelineRequest(SHOPGATE_USER_UPDATE_FAVORITES).setInput({
|
|
25
|
+
productId,
|
|
26
|
+
...(hasMultiSupport ? {
|
|
27
|
+
favoritesListId: takenListId
|
|
28
|
+
} : null),
|
|
29
|
+
...(isNumber(quantity) ? {
|
|
30
|
+
quantity
|
|
31
|
+
} : {}),
|
|
32
|
+
...(isString(notes) ? {
|
|
33
|
+
notes
|
|
34
|
+
} : {})
|
|
35
|
+
}).setRetries(0).dispatch();
|
|
36
|
+
try {
|
|
37
|
+
await request;
|
|
38
|
+
dispatch(successUpdateFavorites(productId, takenListId));
|
|
39
|
+
} catch (error) {
|
|
40
|
+
dispatch(errorUpdateFavorites(productId, error, takenListId));
|
|
41
|
+
}
|
|
42
|
+
return request;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export default mutable(updateFavorites);
|
|
@@ -1,6 +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_UPDATE_FAVORITES_LIST } from "../constants/Pipelines";
|
|
4
|
+
import { SUCCESS_UPDATE_FAVORITES_LIST } from "../constants";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* Adds a new favorite list.
|
|
3
8
|
* @param {string} listId Id of the wishlist.
|
|
4
9
|
* @param {string} name Name of the wishlist.
|
|
5
10
|
* @returns {Function} A redux thunk.
|
|
6
|
-
*/
|
|
11
|
+
*/
|
|
12
|
+
function updateFavoritesList(listId, name) {
|
|
13
|
+
return async dispatch => {
|
|
14
|
+
const request = new PipelineRequest(SHOPGATE_USER_UPDATE_FAVORITES_LIST).setInput({
|
|
15
|
+
id: listId,
|
|
16
|
+
name
|
|
17
|
+
}).setRetries(0).dispatch();
|
|
18
|
+
try {
|
|
19
|
+
await request;
|
|
20
|
+
dispatch({
|
|
21
|
+
type: SUCCESS_UPDATE_FAVORITES_LIST,
|
|
22
|
+
listId,
|
|
23
|
+
name
|
|
24
|
+
});
|
|
25
|
+
} catch (_) {
|
|
26
|
+
// Fail silently
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export default mutable(updateFavoritesList);
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const SHOPGATE_USER_GET_FAVORITES = 'shopgate.user.getFavorites';
|
|
2
|
+
export const SHOPGATE_USER_GET_FAVORITE_IDS = 'shopgate.user.getFavoriteIds';
|
|
3
|
+
export const SHOPGATE_USER_ADD_FAVORITES = 'shopgate.user.addFavorites';
|
|
4
|
+
export const SHOPGATE_USER_DELETE_FAVORITES = 'shopgate.user.deleteFavorites';
|
|
5
|
+
export const SHOPGATE_USER_UPDATE_FAVORITES = 'shopgate.user.updateFavorites';
|
|
6
|
+
export const SHOPGATE_USER_GET_FAVORITES_LIST = 'shopgate.user.getFavoritesLists';
|
|
7
|
+
export const SHOPGATE_USER_ADD_FAVORITES_LIST = 'shopgate.user.addFavoritesList';
|
|
8
|
+
export const SHOPGATE_USER_UPDATE_FAVORITES_LIST = 'shopgate.user.updateFavoritesList';
|
|
9
|
+
export const SHOPGATE_USER_REMOVE_FAVORITES_LIST = 'shopgate.user.removeFavoritesList';
|
|
@@ -3,7 +3,35 @@
|
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the Apache 2.0 license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// FEATURES
|
|
9
|
+
const NAV_MENU = 'nav-menu';
|
|
10
|
+
|
|
11
|
+
// CONTENTS
|
|
12
|
+
export const FAVORITES = 'favorites';
|
|
13
|
+
const ADD_TO_CART = 'add-to-cart';
|
|
14
|
+
const AVAILABILITY_TEXT = 'availability-text';
|
|
15
|
+
const PRODUCT_NAME = 'product-name';
|
|
16
|
+
const PRODUCT_PRICE = 'product-price';
|
|
17
|
+
const EMPTY = 'empty';
|
|
18
|
+
|
|
19
|
+
// POSITIONS
|
|
20
|
+
const BEFORE = 'before';
|
|
21
|
+
const AFTER = 'after';
|
|
22
|
+
export const NAV_MENU_FAVORITES_BEFORE = `${NAV_MENU}.${FAVORITES}.${BEFORE}`;
|
|
23
|
+
export const NAV_MENU_FAVORITES = `${NAV_MENU}.${FAVORITES}`;
|
|
24
|
+
export const NAV_MENU_FAVORITES_AFTER = `${NAV_MENU}.${FAVORITES}.${AFTER}`;
|
|
25
|
+
export const FAVORITES_ADD_TO_CART_BEFORE = `${FAVORITES}.${ADD_TO_CART}.${BEFORE}`;
|
|
26
|
+
export const FAVORITES_ADD_TO_CART = `${FAVORITES}.${ADD_TO_CART}`;
|
|
27
|
+
export const FAVORITES_ADD_TO_CART_AFTER = `${FAVORITES}.${ADD_TO_CART}.${AFTER}`;
|
|
28
|
+
export const FAVORITES_PRODUCT_NAME_BEFORE = `${FAVORITES}.${PRODUCT_NAME}.${BEFORE}`;
|
|
29
|
+
export const FAVORITES_PRODUCT_NAME = `${FAVORITES}.${PRODUCT_NAME}`;
|
|
30
|
+
export const FAVORITES_PRODUCT_NAME_AFTER = `${FAVORITES}.${PRODUCT_NAME}.${AFTER}`;
|
|
31
|
+
export const FAVORITES_PRODUCT_PRICE_BEFORE = `${FAVORITES}.${PRODUCT_PRICE}.${BEFORE}`;
|
|
32
|
+
export const FAVORITES_PRODUCT_PRICE = `${FAVORITES}.${PRODUCT_PRICE}`;
|
|
33
|
+
export const FAVORITES_PRODUCT_PRICE_AFTER = `${FAVORITES}.${PRODUCT_PRICE}.${AFTER}`;
|
|
34
|
+
export const FAVORITES_AVAILABILITY_TEXT_BEFORE = `${FAVORITES}.${AVAILABILITY_TEXT}.${BEFORE}`;
|
|
35
|
+
export const FAVORITES_AVAILABILITY_TEXT = `${FAVORITES}.${AVAILABILITY_TEXT}`;
|
|
36
|
+
export const FAVORITES_AVAILABILITY_TEXT_AFTER = `${FAVORITES}.${AVAILABILITY_TEXT}.${AFTER}`;
|
|
37
|
+
export const FAVORITES_EMPTY = `${FAVORITES}.${EMPTY}`;
|
|
@@ -1,5 +1,37 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
1
|
+
export const FAVORITES_PATH = '/favourite_list';
|
|
2
|
+
export const ADD_PRODUCT_TO_FAVORITES = 'ADD_PRODUCT_TO_FAVORITES';
|
|
3
|
+
export const UPDATE_PRODUCT_IN_FAVORITES = 'UPDATE_PRODUCT_IN_FAVORITES';
|
|
4
|
+
export const REMOVE_PRODUCT_FROM_FAVORITES = 'REMOVE_PRODUCT_FROM_FAVORITES';
|
|
5
|
+
export const REQUEST_UPDATE_FAVORITES = 'REQUEST_UPDATE_FAVORITES';
|
|
6
|
+
export const SUCCESS_UPDATE_FAVORITES = 'SUCCESS_UPDATE_FAVORITES';
|
|
7
|
+
export const ERROR_UPDATE_FAVORITES = 'ERROR_UPDATE_FAVORITES';
|
|
8
|
+
export const REQUEST_FAVORITES = 'REQUEST_FAVORITES';
|
|
9
|
+
export const RECEIVE_FAVORITES = 'RECEIVE_FAVORITES';
|
|
10
|
+
export const ERROR_FAVORITES = 'ERROR_FAVORITES';
|
|
11
|
+
export const ERROR_FETCH_FAVORITES = 'ERROR_FETCH_FAVORITES';
|
|
12
|
+
export const REQUEST_ADD_FAVORITES = 'REQUEST_ADD_FAVORITES';
|
|
13
|
+
export const SUCCESS_ADD_FAVORITES = 'SUCCESS_ADD_FAVORITES';
|
|
14
|
+
export const ERROR_ADD_FAVORITES = 'ERROR_ADD_FAVORITES';
|
|
15
|
+
export const REQUEST_REMOVE_FAVORITES = 'REQUEST_REMOVE_FAVORITES';
|
|
16
|
+
export const SUCCESS_REMOVE_FAVORITES = 'SUCCESS_REMOVE_FAVORITES';
|
|
17
|
+
export const ERROR_REMOVE_FAVORITES = 'ERROR_REMOVE_FAVORITES';
|
|
18
|
+
export const CANCEL_REQUEST_SYNC_FAVORITES = 'CANCEL_REQUEST_SYNC_FAVORITES';
|
|
19
|
+
export const IDLE_SYNC_FAVORITES = 'IDLE_SYNC_FAVORITES';
|
|
20
|
+
export const REQUEST_FLUSH_FAVORITES_BUFFER = 'REQUEST_FLUSH_FAVORITES_BUFFER';
|
|
21
|
+
|
|
22
|
+
// Defines a local error code which is not related to a backend call
|
|
23
|
+
export const FAVORITES_LIMIT_ERROR = 'FAVORITES_LIMIT_ERROR';
|
|
24
|
+
export const FAVORITES_LIFETIME = 3600000; // 1 hour
|
|
25
|
+
export const FETCH_FAVORITES_THROTTLE = process.env && process.env.NODE_ENV === 'test' ? 0 : 2000;
|
|
26
|
+
export const FAVORITE_ACTION_BUFFER_TIME = 500;
|
|
27
|
+
export const FAVORITE_BUTTON_DEBOUNCE_TIME = 200; // Handles duplicated add/remove button clicks
|
|
28
|
+
export const FAVORITE_QUANTITY_DEBOUNCE_TIME = 200; // Handles duplicated update button clicks
|
|
29
|
+
|
|
30
|
+
export const RECEIVE_FAVORITES_LISTS = 'SUCCESS_FETCH_FAVORITES_LIST';
|
|
31
|
+
export const SUCCESS_ADD_FAVORITES_LIST = 'SUCCESS_ADD_FAVORITES_LIST';
|
|
32
|
+
export const SUCCESS_UPDATE_FAVORITES_LIST = 'SUCCESS_UPDATE_FAVORITES_LIST';
|
|
33
|
+
export const SUCCESS_REMOVE_FAVORITES_LIST = 'SUCCESS_REMOVE_FAVORITES_LIST';
|
|
34
|
+
export const OPEN_FAVORITE_LIST_CHOOSER = 'OPEN_FAVORITE_LIST_CHOOSER';
|
|
35
|
+
export const CLOSE_FAVORITE_LIST_CHOOSER = 'CLOSE_FAVORITE_LIST_CHOOSER';
|
|
36
|
+
export const OPEN_FAVORITE_COMMENT_DIALOG = 'OPEN_FAVORITE_COMMENT_DIALOG';
|
|
37
|
+
export const CLOSE_FAVORITE_COMMENT_DIALOG = 'CLOSE_FAVORITE_COMMENT_DIALOG';
|
package/favorites/index.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
// ACTIONS
|
|
2
|
-
export{default as fetchFavorites}from"./actions/fetchFavorites";
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
|
|
2
|
+
export { default as fetchFavorites } from "./actions/fetchFavorites";
|
|
3
|
+
export { addFavorite, removeFavorites, requestSync as toggleFavorites } from "./actions/toggleFavorites";
|
|
4
|
+
export { default as fetchFavoritesListsWithItems } from "./actions/fetchFavoritesListsWithItems";
|
|
5
|
+
|
|
6
|
+
// CONSTANTS
|
|
7
|
+
export * from "./constants/index";
|
|
8
|
+
export * from "./constants/Pipelines";
|
|
9
|
+
export * from "./constants/Portals";
|
|
10
|
+
|
|
11
|
+
// SELECTORS
|
|
12
|
+
export * from "./selectors";
|
|
13
|
+
|
|
14
|
+
// STREAMS
|
|
15
|
+
export * from "./streams";
|
package/favorites/mock.js
CHANGED
|
@@ -1,15 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
import "core-js/modules/es.array.reduce.js";
|
|
2
|
+
import { mockedProducts as mockedList } from "../product/mock";
|
|
3
|
+
export const mockedDefaultListId = 'DEFAULT';
|
|
4
|
+
const mockedStateWithoutProducts = {
|
|
5
|
+
favorites: {
|
|
6
|
+
byList: {
|
|
7
|
+
[mockedDefaultListId]: {
|
|
8
|
+
isFetching: false,
|
|
9
|
+
expires: 0,
|
|
10
|
+
ids: []
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
lists: {
|
|
14
|
+
expires: 0,
|
|
15
|
+
lists: [{
|
|
16
|
+
id: mockedDefaultListId,
|
|
17
|
+
name: 'Wish List'
|
|
18
|
+
}]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
2
24
|
* Creates a products state from the mocked list.
|
|
3
25
|
* @return {Object}
|
|
4
|
-
*/
|
|
26
|
+
*/
|
|
27
|
+
const createProductsState = () => {
|
|
28
|
+
const productsById = mockedList.products.reduce((result, current) => ({
|
|
29
|
+
...result,
|
|
30
|
+
[current.id]: {
|
|
31
|
+
isFetching: false,
|
|
32
|
+
expires: 0,
|
|
33
|
+
productData: current
|
|
34
|
+
}
|
|
35
|
+
}), {});
|
|
36
|
+
return {
|
|
37
|
+
product: {
|
|
38
|
+
productsById
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const mockedStateWithProducts = {
|
|
43
|
+
...createProductsState(),
|
|
44
|
+
favorites: {
|
|
45
|
+
byList: {
|
|
46
|
+
[mockedDefaultListId]: {
|
|
47
|
+
isFetching: false,
|
|
48
|
+
expires: 0,
|
|
49
|
+
ids: [mockedList.products[0].id, mockedList.products[1].id]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
lists: {
|
|
53
|
+
expires: 0,
|
|
54
|
+
lists: [{
|
|
55
|
+
id: mockedDefaultListId,
|
|
56
|
+
name: 'Wish List'
|
|
57
|
+
}]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
5
63
|
* Gets mocked state.
|
|
6
64
|
* @param {boolean} withProducts When true products are returned.
|
|
7
65
|
* @param {boolean} validCache When true, `.expires` flag is > `Date.now()`
|
|
8
66
|
* @returns {Object}
|
|
9
|
-
*/
|
|
67
|
+
*/
|
|
68
|
+
const getMockedState = ({
|
|
69
|
+
withProducts,
|
|
70
|
+
validCache = false
|
|
71
|
+
}) => {
|
|
72
|
+
const data = withProducts ? mockedStateWithProducts : mockedStateWithoutProducts;
|
|
73
|
+
if (validCache) {
|
|
74
|
+
data.favorites.byList[mockedDefaultListId].expires = Date.now() + 999999;
|
|
75
|
+
}
|
|
76
|
+
return data;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
10
80
|
* Gets mocked state.
|
|
11
81
|
* @param {'then'|string} variant Variant as in MockedPipelineResponse.
|
|
12
82
|
* @param {boolean} withProducts When true products are returned.
|
|
13
83
|
* @param {boolean} validCache When true, `.expires` flag is > `Date.now()`
|
|
14
84
|
* @returns {Function}
|
|
15
|
-
*/
|
|
85
|
+
*/
|
|
86
|
+
const mockedGetState = (variant, {
|
|
87
|
+
withProducts = false,
|
|
88
|
+
validCache = false
|
|
89
|
+
} = {}) => () => {
|
|
90
|
+
if (variant === 'then') {
|
|
91
|
+
return getMockedState({
|
|
92
|
+
withProducts,
|
|
93
|
+
validCache
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return getMockedState({
|
|
97
|
+
withProducts: false
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
export { mockedList, mockedGetState };
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
import{combineReducers}from'redux';
|
|
1
|
+
import { combineReducers } from 'redux';
|
|
2
|
+
import products from "./products";
|
|
3
|
+
import lists from "./lists";
|
|
4
|
+
export default combineReducers({
|
|
5
|
+
products,
|
|
6
|
+
lists
|
|
7
|
+
});
|