Extract navigation helper

MAILPOET-5216
This commit is contained in:
John Oleksowicz
2024-02-08 15:12:19 -06:00
committed by Aschepikov
parent 3067b2715d
commit 5f99a11cad
6 changed files with 20 additions and 18 deletions

View File

@ -0,0 +1,15 @@
import { History } from 'history';
import { updateSettings } from './update-settings';
export const navigateToPath = (
history: History,
path: string,
replaceCurrent = false,
) => {
void updateSettings({ welcome_wizard_current_step: path });
if (replaceCurrent) {
history.replace(path);
} else {
history.push(path);
}
};

View File

@ -1,5 +1,5 @@
import { History } from 'history';
import { updateSettings } from './update-settings';
import { navigateToPath } from './navigate-to-path';
const getSteps = (): string[] => {
const steps = ['WelcomeWizardSenderStep'];
@ -20,19 +20,6 @@ export const getStepsCount = (): number => getSteps().length;
export const mapStepNumberToStepName = (stepNumber: number): string | null =>
getSteps()[stepNumber - 1] || null;
export const navigateToPath = (
history: History,
path: string,
replaceCurrent = false,
) => {
void updateSettings({ welcome_wizard_current_step: path });
if (replaceCurrent) {
history.replace(path);
} else {
history.push(path);
}
};
export const redirectToNextStep = async (
history: History,
finishWizard: () => void,

View File

@ -10,7 +10,7 @@ import { useEffect } from 'react';
import { MSSStepFirstPart } from './pitch-mss-step/first-part';
import { MSSStepSecondPart } from './pitch-mss-step/second-part';
import { MSSStepThirdPart } from './pitch-mss-step/third-part';
import { navigateToPath } from '../steps-numbers';
import { navigateToPath } from '../navigate-to-path';
function WelcomeWizardPitchMSSStep(): JSX.Element {
const { path } = useRouteMatch();

View File

@ -7,7 +7,7 @@ import { Button, List } from 'common';
import { History } from 'history';
import { OwnEmailServiceNote } from './own-email-service-note';
import { useSelector } from '../../../settings/store/hooks';
import { navigateToPath } from '../../steps-numbers';
import { navigateToPath } from '../../navigate-to-path';
const mailpoetAccountUrl =
'https://account.mailpoet.com/?ref=plugin-wizard&utm_source=plugin&utm_medium=onboarding&utm_campaign=purchase';

View File

@ -7,7 +7,7 @@ import { KeyInput } from 'common/premium-key/key-input';
import { useEffect } from 'react';
import { useSelector } from 'settings/store/hooks';
import { OwnEmailServiceNote } from './own-email-service-note';
import { navigateToPath } from '../../steps-numbers';
import { navigateToPath } from '../../navigate-to-path';
function MSSStepSecondPart(): JSX.Element {
const history = useHistory();

View File

@ -14,7 +14,6 @@ import { createSenderSettings } from './create-sender-settings.jsx';
import {
getStepsCount,
mapStepNumberToStepName,
navigateToPath,
redirectToNextStep,
} from './steps-numbers';
import { Steps } from '../common/steps/steps';
@ -24,6 +23,7 @@ import { ErrorBoundary } from '../common';
import { HideScreenOptions } from '../common/hide-screen-options/hide-screen-options';
import { finishWizard } from './finish-wizard';
import { updateSettings } from './update-settings';
import { navigateToPath } from './navigate-to-path';
type WelcomeWizardStepsControllerPropType = {
match: { params: { step: string } };