mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +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 StepWelcome from './StepWelcome';
|
||||
import StepBusiness from './StepBusiness';
|
||||
import StepProducts from './StepProducts';
|
||||
import { useOnboardingStep } from '../../../data';
|
||||
import { getSteps } from './availableSteps';
|
||||
|
||||
const Onboarding = () => {
|
||||
const { step, setStep, setCompleted } = useOnboardingStep();
|
||||
const { step, setStep, setCompleted, flags } = useOnboardingStep();
|
||||
|
||||
return (
|
||||
<Container page="onboarding">
|
||||
|
@ -14,14 +12,15 @@ const Onboarding = () => {
|
|||
currentStep={ step }
|
||||
setStep={ setStep }
|
||||
setCompleted={ setCompleted }
|
||||
flags={ flags }
|
||||
/>
|
||||
</div>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
const OnboardingStep = ( { currentStep, setStep, setCompleted } ) => {
|
||||
const stepperOrder = [ StepWelcome, StepBusiness, StepProducts ];
|
||||
const OnboardingStep = ( { currentStep, setStep, setCompleted, flags } ) => {
|
||||
const stepperOrder = getSteps( flags );
|
||||
|
||||
const isValidStep = ( step ) =>
|
||||
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 { PRODUCT_TYPES, STORE_NAME } from '../constants';
|
||||
import { getFlags } from './selectors';
|
||||
|
||||
const useOnboardingDetails = () => {
|
||||
const {
|
||||
|
@ -23,6 +24,11 @@ const useOnboardingDetails = () => {
|
|||
return select( STORE_NAME ).getTransientData().isReady;
|
||||
} );
|
||||
|
||||
// Read-only flags.
|
||||
const flags = useSelect( ( select ) => {
|
||||
return select( STORE_NAME ).getFlags();
|
||||
} );
|
||||
|
||||
// Persistent accessors.
|
||||
const step = useSelect( ( select ) => {
|
||||
return select( STORE_NAME ).getPersistentData().step || 0;
|
||||
|
@ -91,6 +97,7 @@ const useOnboardingDetails = () => {
|
|||
setDetailAndPersist( setIsCasualSeller, value ),
|
||||
products,
|
||||
toggleProduct,
|
||||
flags,
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -133,8 +140,8 @@ export const useOnboardingStepProducts = () => {
|
|||
};
|
||||
|
||||
export const useOnboardingStep = () => {
|
||||
const { isReady, step, setStep, completed, setCompleted } =
|
||||
const { isReady, step, setStep, completed, setCompleted, flags } =
|
||||
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