Skip to content

Commit

Permalink
refactor(uselistcollaboratorshook): shift parsing to be, extract erro…
Browse files Browse the repository at this point in the history
…r message from body as default
  • Loading branch information
seaerchin committed Nov 14, 2022
1 parent c4bdf86 commit 6c990e3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/hooks/collaboratorHooks/useListCollaboratorsHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { LIST_COLLABORATORS_KEY } from "constants/queryKeys"

import useRedirectHook from "hooks/useRedirectHook"

import { getAxiosErrorMessage } from "utils/axios"

import { CollaboratorService } from "services"
import { Collaborator } from "types/collaborators"
import { MiddlewareError } from "types/error"
import { useErrorToast, DEFAULT_RETRY_MSG } from "utils"

const EXCEPTION_ERROR_MESSAGE = `The list of collaborators could not be retrieved. ${DEFAULT_RETRY_MSG}`

export const useListCollaborators = (
siteName: string
): UseQueryResult<Collaborator[], AxiosError<MiddlewareError>> => {
Expand All @@ -19,10 +23,7 @@ export const useListCollaborators = (
[LIST_COLLABORATORS_KEY, siteName],
() =>
CollaboratorService.listCollaborators(siteName).then((data) => {
return data.collaborators.map(({ SiteMember, ...rest }) => ({
...rest,
role: SiteMember.role,
}))
return data.collaborators
}),
{
onError: (err) => {
Expand All @@ -32,7 +33,7 @@ export const useListCollaborators = (
setRedirectToPage("/sites")
} else {
errorToast({
description: `The list of collaborators could not be retrieved. ${DEFAULT_RETRY_MSG}`,
description: getAxiosErrorMessage(err, EXCEPTION_ERROR_MESSAGE),
})
}
},
Expand Down

0 comments on commit 6c990e3

Please sign in to comment.