mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
🏗️ Add conditional routing to onboarding steps
This commit is contained in:
parent
847bce3510
commit
426230bee9
3 changed files with 28 additions and 8 deletions
|
@ -1,11 +1,9 @@
|
||||||
import Container from '../../ReusableComponents/Container';
|
import Container from '../../ReusableComponents/Container';
|
||||||
import StepWelcome from './StepWelcome';
|
|
||||||
import StepBusiness from './StepBusiness';
|
|
||||||
import StepProducts from './StepProducts';
|
|
||||||
import { useOnboardingStep } from '../../../data';
|
import { useOnboardingStep } from '../../../data';
|
||||||
|
import { getSteps } from './availableSteps';
|
||||||
|
|
||||||
const Onboarding = () => {
|
const Onboarding = () => {
|
||||||
const { step, setStep, setCompleted } = useOnboardingStep();
|
const { step, setStep, setCompleted, flags } = useOnboardingStep();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container page="onboarding">
|
<Container page="onboarding">
|
||||||
|
@ -14,14 +12,15 @@ const Onboarding = () => {
|
||||||
currentStep={ step }
|
currentStep={ step }
|
||||||
setStep={ setStep }
|
setStep={ setStep }
|
||||||
setCompleted={ setCompleted }
|
setCompleted={ setCompleted }
|
||||||
|
flags={ flags }
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const OnboardingStep = ( { currentStep, setStep, setCompleted } ) => {
|
const OnboardingStep = ( { currentStep, setStep, setCompleted, flags } ) => {
|
||||||
const stepperOrder = [ StepWelcome, StepBusiness, StepProducts ];
|
const stepperOrder = getSteps( flags );
|
||||||
|
|
||||||
const isValidStep = ( step ) =>
|
const isValidStep = ( step ) =>
|
||||||
typeof step === 'number' &&
|
typeof step === 'number' &&
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
import StepWelcome from './StepWelcome';
|
||||||
|
import StepBusiness from './StepBusiness';
|
||||||
|
import StepProducts from './StepProducts';
|
||||||
|
|
||||||
|
export const getSteps = ( flags ) => {
|
||||||
|
console.log( 'Step Flags:', flags );
|
||||||
|
const allSteps = [ StepWelcome, StepBusiness, StepProducts ];
|
||||||
|
|
||||||
|
if ( ! flags.canUseCasualSelling ) {
|
||||||
|
return allSteps.filter( ( step ) => step !== StepBusiness );
|
||||||
|
}
|
||||||
|
|
||||||
|
return allSteps;
|
||||||
|
};
|
|
@ -1,5 +1,6 @@
|
||||||
import { useSelect, useDispatch } from '@wordpress/data';
|
import { useSelect, useDispatch } from '@wordpress/data';
|
||||||
import { PRODUCT_TYPES, STORE_NAME } from '../constants';
|
import { PRODUCT_TYPES, STORE_NAME } from '../constants';
|
||||||
|
import { getFlags } from './selectors';
|
||||||
|
|
||||||
const useOnboardingDetails = () => {
|
const useOnboardingDetails = () => {
|
||||||
const {
|
const {
|
||||||
|
@ -23,6 +24,11 @@ const useOnboardingDetails = () => {
|
||||||
return select( STORE_NAME ).getTransientData().isReady;
|
return select( STORE_NAME ).getTransientData().isReady;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// Read-only flags.
|
||||||
|
const flags = useSelect( ( select ) => {
|
||||||
|
return select( STORE_NAME ).getFlags();
|
||||||
|
} );
|
||||||
|
|
||||||
// Persistent accessors.
|
// Persistent accessors.
|
||||||
const step = useSelect( ( select ) => {
|
const step = useSelect( ( select ) => {
|
||||||
return select( STORE_NAME ).getPersistentData().step || 0;
|
return select( STORE_NAME ).getPersistentData().step || 0;
|
||||||
|
@ -91,6 +97,7 @@ const useOnboardingDetails = () => {
|
||||||
setDetailAndPersist( setIsCasualSeller, value ),
|
setDetailAndPersist( setIsCasualSeller, value ),
|
||||||
products,
|
products,
|
||||||
toggleProduct,
|
toggleProduct,
|
||||||
|
flags,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -133,8 +140,8 @@ export const useOnboardingStepProducts = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useOnboardingStep = () => {
|
export const useOnboardingStep = () => {
|
||||||
const { isReady, step, setStep, completed, setCompleted } =
|
const { isReady, step, setStep, completed, setCompleted, flags } =
|
||||||
useOnboardingDetails();
|
useOnboardingDetails();
|
||||||
|
|
||||||
return { isReady, step, setStep, completed, setCompleted };
|
return { isReady, step, setStep, completed, setCompleted, flags };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue