From 5f99a11cadd00a90b0d2c46a581df2d53aa7fc7e Mon Sep 17 00:00:00 2001 From: John Oleksowicz Date: Thu, 8 Feb 2024 15:12:19 -0600 Subject: [PATCH] Extract navigation helper MAILPOET-5216 --- .../assets/js/src/wizard/navigate-to-path.tsx | 15 +++++++++++++++ mailpoet/assets/js/src/wizard/steps-numbers.ts | 15 +-------------- .../assets/js/src/wizard/steps/pitch-mss-step.tsx | 2 +- .../wizard/steps/pitch-mss-step/first-part.tsx | 2 +- .../wizard/steps/pitch-mss-step/second-part.tsx | 2 +- .../js/src/wizard/welcome-wizard-controller.tsx | 2 +- 6 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 mailpoet/assets/js/src/wizard/navigate-to-path.tsx diff --git a/mailpoet/assets/js/src/wizard/navigate-to-path.tsx b/mailpoet/assets/js/src/wizard/navigate-to-path.tsx new file mode 100644 index 0000000000..893c46c984 --- /dev/null +++ b/mailpoet/assets/js/src/wizard/navigate-to-path.tsx @@ -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); + } +}; diff --git a/mailpoet/assets/js/src/wizard/steps-numbers.ts b/mailpoet/assets/js/src/wizard/steps-numbers.ts index 2463d984bb..3d8653676e 100644 --- a/mailpoet/assets/js/src/wizard/steps-numbers.ts +++ b/mailpoet/assets/js/src/wizard/steps-numbers.ts @@ -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, diff --git a/mailpoet/assets/js/src/wizard/steps/pitch-mss-step.tsx b/mailpoet/assets/js/src/wizard/steps/pitch-mss-step.tsx index c1dff3b55f..6d1f5b9929 100644 --- a/mailpoet/assets/js/src/wizard/steps/pitch-mss-step.tsx +++ b/mailpoet/assets/js/src/wizard/steps/pitch-mss-step.tsx @@ -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(); diff --git a/mailpoet/assets/js/src/wizard/steps/pitch-mss-step/first-part.tsx b/mailpoet/assets/js/src/wizard/steps/pitch-mss-step/first-part.tsx index ef26527f68..b6dfd65f77 100644 --- a/mailpoet/assets/js/src/wizard/steps/pitch-mss-step/first-part.tsx +++ b/mailpoet/assets/js/src/wizard/steps/pitch-mss-step/first-part.tsx @@ -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'; diff --git a/mailpoet/assets/js/src/wizard/steps/pitch-mss-step/second-part.tsx b/mailpoet/assets/js/src/wizard/steps/pitch-mss-step/second-part.tsx index 0d84fd8f16..2852dbafce 100644 --- a/mailpoet/assets/js/src/wizard/steps/pitch-mss-step/second-part.tsx +++ b/mailpoet/assets/js/src/wizard/steps/pitch-mss-step/second-part.tsx @@ -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(); diff --git a/mailpoet/assets/js/src/wizard/welcome-wizard-controller.tsx b/mailpoet/assets/js/src/wizard/welcome-wizard-controller.tsx index 7a841d1af1..4d7eeb3b51 100644 --- a/mailpoet/assets/js/src/wizard/welcome-wizard-controller.tsx +++ b/mailpoet/assets/js/src/wizard/welcome-wizard-controller.tsx @@ -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 } };