diff --git a/src/app/personside/dialogpanel/fellesStyling.tsx b/src/app/personside/dialogpanel/fellesStyling.tsx
index 620c39fa37..f745f7f8b7 100644
--- a/src/app/personside/dialogpanel/fellesStyling.tsx
+++ b/src/app/personside/dialogpanel/fellesStyling.tsx
@@ -99,14 +99,12 @@ export function DialogpanelKvittering(props: {
)}
- {props.traad && (
-
- )}
+
{props.meldingstatus !== SendNyMeldingStatus.ERROR && (
@@ -114,7 +112,7 @@ export function DialogpanelKvittering(props: {
)}
- Start ny dialog
+ {props.meldingstatus !== SendNyMeldingStatus.ERROR ? 'Start ny dialog' : 'Gå tilbake'}
diff --git a/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx b/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx
index 65cbc8e048..b39721d21d 100644
--- a/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx
+++ b/src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx
@@ -1,7 +1,13 @@
import * as React from 'react';
import { FormEvent, useCallback, useMemo, useState } from 'react';
import { MeldingValidator } from './validatorer';
-import { SendMeldingRequest, SendReferatRequest, Traad, TraadType } from '../../../../models/meldinger/meldinger';
+import {
+ Meldingstype,
+ SendMeldingRequest,
+ SendReferatRequest,
+ Traad,
+ TraadType
+} from '../../../../models/meldinger/meldinger';
import { useFodselsnummer } from '../../../../utils/customHooks';
import { MeldingSendtFeilet, ReferatSendtKvittering, SamtaleSendtKvittering } from './SendNyMeldingKvittering';
import { apiBaseUri } from '../../../../api/config';
@@ -14,6 +20,8 @@ import { useValgtenhet } from '../../../../context/valgtenhet-state';
import { useQueryClient } from '@tanstack/react-query';
import journalsakResource from '../../../../rest/resources/journalsakResource';
import SendNyMelding, { OppgavelisteValg, SendNyMeldingState } from './SendNyMelding';
+import useFeatureToggle from '../../../../components/featureToggle/useFeatureToggle';
+import { FeatureToggles } from '../../../../components/featureToggle/toggleIDs';
interface Props {
defaultOppgaveDestinasjon: OppgavelisteValg;
@@ -35,6 +43,8 @@ function SendNyMeldingContainer(props: Props) {
);
const fnr = useFodselsnummer();
+ const { isOn } = useFeatureToggle(FeatureToggles.DebugMeldingsFunksjonalitet);
+
const valgtEnhet = useValgtenhet().enhetId;
const [state, setState] = useState(initialState);
const draftLoader = useCallback(
@@ -80,8 +90,18 @@ function SendNyMeldingContainer(props: Props) {
);
}
+ const cancelAndKeepDraft = (tekst: string) => {
+ updateState({ tekst });
+ setSendNyMeldingStatus({ type: SendNyMeldingStatus.UNDER_ARBEID });
+ };
+
if (sendNyMeldingStatus.type === SendNyMeldingStatus.ERROR) {
- return ;
+ return (
+ cancelAndKeepDraft(sendNyMeldingStatus.fritekst)}
+ />
+ );
}
const handleAvbryt = () => {
@@ -97,6 +117,10 @@ function SendNyMeldingContainer(props: Props) {
const handleSubmit = (event: FormEvent) => {
event.preventDefault();
+ if (isOn) {
+ handleSubmitDebug();
+ return;
+ }
if (sendNyMeldingStatus.type === SendNyMeldingStatus.POSTING) {
return;
}
@@ -169,6 +193,84 @@ function SendNyMeldingContainer(props: Props) {
}
};
+ const handleSubmitDebug = () => {
+ if (sendNyMeldingStatus.type === SendNyMeldingStatus.POSTING) {
+ return;
+ }
+ const callback = () => {
+ removeDraft();
+ updateState(initialState);
+ queryClient.invalidateQueries(dialogResource.queryKey(fnr, valgtEnhet));
+ };
+
+ const commonPayload = {
+ traadType: state.traadType,
+ enhet: valgtEnhet,
+ fritekst: state.tekst
+ };
+ if (MeldingValidator.erGyldigReferat(state) && state.tema) {
+ const temagruppe = state.tema;
+ setSendNyMeldingStatus({ type: SendNyMeldingStatus.POSTING });
+ const request: SendMeldingRequest = {
+ ...commonPayload,
+ temagruppe
+ };
+
+ post(`${apiBaseUri}/dialog/${fnr}/sendmelding`, request, 'Send-Referat')
+ .then((traad) => {
+ const kvitteringNyMelding: KvitteringNyMelding = {
+ fritekst: request.fritekst,
+ traad: traad
+ };
+ callback();
+ setSendNyMeldingStatus({
+ type: SendNyMeldingStatus.REFERAT_SENDT,
+ request: {
+ fritekst: request.fritekst,
+ enhet: valgtEnhet,
+ meldingstype: Meldingstype.SAMTALEREFERAT_TELEFON,
+ temagruppe
+ },
+ kvitteringNyMelding
+ });
+ })
+ .catch((error) => {
+ console.error('Send-Referat feilet', error);
+ setSendNyMeldingStatus({ type: SendNyMeldingStatus.ERROR, fritekst: request.fritekst });
+ updateState({ visFeilmeldinger: true });
+ });
+ } else if (MeldingValidator.erGyldigSamtale(state) && state.sak) {
+ setSendNyMeldingStatus({ type: SendNyMeldingStatus.POSTING });
+ const request: SendMeldingRequest = {
+ ...commonPayload,
+ sak: state.sak,
+ avsluttet: state.avsluttet,
+ erOppgaveTilknyttetAnsatt: state.oppgaveListe === OppgavelisteValg.MinListe
+ };
+
+ post(`${apiBaseUri}/dialog/${fnr}/sendmelding`, request, 'Send-Sporsmal')
+ .then((traad) => {
+ const kvitteringNyMelding: KvitteringNyMelding = {
+ fritekst: request.fritekst,
+ traad: traad
+ };
+ queryClient.invalidateQueries(journalsakResource.queryKey(fnr));
+ callback();
+ setSendNyMeldingStatus({ type: SendNyMeldingStatus.SAMTALE_SENDT, kvitteringNyMelding });
+ })
+ .catch((error) => {
+ console.error('Send-Sporsmal feilet', error);
+ setSendNyMeldingStatus({
+ type: SendNyMeldingStatus.ERROR,
+ fritekst: request.fritekst
+ });
+ updateState({ visFeilmeldinger: true });
+ });
+ } else {
+ updateState({ visFeilmeldinger: true });
+ }
+ };
+
return (
void }) {
return (