Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the back button in the normal flow when a user lands from the error state. #466

Merged
merged 7 commits into from
Feb 28, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
sendOnboardingEvent,
} from '../../../../utils/analytics/hiive';
import { ACTION_ONBOARDING_COMPLETE } from '../../../../utils/analytics/hiive/constants';
import { stepWelcome } from '../../../../steps/GetStarted/Welcome/step';

/**
* Back step Navigation button.
Expand All @@ -21,7 +22,7 @@ import { ACTION_ONBOARDING_COMPLETE } from '../../../../utils/analytics/hiive/co
*
* @return {WPComponent} Back Component
*/
const Back = ( { path, showErrorDialog } ) => {
const Back = ( { path, showErrorDialog, disabled } ) => {
const { setNavErrorContinuePath } = useDispatch( nfdOnboardingStore );
const navigate = useNavigate();
const navigateBack = () => {
Expand All @@ -36,6 +37,7 @@ const Back = ( { path, showErrorDialog } ) => {
className="navigation-buttons navigation-buttons_back"
onClick={ navigateBack }
variant="secondary"
disabled={ disabled }
>
<Icon icon={ chevronLeft } />
{ __( 'Back', 'wp-module-onboarding' ) }
Expand Down Expand Up @@ -108,19 +110,22 @@ const Finish = ( { currentData, saveDataAndExitFunc } ) => (
* @return {WPComponent} StepNavigation Component
*/
const StepNavigation = () => {
const { previousStep, nextStep, currentData, showErrorDialog } = useSelect(
( select ) => {
return {
nextStep: select( nfdOnboardingStore ).getNextStep(),
previousStep: select( nfdOnboardingStore ).getPreviousStep(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
showErrorDialog:
select( nfdOnboardingStore ).getShowErrorDialog(),
};
},
[]
);
const {
currentStep,
previousStep,
nextStep,
currentData,
showErrorDialog,
} = useSelect( ( select ) => {
return {
currentStep: select( nfdOnboardingStore ).getCurrentStep(),
nextStep: select( nfdOnboardingStore ).getNextStep(),
previousStep: select( nfdOnboardingStore ).getPreviousStep(),
currentData:
select( nfdOnboardingStore ).getCurrentOnboardingData(),
showErrorDialog: select( nfdOnboardingStore ).getShowErrorDialog(),
};
}, [] );
const isFirstStep = null === previousStep || false === previousStep;
const isLastStep = null === nextStep || false === nextStep;
return (
Expand All @@ -130,6 +135,11 @@ const StepNavigation = () => {
<Back
path={ previousStep.path }
showErrorDialog={ showErrorDialog }
disabled={
currentStep === stepWelcome
? currentData.continueWithoutAi
: false
}
/>
) }
{ isLastStep ? (
Expand Down
4 changes: 4 additions & 0 deletions src/OnboardingSPA/components/SiteGenError/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const SiteGenSiteError = () => {
updateInitialize,
setCurrentOnboardingData,
updateSiteGenErrorStatus,
setContinueWithoutAi,
} = useDispatch( nfdOnboardingStore );

useEffect( () => {
Expand Down Expand Up @@ -75,7 +76,10 @@ const SiteGenSiteError = () => {

window.nfdOnboarding.currentFlow = newFlow;
currentData.activeFlow = newFlow;
currentData.continueWithoutAi = true;
setContinueWithoutAi( true );
setCurrentOnboardingData( currentData );
updateSiteGenErrorStatus( false );
if ( SITEGEN_FLOW !== newFlow ) {
updateInitialize( true );
}
Expand Down
3 changes: 3 additions & 0 deletions src/OnboardingSPA/components/StartOptions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const StartOptions = ( { questionnaire, oldFlow, options } ) => {
updateDesignRoutes,
updateInitialize,
setCurrentOnboardingData,
setContinueWithoutAi,
} = useDispatch( nfdOnboardingStore );

const switchFlow = ( newFlow ) => {
Expand All @@ -43,6 +44,8 @@ const StartOptions = ( { questionnaire, oldFlow, options } ) => {

window.nfdOnboarding.currentFlow = newFlow;
currentData.activeFlow = newFlow;
currentData.continueWithoutAi = false;
setContinueWithoutAi( false );
setCurrentOnboardingData( currentData );
if ( SITEGEN_FLOW !== newFlow ) {
updateInitialize( true );
Expand Down
6 changes: 6 additions & 0 deletions src/OnboardingSPA/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,9 @@ export function setInteractionDisabled( interactionDisabled ) {
interactionDisabled,
};
}
export function setContinueWithoutAi( continueWithoutAi ) {
return {
type: 'SET_FLOW_WITHOUT_AI',
continueWithoutAi,
};
}
5 changes: 5 additions & 0 deletions src/OnboardingSPA/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export function flow(
...state,
interactionDisabled: action.interactionDisabled,
};
case 'SET_FLOW_WITHOUT_AI':
return {
...state,
flow: action.continueWithoutAi,
};
}

return state;
Expand Down
Loading