Skip to content

Commit

Permalink
debug send referat bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesperpaulsen committed Oct 27, 2023
1 parent de3d3c2 commit e20f798
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 13 deletions.
16 changes: 7 additions & 9 deletions src/app/personside/dialogpanel/fellesStyling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,20 @@ export function DialogpanelKvittering(props: {
</ErrorBoundary>
)}
<ErrorBoundary boundaryName="Sendt melding preview">
{props.traad && (
<Preview
fritekst={props.fritekst}
tittel={traadstittel(props.traad)}
meldingstatus={props.meldingstatus}
traad={props.traad}
/>
)}
<Preview
fritekst={props.fritekst}
tittel={props.traad ? traadstittel(props.traad) : props.tittel}
meldingstatus={props.meldingstatus}
traad={props.traad}
/>
</ErrorBoundary>
{props.meldingstatus !== SendNyMeldingStatus.ERROR && (
<ErrorBoundary boundaryName="Sendt melding verktøylinje">
<MeldingSendtVerktoyLinje traad={props.traad} />
</ErrorBoundary>
)}
<KnappBase type="standard" onClick={props.lukk}>
Start ny dialog
{props.meldingstatus !== SendNyMeldingStatus.ERROR ? 'Start ny dialog' : 'Gå tilbake'}
</KnappBase>
<GaaTilNesteOppgaveKnapp lukk={props.lukk} />
</DialogpanelKvitteringStyling>
Expand Down
106 changes: 104 additions & 2 deletions src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -35,6 +43,8 @@ function SendNyMeldingContainer(props: Props) {
);
const fnr = useFodselsnummer();

const { isOn } = useFeatureToggle(FeatureToggles.DebugMeldingsFunksjonalitet);

const valgtEnhet = useValgtenhet().enhetId;
const [state, setState] = useState<SendNyMeldingState>(initialState);
const draftLoader = useCallback(
Expand Down Expand Up @@ -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 <MeldingSendtFeilet fritekst={sendNyMeldingStatus.fritekst} lukk={lukkSendtKvittering} />;
return (
<MeldingSendtFeilet
fritekst={sendNyMeldingStatus.fritekst}
lukk={() => cancelAndKeepDraft(sendNyMeldingStatus.fritekst)}
/>
);
}

const handleAvbryt = () => {
Expand All @@ -97,6 +117,10 @@ function SendNyMeldingContainer(props: Props) {

const handleSubmit = (event: FormEvent) => {
event.preventDefault();
if (isOn) {
handleSubmitDebug();
return;
}
if (sendNyMeldingStatus.type === SendNyMeldingStatus.POSTING) {
return;
}
Expand Down Expand Up @@ -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<Traad>(`${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<Traad>(`${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 (
<SendNyMelding
updateState={updateState}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function SamtaleSendtKvittering(props: { kvitteringNyMelding: KvitteringN
export function MeldingSendtFeilet(props: { fritekst: string; lukk: () => void }) {
return (
<DialogpanelKvittering
tittel="Melding ble sendt, men feil i baksystem"
tittel="Meldingen ble ikke sendt"
fritekst={props.fritekst}
lukk={props.lukk}
meldingstatus={SendNyMeldingStatus.ERROR}
Expand Down
3 changes: 2 additions & 1 deletion src/components/featureToggle/toggleIDs.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export enum FeatureToggles {
BrukSoknadsstatus = 'modiapersonoversikt.soknadsstatus-api'
BrukSoknadsstatus = 'modiapersonoversikt.soknadsstatus-api',
DebugMeldingsFunksjonalitet = 'modiapersonoversikt.ny-send-melding-container'
}

0 comments on commit e20f798

Please sign in to comment.