UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

4 lines 1.14 kB
import{PipelineRequest}from'@shopgate/pwa-core';import{requestUrl,receiveUrl,errorUrl}from"../../action-creators/url";import{SHOPGATE_USER_GET_REGISTRATION_URL}from"../../constants/Pipelines";import{URL_TYPE_REGISTER}from"../../constants/Registration";import{shouldFetchData,mutable}from"../../helpers/redux";import{getEntryByType}from"../../selectors/url";import{getRegisterUrl}from"../../selectors/user";/** * Get the url for the registration. * @return {Function} A redux thunk. */function fetchRegisterUrl(){return function(dispatch,getState){return new Promise(function(resolve,reject){var state=getState();var entry=getEntryByType(state,{type:URL_TYPE_REGISTER});if(!shouldFetchData(entry,'url')){resolve(getRegisterUrl(state));return;}dispatch(requestUrl(URL_TYPE_REGISTER));new PipelineRequest(SHOPGATE_USER_GET_REGISTRATION_URL).setTrusted().dispatch().then(function(_ref){var url=_ref.url,expires=_ref.expires;dispatch(receiveUrl(URL_TYPE_REGISTER,url,expires));resolve(url);})["catch"](function(){dispatch(errorUrl(URL_TYPE_REGISTER));reject();});});};}/** @mixes {MutableFunction} */export default mutable(fetchRegisterUrl);