diff --git a/components/StepWizard/Step.tsx b/components/StepWizard/Step.tsx index 7bd28d7d..b6e2e309 100644 --- a/components/StepWizard/Step.tsx +++ b/components/StepWizard/Step.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useStepWizard } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; export type StepType = { stepIndex?: number; diff --git a/components/StepWizard/StepWizard.tsx b/components/StepWizard/StepWizard.tsx index e94e2662..c25ba98a 100644 --- a/components/StepWizard/StepWizard.tsx +++ b/components/StepWizard/StepWizard.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { Label } from '@navikt/ds-react'; -import { useStepWizard } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import * as classes from './StepWizard.module.css'; type StepWizardProps = { diff --git a/components/pageComponents/standard/AndreUtbetalinger/AndreUtbetalinger.tsx b/components/pageComponents/standard/AndreUtbetalinger/AndreUtbetalinger.tsx index 6a187049..3995d826 100644 --- a/components/pageComponents/standard/AndreUtbetalinger/AndreUtbetalinger.tsx +++ b/components/pageComponents/standard/AndreUtbetalinger/AndreUtbetalinger.tsx @@ -15,7 +15,7 @@ import React, { useEffect, useMemo, useState } from 'react'; import { JaEllerNei } from 'types/Generic'; import { Soknad } from 'types/Soknad'; import * as yup from 'yup'; -import { completeAndGoToNextStep, useStepWizard } from 'context/stepWizardContextV2'; +import { completeAndGoToNextStep } from 'context/stepWizardContextV2'; import ColorPanel from 'components/panel/ColorPanel'; import { LucaGuidePanel } from '@navikt/aap-felles-react'; import { useDebounceLagreSoknad } from 'hooks/useDebounceLagreSoknad'; @@ -33,6 +33,7 @@ import { updateSøknadData, } from 'context/soknadcontext/actions'; import { useSoknad } from 'hooks/SoknadHook'; +import { useStepWizard } from 'hooks/StepWizardHook'; interface Props { onBackClick: () => void; diff --git a/components/pageComponents/standard/Barnetillegg/Barnetillegg.tsx b/components/pageComponents/standard/Barnetillegg/Barnetillegg.tsx index 80fe894f..345b13ea 100644 --- a/components/pageComponents/standard/Barnetillegg/Barnetillegg.tsx +++ b/components/pageComponents/standard/Barnetillegg/Barnetillegg.tsx @@ -5,7 +5,8 @@ import { Barn, ManuelleBarn, Soknad } from 'types/Soknad'; import * as classes from './Barnetillegg.module.css'; import { Add } from '@navikt/ds-icons'; import * as yup from 'yup'; -import { completeAndGoToNextStep, useStepWizard } from 'context/stepWizardContextV2'; +import { completeAndGoToNextStep } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import { AddBarnModal, CreateOrUpdateManuelleBarn, Relasjon } from './AddBarnModal'; import { LucaGuidePanel } from '@navikt/aap-felles-react'; import { useDebounceLagreSoknad } from 'hooks/useDebounceLagreSoknad'; diff --git a/components/pageComponents/standard/Behandlere/Behandlere.tsx b/components/pageComponents/standard/Behandlere/Behandlere.tsx index 72a78f21..b07ca0d7 100644 --- a/components/pageComponents/standard/Behandlere/Behandlere.tsx +++ b/components/pageComponents/standard/Behandlere/Behandlere.tsx @@ -3,7 +3,8 @@ import React, { useEffect, useState } from 'react'; import { Add } from '@navikt/ds-icons'; import { Behandler, Soknad } from 'types/Soknad'; import * as yup from 'yup'; -import { completeAndGoToNextStep, useStepWizard } from 'context/stepWizardContextV2'; +import { completeAndGoToNextStep } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import { EndreEllerLeggTilBehandlerModal } from './EndreEllerLeggTilBehandlerModal'; import { LucaGuidePanel } from '@navikt/aap-felles-react'; import * as classes from './Behandlere.module.css'; diff --git a/components/pageComponents/standard/Medlemskap/Medlemskap.tsx b/components/pageComponents/standard/Medlemskap/Medlemskap.tsx index 4e007a54..58638682 100644 --- a/components/pageComponents/standard/Medlemskap/Medlemskap.tsx +++ b/components/pageComponents/standard/Medlemskap/Medlemskap.tsx @@ -14,7 +14,8 @@ import { Add } from '@navikt/ds-icons'; import UtenlandsPeriodeVelger from '..//UtenlandsPeriodeVelger/UtenlandsPeriodeVelger'; import { validate } from 'lib/utils/validationUtils'; import { Soknad, UtenlandsPeriode } from 'types/Soknad'; -import { completeAndGoToNextStep, useStepWizard } from 'context/stepWizardContextV2'; +import { completeAndGoToNextStep } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import ColorPanel from 'components/panel/ColorPanel'; import { LucaGuidePanel } from '@navikt/aap-felles-react'; import { setFocusOnErrorSummary } from 'components/schema/FormErrorSummary'; diff --git a/components/pageComponents/standard/Oppsummering/Oppsummering.tsx b/components/pageComponents/standard/Oppsummering/Oppsummering.tsx index cf8ed8d4..bd8f6927 100644 --- a/components/pageComponents/standard/Oppsummering/Oppsummering.tsx +++ b/components/pageComponents/standard/Oppsummering/Oppsummering.tsx @@ -14,7 +14,8 @@ import OppsummeringKontaktinfo from './OppsummeringKontaktinfo/OppsummeringKonta import OppsummeringUtenlandsopphold from './OppsummeringUtenlandsopphold/OppsummeringUtenlandsopphold'; import OppsummeringBehandler from './OppsummeringBehandler/OppsummeringBehandler'; import * as yup from 'yup'; -import { goToNamedStep, useStepWizard } from 'context/stepWizardContextV2'; +import { goToNamedStep } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import { StepNames } from 'pages'; import { LucaGuidePanel } from '@navikt/aap-felles-react'; import { OppsummeringVedlegg } from './OppsummeringVedlegg/OppsummeringVedlegg'; diff --git a/components/pageComponents/standard/StartDato/StartDato.tsx b/components/pageComponents/standard/StartDato/StartDato.tsx index ec48bb02..ba9ae350 100644 --- a/components/pageComponents/standard/StartDato/StartDato.tsx +++ b/components/pageComponents/standard/StartDato/StartDato.tsx @@ -4,7 +4,8 @@ import { Alert, BodyShort, Heading, Label, Radio, RadioGroup, TextField } from ' import { JaEllerNei } from 'types/Generic'; import ColorPanel from 'components/panel/ColorPanel'; import * as yup from 'yup'; -import { completeAndGoToNextStep, useStepWizard } from 'context/stepWizardContextV2'; +import { completeAndGoToNextStep } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import { LucaGuidePanel } from '@navikt/aap-felles-react'; import { useDebounceLagreSoknad } from 'hooks/useDebounceLagreSoknad'; import * as classes from './StartDato.module.css'; diff --git a/components/pageComponents/standard/Student/Student.tsx b/components/pageComponents/standard/Student/Student.tsx index 00bffca6..4259922d 100644 --- a/components/pageComponents/standard/Student/Student.tsx +++ b/components/pageComponents/standard/Student/Student.tsx @@ -3,7 +3,8 @@ import { Alert, BodyShort, Heading, Radio, RadioGroup } from '@navikt/ds-react'; import { JaNeiVetIkke } from 'types/Generic'; import React, { useEffect, useMemo, useState } from 'react'; import * as yup from 'yup'; -import { completeAndGoToNextStep, useStepWizard } from 'context/stepWizardContextV2'; +import { completeAndGoToNextStep } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import ColorPanel from 'components/panel/ColorPanel'; import { LucaGuidePanel } from '@navikt/aap-felles-react'; import { useDebounceLagreSoknad } from 'hooks/useDebounceLagreSoknad'; diff --git a/components/pageComponents/standard/Vedlegg/Vedlegg.tsx b/components/pageComponents/standard/Vedlegg/Vedlegg.tsx index cadeedd5..819de587 100644 --- a/components/pageComponents/standard/Vedlegg/Vedlegg.tsx +++ b/components/pageComponents/standard/Vedlegg/Vedlegg.tsx @@ -1,7 +1,8 @@ import { Soknad } from 'types/Soknad'; import React, { useEffect } from 'react'; import { Alert, BodyLong, BodyShort, Heading, Label, Textarea } from '@navikt/ds-react'; -import { completeAndGoToNextStep, useStepWizard } from 'context/stepWizardContextV2'; +import { completeAndGoToNextStep } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import { useDebounceLagreSoknad } from 'hooks/useDebounceLagreSoknad'; import { FileInput, LucaGuidePanel } from '@navikt/aap-felles-react'; import { useIntl } from 'react-intl'; diff --git a/components/pageComponents/standard/Yrkesskade/Yrkesskade.tsx b/components/pageComponents/standard/Yrkesskade/Yrkesskade.tsx index 9a0bb5d9..a10ec262 100644 --- a/components/pageComponents/standard/Yrkesskade/Yrkesskade.tsx +++ b/components/pageComponents/standard/Yrkesskade/Yrkesskade.tsx @@ -12,7 +12,8 @@ import { import { Soknad } from 'types/Soknad'; import { JaEllerNei } from 'types/Generic'; import * as yup from 'yup'; -import { completeAndGoToNextStep, useStepWizard } from 'context/stepWizardContextV2'; +import { completeAndGoToNextStep } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import { LucaGuidePanel } from '@navikt/aap-felles-react'; import { useDebounceLagreSoknad } from 'hooks/useDebounceLagreSoknad'; import { setFocusOnErrorSummary } from 'components/schema/FormErrorSummary'; diff --git a/context/stepWizardContextV2.tsx b/context/stepWizardContextV2.tsx index 5d692232..6ea1ff6b 100644 --- a/context/stepWizardContextV2.tsx +++ b/context/stepWizardContextV2.tsx @@ -1,4 +1,4 @@ -import React, { createContext, Dispatch, ReactNode, useContext, useMemo, useReducer } from 'react'; +import React, { createContext, Dispatch, ReactNode, useMemo, useReducer } from 'react'; import { StepType } from 'components/StepWizard/Step'; interface DispatchStepWizardAction { @@ -15,6 +15,7 @@ interface DispatchStepWizardAction { type StepWizardState = { stepList: Array; }; + export type StepWizardContextState = { stepList: Array; currentStepIndex: number; @@ -109,35 +110,22 @@ export const StepWizardProvider = ({ children }: Props) => { }, [state, dispatch]); return {children}; }; -export const useStepWizard = () => { - const context = useContext(StepWizardContext); - if (context === undefined) { - throw new Error('useStepWizard must be used within a StepWizardProvider'); - } - return context; -}; export const setStepList = async ( stepList: StepType[], - dispatch: Dispatch + dispatch: Dispatch, ) => { dispatch({ type: 'SET_STEP_LIST', payload: stepList }); }; -export const setCurrentStepIndex = async ( - index: number, - dispatch: Dispatch -) => { - dispatch({ type: 'SET_ACTIVE_STEP', payload: index }); -}; + export const completeAndGoToNextStep = async (dispatch: Dispatch) => { dispatch({ type: 'COMPLETE_AND_GOTO_NEXT_STEP' }); }; + export const goToPreviousStep = async (dispatch: Dispatch) => { dispatch({ type: 'GOTO_PREVIOUS_STEP' }); }; + export const goToNamedStep = async (dispatch: Dispatch, name: string) => { dispatch({ type: 'GOTO_NAMED_STEP', payload: name }); }; -export const resetStepWizard = async (dispatch: Dispatch) => { - dispatch({ type: 'RESET_STEP_WIZARD' }); -}; diff --git a/hooks/StepWizardHook.ts b/hooks/StepWizardHook.ts new file mode 100644 index 00000000..fa4cf488 --- /dev/null +++ b/hooks/StepWizardHook.ts @@ -0,0 +1,10 @@ +import { useContext } from 'react'; +import { StepWizardContext } from 'context/stepWizardContextV2'; + +export const useStepWizard = () => { + const context = useContext(StepWizardContext); + if (context === undefined) { + throw new Error('useStepWizard must be used within a StepWizardProvider'); + } + return context; +}; diff --git a/pages/[step].tsx b/pages/[step].tsx index 18590bb2..80d10fa3 100644 --- a/pages/[step].tsx +++ b/pages/[step].tsx @@ -5,8 +5,8 @@ import { completeAndGoToNextStep, goToPreviousStep, setStepList, - useStepWizard, } from 'context/stepWizardContextV2'; +import { useStepWizard } from 'hooks/StepWizardHook'; import { useDebounceLagreSoknad } from 'hooks/useDebounceLagreSoknad'; import { StepWizard } from 'components/StepWizard'; import {