@shopgate/pwa-common-commerce
Version:
Commerce library for the Shopgate Connect PWA.
127 lines • 10.2 kB
JavaScript
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";import{makeGetFavorites}from"../selectors";/**
* First action to add one product to favorites.
* @param {number} productId Id of the product to add.
* @param {string} listId List identifier.
* @param {number} quantity New favorites quantity to set
* @param {string} notes New favorites notes to set
* @param {boolean} showToast Whether to show a confirmation toast after product was added
* @returns {Object}
*/export var addProductToFavorites=function addProductToFavorites(productId,listId,quantity,notes){var showToast=arguments.length>4&&arguments[4]!==undefined?arguments[4]:true;return{type:ADD_PRODUCT_TO_FAVORITES,productId:productId,listId:listId,quantity:quantity,notes:notes,showToast:showToast};};/**
* First action to update a product in favorites.
* @param {number} productId Id of the product to add.
* @param {string} listId List identifier.
* @param {number} quantity The quantity of the product.
* @param {string} notes Notes about the product.
* @returns {Object}
*/export var updateProductInFavorites=function updateProductInFavorites(productId,listId,quantity,notes){return{type:UPDATE_PRODUCT_IN_FAVORITES,productId:productId,listId:listId,notes:notes,quantity:quantity};};/**
* First action to remove one product to favorites.
* @param {number} productId Id of the product to remove.
* @param {boolean} withRelatives States, whether to remove all relative products or not.
* @param {string} listId List identifier.
* @returns {Object}
*/export var removeProductFromFavorites=function removeProductFromFavorites(productId,withRelatives,listId){return{type:REMOVE_PRODUCT_FROM_FAVORITES,productId:productId,withRelatives:withRelatives,listId:listId};};/**
* Error on fetch favorites action.
* @param {Error} error Error.
* @param {string} listId List identifier.
* @returns {Object}
*/export var errorFetchFavorites=function errorFetchFavorites(error,listId){return{type:ERROR_FETCH_FAVORITES,error:error,listId:listId};};/**
* Error on favorites action.
* @param {string} productId Product identifier.
* @param {Error} error Error.
* @returns {Object}
*/export var errorFavorites=function errorFavorites(productId,error){return{type:ERROR_FAVORITES,productId:productId,error:error};};/**
* Request add favorites action. This action just updates the redux store.
* @param {string} productId Product identifier.
* @param {string} listId List identifier.
* @param {number} quantity New favorites quantity to set
* @param {string} notes New favorites notes to set
* @param {boolean} showToast Whether to show a confirmation toast after product was added
* @returns {Object}
*/export var requestAddFavorites=function requestAddFavorites(productId,listId,quantity,notes){var showToast=arguments.length>4&&arguments[4]!==undefined?arguments[4]:true;return{type:REQUEST_ADD_FAVORITES,productId:productId,listId:listId,quantity:quantity,notes:notes,showToast:showToast};};/**
* Action to be triggered upon successful addFavorites pipeline call.
* @param {string} productId Product identifier.
* @param {string} listId List identifier.
* @param {boolean} showToast Whether to show a confirmation toast after product was added
* @returns {Object}
*/export var successAddFavorites=function successAddFavorites(productId,listId){var showToast=arguments.length>2&&arguments[2]!==undefined?arguments[2]:true;return{type:SUCCESS_ADD_FAVORITES,productId:productId,listId:listId,showToast:showToast};};/**
* Action to be triggered upon a failed addFavorites pipeline call.
* @param {string} productId Product identifier.
* @param {Error} error The error that occurred.
* @param {string} listId List identifier.
* @returns {Object}
*/export var errorAddFavorites=function errorAddFavorites(productId,error,listId){return{type:ERROR_ADD_FAVORITES,productId:productId,listId:listId,error:error};};/**
* Request update favorites action. This action just updates the redux store.
* @param {string} productId Product identifier.
* @param {string} listId List identifier.
* @param {number} quantity The quantity of the product
* @param {string} notes Notes about the product
* @returns {Object}
*/export var requestUpdateFavorites=function requestUpdateFavorites(productId,listId,quantity,notes){return{type:REQUEST_UPDATE_FAVORITES,productId:productId,listId:listId,notes:notes,quantity:quantity};};/**
* Action to be triggered upon successful updateFavorites pipeline call.
* @param {string} productId Product identifier.
* @param {string} listId List identifier.
* @returns {Object}
*/export var successUpdateFavorites=function successUpdateFavorites(productId,listId){return{type:SUCCESS_UPDATE_FAVORITES,productId:productId,listId:listId};};/**
* Action to be triggered upon failed updateFavorites pipeline call.
* @param {string} productId Product identifier.
* @param {string} listId List identifier.
* @param {Error} error The error that occurred.
* @returns {Object}
*/export var errorUpdateFavorites=function errorUpdateFavorites(productId,listId,error){return{type:ERROR_UPDATE_FAVORITES,productId:productId,listId:listId,error:error};};/**
* Request remove favorites action. This action just updates the redux store.
* @param {string} productId Product identifier.
* @param {string} listId List identifier.
* @returns {Object}
*/export var requestRemoveFavorites=function requestRemoveFavorites(productId,listId){return function(dispatch,getState){var getFavorites=makeGetFavorites(function(){return listId;});var favorites=getFavorites(getState());var matchingFavorite=favorites.find(function(_ref){var itemProductId=_ref.productId;return itemProductId===productId;})||{};return dispatch({type:REQUEST_REMOVE_FAVORITES,productId:productId,listId:listId,quantity:matchingFavorite.quantity||1,notes:matchingFavorite.notes||''});};};/**
* Action to be triggered upon successful removeFavorites (deleteFavorites) pipeline call.
* @param {string} productId Product identifier.
* @param {number} takenListId List id
* @returns {Object}
*/export var successRemoveFavorites=function successRemoveFavorites(productId,takenListId){return{type:SUCCESS_REMOVE_FAVORITES,productId:productId,listId:takenListId};};/**
* Action to be triggered upon a failed removeFavorites (deleteFavorites) pipeline call.
* @param {string} productId Product identifier.
* @param {string} takenListId List id
* @param {Error} error The error that occurred.
* @param {number} quantity Quantity of the favorite
* @param {string} notes Notes of the favorite
* @returns {Object}
*/export var errorRemoveFavorites=function errorRemoveFavorites(productId,takenListId,error,quantity,notes){return{type:ERROR_REMOVE_FAVORITES,productId:productId,listId:takenListId,error:error,quantity:quantity,notes:notes};};/**
* Return the flush favorites buffer Now action object
* @param {string} listId The Id of the wishlist.
* @return {Object}
*/export var requestFlushFavoritesBuffer=function requestFlushFavoritesBuffer(listId){return{type:REQUEST_FLUSH_FAVORITES_BUFFER,listId:listId};};/**
* Idle sync action.
* @param {string} listId The Id of the wishlist.
* @returns {Object}
*/export var idleSyncFavorites=function idleSyncFavorites(listId){return{type:IDLE_SYNC_FAVORITES,listId:listId};};/**
* Action to cancel one or multiple request to add or to remove favorites.
* @param {number} [count=1] Optional count of sync requests.
* @param {string} listId The Id of the wishlist.
* @returns {Object}
*/export var cancelRequestSyncFavorites=function cancelRequestSyncFavorites(){var count=arguments.length>0&&arguments[0]!==undefined?arguments[0]:1;var listId=arguments.length>1?arguments[1]:undefined;return{type:CANCEL_REQUEST_SYNC_FAVORITES,count:count,listId:listId};};/**
* Receive favorites action.
* @param {Array} items Wishlist items.
* @param {number} requestTimestamp Time when request was initiated (ms).
* @param {string} listId The Id of the wishlist.
* @returns {Object}
*/export var receiveFavorites=function receiveFavorites(items,requestTimestamp){var listId=arguments.length>2&&arguments[2]!==undefined?arguments[2]:null;return{type:RECEIVE_FAVORITES,items:items,requestTimestamp:requestTimestamp,listId:listId};};/**
* Request favorites action.
* @param {string} listId The Id of the wishlist.
* @returns {Object}
*/export var requestFavorites=function requestFavorites(){var listId=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;return{type:REQUEST_FAVORITES,listId:listId};};/**
* Opens the favorite list chooser.
* @param {string} productId The Id of the product.
* @param {boolean} withRelatives States, whether to remove all relative products or not.
* @returns {Object}
*/export var openFavoritesListChooser=function openFavoritesListChooser(productId){var withRelatives=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;return{type:OPEN_FAVORITE_LIST_CHOOSER,productId:productId,withRelatives:withRelatives};};/**
* Opens the favorite list chooser.
* @returns {Object}
*/export var closeFavoritesListChooser=function closeFavoritesListChooser(){return{type:CLOSE_FAVORITE_LIST_CHOOSER};};/**
* Opens the favorite comment sheet
* @param {string} productId The id of the product.
* @param {string} listId The id of the list.
* @returns {Object}
*/export var openFavoritesCommentDialog=function openFavoritesCommentDialog(productId,listId){return{type:OPEN_FAVORITE_COMMENT_DIALOG,productId:productId,listId:listId};};/**
* Closes the favorite comment sheet
* @returns {Object}
*/export var closeFavoritesCommentDialog=function closeFavoritesCommentDialog(){return{type:CLOSE_FAVORITE_COMMENT_DIALOG};};