Skip to content

Commit

Permalink
[KAIZEN-0] Legge til prompt om man prøver å lukke siden mens en meldi…
Browse files Browse the repository at this point in the history
…ng sendes
  • Loading branch information
Jesperpaulsen committed Jan 11, 2024
1 parent d4193d4 commit 3679753
Showing 1 changed file with 16 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 @@ -68,6 +68,21 @@ function SendNyMeldingContainer(props: Props) {
const [sendNyMeldingStatus, setSendNyMeldingStatus] = useState<SendNyMeldingPanelState>({
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);
Expand Down

0 comments on commit 3679753

Please sign in to comment.