From da665538fc33a653aa17c39c1e49ea50a2a1a4e6 Mon Sep 17 00:00:00 2001 From: abrha Date: Thu, 25 Jan 2024 12:34:01 +0100 Subject: [PATCH] [KAIZEN-0] fjern fnr i path --- .../journalforing/JournalforSak.tsx | 10 ++++- .../oppgave/useForesl\303\245tteEnheter.ts" | 10 ++++- .../dokumentvisning/SaksDokumentVisning.tsx | 12 ++++- src/components/ObjectHttpFeilHandtering.tsx | 42 +++++++++++------- src/mock/index.ts | 44 +++++++++++++++++++ src/rest/resources/journalsakResource.tsx | 11 ++++- src/rest/resources/sakstemaResource.tsx | 2 +- 7 files changed, 107 insertions(+), 24 deletions(-) diff --git a/src/app/personside/infotabs/meldinger/traadvisning/verktoylinje/journalforing/JournalforSak.tsx b/src/app/personside/infotabs/meldinger/traadvisning/verktoylinje/journalforing/JournalforSak.tsx index bec0fbfdd2..4df2a04c51 100644 --- a/src/app/personside/infotabs/meldinger/traadvisning/verktoylinje/journalforing/JournalforSak.tsx +++ b/src/app/personside/infotabs/meldinger/traadvisning/verktoylinje/journalforing/JournalforSak.tsx @@ -17,6 +17,8 @@ import dialogResource from '../../../../../../../rest/resources/dialogResource'; import { useValgtenhet } from '../../../../../../../context/valgtenhet-state'; import { useQueryClient } from '@tanstack/react-query'; import journalsakResource from '../../../../../../../rest/resources/journalsakResource'; +import useFeatureToggle from '../../../../../../../components/featureToggle/useFeatureToggle'; +import { FeatureToggles } from '../../../../../../../components/featureToggle/toggleIDs'; interface Props { sak: JournalforingsSak; @@ -62,7 +64,13 @@ export function JournalforSak(props: Props) { setSubmitting(true); const enhetheader = valgtEnhet ? `?enhet=${valgtEnhet}` : ''; - post(`${apiBaseUri}/journalforing/${fnr}/${props.traad.traadId}${enhetheader}`, props.sak, 'Journalføring') + const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath); + const url = isOn + ? `${apiBaseUri}/v2/journalforing/${props.traad.traadId}${enhetheader}` + : `${apiBaseUri}/journalforing/${fnr}/${props.traad.traadId}${enhetheader}`; + const body = isOn ? { ...props.sak, fnr } : props.sak; + + post(url, body, 'Journalføring') .then(() => { setSubmitting(false); setJournalforingSuksess(true); diff --git "a/src/app/personside/infotabs/meldinger/traadvisning/verktoylinje/oppgave/useForesl\303\245tteEnheter.ts" "b/src/app/personside/infotabs/meldinger/traadvisning/verktoylinje/oppgave/useForesl\303\245tteEnheter.ts" index b8e702eafe..ca1858eb2a 100644 --- "a/src/app/personside/infotabs/meldinger/traadvisning/verktoylinje/oppgave/useForesl\303\245tteEnheter.ts" +++ "b/src/app/personside/infotabs/meldinger/traadvisning/verktoylinje/oppgave/useForesl\303\245tteEnheter.ts" @@ -2,9 +2,11 @@ import { useFodselsnummer } from '../../../../../../../utils/customHooks'; import { useEffect, useMemo, useState } from 'react'; import { Enhet } from '../../../../../../../models/meldinger/oppgave'; import { loggError, loggEvent } from '../../../../../../../utils/logger/frontendLogger'; -import { apiBaseUri, includeCredentials } from '../../../../../../../api/config'; +import { apiBaseUri, includeCredentials, postConfig } from '../../../../../../../api/config'; import { OppgaveSkjemaForm } from './oppgaveInterfaces'; import { UseFormReturn } from 'react-hook-form'; +import useFeatureToggle from '../../../../../../../components/featureToggle/useFeatureToggle'; +import { FeatureToggles } from '../../../../../../../components/featureToggle/toggleIDs'; function useForeslatteEnheter({ watch }: UseFormReturn) { const fnr = useFodselsnummer(); @@ -32,9 +34,13 @@ function useForeslatteEnheter({ watch }: UseFormReturn) { .map((entry) => entry[0] + '=' + entry[1]) .join('&'); + const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath); + const fetchResponse = isOn + ? fetch(`${apiBaseUri}/v2/enheter/oppgavebehandlere/v2/foreslatte`, postConfig(request)) + : fetch(`${apiBaseUri}/enheter/oppgavebehandlere/v2/foreslatte?${queryParams}`, includeCredentials); setPending(true); loggEvent('Fetch', 'LagOppgave-ForeslåtteEnheter'); - fetch(`${apiBaseUri}/enheter/oppgavebehandlere/v2/foreslatte?${queryParams}`, includeCredentials) + fetchResponse .then((response) => response.json()) .then(setForeslatteEnheter) .catch((e) => loggError(e, 'Feil ved henting av foreslåtte enheter')) diff --git a/src/app/personside/infotabs/saksoversikt/dokumentvisning/SaksDokumentVisning.tsx b/src/app/personside/infotabs/saksoversikt/dokumentvisning/SaksDokumentVisning.tsx index 136c1f7f76..23a5ca7490 100644 --- a/src/app/personside/infotabs/saksoversikt/dokumentvisning/SaksDokumentVisning.tsx +++ b/src/app/personside/infotabs/saksoversikt/dokumentvisning/SaksDokumentVisning.tsx @@ -10,6 +10,8 @@ import styled from 'styled-components'; import { getMockableUrl } from './mockable-dokument-url'; import { parseQueryString } from '../../../../../utils/url-utils'; import { apiBaseUri } from '../../../../../api/config'; +import useFeatureToggle from '../../../../../components/featureToggle/useFeatureToggle'; +import { FeatureToggles } from '../../../../../components/featureToggle/toggleIDs'; interface Props { fnr: string; @@ -42,9 +44,12 @@ function DokumentVisning(props: Props) { } const url = getMockableUrl(byggDokumentVisningUrl(props.url, props.fnr)); + const urlV2 = getMockableUrl(byggDokumentVisningUrlV2(props.url)); + + const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath); return ( - + {errMsg} @@ -57,6 +62,11 @@ function byggDokumentVisningUrl(url: string, fodselsnummer: string): string { return `${apiBaseUri}/saker/${fodselsnummer}/dokument/${journalpost}/${dokument}`; } +function byggDokumentVisningUrlV2(url: string): string { + const { journalpost, dokument } = parseQueryString<{ journalpost: string; dokument: string }>(url); // Format til url: 'journalpost=etcoicxr&dokument=q90p8dnw' + return `${apiBaseUri}/v2/saker/dokument/${journalpost}/${dokument}`; +} + function feilmelding(statusKode: number) { switch (statusKode) { case 401: diff --git a/src/components/ObjectHttpFeilHandtering.tsx b/src/components/ObjectHttpFeilHandtering.tsx index aedf47cbfe..0993b6c01f 100644 --- a/src/components/ObjectHttpFeilHandtering.tsx +++ b/src/components/ObjectHttpFeilHandtering.tsx @@ -1,38 +1,46 @@ import * as React from 'react'; import { ReactNode, useEffect, useState } from 'react'; import { CenteredLazySpinner } from './LazySpinner'; +import useFeatureToggle from './featureToggle/useFeatureToggle'; +import { FeatureToggles } from './featureToggle/toggleIDs'; +import { postConfig } from '../api/config'; export type Omit = Pick>; interface Props extends Omit, HTMLObjectElement>, 'onError'> { url: string; + fnr: string; onError: (status: number) => void; children: ReactNode; } -export function ObjectHttpFeilHandtering({ url, onError, children, ...rest }: Props) { +export function ObjectHttpFeilHandtering({ url, fnr, onError, children, ...rest }: Props) { const [blobUrl, setBlobUrl] = useState(''); const [contentType, setContentType] = useState(''); const [isError, setError] = useState(false); + const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath); + useEffect(() => { let objectUrl = ''; - fetch(url) - .then((res) => { - if (!res.ok) { - setError(true); - onError(res.status); - } else { - setContentType(res.headers.get('Content-Type') ?? 'application/pdf'); - setError(false); - } - return res.blob(); - }) - .then((blob) => { - objectUrl = URL.createObjectURL(blob); - - setBlobUrl(objectUrl); - }); + isOn + ? fetch(url, postConfig(fnr)) + : fetch(url) + .then((res) => { + if (!res.ok) { + setError(true); + onError(res.status); + } else { + setContentType(res.headers.get('Content-Type') ?? 'application/pdf'); + setError(false); + } + return res.blob(); + }) + .then((blob) => { + objectUrl = URL.createObjectURL(blob); + + setBlobUrl(objectUrl); + }); return () => { window.URL.revokeObjectURL(objectUrl); diff --git a/src/mock/index.ts b/src/mock/index.ts index 23a1dde26f..c8fdd53c55 100644 --- a/src/mock/index.ts +++ b/src/mock/index.ts @@ -88,6 +88,15 @@ function setupTilgangskontroll(mock: FetchMock) { ) ); + mock.post( + apiBaseUri + '/v2/tilgang', + withDelayedResponse( + randomDelay(), + () => (Math.random() > 0.98 ? 400 : 200), + mockGeneratorMedFodselsnummer(tilgangskontrollMock) + ) + ); + mock.post( apiBaseUri + '/v2/tilgang', withDelayedResponse( @@ -132,6 +141,18 @@ function setupSaksoversiktMock(mock: FetchMock) { ) ) ); + + mock.post( + apiBaseUri + '/v2/saker/sakstema', + verify( + harEnhetIdSomQueryParam, + withDelayedResponse( + randomDelay(), + fodselsNummerErGyldigStatus, + mockGeneratorMedFodselsnummer(getMockSaksoversikt) + ) + ) + ); } function setupSaksoversiktV2Mock(mock: FetchMock) { @@ -146,6 +167,18 @@ function setupSaksoversiktV2Mock(mock: FetchMock) { ) ) ); + + mock.post( + apiBaseUri + '/v2/saker/v2/sakstema', + verify( + harEnhetIdSomQueryParam, + withDelayedResponse( + randomDelay(), + fodselsNummerErGyldigStatus, + mockGeneratorMedFodselsnummer(getMockSaksoversiktV2) + ) + ) + ); } function setupSaksoversiktV3Mock(mock: FetchMock) { @@ -313,6 +346,10 @@ function setupJournalforingMock(mock: FetchMock) { apiBaseUri + '/journalforing/:fnr/saker/', withDelayedResponse(randomDelay(), STATUS_OK, () => saker) ); + mock.post( + apiBaseUri + '/v2/journalforing/saker/', + withDelayedResponse(randomDelay(), STATUS_OK, () => saker) + ); mock.post( apiBaseUri + '/journalforing/:fnr/:traadId', verify( @@ -320,6 +357,13 @@ function setupJournalforingMock(mock: FetchMock) { withDelayedResponse(randomDelay(), STATUS_OK, () => ({})) ) ); + mock.post( + apiBaseUri + '/v2/journalforing/:traadId', + verify( + harEnhetIdSomQueryParam, + withDelayedResponse(randomDelay(), STATUS_OK, () => ({})) + ) + ); } function opprettOppgaveMock(mock: FetchMock) { diff --git a/src/rest/resources/journalsakResource.tsx b/src/rest/resources/journalsakResource.tsx index c5377fae99..0907406f73 100644 --- a/src/rest/resources/journalsakResource.tsx +++ b/src/rest/resources/journalsakResource.tsx @@ -1,13 +1,19 @@ import { apiBaseUri } from '../../api/config'; import { useFodselsnummer } from '../../utils/customHooks'; import { useQuery, useQueryClient, UseQueryResult } from '@tanstack/react-query'; -import { FetchError, get } from '../../api/api'; +import { FetchError, get, post } from '../../api/api'; import { Result } from '../../app/personside/infotabs/meldinger/traadvisning/verktoylinje/journalforing/JournalforingPanel'; +import useFeatureToggle from '../../components/featureToggle/useFeatureToggle'; +import { FeatureToggles } from '../../components/featureToggle/toggleIDs'; function url(fnr: string): string { return `${apiBaseUri}/journalforing/${fnr}/saker/`; } +function urlV2(): string { + return `${apiBaseUri}/v2/journalforing/saker/`; +} + const resource = { queryKey(fnr: string) { return ['journalsak', fnr]; @@ -15,7 +21,8 @@ const resource = { usePrefetch() { const fnr = useFodselsnummer(); const queryClient = useQueryClient(); - queryClient.prefetchQuery(this.queryKey(fnr), () => get(url(fnr))); + const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath); + queryClient.prefetchQuery(this.queryKey(fnr), () => (isOn ? post(urlV2(), { fnr }) : get(url(fnr)))); }, useFetch(): UseQueryResult { const fnr = useFodselsnummer(); diff --git a/src/rest/resources/sakstemaResource.tsx b/src/rest/resources/sakstemaResource.tsx index 3218878db6..21bf2632f4 100644 --- a/src/rest/resources/sakstemaResource.tsx +++ b/src/rest/resources/sakstemaResource.tsx @@ -36,7 +36,7 @@ function urlV2(fnr: string, enhet?: string) { function urlUtenFnrIPath(enhet?: string) { const header = enhet ? `?enhet=${enhet}` : ''; - return `${apiBaseUri}/saker/sakstema/${header}`; + return `${apiBaseUri}/v2/saker/sakstema/${header}`; } function urlUtenFnrIPathV2(enhet?: string) {