From 7d279dc517d7609d9195e54078a37c05ca9a4d83 Mon Sep 17 00:00:00 2001 From: Anders Rognstad Date: Mon, 4 Dec 2023 20:00:50 +0100 Subject: [PATCH] Fix querykey --- src/data/personregisterHooks.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/data/personregisterHooks.ts b/src/data/personregisterHooks.ts index 5e07b0f8..0d548b76 100644 --- a/src/data/personregisterHooks.ts +++ b/src/data/personregisterHooks.ts @@ -7,12 +7,14 @@ import { ApiErrorException } from '@/api/errors'; import { FetchPersonregisterFailed } from '@/context/notification/Notifications'; import { useNotifications } from '@/context/notification/NotificationContext'; import { useAsyncError } from '@/data/useAsyncError'; +import { useAktivEnhet } from '@/context/aktivEnhet/AktivEnhetContext'; export const personregisterQueryKeys = { - personregister: ['personregister'], + personregister: (enhetId: string | undefined) => ['personregister', enhetId], }; export const usePersonregisterQuery = () => { + const { aktivEnhet } = useAktivEnhet(); const { data } = usePersonoversiktQuery(); const { displayNotification, clearNotification } = useNotifications(); const throwError = useAsyncError(); @@ -29,9 +31,9 @@ export const usePersonregisterQuery = () => { }; return useQuery({ - queryKey: personregisterQueryKeys.personregister, + queryKey: personregisterQueryKeys.personregister(aktivEnhet), queryFn: fetchPersonregister, - enabled: fnrForPersonerListe.length > 0, + enabled: !!aktivEnhet && fnrForPersonerListe.length > 0, onError: (error) => { if (error instanceof ApiErrorException && error.code === 403) { throwError(error);