Skip to content

Commit

Permalink
[KAIZEN-0] Legg til prompt om man lukker siden mens melding sendes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesperpaulsen committed Jan 11, 2024
1 parent d4d48ae commit 3a8a148
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 });
Expand Down

0 comments on commit 3a8a148

Please sign in to comment.