File size: 696 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { useSelector } from 'calypso/state';
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';
import type { StepperStep } from '../declarative-flow/internals/types';
/**
 * Returns the slug of the first step that should be rendered when the flow is visited without a specified step, while considering the logged in state of the user.
 * @param stepPaths the slugs of all the steps in the flow.
 * @returns the slug of the appropriate step.
 */
export const useFirstStep = ( stepPaths: StepperStep[ 'slug' ][] ) => {
	const isLoggedIn = useSelector( isUserLoggedIn );

	if ( stepPaths[ 0 ] === 'user' && isLoggedIn ) {
		return stepPaths[ 1 ];
	}

	return stepPaths[ 0 ];
};