File size: 871 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import { isAnyHostingFlow } from '@automattic/onboarding';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'calypso/state';
import { getCurrentUserId, isCurrentUserEmailVerified } from 'calypso/state/current-user/selectors';
import { savePreference } from 'calypso/state/preferences/actions';
export function useSaveHostingFlowPathStep( flow: string | null, currentPath: string ) {
const dispatch = useDispatch();
const userId = useSelector( getCurrentUserId );
const isEmailVerified = useSelector( isCurrentUserEmailVerified );
const pathStep = isEmailVerified ? null : currentPath;
useEffect( () => {
if ( ! isEmailVerified && isAnyHostingFlow( flow ) ) {
const prefKey = `hosting-flow-path-step-${ userId }`;
dispatch( savePreference( prefKey, pathStep ) );
}
}, [ userId, isEmailVerified, pathStep, flow, dispatch ] );
}
|