Skip to content

Commit 05297a7

Browse files
authored
Håndtere at man ikke kan plukke fra kø uten 404, i stedet returneres array (#3643)
1 parent 975a069 commit 05297a7

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/client/app/api/queries/saksbehandlerQueries.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { SøkeboksOppgaveDto } from 'saksbehandler/sokeboks/SøkeboksOppgaveDto'
1111
import EndreOppgaveType from 'types/EndreOppgaveType';
1212
import { OppgaveNøkkel } from 'types/OppgaveNøkkel';
1313
import OppgaveV3 from 'types/OppgaveV3';
14-
import { OppgavekøV3, OppgavekøV3Enkel } from 'types/OppgavekøV3Type';
14+
import { OppgavekøV3 } from 'types/OppgavekøV3Type';
1515
import { axiosInstance } from 'utils/reactQueryConfig';
1616

1717
export const useInnloggetSaksbehandler = (options?: Omit<UseQueryOptions<NavAnsatt, Error>, 'queryKey'>) =>
@@ -96,16 +96,18 @@ export const useEndreReservasjoner = (onSuccess?: () => void) => {
9696
},
9797
});
9898
};
99-
export const usePlukkOppgaveMutation = (callback?: (oppgave: ReservasjonV3FraKøDto) => void) => {
99+
export const usePlukkOppgaveMutation = (callback?: (oppgave: ReservasjonV3FraKøDto[]) => void) => {
100100
const queryClient = useQueryClient();
101101

102102
return useMutation({
103-
mutationFn: (data: { oppgaveKøId: string }): Promise<ReservasjonV3FraKøDto> =>
103+
mutationFn: (data: { oppgaveKøId: string }): Promise<ReservasjonV3FraKøDto[]> =>
104104
axiosInstance.post(`${apiPaths.hentOppgaveFraKoV3(data.oppgaveKøId)}`, data).then((response) => response.data),
105-
onSuccess: (data: ReservasjonV3FraKøDto) => {
106-
queryClient.refetchQueries({ queryKey: [apiPaths.saksbehandlerReservasjoner] }).then(() => {
107-
if (callback) callback(data);
108-
});
105+
onSuccess: async (data: ReservasjonV3FraKøDto[] | ReservasjonV3FraKøDto) => {
106+
const array = Array.isArray(data) ? data : [data]; // Midlertidig, for å slippe å deploye backend og frontend helt samtidig
107+
if (callback) callback(array);
108+
if (array.length > 0) {
109+
await queryClient.refetchQueries({ queryKey: [apiPaths.saksbehandlerReservasjoner] });
110+
}
109111
},
110112
});
111113
};

src/client/app/saksbehandler/behandlingskoer/components/OppgavekoPanel.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ const OppgavekoPanel: FunctionComponent<OwnProps> = ({ apneOppgave }) => {
3737
resetRequestData,
3838
} = useRestApiRunner<Oppgave>(K9LosApiKeys.FÅ_OPPGAVE_FRA_KO);
3939

40-
const { mutate, error } = usePlukkOppgaveMutation((oppgave) => {
41-
leggTilBehandletOppgave(oppgave.oppgaveNøkkelDto);
42-
window.location.assign(oppgave.oppgavebehandlingsUrl);
40+
const { mutate } = usePlukkOppgaveMutation(async (reservasjoner) => {
41+
if (reservasjoner.length > 0) {
42+
const { oppgaveNøkkelDto, oppgavebehandlingsUrl } = reservasjoner[0];
43+
await leggTilBehandletOppgave(oppgaveNøkkelDto);
44+
window.location.assign(oppgavebehandlingsUrl);
45+
} else {
46+
setVisFinnesIngenBehandlingerIKoModal(true);
47+
}
4348
});
4449

4550
useEffect(() => {
@@ -54,12 +59,6 @@ const OppgavekoPanel: FunctionComponent<OwnProps> = ({ apneOppgave }) => {
5459
}
5560
}, [restApiState, restApiError]);
5661

57-
useEffect(() => {
58-
if (error && error.toString().includes('404')) {
59-
setVisFinnesIngenBehandlingerIKoModal(true);
60-
}
61-
}, [error]);
62-
6362
const plukkNyOppgave = () => {
6463
if (!erKoV3(valgtOppgavekoId)) {
6564
setLoadingOppgaveFraKo(true);

0 commit comments

Comments
 (0)