diff --git a/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx b/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx index f72a55e9c..5bd9eb3d2 100644 --- a/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx +++ b/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { FormEvent, useCallback, useMemo, useState } from 'react'; +import { FormEvent, useCallback, useEffect, useMemo, useState } from 'react'; import { MeldingValidator } from './validatorer'; import { Meldingstype, @@ -21,6 +21,8 @@ import journalsakResource from '../../../../rest/resources/journalsakResource'; import SendNyMelding, { OppgavelisteValg, SendNyMeldingState } from './SendNyMelding'; import useFeatureToggle from '../../../../components/featureToggle/useFeatureToggle'; import { FeatureToggles } from '../../../../components/featureToggle/toggleIDs'; +import { Prompt } from 'react-router'; +import IfFeatureToggleOn from '../../../../components/featureToggle/IfFeatureToggleOn'; interface Props { defaultOppgaveDestinasjon: OppgavelisteValg; @@ -66,6 +68,21 @@ function SendNyMeldingContainer(props: Props) { const [sendNyMeldingStatus, setSendNyMeldingStatus] = useState({ type: SendNyMeldingStatus.UNDER_ARBEID }); + + useEffect(() => { + const promptUser = (e: BeforeUnloadEvent) => { + if (sendNyMeldingStatus.type !== SendNyMeldingStatus.POSTING) { + return; + } + + e.preventDefault(); + e.returnValue = true; + }; + + window.addEventListener('beforeunload', promptUser); + return () => window.removeEventListener('beforeunload', promptUser); + }, [sendNyMeldingStatus.type]); + const lukkSendtKvittering = () => { setSendNyMeldingStatus({ type: SendNyMeldingStatus.UNDER_ARBEID }); setState(initialState); @@ -204,14 +221,24 @@ function SendNyMeldingContainer(props: Props) { }; return ( - + <> + + + + + ); } diff --git a/src/components/featureToggle/toggleIDs.ts b/src/components/featureToggle/toggleIDs.ts index 49aa2b0b6..104fe9b26 100644 --- a/src/components/featureToggle/toggleIDs.ts +++ b/src/components/featureToggle/toggleIDs.ts @@ -1,6 +1,6 @@ export enum FeatureToggles { BrukSoknadsstatus = 'modiapersonoversikt.soknadsstatus-api', BrukWebworkerPaaInnLogging = 'modiapersonoversikt.web-worker-paa-innlogging', - DebugMeldingsFunksjonalitet = 'modiapersonoversikt.ny-send-melding-container', - IkkeFnrIPath = 'modiapersonoversikt.ikke-fnr-i-path' + IkkeFnrIPath = 'modiapersonoversikt.ikke-fnr-i-path', + VisPromptMeldingSending = 'modiapersonoversikt.vis-promt-naar-melding-sendes' }