Extract navigation helper
MAILPOET-5216
This commit is contained in:
committed by
Aschepikov
parent
3067b2715d
commit
5f99a11cad
15
mailpoet/assets/js/src/wizard/navigate-to-path.tsx
Normal file
15
mailpoet/assets/js/src/wizard/navigate-to-path.tsx
Normal 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);
|
||||||
|
}
|
||||||
|
};
|
@ -1,5 +1,5 @@
|
|||||||
import { History } from 'history';
|
import { History } from 'history';
|
||||||
import { updateSettings } from './update-settings';
|
import { navigateToPath } from './navigate-to-path';
|
||||||
|
|
||||||
const getSteps = (): string[] => {
|
const getSteps = (): string[] => {
|
||||||
const steps = ['WelcomeWizardSenderStep'];
|
const steps = ['WelcomeWizardSenderStep'];
|
||||||
@ -20,19 +20,6 @@ export const getStepsCount = (): number => getSteps().length;
|
|||||||
export const mapStepNumberToStepName = (stepNumber: number): string | null =>
|
export const mapStepNumberToStepName = (stepNumber: number): string | null =>
|
||||||
getSteps()[stepNumber - 1] || 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 (
|
export const redirectToNextStep = async (
|
||||||
history: History,
|
history: History,
|
||||||
finishWizard: () => void,
|
finishWizard: () => void,
|
||||||
|
@ -10,7 +10,7 @@ import { useEffect } from 'react';
|
|||||||
import { MSSStepFirstPart } from './pitch-mss-step/first-part';
|
import { MSSStepFirstPart } from './pitch-mss-step/first-part';
|
||||||
import { MSSStepSecondPart } from './pitch-mss-step/second-part';
|
import { MSSStepSecondPart } from './pitch-mss-step/second-part';
|
||||||
import { MSSStepThirdPart } from './pitch-mss-step/third-part';
|
import { MSSStepThirdPart } from './pitch-mss-step/third-part';
|
||||||
import { navigateToPath } from '../steps-numbers';
|
import { navigateToPath } from '../navigate-to-path';
|
||||||
|
|
||||||
function WelcomeWizardPitchMSSStep(): JSX.Element {
|
function WelcomeWizardPitchMSSStep(): JSX.Element {
|
||||||
const { path } = useRouteMatch();
|
const { path } = useRouteMatch();
|
||||||
|
@ -7,7 +7,7 @@ import { Button, List } from 'common';
|
|||||||
import { History } from 'history';
|
import { History } from 'history';
|
||||||
import { OwnEmailServiceNote } from './own-email-service-note';
|
import { OwnEmailServiceNote } from './own-email-service-note';
|
||||||
import { useSelector } from '../../../settings/store/hooks';
|
import { useSelector } from '../../../settings/store/hooks';
|
||||||
import { navigateToPath } from '../../steps-numbers';
|
import { navigateToPath } from '../../navigate-to-path';
|
||||||
|
|
||||||
const mailpoetAccountUrl =
|
const mailpoetAccountUrl =
|
||||||
'https://account.mailpoet.com/?ref=plugin-wizard&utm_source=plugin&utm_medium=onboarding&utm_campaign=purchase';
|
'https://account.mailpoet.com/?ref=plugin-wizard&utm_source=plugin&utm_medium=onboarding&utm_campaign=purchase';
|
||||||
|
@ -7,7 +7,7 @@ import { KeyInput } from 'common/premium-key/key-input';
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useSelector } from 'settings/store/hooks';
|
import { useSelector } from 'settings/store/hooks';
|
||||||
import { OwnEmailServiceNote } from './own-email-service-note';
|
import { OwnEmailServiceNote } from './own-email-service-note';
|
||||||
import { navigateToPath } from '../../steps-numbers';
|
import { navigateToPath } from '../../navigate-to-path';
|
||||||
|
|
||||||
function MSSStepSecondPart(): JSX.Element {
|
function MSSStepSecondPart(): JSX.Element {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
@ -14,7 +14,6 @@ import { createSenderSettings } from './create-sender-settings.jsx';
|
|||||||
import {
|
import {
|
||||||
getStepsCount,
|
getStepsCount,
|
||||||
mapStepNumberToStepName,
|
mapStepNumberToStepName,
|
||||||
navigateToPath,
|
|
||||||
redirectToNextStep,
|
redirectToNextStep,
|
||||||
} from './steps-numbers';
|
} from './steps-numbers';
|
||||||
import { Steps } from '../common/steps/steps';
|
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 { HideScreenOptions } from '../common/hide-screen-options/hide-screen-options';
|
||||||
import { finishWizard } from './finish-wizard';
|
import { finishWizard } from './finish-wizard';
|
||||||
import { updateSettings } from './update-settings';
|
import { updateSettings } from './update-settings';
|
||||||
|
import { navigateToPath } from './navigate-to-path';
|
||||||
|
|
||||||
type WelcomeWizardStepsControllerPropType = {
|
type WelcomeWizardStepsControllerPropType = {
|
||||||
match: { params: { step: string } };
|
match: { params: { step: string } };
|
||||||
|
Reference in New Issue
Block a user