-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use own endpoint for requesting more information (#3523)
- Loading branch information
Showing
4 changed files
with
84 additions
and
15 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
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
49 changes: 49 additions & 0 deletions
49
frontend/benefit/handler/src/hooks/useRequireAdditionalInformation.ts
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,49 @@ | ||
import { AxiosError } from 'axios'; | ||
import { HandlerEndpoint } from 'benefit-shared/backend-api/backend-api'; | ||
import { APPLICATION_STATUSES } from 'benefit-shared/constants'; | ||
import { useTranslation } from 'next-i18next'; | ||
import { useMutation, UseMutationResult, useQueryClient } from 'react-query'; | ||
import showErrorToast from 'shared/components/toast/show-error-toast'; | ||
import useBackendAPI from 'shared/hooks/useBackendAPI'; | ||
|
||
type Payload = { | ||
id: string; | ||
status: APPLICATION_STATUSES.INFO_REQUIRED | APPLICATION_STATUSES.HANDLING; | ||
}; | ||
|
||
const useRequireAdditionalInformation = (): UseMutationResult< | ||
null, | ||
Error, | ||
Payload | ||
> => { | ||
const { axios, handleResponse } = useBackendAPI(); | ||
const queryClient = useQueryClient(); | ||
const { t } = useTranslation(); | ||
|
||
return useMutation<null, Error, Payload>( | ||
'require_additional_information', | ||
({ id, status }: Payload) => | ||
handleResponse( | ||
axios.patch( | ||
`${HandlerEndpoint.HANDLER_REQUIRE_ADDITIONAL_INFORMATION(id)}`, | ||
{ status } | ||
) | ||
), | ||
{ | ||
onSuccess: () => { | ||
void queryClient.invalidateQueries('application'); | ||
void queryClient.invalidateQueries('applications'); | ||
}, | ||
onError: (error: AxiosError<Error, Record<string, string[]>>) => { | ||
showErrorToast( | ||
t('common:error.generic.label'), | ||
t('common:error.generic.text') | ||
); | ||
// eslint-disable-next-line no-console | ||
console.log(error); | ||
}, | ||
} | ||
); | ||
}; | ||
|
||
export default useRequireAdditionalInformation; |
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