File size: 1,931 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import { Onboard } from '@automattic/data-stores';
import { useDispatch } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { useQuery } from '../../../hooks/use-query';
import { useSiteSlug } from '../../../hooks/use-site-slug';
import { ONBOARD_STORE } from '../../../stores';
import { STEPS } from '../../internals/steps';
import { ProcessingResult } from '../../internals/steps-repository/processing-step/constants';
import { ProvidedDependencies } from '../../internals/types';
import type { Flow } from '../../internals/types';
const updateOptions: Flow = {
name: 'update-options',
isSignupFlow: false,
useSteps() {
return [ STEPS.OPTIONS, STEPS.PROCESSING, STEPS.ERROR ];
},
useSideEffect() {
const { setIntent } = useDispatch( ONBOARD_STORE );
useEffect( () => {
setIntent( Onboard.SiteIntent.UpdateOptions );
}, [] );
},
useStepNavigation( currentStep, navigate ) {
const siteSlug = useSiteSlug();
const flowToReturnTo = useQuery().get( 'flowToReturnTo' ) || 'free';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function submit( providedDependencies: ProvidedDependencies = {} ) {
switch ( currentStep ) {
case 'processing': {
const processingResult = providedDependencies.processingResult as ProcessingResult;
if ( processingResult === ProcessingResult.FAILURE ) {
return navigate( 'error' );
}
return window.location.assign(
`/setup/${ flowToReturnTo }/launchpad?siteSlug=${ siteSlug }`
);
}
case 'options': {
return navigate( `processing?siteSlug=${ siteSlug }&flowToReturnTo=${ flowToReturnTo }` );
}
}
}
const goBack = async () => {
switch ( currentStep ) {
case 'options':
return window.location.assign(
`/setup/${ flowToReturnTo }/launchpad?siteSlug=${ siteSlug }`
);
}
};
return { goBack, submit };
},
};
export default updateOptions;
|