@shopgate/engage
Version:
Shopgate's ENGAGE library.
5 lines • 1.34 kB
JavaScript
import{makeGetPrevRoute,getCurrentRoute,historyPop}from'@shopgate/engage/core';import{LOGIN_PATH}from'@shopgate/pwa-common/constants/RoutePaths';import{REGISTRATION_FORM_LOGIN_STRATEGY}from'@shopgate/pwa-common/constants/user';import{successLogin}from'@shopgate/pwa-common/action-creators';import{registrationSuccess$}from"../streams";/**
* @param {Function} subscribe Subscribes to an observable.
*/export default function registration(subscribe){subscribe(registrationSuccess$,function(_ref){var _action$response;var dispatch=_ref.dispatch,getState=_ref.getState,action=_ref.action;var currentRoute=getCurrentRoute(getState());var redirect;if(currentRoute){// Try to get the login page from the router stack to extract the original redirect target
var getPrevRoute=makeGetPrevRoute();var routeId=currentRoute.id;var _ref3=getPrevRoute(getState(),{routeId:routeId})||{},pattern=_ref3.pattern,state=_ref3.state;if(pattern===LOGIN_PATH&&(state===null||state===void 0?void 0:state.redirect)){redirect=state.redirect;}}// TODO improve navigation since the login page will be briefly visible
dispatch(historyPop());dispatch(successLogin(redirect,REGISTRATION_FORM_LOGIN_STRATEGY,action===null||action===void 0?void 0:(_action$response=action.response)===null||_action$response===void 0?void 0:_action$response.sessionLifetimeInSeconds));});}