-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lag optimistic response på bostøtte-spørring
Forhindrer forhåpentligvis at folk spammer en radioknapp?
- Loading branch information
Showing
8 changed files
with
1,384 additions
and
724 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,54 @@ | ||
import {useGetBostotte, useUpdateBostotte} from "../../../generated/new/bostotte-controller/bostotte-controller"; | ||
import {useBehandlingsId} from "../common/useBehandlingsId"; | ||
import {updateBostotte, updateSamtykke1, useHentBostotte} from "../../../generated/bostotte-ressurs/bostotte-ressurs"; | ||
import {useQueryClient} from "@tanstack/react-query"; | ||
|
||
export const useInntekterBostotte = (skipFirstStep?: boolean) => { | ||
export const useInntekterBostotte = () => { | ||
const behandlingsId = useBehandlingsId(); | ||
const queryClient = useQueryClient(); | ||
const {data: bostotte, queryKey} = useHentBostotte(behandlingsId); | ||
const {data: bostotte, queryKey, isPending} = useGetBostotte(behandlingsId); | ||
const { | ||
mutate, | ||
isPending: isUpdatePending, | ||
variables, | ||
} = useUpdateBostotte({ | ||
mutation: { | ||
onSettled: () => queryClient.invalidateQueries({queryKey}), | ||
}, | ||
}); | ||
|
||
const isLoading = false; | ||
const setSamtykke = async (nyttHarSamtykke: boolean) => { | ||
if (!bostotte) return; | ||
// FIXME: Replace with contentful PUT | ||
await updateSamtykke1(behandlingsId, nyttHarSamtykke); | ||
mutate({soknadId: behandlingsId, data: {hasSamtykke: nyttHarSamtykke}}); | ||
await queryClient.invalidateQueries({queryKey}); | ||
}; | ||
|
||
const setBekreftelse = async (harInntektHusbanken: boolean) => { | ||
if (!bostotte) return; | ||
|
||
const samtykke = skipFirstStep ? undefined : harInntektHusbanken ? bostotte.samtykke : false; | ||
const oppdatert = { | ||
...bostotte, | ||
bekreftelse: harInntektHusbanken, | ||
samtykke, | ||
}; | ||
|
||
if (!harInntektHusbanken) await updateSamtykke1(behandlingsId, false); | ||
mutate({soknadId: behandlingsId, data: {hasBostotte: harInntektHusbanken}}); | ||
}; | ||
|
||
await updateBostotte(behandlingsId, oppdatert); | ||
await queryClient.invalidateQueries({queryKey}); | ||
const setBostotte = async (harBekreftelse: boolean, harSamtykke?: boolean) => { | ||
mutate({soknadId: behandlingsId, data: {hasBostotte: harBekreftelse, hasSamtykke: harSamtykke}}); | ||
}; | ||
if (skipFirstStep) { | ||
setBekreftelse(true); | ||
} | ||
|
||
const bekreftelse = bostotte?.bekreftelse; | ||
const bekreftelse = bostotte?.hasBostotte; | ||
|
||
// Tidspunkt for mottatt samtykke ellers false | ||
const tidSamtykkeMottatt = | ||
!!bostotte?.samtykke && !!bostotte?.samtykkeTidspunkt && new Date(bostotte.samtykkeTidspunkt); | ||
|
||
const dataHentet = !!bostotte?.samtykke; //&& !bostotte?.stotteFraHusbankenFeilet; | ||
|
||
return {bostotte, bekreftelse, tidSamtykkeMottatt, dataHentet, setSamtykke, setBekreftelse, isLoading}; | ||
!!bostotte?.hasSamtykke && !!bostotte?.samtykkeTidspunkt && new Date(bostotte.samtykkeTidspunkt); | ||
|
||
const dataHentet = !!bostotte?.hasSamtykke; //&& !bostotte?.stotteFraHusbankenFeilet; | ||
|
||
return { | ||
bostotte, | ||
bekreftelse, | ||
tidSamtykkeMottatt, | ||
dataHentet, | ||
setSamtykke, | ||
setBekreftelse, | ||
isUpdatePending, | ||
isQueryPending: isPending, | ||
setBostotte, | ||
variables, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters