Skip to content

Commit

Permalink
[KAIZEN-0] fjern fnr i path
Browse files Browse the repository at this point in the history
  • Loading branch information
abrhanav committed Jan 25, 2024
1 parent caa6abf commit da66553
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OppgaveSkjemaForm>) {
const fnr = useFodselsnummer();
Expand Down Expand Up @@ -32,9 +34,13 @@ function useForeslatteEnheter({ watch }: UseFormReturn<OppgaveSkjemaForm>) {
.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'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<ObjectHttpFeilHandtering url={url} width="100%" height="100%" onError={onError}>
<ObjectHttpFeilHandtering url={isOn ? urlV2 : url} fnr={props.fnr} width="100%" height="100%" onError={onError}>
<ErrorStyle>
<AlertStripeAdvarsel>{errMsg}</AlertStripeAdvarsel>
</ErrorStyle>
Expand All @@ -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:
Expand Down
42 changes: 25 additions & 17 deletions src/components/ObjectHttpFeilHandtering.tsx
Original file line number Diff line number Diff line change
@@ -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<T, U> = Pick<T, Exclude<keyof T, U>>;
interface Props
extends Omit<React.DetailedHTMLProps<React.ObjectHTMLAttributes<HTMLObjectElement>, 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);
Expand Down
44 changes: 44 additions & 0 deletions src/mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -313,13 +346,24 @@ 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(
harEnhetIdSomQueryParam,
withDelayedResponse(randomDelay(), STATUS_OK, () => ({}))
)
);
mock.post(
apiBaseUri + '/v2/journalforing/:traadId',
verify(
harEnhetIdSomQueryParam,
withDelayedResponse(randomDelay(), STATUS_OK, () => ({}))
)
);
}

function opprettOppgaveMock(mock: FetchMock) {
Expand Down
11 changes: 9 additions & 2 deletions src/rest/resources/journalsakResource.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
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];
},
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<Result, FetchError> {
const fnr = useFodselsnummer();
Expand Down
2 changes: 1 addition & 1 deletion src/rest/resources/sakstemaResource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit da66553

Please sign in to comment.