From 36797532956851a9385a8cd7c3b1369671be62c2 Mon Sep 17 00:00:00 2001 From: Jesper Paulsen Date: Thu, 11 Jan 2024 12:59:20 +0100 Subject: [PATCH] =?UTF-8?q?[KAIZEN-0]=20Legge=20til=20prompt=20om=20man=20?= =?UTF-8?q?pr=C3=B8ver=20=C3=A5=20lukke=20siden=20mens=20en=20melding=20se?= =?UTF-8?q?ndes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sendMelding/SendNyMeldingContainer.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx b/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx index 3e468db06..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, @@ -68,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);