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:
committed by
Aschepikov
parent
c6a6d7d8e1
commit
b2679bface
@@ -1,14 +1,22 @@
|
|||||||
export const getStepsCount = (): number => {
|
const getSteps = (): string[] => {
|
||||||
let stepsCount = 3;
|
const steps = ['WelcomeWizardSenderStep'];
|
||||||
|
if (!window.mailpoet_is_dotcom) {
|
||||||
|
steps.push('WelcomeWizardUsageTrackingStep');
|
||||||
|
}
|
||||||
if (window.mailpoet_woocommerce_active) {
|
if (window.mailpoet_woocommerce_active) {
|
||||||
stepsCount += 1;
|
steps.push('WizardWooCommerceStep');
|
||||||
}
|
}
|
||||||
if (window.mailpoet_has_valid_api_key) {
|
if (!window.mailpoet_has_valid_api_key) {
|
||||||
stepsCount -= 1; // skip the MSS step if user already set 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 = (
|
export const redirectToNextStep = (
|
||||||
history: { push: (string) => void },
|
history: { push: (string) => void },
|
||||||
finishWizard: () => void,
|
finishWizard: () => void,
|
||||||
@@ -21,19 +29,3 @@ export const redirectToNextStep = (
|
|||||||
finishWizard();
|
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;
|
|
||||||
};
|
|
||||||
|
@@ -86,16 +86,11 @@ function WelcomeWizardStepsController({
|
|||||||
|
|
||||||
const submitSender = useCallback(async () => {
|
const submitSender = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
let currentStep = step;
|
if (window.mailpoet_is_dotcom && !window.wizard_has_tracking_settings) {
|
||||||
if (window.mailpoet_is_dotcom) {
|
await updateTracking(true, true);
|
||||||
// Skip the next step
|
|
||||||
currentStep += 1;
|
|
||||||
if (!window.wizard_has_tracking_settings) {
|
|
||||||
await updateTracking(true, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await updateSettings(createSenderSettings(sender)).then(() =>
|
await updateSettings(createSenderSettings(sender)).then(() =>
|
||||||
redirect(currentStep),
|
redirect(step),
|
||||||
);
|
);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}, [redirect, sender, step, updateTracking]);
|
}, [redirect, sender, step, updateTracking]);
|
||||||
@@ -105,18 +100,13 @@ function WelcomeWizardStepsController({
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const defaultSenderInfo = { address: window.admin_email, name: '' };
|
const defaultSenderInfo = { address: window.admin_email, name: '' };
|
||||||
let currentStep = step;
|
|
||||||
|
|
||||||
if (window.mailpoet_is_dotcom) {
|
if (window.mailpoet_is_dotcom && !window.wizard_has_tracking_settings) {
|
||||||
// Skip the next step
|
await updateTracking(true, true);
|
||||||
currentStep += 1;
|
|
||||||
if (!window.wizard_has_tracking_settings) {
|
|
||||||
await updateTracking(true, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await updateSettings(createSenderSettings(defaultSenderInfo)).then(() => {
|
await updateSettings(createSenderSettings(defaultSenderInfo)).then(() => {
|
||||||
setSender(defaultSenderInfo);
|
setSender(defaultSenderInfo);
|
||||||
redirect(currentStep);
|
redirect(step);
|
||||||
});
|
});
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user