-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Hvis perioder er like skal de som default sammenslås * Kan angre sammenslåing --------- Co-authored-by: Ole Christian Kvernberg <[email protected]>
- Loading branch information
1 parent
60ac9ef
commit 93f3125
Showing
9 changed files
with
203 additions
and
70 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { useHttp } from '@navikt/familie-http'; | ||
import { type Ressurs, RessursStatus } from '@navikt/familie-typer'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
export const useSammenslåPerioder = (behandlingId: string) => { | ||
const { request } = useHttp(); | ||
const [erPerioderLike, settErPerioderLike] = useState<boolean>(false); | ||
const [feilmelding, settFeilmelding] = useState<string>(); | ||
const [laster, settLaster] = useState<boolean>(false); | ||
|
||
const hentErPerioderLike = useCallback(async (): Promise<boolean> => { | ||
const response: Ressurs<boolean> = await request<void, boolean>({ | ||
method: 'GET', | ||
url: `/familie-tilbake/api/perioder/sjekk-likhet/${behandlingId}`, | ||
}); | ||
|
||
if (response.status === RessursStatus.SUKSESS) { | ||
settErPerioderLike(response.data); | ||
return response.data; | ||
} else { | ||
settErPerioderLike(false); | ||
return false; | ||
} | ||
}, [behandlingId, request]); | ||
|
||
const sammenslåPerioder = async () => { | ||
settLaster(true); | ||
const response: Ressurs<string> = await request<void, string>({ | ||
method: 'POST', | ||
url: `/familie-tilbake/api/perioder/sammensla/${behandlingId}`, | ||
}); | ||
|
||
if (response.status === RessursStatus.SUKSESS) { | ||
settLaster(false); | ||
return response.data; | ||
} else if ( | ||
response.status === RessursStatus.FEILET || | ||
response.status === RessursStatus.FUNKSJONELL_FEIL || | ||
response.status === RessursStatus.IKKE_TILGANG | ||
) { | ||
settFeilmelding(response.frontendFeilmelding); | ||
settLaster(false); | ||
return false; | ||
} | ||
}; | ||
|
||
const angreSammenslåingAvPerioder = async () => { | ||
settLaster(true); | ||
const response: Ressurs<string> = await request<void, string>({ | ||
method: 'POST', | ||
url: `/familie-tilbake/api/perioder/angre-sammenslaing/${behandlingId}`, | ||
}); | ||
|
||
if (response.status === RessursStatus.SUKSESS) { | ||
settLaster(false); | ||
return response.data; | ||
} else if ( | ||
response.status === RessursStatus.FEILET || | ||
response.status === RessursStatus.FUNKSJONELL_FEIL || | ||
response.status === RessursStatus.IKKE_TILGANG | ||
) { | ||
settFeilmelding(response.frontendFeilmelding); | ||
settLaster(false); | ||
return false; | ||
} | ||
}; | ||
|
||
const hentErPerioderSammenslått = useCallback(async (): Promise<boolean> => { | ||
const response: Ressurs<boolean> = await request<void, boolean>({ | ||
method: 'GET', | ||
url: `/familie-tilbake/api/perioder/hent-sammenslatt/${behandlingId}`, | ||
}); | ||
|
||
if (response.status === RessursStatus.SUKSESS) { | ||
return response.data; | ||
} else { | ||
return false; | ||
} | ||
}, [behandlingId, request]); | ||
|
||
return { | ||
hentErPerioderLike, | ||
hentErPerioderSammenslått, | ||
sammenslåPerioder, | ||
angreSammenslåingAvPerioder, | ||
erPerioderLike, | ||
feilmelding, | ||
laster, | ||
}; | ||
}; |
This file was deleted.
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
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
Oops, something went wrong.