Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KAIZEN-0] Ikke fnr i path toggle #2085

Merged
merged 11 commits into from
Dec 6, 2023
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { FormEvent, useRef, useState, useCallback, useMemo } from 'react';
import { FortsettDialogValidator } from './validatorer';
import { SendMeldingRequest, Traad, TraadType } from '../../../../models/meldinger/meldinger';
import { SendMeldingRequest, SendMeldingRequestV2, Traad, TraadType } from '../../../../models/meldinger/meldinger';
import { setIngenValgtTraadDialogpanel } from '../../../../redux/oppgave/actions';
import { useFodselsnummer } from '../../../../utils/customHooks';
import { useDispatch } from 'react-redux';
Expand Down Expand Up @@ -32,6 +32,8 @@ import { useValgtenhet } from '../../../../context/valgtenhet-state';
import { useQueryClient, UseQueryResult } from '@tanstack/react-query';
import journalsakResource from '../../../../rest/resources/journalsakResource';
import FortsettDialog from './FortsettDialog';
import useFeatureToggle from '../../../../components/featureToggle/useFeatureToggle';
import { FeatureToggles } from '../../../../components/featureToggle/toggleIDs';

interface Props {
traad: Traad;
Expand Down Expand Up @@ -59,6 +61,7 @@ export function finnPlukketOppgaveForTraad(
}

function FortsettDialogContainer(props: Props) {
const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath);
const queryClient = useQueryClient();
const initialState = useMemo(
() => ({
Expand Down Expand Up @@ -139,17 +142,24 @@ function FortsettDialogContainer(props: Props) {
oppgaveId: oppgaveId,
avsluttet: state.avsluttet
};
const url = isOn ? `${apiBaseUri}/dialog/sendmelding` : `${apiBaseUri}/dialog/${fnr}/sendmelding`;

if (FortsettDialogValidator.erGyldigSamtalereferat(state)) {
setDialogStatus({ type: DialogPanelStatus.POSTING });
const request: SendMeldingRequest = {
...commonPayload,
erOppgaveTilknyttetAnsatt: true
};
const requestV2: SendMeldingRequestV2 = {
...commonPayload,
fnr,
erOppgaveTilknyttetAnsatt: true
};
const kvitteringsData: KvitteringsData = {
fritekst: request.fritekst,
traad: props.traad
};
post(`${apiBaseUri}/dialog/${fnr}/sendmelding`, request, 'Send-Svar')
post(url, isOn ? requestV2 : request, 'Send-Svar')
.then(() => {
callback();
setDialogStatus({ type: DialogPanelStatus.SVAR_SENDT, kvitteringsData: kvitteringsData });
Expand All @@ -175,11 +185,17 @@ function FortsettDialogContainer(props: Props) {
erOppgaveTilknyttetAnsatt: state.avsluttet ? false : erOppgaveTilknyttetAnsatt,
sak: state.sak ? state.sak : undefined
};
const requestV2: SendMeldingRequestV2 = {
...commonPayload,
fnr,
erOppgaveTilknyttetAnsatt: state.avsluttet ? false : erOppgaveTilknyttetAnsatt,
sak: state.sak ? state.sak : undefined
};
const kvitteringsData: KvitteringsData = {
fritekst: request.fritekst,
traad: props.traad
};
post(`${apiBaseUri}/dialog/${fnr}/sendmelding`, request, 'Svar-Med-Spørsmål')
post(url, isOn ? requestV2 : request, 'Svar-Med-Spørsmål')
.then(() => {
callback();
queryClient.invalidateQueries(journalsakResource.queryKey(fnr));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import { useFodselsnummer, useOnMount } from '../../../../utils/customHooks';
import { loggError } from '../../../../utils/logger/frontendLogger';
import { AlertStripeFeil } from 'nav-frontend-alertstriper';
import { CenteredLazySpinner } from '../../../../components/LazySpinner';
import { OpprettHenvendelseRequest, OpprettHenvendelseResponse, Traad } from '../../../../models/meldinger/meldinger';
import {
OpprettHenvendelseRequest,
OpprettHenvendelseRequestV2,
OpprettHenvendelseResponse,
Traad
} from '../../../../models/meldinger/meldinger';
import { useDispatch } from 'react-redux';
import { apiBaseUri } from '../../../../api/config';
import { postWithConflictVerification, RespectConflictError } from '../../../../api/api';
import { useState } from 'react';
import { setIngenValgtTraadDialogpanel } from '../../../../redux/oppgave/actions';
import tildelteoppgaverResource from '../../../../rest/resources/tildelteoppgaverResource';
import { useValgtenhet } from '../../../../context/valgtenhet-state';
import useFeatureToggle from '../../../../components/featureToggle/useFeatureToggle';
import { FeatureToggles } from '../../../../components/featureToggle/toggleIDs';

interface NotFinishedOpprettHenvendelse {
success: false;
Expand All @@ -31,12 +38,21 @@ function useOpprettHenvendelse(traad: Traad): OpprettHenvendelseReturns {
const tildelteoppgaver = tildelteoppgaverResource.useFetch();
const dispatch = useDispatch();
const fnr = useFodselsnummer();
const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath);

useOnMount(function getBehandlingsId() {
const opprettHenvendelseRequest: OpprettHenvendelseRequest = { enhet: valgtEnhet, traadId: traad.traadId };
const opprettHenvendelseRequestV2: OpprettHenvendelseRequestV2 = {
fnr,
enhet: valgtEnhet,
traadId: traad.traadId
};

const request = isOn ? opprettHenvendelseRequestV2 : opprettHenvendelseRequest;
const url = isOn ? `${apiBaseUri}/dialog/fortsett/opprett` : `${apiBaseUri}/dialog/${fnr}/fortsett/opprett`;
postWithConflictVerification(
`${apiBaseUri}/dialog/${fnr}/fortsett/opprett`,
opprettHenvendelseRequest,
url,
request,
'Opprett-henvendelse',
'Oppgaven tilknyttet denne meldingen er allerede tilordnet en saksbehandler. Vil du overstyre dette?'
)
Expand Down
110 changes: 18 additions & 92 deletions src/app/personside/dialogpanel/sendMelding/SendNyMeldingContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MeldingValidator } from './validatorer';
import {
Meldingstype,
SendMeldingRequest,
SendReferatRequest,
SendMeldingRequestV2,
Traad,
TraadType
} from '../../../../models/meldinger/meldinger';
Expand All @@ -14,7 +14,6 @@ import { apiBaseUri } from '../../../../api/config';
import { post } from '../../../../api/api';
import { KvitteringNyMelding, SendNyMeldingPanelState, SendNyMeldingStatus } from './SendNyMeldingTypes';
import useDraft, { Draft } from '../use-draft';
import { feilMeldinger } from './FeilMeldinger';
import dialogResource from '../../../../rest/resources/dialogResource';
import { useValgtenhet } from '../../../../context/valgtenhet-state';
import { useQueryClient } from '@tanstack/react-query';
Expand Down Expand Up @@ -43,7 +42,7 @@ function SendNyMeldingContainer(props: Props) {
);
const fnr = useFodselsnummer();

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

const valgtEnhet = useValgtenhet().enhetId;
const [state, setState] = useState<SendNyMeldingState>(initialState);
Expand Down Expand Up @@ -110,17 +109,8 @@ function SendNyMeldingContainer(props: Props) {
setSendNyMeldingStatus({ type: SendNyMeldingStatus.UNDER_ARBEID });
};

const handleFeilMelding = (error: Error) => {
const feilType = JSON.parse(error.toString()).type;
return feilMeldinger[feilType];
};

const handleSubmit = (event: FormEvent) => {
event.preventDefault();
if (isOn) {
handleSubmitDebug();
return;
}
if (sendNyMeldingStatus.type === SendNyMeldingStatus.POSTING) {
return;
}
Expand All @@ -135,85 +125,8 @@ function SendNyMeldingContainer(props: Props) {
enhet: valgtEnhet,
fritekst: state.tekst
};
const tema = state.tema;
if (MeldingValidator.erGyldigReferat(state) && tema) {
setSendNyMeldingStatus({ type: SendNyMeldingStatus.POSTING });
const request: SendMeldingRequest = {
...commonPayload,
temagruppe: state.tema
};

post<Traad>(`${apiBaseUri}/dialog/${fnr}/sendmelding`, request, 'Send-Referat')
.then((traad) => {
const kvitteringNyMelding: KvitteringNyMelding = {
fritekst: request.fritekst,
traad: traad
};
callback();
const referatRequest: SendReferatRequest = {
enhet: valgtEnhet,
fritekst: request.fritekst,
temagruppe: tema,
meldingstype: Meldingstype.SAMTALEREFERAT_OPPMOTE
};
setSendNyMeldingStatus({
type: SendNyMeldingStatus.REFERAT_SENDT,
request: referatRequest,
kvitteringNyMelding
});
})
.catch((error) => {
console.error('Send-Referat feilet', error);
setSendNyMeldingStatus({ type: SendNyMeldingStatus.ERROR, fritekst: request.fritekst });
});
} 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
};
const url = isOn ? `${apiBaseUri}/dialog/sendmelding` : `${apiBaseUri}/dialog/${fnr}/sendmelding`;

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) => {
callback();
console.error('Send-Sporsmal feilet', error);
setSendNyMeldingStatus({
type: SendNyMeldingStatus.ERROR,
fritekst: handleFeilMelding(error)
});
updateState({ visFeilmeldinger: true });
});
} else {
updateState({ visFeilmeldinger: true });
}
};

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 });
Expand All @@ -222,7 +135,12 @@ function SendNyMeldingContainer(props: Props) {
temagruppe
};

post<Traad>(`${apiBaseUri}/dialog/${fnr}/sendmelding`, request, 'Send-Referat')
const requestV2: SendMeldingRequestV2 = {
...commonPayload,
fnr,
temagruppe
};
post<Traad>(url, isOn ? requestV2 : request, 'Send-Referat')
.then((traad) => {
const kvitteringNyMelding: KvitteringNyMelding = {
fritekst: request.fritekst,
Expand Down Expand Up @@ -254,7 +172,15 @@ function SendNyMeldingContainer(props: Props) {
erOppgaveTilknyttetAnsatt: state.oppgaveListe === OppgavelisteValg.MinListe
};

post<Traad>(`${apiBaseUri}/dialog/${fnr}/sendmelding`, request, 'Send-Sporsmal')
const requestV2: SendMeldingRequestV2 = {
...commonPayload,
fnr: fnr,
sak: state.sak,
avsluttet: state.avsluttet,
erOppgaveTilknyttetAnsatt: state.oppgaveListe === OppgavelisteValg.MinListe
};

post<Traad>(url, isOn ? requestV2 : request, 'Send-Sporsmal')
.then((traad) => {
const kvitteringNyMelding: KvitteringNyMelding = {
fritekst: request.fritekst,
Expand Down
3 changes: 2 additions & 1 deletion src/components/featureToggle/toggleIDs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum FeatureToggles {
BrukSoknadsstatus = 'modiapersonoversikt.soknadsstatus-api',
BrukWebworkerPaaInnLogging = 'modiapersonoversikt.web-worker-paa-innlogging',
DebugMeldingsFunksjonalitet = 'modiapersonoversikt.ny-send-melding-container'
DebugMeldingsFunksjonalitet = 'modiapersonoversikt.ny-send-melding-container',
IkkeFnrIPath = 'modiapersonoversikt.ikke-fnr-i-path'
}
8 changes: 4 additions & 4 deletions src/mock/dialoger/sf-dialoger-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const fodselsNummerErGyldigStatus = (req: MockRequest) =>
erGyldigFødselsnummer(req.pathParams.fodselsnummer) ? STATUS_OK() : STATUS_BAD_REQUEST();

function setupMeldingerMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/dialog/:fodselsnummer/meldinger',
mock.post(
apiBaseUri + '/dialog/meldinger',
verify(
harEnhetIdSomQueryParam,
withDelayedResponse(
Expand Down Expand Up @@ -68,7 +68,7 @@ function simulateSf(trader: Traad[]): Traad[] {

function setupOpprettHenvendelseMock(mock: FetchMock) {
mock.post(
apiBaseUri + '/dialog/:fnr/fortsett/opprett',
apiBaseUri + '/dialog/fortsett/opprett',
withDelayedResponse(randomDelay(), STATUS_OK, (request) =>
meldingerBackendMock.opprettHenvendelse(request.body)
)
Expand All @@ -77,7 +77,7 @@ function setupOpprettHenvendelseMock(mock: FetchMock) {

function setupSendMeldingMock(mock: FetchMock) {
mock.post(
apiBaseUri + '/dialog/:fodselsnummer/sendmelding',
apiBaseUri + '/dialog/sendmelding',
withDelayedResponse(randomDelay() * 2, STATUS_OK, (request) => {
return meldingerBackendMock.sendMelding(request.body);
})
Expand Down
20 changes: 10 additions & 10 deletions src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ function setupTilgangskontroll(mock: FetchMock) {
}

function setupPersondataMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/v2/person/:fodselsnummer',
mock.post(
apiBaseUri + '/v2/person',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand All @@ -99,8 +99,8 @@ function setupPersondataMock(mock: FetchMock) {
}

function setupAktorIdMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/v2/person/:fodselsnummer/aktorid',
mock.post(
apiBaseUri + '/v2/person/aktorid',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand Down Expand Up @@ -180,8 +180,8 @@ function setupPleiepengerMock(mock: FetchMock) {
}

function setupOppfolgingMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/oppfolging/:fodselsnummer',
mock.post(
apiBaseUri + '/oppfolging',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand All @@ -191,8 +191,8 @@ function setupOppfolgingMock(mock: FetchMock) {
}

function setupYtelserOgKontrakter(mock: FetchMock) {
mock.get(
apiBaseUri + '/oppfolging/:fodselsnummer/ytelserogkontrakter',
mock.post(
apiBaseUri + '/oppfolging/ytelserogkontrakter',
withDelayedResponse(
randomDelay(),
fodselsNummerErGyldigStatus,
Expand Down Expand Up @@ -255,8 +255,8 @@ function setupPersonsokMock(mock: FetchMock) {
}

function setupTildelteOppgaverMock(mock: FetchMock) {
mock.get(
apiBaseUri + '/oppgaver/tildelt/:fnr',
mock.post(
apiBaseUri + '/oppgaver/tildelt',
withDelayedResponse(randomDelay(), STATUS_OK, () => oppgaveBackendMock.getTildelteOppgaver())
);
}
Expand Down
Loading