Skip to content

Commit

Permalink
Håndtere at man ikke kan plukke fra kø uten 404, i stedet returneres …
Browse files Browse the repository at this point in the history
…array (#3643)
  • Loading branch information
mbolstad authored Feb 5, 2025
1 parent 975a069 commit 05297a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
16 changes: 9 additions & 7 deletions src/client/app/api/queries/saksbehandlerQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SøkeboksOppgaveDto } from 'saksbehandler/sokeboks/SøkeboksOppgaveDto'
import EndreOppgaveType from 'types/EndreOppgaveType';
import { OppgaveNøkkel } from 'types/OppgaveNøkkel';
import OppgaveV3 from 'types/OppgaveV3';
import { OppgavekøV3, OppgavekøV3Enkel } from 'types/OppgavekøV3Type';
import { OppgavekøV3 } from 'types/OppgavekøV3Type';
import { axiosInstance } from 'utils/reactQueryConfig';

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

return useMutation({
mutationFn: (data: { oppgaveKøId: string }): Promise<ReservasjonV3FraKøDto> =>
mutationFn: (data: { oppgaveKøId: string }): Promise<ReservasjonV3FraKøDto[]> =>
axiosInstance.post(`${apiPaths.hentOppgaveFraKoV3(data.oppgaveKøId)}`, data).then((response) => response.data),
onSuccess: (data: ReservasjonV3FraKøDto) => {
queryClient.refetchQueries({ queryKey: [apiPaths.saksbehandlerReservasjoner] }).then(() => {
if (callback) callback(data);
});
onSuccess: async (data: ReservasjonV3FraKøDto[] | ReservasjonV3FraKøDto) => {
const array = Array.isArray(data) ? data : [data]; // Midlertidig, for å slippe å deploye backend og frontend helt samtidig
if (callback) callback(array);
if (array.length > 0) {
await queryClient.refetchQueries({ queryKey: [apiPaths.saksbehandlerReservasjoner] });
}
},
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ const OppgavekoPanel: FunctionComponent<OwnProps> = ({ apneOppgave }) => {
resetRequestData,
} = useRestApiRunner<Oppgave>(K9LosApiKeys.FÅ_OPPGAVE_FRA_KO);

const { mutate, error } = usePlukkOppgaveMutation((oppgave) => {
leggTilBehandletOppgave(oppgave.oppgaveNøkkelDto);
window.location.assign(oppgave.oppgavebehandlingsUrl);
const { mutate } = usePlukkOppgaveMutation(async (reservasjoner) => {
if (reservasjoner.length > 0) {
const { oppgaveNøkkelDto, oppgavebehandlingsUrl } = reservasjoner[0];
await leggTilBehandletOppgave(oppgaveNøkkelDto);
window.location.assign(oppgavebehandlingsUrl);
} else {
setVisFinnesIngenBehandlingerIKoModal(true);
}
});

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

useEffect(() => {
if (error && error.toString().includes('404')) {
setVisFinnesIngenBehandlingerIKoModal(true);
}
}, [error]);

const plukkNyOppgave = () => {
if (!erKoV3(valgtOppgavekoId)) {
setLoadingOppgaveFraKo(true);
Expand Down

0 comments on commit 05297a7

Please sign in to comment.