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] Fjerne fnr fra path i tilgangskontroll resource #2089

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/rest/resources/tilgangskontrollResource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { BigCenteredLazySpinner } from '../../components/BigCenteredLazySpinner'
import FillCenterAndFadeIn from '../../components/FillCenterAndFadeIn';
import { useGjeldendeBruker } from '../../redux/gjeldendeBruker/types';
import { useQuery, UseQueryResult } from '@tanstack/react-query';
import { FetchError, get } from '../../api/api';
import { FetchError, get, post } from '../../api/api';
import { useValgtenhet } from '../../context/valgtenhet-state';
import useFeatureToggle from '../../components/featureToggle/useFeatureToggle';
import { FeatureToggles } from '../../components/featureToggle/toggleIDs';

const defaults: DefaultConfig = {
ifPending: BigCenteredLazySpinner,
Expand Down Expand Up @@ -49,11 +51,17 @@ function url(fnr: string | undefined, enhet: string | undefined) {
return `${apiBaseUri}/tilgang${params}`;
}

function urlV2(enhet: string | undefined) {
const params = enhet ? `?enhet=${enhet}` : '';
return `${apiBaseUri}/tilgang${params}`;
}

const resource = {
useFetch(): UseQueryResult<TilgangDTO, FetchError> {
const fnr = useGjeldendeBruker();
const enhet = useValgtenhet().enhetId;
return useQuery(queryKey(fnr), () => get(url(fnr, enhet)));
const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath);
return useQuery(queryKey(fnr), () => (isOn ? post(urlV2(enhet), fnr) : get(url(fnr, enhet))));
},
useRenderer(renderer: RendererOrConfig<TilgangDTO>) {
const response = this.useFetch();
Expand Down