diff --git a/src/rest/resources/sakstemaResource.tsx b/src/rest/resources/sakstemaResource.tsx index 1ddb33e3c..c8a0bfe63 100644 --- a/src/rest/resources/sakstemaResource.tsx +++ b/src/rest/resources/sakstemaResource.tsx @@ -8,7 +8,9 @@ import { useSelector } from 'react-redux'; import { AppState } from '../../redux/reducers'; import { useValgtenhet } from '../../context/valgtenhet-state'; import { useQuery, UseQueryResult } from '@tanstack/react-query'; -import { FetchError, get } from '../../api/api'; +import { FetchError, get, post } from '../../api/api'; +import useFeatureToggle from '../../components/featureToggle/useFeatureToggle'; +import { FeatureToggles } from '../../components/featureToggle/toggleIDs'; const defaults: DefaultConfig = { ifPending: , @@ -32,6 +34,16 @@ function urlV2(fnr: string, enhet?: string) { return `${apiBaseUri}/saker/${fnr}/v2/sakstema${header}`; } +function urlUtenFnrIPath(enhet?: string) { + const header = enhet ? `?enhet=${enhet}` : ''; + return `${apiBaseUri}/saker/sakstema/${header}`; +} + +function urlUtenFnrIPathV2(enhet?: string) { + const header = enhet ? `?enhet=${enhet}` : ''; + return `${apiBaseUri}/saker/v2/sakstema/${header}`; +} + function useFnrEnhet(): [string, string | undefined] { const fnr = useSelector((state: AppState) => state.gjeldendeBruker.fødselsnummer); const enhet = useValgtenhet().enhetId; @@ -41,7 +53,15 @@ function useFnrEnhet(): [string, string | undefined] { const resource = { useFetch(): UseQueryResult { const [fnr, enhet] = useFnrEnhet(); - return useQuery(queryKey(fnr, enhet), () => get(url(fnr, enhet))); + const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath); + + let fetchFn = () => get(url(fnr, enhet)); + + if (isOn) { + fetchFn = () => post(urlUtenFnrIPath(enhet), { fnr }); + } + + return useQuery(queryKey(fnr, enhet), fetchFn); }, useRenderer(renderer: RendererOrConfig) { const response = this.useFetch(); @@ -52,7 +72,15 @@ const resource = { export const sakstemaResourceV2 = { useFetch(): UseQueryResult { const [fnr, enhet] = useFnrEnhet(); - return useQuery(queryKeyV2(fnr, enhet), () => get(urlV2(fnr, enhet))); + const { isOn } = useFeatureToggle(FeatureToggles.IkkeFnrIPath); + + let fetchFn = () => get(urlV2(fnr, enhet)); + + if (isOn) { + fetchFn = () => post(urlUtenFnrIPathV2(enhet), { fnr }); + } + + return useQuery(queryKeyV2(fnr, enhet), fetchFn); }, useRenderer(renderer: RendererOrConfig) { const response = this.useFetch(); diff --git a/src/rest/resources/sakstemaV2Resource.tsx b/src/rest/resources/sakstemaV2Resource.tsx deleted file mode 100644 index c4a470f59..000000000 --- a/src/rest/resources/sakstemaV2Resource.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import * as React from 'react'; -import { applyDefaults, DefaultConfig, RendererOrConfig, useRest } from '../useRest'; -import { CenteredLazySpinner } from '../../components/LazySpinner'; -import AlertStripe from 'nav-frontend-alertstriper'; -import { apiBaseUri } from '../../api/config'; -import { SakstemaSoknadsstatusResponse } from '../../models/saksoversikt/sakstema'; -import { useSelector } from 'react-redux'; -import { AppState } from '../../redux/reducers'; -import { useValgtenhet } from '../../context/valgtenhet-state'; -import { useQuery, UseQueryResult } from '@tanstack/react-query'; -import { FetchError, get } from '../../api/api'; - -const defaults: DefaultConfig = { - ifPending: , - ifError: Kunne ikke laste inn tema -}; -function queryKey(fnr: string, enhet: string | undefined): [string, string, string | undefined] { - return ['sakstema', fnr, enhet]; -} -function url(fnr: string, enhet: string | undefined) { - const header = enhet ? `?enhet=${enhet}` : ''; - return `${apiBaseUri}/saker/${fnr}/sakstema${header}`; -} - -function useFnrEnhet(): [string, string | undefined] { - const fnr = useSelector((state: AppState) => state.gjeldendeBruker.fødselsnummer); - const enhet = useValgtenhet().enhetId; - return [fnr, enhet]; -} - -const resource = { - useFetch(): UseQueryResult { - const [fnr, enhet] = useFnrEnhet(); - return useQuery(queryKey(fnr, enhet), () => get(url(fnr, enhet))); - }, - useRenderer(renderer: RendererOrConfig) { - const response = this.useFetch(); - return useRest(response, applyDefaults(defaults, renderer)); - } -}; - -export default resource;