@shopgate/pwa-common-commerce 7.30.0-alpha.7 → 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,3 +1,13 @@
|
|
|
1
|
-
import{combineReducers}from'redux';
|
|
1
|
+
import { combineReducers } from 'redux';
|
|
2
|
+
import rootCategories from "./rootCategories";
|
|
3
|
+
import categoriesById from "./categoriesById";
|
|
4
|
+
import childrenByCategoryId from "./childrenByCategoryId";
|
|
5
|
+
|
|
6
|
+
/**
|
|
2
7
|
* The category reducer.
|
|
3
|
-
*/
|
|
8
|
+
*/
|
|
9
|
+
export default combineReducers({
|
|
10
|
+
categoriesById,
|
|
11
|
+
childrenByCategoryId,
|
|
12
|
+
rootCategories
|
|
13
|
+
});
|
|
@@ -1,7 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
import { CATEGORY_LIFETIME, REQUEST_ROOT_CATEGORIES, RECEIVE_ROOT_CATEGORIES, ERROR_ROOT_CATEGORIES } from "../constants";
|
|
2
|
+
import handleReceivedCategories from "./helpers/handleReceivedCategories";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Stores a collection of category IDs that represent the
|
|
3
6
|
* highest level of categories with no parent.
|
|
4
7
|
* @param {Object} [state={}] The current application state.
|
|
5
8
|
* @param {Object} action The action object.
|
|
6
9
|
* @return {Object} The store data.
|
|
7
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
const rootCategories = (state = {}, action) => {
|
|
12
|
+
switch (action.type) {
|
|
13
|
+
case REQUEST_ROOT_CATEGORIES:
|
|
14
|
+
return {
|
|
15
|
+
...state,
|
|
16
|
+
categories: null,
|
|
17
|
+
expires: 0,
|
|
18
|
+
isFetching: true
|
|
19
|
+
};
|
|
20
|
+
case RECEIVE_ROOT_CATEGORIES:
|
|
21
|
+
return {
|
|
22
|
+
...state,
|
|
23
|
+
categories: handleReceivedCategories(action.categories),
|
|
24
|
+
expires: Date.now() + CATEGORY_LIFETIME,
|
|
25
|
+
isFetching: false
|
|
26
|
+
};
|
|
27
|
+
case ERROR_ROOT_CATEGORIES:
|
|
28
|
+
return {
|
|
29
|
+
...state,
|
|
30
|
+
isFetching: false
|
|
31
|
+
};
|
|
32
|
+
default:
|
|
33
|
+
return state;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export default rootCategories;
|
|
@@ -1,80 +1,160 @@
|
|
|
1
|
-
import{createSelector}from'reselect';
|
|
1
|
+
import { createSelector } from 'reselect';
|
|
2
|
+
import { getCurrentRoute, getCurrentParams } from '@shopgate/pwa-common/selectors/router';
|
|
3
|
+
import { hex2bin } from '@shopgate/pwa-common/helpers/data';
|
|
4
|
+
|
|
5
|
+
/**
|
|
2
6
|
* Retrieves the category state from the state.
|
|
3
7
|
* @param {Object} state The application state.
|
|
4
8
|
* @param {Object} props The component props.
|
|
5
9
|
* @returns {Object} The category state.
|
|
6
|
-
*/
|
|
10
|
+
*/
|
|
11
|
+
const getCategoryState = state => state.category;
|
|
12
|
+
|
|
13
|
+
/**
|
|
7
14
|
* Retrieves the categoriesById state from the category state.
|
|
8
15
|
* @param {Object} state The application state.
|
|
9
16
|
* @param {Object} props The component props.
|
|
10
17
|
* @returns {Object} The categoriesById state.
|
|
11
|
-
*/
|
|
18
|
+
*/
|
|
19
|
+
const getCategoriesByIdState = createSelector(getCategoryState, (state = {}) => state.categoriesById || {});
|
|
20
|
+
|
|
21
|
+
/**
|
|
12
22
|
* Retrieves the childrenByCategoryId state from the category state.
|
|
13
23
|
* @param {Object} state The application state.
|
|
14
24
|
* @param {Object} props The component props.
|
|
15
25
|
* @returns {Object} The childrenByCategoryId state.
|
|
16
|
-
*/
|
|
26
|
+
*/
|
|
27
|
+
const getChildrenByCategoryIdState = createSelector(getCategoryState, (state = {}) => state.childrenByCategoryId || {});
|
|
28
|
+
|
|
29
|
+
/**
|
|
17
30
|
* Retrieves the rootCategories state from the category state.
|
|
18
31
|
* @param {Object} state The application state.
|
|
19
32
|
* @returns {Object}
|
|
20
|
-
*/
|
|
33
|
+
*/
|
|
34
|
+
export const getRootCategoriesState = createSelector(getCategoryState, (state = {}) => state.rootCategories || {});
|
|
35
|
+
|
|
36
|
+
/**
|
|
21
37
|
* Retrieves a category id either from the selector props, or the params of the active route.
|
|
22
38
|
* @param {Object} state The application state.
|
|
23
39
|
* @param {Object} props The component props.
|
|
24
40
|
* @returns {string|null} The category ID.
|
|
25
|
-
*/
|
|
41
|
+
*/
|
|
42
|
+
export const getCategoryId = createSelector((state, props = {}) => props.categoryId, getCurrentParams, (categoryId, routeParams) => {
|
|
43
|
+
if (typeof categoryId !== 'undefined') {
|
|
44
|
+
return categoryId;
|
|
45
|
+
}
|
|
46
|
+
if (!routeParams || !routeParams.categoryId) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return hex2bin(routeParams.categoryId);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
26
53
|
* Retrieves the child categories for a specific parent category from the state.
|
|
27
54
|
* @param {Object} state The application state.
|
|
28
55
|
* @param {Object} props The component props.
|
|
29
56
|
* @returns {Object}
|
|
30
|
-
*/
|
|
57
|
+
*/
|
|
58
|
+
export const getChildCategoriesForCategory = createSelector(getCategoryId, getChildrenByCategoryIdState, (categoryId, childCategories) => childCategories[categoryId]);
|
|
59
|
+
|
|
60
|
+
/**
|
|
31
61
|
* Retrieves a category from state.
|
|
32
62
|
* The category can either be referenced by a categoryId within the props,
|
|
33
63
|
* or by a categoryId within the params of the active route state.
|
|
34
64
|
* @param {Object} state The current application state.
|
|
35
65
|
* @param {Object} props The component props.
|
|
36
66
|
* @return {Object|null}
|
|
37
|
-
*/
|
|
67
|
+
*/
|
|
68
|
+
export const getCategory = createSelector(getCategoryId, getCategoriesByIdState, (categoryId, categoriesById) => {
|
|
69
|
+
if (!categoriesById || !categoriesById[categoryId]) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
return categoriesById[categoryId];
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
/**
|
|
38
76
|
* Retrieves the root categories.
|
|
39
77
|
* @param {Object} state The application state.
|
|
40
78
|
* @param {Object} props The component props.
|
|
41
79
|
* @returns {Array}
|
|
42
|
-
*/
|
|
80
|
+
*/
|
|
81
|
+
export const getRootCategories = createSelector(getRootCategoriesState, getCategoriesByIdState, (rootCategories, categoriesById) => {
|
|
82
|
+
if (Object.keys(rootCategories).length === 0) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
if (!rootCategories.categories) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
return rootCategories.categories.map(id => categoriesById[id]).filter(Boolean);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
43
92
|
* Retrieves the number of child categories for a category.
|
|
44
93
|
* The category can either be referenced by a categoryId within the props,
|
|
45
94
|
* or by a categoryId within the params of the active route state.
|
|
46
95
|
* @param {Object} state The current application state.
|
|
47
96
|
* @param {Object} props The component props.
|
|
48
97
|
* @returns {number|null}
|
|
49
|
-
*/
|
|
98
|
+
*/
|
|
99
|
+
export const getCategoryChildCount = createSelector(getCategory, category => category ? category.childrenCount : null);
|
|
100
|
+
|
|
101
|
+
/**
|
|
50
102
|
* Determines if a category has child categories.
|
|
51
103
|
* The category can either be referenced by a categoryId within the props,
|
|
52
104
|
* or by a categoryId within the params of the active route state.
|
|
53
105
|
* @param {Object} state The application state.
|
|
54
106
|
* @param {Object} props The component props.
|
|
55
107
|
* @returns {boolean}
|
|
56
|
-
*/
|
|
108
|
+
*/
|
|
109
|
+
export const hasCategoryChildren = createSelector(getCategoryChildCount, count => count > 0);
|
|
110
|
+
|
|
111
|
+
/**
|
|
57
112
|
* Retrieves the child categories of a category.
|
|
58
113
|
* The category can either be referenced by a categoryId within the props,
|
|
59
114
|
* or by a categoryId within the params of the active route state.
|
|
60
115
|
* @param {Object} state The application state.
|
|
61
116
|
* @param {Object} props The component props.
|
|
62
117
|
* @returns {Array|null}
|
|
63
|
-
*/
|
|
118
|
+
*/
|
|
119
|
+
export const getCategoryChildren = createSelector([getChildCategoriesForCategory, getCategoriesByIdState], (childCategories, categoriesById) => {
|
|
120
|
+
if (!childCategories || !childCategories.children) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return childCategories.children.map(id => categoriesById[id]).filter(Boolean);
|
|
124
|
+
});
|
|
125
|
+
export const areCategoryChildrenFetching = createSelector([getChildCategoriesForCategory], childCategories => {
|
|
126
|
+
if (!childCategories || !childCategories.isFetching) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return childCategories.isFetching;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/**
|
|
64
133
|
* Retrieves the number of products inside a category.
|
|
65
134
|
* The category can either be referenced by a categoryId within the props,
|
|
66
135
|
* or by a categoryId within the params of the active route state.
|
|
67
136
|
* @param {Object} state The application state.
|
|
68
137
|
* @param {Object} props The component props.
|
|
69
138
|
* @returns {number|null}
|
|
70
|
-
*/
|
|
139
|
+
*/
|
|
140
|
+
export const getCategoryProductCount = createSelector(getCategoriesByIdState, getCategoryId, (categoriesById, categoryId) => {
|
|
141
|
+
if (!categoriesById[categoryId] || !categoriesById[categoryId].productCount && categoriesById[categoryId].productCount !== 0) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return categoriesById[categoryId].productCount;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
71
148
|
* Determines if a category has products.
|
|
72
149
|
* The category can either be referenced by a categoryId within the props,
|
|
73
150
|
* or by a categoryId within the params of the active route state.
|
|
74
151
|
* @param {Object} state The application state.
|
|
75
152
|
* @param {Object} props The component props.
|
|
76
153
|
* @returns {boolean}
|
|
77
|
-
*/
|
|
154
|
+
*/
|
|
155
|
+
export const hasCategoryProducts = createSelector(getCategoryProductCount, count => count > 0);
|
|
156
|
+
|
|
157
|
+
/**
|
|
78
158
|
* Retrieves the name of a category. When no category can be determined it return the title of
|
|
79
159
|
* the active route.
|
|
80
160
|
* The category can either be referenced by a categoryId within the props,
|
|
@@ -82,7 +162,26 @@ import{createSelector}from'reselect';import{getCurrentRoute,getCurrentParams}fro
|
|
|
82
162
|
* @param {Object} state The application state.
|
|
83
163
|
* @param {Object} props The component props.
|
|
84
164
|
* @returns {number|null}
|
|
85
|
-
*/
|
|
165
|
+
*/
|
|
166
|
+
export const getCategoryName = createSelector(getCurrentRoute, getCategory, (route, category) => {
|
|
167
|
+
if (category) {
|
|
168
|
+
return category.name;
|
|
169
|
+
}
|
|
170
|
+
if (route.state.title) {
|
|
171
|
+
return route.state.title;
|
|
172
|
+
}
|
|
173
|
+
return null;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
/**
|
|
86
177
|
* Selector mappings for PWA < 6.10
|
|
87
178
|
* @deprecated
|
|
88
|
-
*/
|
|
179
|
+
*/
|
|
180
|
+
export const getCategoryById = getCategory;
|
|
181
|
+
export const getCurrentCategoryId = getCategory;
|
|
182
|
+
export const getCurrentCategory = getCategory;
|
|
183
|
+
export const getCurrentCategoryChildCount = getCategoryChildCount;
|
|
184
|
+
export const getCurrentCategories = getCategoryChildren;
|
|
185
|
+
export const getChildCategoriesById = getCategoryChildren;
|
|
186
|
+
export const hasChildren = hasCategoryChildren;
|
|
187
|
+
export const hasProducts = hasCategoryProducts;
|
|
@@ -1,10 +1,88 @@
|
|
|
1
|
-
import{main$,routeWillEnter$,routeDidEnter$,routeDidLeave$,routeWillLeave$}from'@shopgate/pwa-common/streams';
|
|
1
|
+
import { main$, routeWillEnter$, routeDidEnter$, routeDidLeave$, routeWillLeave$ } from '@shopgate/pwa-common/streams';
|
|
2
|
+
import { routeDidUpdate$ } from '@shopgate/pwa-common/streams/router';
|
|
3
|
+
import { HISTORY_POP_ACTION } from '@shopgate/pwa-common/constants/ActionTypes';
|
|
4
|
+
import { filtersDidUpdate$ } from '@shopgate/pwa-common-commerce/filter/streams';
|
|
5
|
+
import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
|
|
6
|
+
import { hex2bin } from '@shopgate/pwa-common/helpers/data';
|
|
7
|
+
import { filterWillLeave$ } from "../../filter/streams";
|
|
8
|
+
import { CATEGORY_PATTERN, CATEGORY_ALL_PATTERN, RECEIVE_ROOT_CATEGORIES, ERROR_CATEGORY, RECEIVE_CATEGORY, CATEGORY_PATH } from "../constants";
|
|
9
|
+
export const categoryWillEnter$ = routeWillEnter$.filter(({
|
|
10
|
+
action
|
|
11
|
+
}) => action.route.pattern === CATEGORY_PATTERN);
|
|
12
|
+
export const categoryDidEnter$ = routeDidEnter$.filter(({
|
|
13
|
+
action
|
|
14
|
+
}) => action.route.pattern === CATEGORY_PATTERN);
|
|
15
|
+
export const categoryDidLeave$ = routeDidLeave$.filter(({
|
|
16
|
+
action
|
|
17
|
+
}) => action.route.pattern === CATEGORY_PATTERN);
|
|
18
|
+
export const categoryAllWillEnter$ = routeWillEnter$.filter(({
|
|
19
|
+
action
|
|
20
|
+
}) => action.route.pattern === CATEGORY_ALL_PATTERN);
|
|
21
|
+
export const categoryAllDidEnter$ = routeDidEnter$.filter(({
|
|
22
|
+
action
|
|
23
|
+
}) => action.route.pattern === CATEGORY_ALL_PATTERN);
|
|
24
|
+
export const categoryAllDidLeave$ = routeDidLeave$.filter(({
|
|
25
|
+
action
|
|
26
|
+
}) => action.route.pattern === CATEGORY_ALL_PATTERN);
|
|
27
|
+
|
|
28
|
+
/**
|
|
2
29
|
* Gets triggered when the root categories received.
|
|
3
|
-
*/
|
|
30
|
+
*/
|
|
31
|
+
export const receivedRootCategories$ = main$.filter(({
|
|
32
|
+
action
|
|
33
|
+
}) => action.type === RECEIVE_ROOT_CATEGORIES);
|
|
34
|
+
|
|
35
|
+
/**
|
|
4
36
|
* Gets trigger when category error is dispatched.
|
|
5
|
-
*/
|
|
37
|
+
*/
|
|
38
|
+
export const categoryError$ = main$.filter(({
|
|
39
|
+
action
|
|
40
|
+
}) => action.type === ERROR_CATEGORY);
|
|
41
|
+
export const categoryDidBackEnter$ = categoryDidEnter$.filter(({
|
|
42
|
+
action
|
|
43
|
+
}) => action.historyAction === HISTORY_POP_ACTION);
|
|
44
|
+
export const categoryWillLeave$ = routeWillLeave$.filter(({
|
|
45
|
+
action
|
|
46
|
+
}) => action.route.pattern === `${CATEGORY_PATH}/:categoryId`);
|
|
47
|
+
|
|
48
|
+
/**
|
|
6
49
|
* Filters stream state by type.
|
|
7
50
|
* @param {Object} data The stream data.
|
|
8
51
|
* @param {string} type The action type to filter.
|
|
9
52
|
* @returns {boolean}
|
|
10
|
-
*/
|
|
53
|
+
*/
|
|
54
|
+
const filterDataByType = (data, type) => {
|
|
55
|
+
const {
|
|
56
|
+
action,
|
|
57
|
+
getState
|
|
58
|
+
} = data;
|
|
59
|
+
if (action.type !== type) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (typeof action.categoryId === 'undefined') {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const route = getCurrentRoute(getState());
|
|
66
|
+
if (!route.params.categoryId) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return action.categoryId === hex2bin(route.params.categoryId);
|
|
70
|
+
};
|
|
71
|
+
export const receivedVisibleCategory$ = main$.filter(data => filterDataByType(data, RECEIVE_CATEGORY));
|
|
72
|
+
export const errorVisibleCategory$ = main$.filter(data => filterDataByType(data, ERROR_CATEGORY));
|
|
73
|
+
export const categoryFiltersDidUpdate$ = filtersDidUpdate$.filter(({
|
|
74
|
+
getState
|
|
75
|
+
}) => {
|
|
76
|
+
const {
|
|
77
|
+
pattern
|
|
78
|
+
} = getCurrentRoute(getState());
|
|
79
|
+
return pattern === CATEGORY_PATTERN;
|
|
80
|
+
});
|
|
81
|
+
export const categoryDidUpdate$ = routeDidUpdate$.filter(({
|
|
82
|
+
action
|
|
83
|
+
}) => action?.route?.pattern === CATEGORY_PATTERN);
|
|
84
|
+
export const categoryAllDidUpdate$ = routeDidUpdate$.filter(({
|
|
85
|
+
action
|
|
86
|
+
}) => action?.route?.pattern === CATEGORY_ALL_PATTERN);
|
|
87
|
+
export const categoryFiltersDidUpdateFromFilterPage$ = categoryDidUpdate$.switchMap(() => filterWillLeave$.first()).switchMap(() => categoryWillEnter$.first());
|
|
88
|
+
export const categoryAllFiltersDidUpdateFromFilterPage$ = categoryAllDidUpdate$.switchMap(() => filterWillLeave$.first()).switchMap(() => categoryAllWillEnter$.first());
|
|
@@ -1,6 +1,99 @@
|
|
|
1
|
-
|
|
1
|
+
import { ACTION_PUSH, ACTION_REPLACE } from '@virtuous/conductor';
|
|
2
|
+
import { buildFetchCategoryProductsParams, getProductsResult } from '@shopgate/engage/product';
|
|
3
|
+
import { getCurrentRoute } from '@shopgate/pwa-common/selectors/router';
|
|
4
|
+
import { historyPop } from '@shopgate/pwa-common/actions/router';
|
|
5
|
+
import expireProductsByHash from '@shopgate/pwa-common-commerce/product/action-creators/expireProductsByHash';
|
|
6
|
+
import fetchCategory from '@shopgate/pwa-common-commerce/category/actions/fetchCategory';
|
|
7
|
+
import fetchCategoryProducts from '@shopgate/pwa-common-commerce/category/actions/fetchCategoryProducts';
|
|
8
|
+
import fetchFilters from '@shopgate/pwa-common-commerce/filter/actions/fetchFilters';
|
|
9
|
+
import { hex2bin } from '@shopgate/pwa-common/helpers/data';
|
|
10
|
+
import { categoryProductsNeedUpdate$ } from '@shopgate/engage/category/streams';
|
|
11
|
+
import { categoryWillEnter$, categoryDidEnter$, errorVisibleCategory$, categoryFiltersDidUpdateFromFilterPage$ } from "../streams";
|
|
12
|
+
|
|
13
|
+
/**
|
|
2
14
|
* Category subscriptions.
|
|
3
15
|
* @param {Function} subscribe The subscribe function.
|
|
4
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
export default function category(subscribe) {
|
|
18
|
+
subscribe(categoryWillEnter$, ({
|
|
19
|
+
dispatch,
|
|
20
|
+
action,
|
|
21
|
+
getState
|
|
22
|
+
}) => {
|
|
23
|
+
if (![ACTION_PUSH, ACTION_REPLACE].includes(action?.historyAction)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const {
|
|
27
|
+
filters,
|
|
28
|
+
offset = 0
|
|
29
|
+
} = action.route.state;
|
|
30
|
+
const categoryId = hex2bin(action.route.params.categoryId);
|
|
31
|
+
const {
|
|
32
|
+
hash,
|
|
33
|
+
expired
|
|
34
|
+
} = getProductsResult(getState(), {
|
|
35
|
+
categoryId,
|
|
36
|
+
routeId: action?.route?.id,
|
|
37
|
+
...buildFetchCategoryProductsParams()
|
|
38
|
+
});
|
|
39
|
+
if (expired) {
|
|
40
|
+
dispatch(expireProductsByHash(hash));
|
|
41
|
+
}
|
|
42
|
+
dispatch(fetchCategory(categoryId));
|
|
43
|
+
dispatch(fetchCategoryProducts({
|
|
44
|
+
categoryId,
|
|
45
|
+
filters,
|
|
46
|
+
offset,
|
|
47
|
+
...buildFetchCategoryProductsParams()
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
subscribe(categoryDidEnter$, ({
|
|
51
|
+
dispatch
|
|
52
|
+
}) => {
|
|
53
|
+
dispatch(fetchFilters());
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
5
57
|
* Gets triggered on pipeline category error.
|
|
6
|
-
*/
|
|
58
|
+
*/
|
|
59
|
+
subscribe(errorVisibleCategory$, ({
|
|
60
|
+
dispatch
|
|
61
|
+
}) => {
|
|
62
|
+
dispatch(historyPop());
|
|
63
|
+
});
|
|
64
|
+
subscribe(categoryProductsNeedUpdate$, ({
|
|
65
|
+
dispatch,
|
|
66
|
+
getState
|
|
67
|
+
}) => {
|
|
68
|
+
const {
|
|
69
|
+
params,
|
|
70
|
+
state: {
|
|
71
|
+
offset = 0,
|
|
72
|
+
filters
|
|
73
|
+
}
|
|
74
|
+
} = getCurrentRoute(getState());
|
|
75
|
+
const categoryId = hex2bin(params.categoryId);
|
|
76
|
+
dispatch(fetchCategoryProducts({
|
|
77
|
+
categoryId,
|
|
78
|
+
filters,
|
|
79
|
+
offset,
|
|
80
|
+
...buildFetchCategoryProductsParams()
|
|
81
|
+
}));
|
|
82
|
+
});
|
|
83
|
+
subscribe(categoryFiltersDidUpdateFromFilterPage$, ({
|
|
84
|
+
dispatch,
|
|
85
|
+
action
|
|
86
|
+
}) => {
|
|
87
|
+
const categoryId = hex2bin(action.route.params.categoryId);
|
|
88
|
+
const {
|
|
89
|
+
filters,
|
|
90
|
+
offset = 0
|
|
91
|
+
} = action.route.state;
|
|
92
|
+
dispatch(fetchCategoryProducts({
|
|
93
|
+
categoryId,
|
|
94
|
+
filters,
|
|
95
|
+
offset,
|
|
96
|
+
...buildFetchCategoryProductsParams()
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import{SUCCESS_CHECKOUT}from"../constants"
|
|
1
|
+
import { SUCCESS_CHECKOUT } from "../constants";
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Creates the dispatched SUCCESS_UPDATE_PRODUCTS_IN_CART action object.
|
|
3
5
|
* @param {Object[]} products cart.items of product type
|
|
4
6
|
* @returns {Object} The dispatched action object.
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
const successCheckout = products => ({
|
|
9
|
+
type: SUCCESS_CHECKOUT,
|
|
10
|
+
products
|
|
11
|
+
});
|
|
12
|
+
export default successCheckout;
|
|
@@ -1,5 +1,30 @@
|
|
|
1
|
-
import PipelineRequest from'@shopgate/pwa-core/classes/PipelineRequest';
|
|
1
|
+
import PipelineRequest from '@shopgate/pwa-core/classes/PipelineRequest';
|
|
2
|
+
import { requestUrl, receiveUrl, errorUrl } from '@shopgate/pwa-common/action-creators/url';
|
|
3
|
+
import { mutable } from '@shopgate/pwa-common/helpers/redux';
|
|
4
|
+
import { SHOPGATE_CHECKOUT_GET_URL } from "../constants/Pipelines";
|
|
5
|
+
import { FETCH_CHECKOUT_URL_TIMEOUT } from "../constants";
|
|
6
|
+
const URL_TYPE_CHECKOUT = 'checkout';
|
|
7
|
+
|
|
8
|
+
/**
|
|
2
9
|
* Get the url for checkout.
|
|
3
10
|
* @return {Function} A redux thunk.
|
|
4
|
-
*/
|
|
5
|
-
|
|
11
|
+
*/
|
|
12
|
+
function fetchCheckoutUrl() {
|
|
13
|
+
return dispatch => new Promise((resolve, reject) => {
|
|
14
|
+
dispatch(requestUrl(URL_TYPE_CHECKOUT));
|
|
15
|
+
new PipelineRequest(SHOPGATE_CHECKOUT_GET_URL).setTimeout(FETCH_CHECKOUT_URL_TIMEOUT) // 12 seconds timeout
|
|
16
|
+
.setRetries(0).dispatch().then(({
|
|
17
|
+
url,
|
|
18
|
+
expires
|
|
19
|
+
}) => {
|
|
20
|
+
dispatch(receiveUrl(URL_TYPE_CHECKOUT, url, expires));
|
|
21
|
+
resolve(url);
|
|
22
|
+
}).catch(() => {
|
|
23
|
+
dispatch(errorUrl(URL_TYPE_CHECKOUT));
|
|
24
|
+
reject();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** @mixes {MutableFunction} */
|
|
30
|
+
export default mutable(fetchCheckoutUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const SHOPGATE_CHECKOUT_GET_URL = 'shopgate.checkout.getUrl';
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export const LEGACY_URL = '/checkout_legacy';
|
|
2
|
+
export const FETCH_CHECKOUT_URL_TIMEOUT = 12000; // 12 seconds timeout for fetching a checkout url.
|
|
3
|
+
export const SUCCESS_CHECKOUT = 'SUCCESS_CHECKOUT';
|
package/checkout/index.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
// ACTIONS
|
|
2
|
-
export{default as fetchCheckoutUrl}from"./actions/fetchCheckoutUrl"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export*from"./
|
|
2
|
+
export { default as fetchCheckoutUrl } from "./actions/fetchCheckoutUrl";
|
|
3
|
+
|
|
4
|
+
// CONSTANTS
|
|
5
|
+
export * from "./constants/index";
|
|
6
|
+
export * from "./constants/Pipelines";
|
|
7
|
+
|
|
8
|
+
// SELECTORS
|
|
9
|
+
export * from "./selectors";
|
|
10
|
+
|
|
11
|
+
// STREAMS
|
|
12
|
+
export * from "./streams";
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import{getUrl}from'@shopgate/pwa-common/selectors/url'
|
|
1
|
+
import { getUrl } from '@shopgate/pwa-common/selectors/url';
|
|
2
|
+
|
|
3
|
+
/**
|
|
2
4
|
* Gets the checkout url.
|
|
3
5
|
* @param {Object} state The application state.
|
|
4
6
|
* @return {string|null}
|
|
5
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export const getCheckoutUrl = state => getUrl(state, {
|
|
9
|
+
type: 'checkout'
|
|
10
|
+
});
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import{main$}from'@shopgate/pwa-common/streams/main';
|
|
1
|
+
import { main$ } from '@shopgate/pwa-common/streams/main';
|
|
2
|
+
import { SUCCESS_CHECKOUT } from "../constants";
|
|
3
|
+
|
|
4
|
+
/**
|
|
2
5
|
* Gets triggered when the checkout has been completed.
|
|
3
6
|
* @type {Observable}
|
|
4
|
-
*/
|
|
7
|
+
*/
|
|
8
|
+
export const checkoutSucceeded$ = main$.filter(({
|
|
9
|
+
action
|
|
10
|
+
}) => action.type === SUCCESS_CHECKOUT);
|
|
@@ -1,10 +1,39 @@
|
|
|
1
|
-
import'rxjs/add/operator/debounceTime';
|
|
1
|
+
import 'rxjs/add/operator/debounceTime';
|
|
2
|
+
import event from '@shopgate/pwa-core/classes/Event';
|
|
3
|
+
import registerEvents from '@shopgate/pwa-core/commands/registerEvents';
|
|
4
|
+
import { appDidStart$ } from '@shopgate/pwa-common/streams/app';
|
|
5
|
+
import { historyReset } from '@shopgate/pwa-common/actions/router';
|
|
6
|
+
import successCheckout from "../action-creators/successCheckout";
|
|
7
|
+
import { checkoutSucceeded$ } from "../streams";
|
|
8
|
+
import { getCartProducts } from "../../cart/selectors";
|
|
9
|
+
|
|
10
|
+
/**
|
|
2
11
|
* Checkout subscriptions.
|
|
3
12
|
* @param {Function} subscribe The subscribe function.
|
|
4
|
-
*/
|
|
13
|
+
*/
|
|
14
|
+
const checkout = subscribe => {
|
|
15
|
+
/**
|
|
5
16
|
* Gets triggered when the app starts.
|
|
6
|
-
*/
|
|
7
|
-
|
|
17
|
+
*/
|
|
18
|
+
subscribe(appDidStart$, ({
|
|
19
|
+
dispatch,
|
|
20
|
+
getState
|
|
21
|
+
}) => {
|
|
22
|
+
// Register for the app event that is triggered when the checkout process is finished
|
|
23
|
+
registerEvents(['checkoutSuccess']);
|
|
24
|
+
event.addCallback('checkoutSuccess', () => {
|
|
25
|
+
dispatch(successCheckout(getCartProducts(getState())));
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
/**
|
|
8
30
|
* After success checkout
|
|
9
|
-
*/
|
|
10
|
-
|
|
31
|
+
*/
|
|
32
|
+
subscribe(checkoutSucceeded$, ({
|
|
33
|
+
dispatch
|
|
34
|
+
}) => {
|
|
35
|
+
// Reset navigation history
|
|
36
|
+
dispatch(historyReset());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
export default checkout;
|