Show correct number of steps

This ensures we display the correct number of total steps when skipping
the tracking step for dotcom users. In order to achieve this I decided
to refactor the step count calculation and step mapping functions in a
way that I hope will be easier to update going forward.

MAILPOET-5549
This commit is contained in:
John Oleksowicz
2023-10-19 14:41:48 -05:00
committed by Aschepikov
parent c6a6d7d8e1
commit b2679bface
2 changed files with 20 additions and 38 deletions

View File

@@ -1,14 +1,22 @@
export const getStepsCount = (): number => {
let stepsCount = 3;
const getSteps = (): string[] => {
const steps = ['WelcomeWizardSenderStep'];
if (!window.mailpoet_is_dotcom) {
steps.push('WelcomeWizardUsageTrackingStep');
}
if (window.mailpoet_woocommerce_active) {
stepsCount += 1;
steps.push('WizardWooCommerceStep');
}
if (window.mailpoet_has_valid_api_key) {
stepsCount -= 1; // skip the MSS step if user already set API key
if (!window.mailpoet_has_valid_api_key) {
steps.push('WelcomeWizardPitchMSSStep');
}
return stepsCount;
return steps;
};
export const getStepsCount = (): number => getSteps().length;
export const mapStepNumberToStepName = (stepNumber: number): string | null =>
getSteps()[stepNumber - 1] || null;
export const redirectToNextStep = (
history: { push: (string) => void },
finishWizard: () => void,
@@ -21,19 +29,3 @@ export const redirectToNextStep = (
finishWizard();
}
};
export const mapStepNumberToStepName = (stepNumber: number): string | null => {
if (stepNumber === 1) {
return 'WelcomeWizardSenderStep';
}
if (stepNumber === 2) {
return 'WelcomeWizardUsageTrackingStep';
}
if (window.mailpoet_woocommerce_active && stepNumber === 3) {
return 'WizardWooCommerceStep';
}
if (!window.mailpoet_has_valid_api_key) {
return 'WelcomeWizardPitchMSSStep';
}
return null;
};

View File

@@ -86,16 +86,11 @@ function WelcomeWizardStepsController({
const submitSender = useCallback(async () => {
setLoading(true);
let currentStep = step;
if (window.mailpoet_is_dotcom) {
// Skip the next step
currentStep += 1;
if (!window.wizard_has_tracking_settings) {
await updateTracking(true, true);
}
if (window.mailpoet_is_dotcom && !window.wizard_has_tracking_settings) {
await updateTracking(true, true);
}
await updateSettings(createSenderSettings(sender)).then(() =>
redirect(currentStep),
redirect(step),
);
setLoading(false);
}, [redirect, sender, step, updateTracking]);
@@ -105,18 +100,13 @@ function WelcomeWizardStepsController({
e.preventDefault();
setLoading(true);
const defaultSenderInfo = { address: window.admin_email, name: '' };
let currentStep = step;
if (window.mailpoet_is_dotcom) {
// Skip the next step
currentStep += 1;
if (!window.wizard_has_tracking_settings) {
await updateTracking(true, true);
}
if (window.mailpoet_is_dotcom && !window.wizard_has_tracking_settings) {
await updateTracking(true, true);
}
await updateSettings(createSenderSettings(defaultSenderInfo)).then(() => {
setSender(defaultSenderInfo);
redirect(currentStep);
redirect(step);
});
setLoading(false);
},