Download wp-calypso/client/signup/hooks/use-branch-steps.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/signup/hooks/use-branch-steps.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/signup/hooks/use-branch-steps.ts
-
curl -L -o use-branch-steps.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/signup/hooks/use-branch-steps.ts
1.69 kB
| import React from 'react'; | |
| import flows from 'calypso/signup/config/flows'; | |
| import { useSelector, useDispatch } from 'calypso/state'; | |
| import { addExcludedSteps, removeExcludedSteps } from 'calypso/state/signup/flow/actions'; | |
| import { getSignupProgress } from 'calypso/state/signup/progress/selectors'; | |
| import type { Dependencies } from 'calypso/signup/types'; | |
| type GetExcludedSteps = ( providedDependencies?: Dependencies ) => string[]; | |
| type BranchSteps = ( providedDependencies: Dependencies ) => void; | |
| /** | |
| * This hook returns the function to do branch steps. Ensure this function is called before submitSignupStep | |
| * because we process all of the steps immediately after submitting. | |
| * Also, it will clean up the exclude steps when the component mounts as the user might go back a step | |
| */ | |
| const useBranchSteps = ( stepName: string, getExcludedSteps: GetExcludedSteps ): BranchSteps => { | |
| const dispatch = useDispatch(); | |
| const signupProgress = useSelector( getSignupProgress ); | |
| const branchSteps = ( providedDependencies: Dependencies ) => { | |
| const excludedSteps = getExcludedSteps( providedDependencies ) || []; | |
| flows.excludeSteps( excludedSteps ); | |
| dispatch( addExcludedSteps( excludedSteps ) ); | |
| }; | |
| const restoreBranchSteps = () => { | |
| const excludedSteps = | |
| getExcludedSteps( signupProgress[ stepName ]?.providedDependencies ) || []; | |
| excludedSteps.forEach( ( step ) => flows.resetExcludedStep( step ) ); | |
| dispatch( removeExcludedSteps( excludedSteps ) ); | |
| }; | |
| // Only do following things when mounted | |
| React.useEffect( () => { | |
| restoreBranchSteps(); | |
| }, [] ); // eslint-disable-line react-hooks/exhaustive-deps | |
| return branchSteps; | |
| }; | |
| export default useBranchSteps; | |