From 0cb939d6bd52e09303056cd5c10af2921f892f1e 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx b/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx index 3e468db06e..0a9a2f850d 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, @@ -129,6 +129,20 @@ function SendNyMeldingContainer(props: Props) { }; const url = isOn ? `${apiBaseUri}/v2/dialog/sendmelding` : `${apiBaseUri}/dialog/${fnr}/sendmelding`; + 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); + }, []); + if (MeldingValidator.erGyldigReferat(state) && state.tema) { const temagruppe = state.tema; setSendNyMeldingStatus({ type: SendNyMeldingStatus.POSTING });