2
0
Files
bot/apps/builder/src/features/collaboration/hooks/useInvitations.ts
2022-11-15 15:14:38 +01:00

27 lines
620 B
TypeScript

import { fetcher } from '@/utils/helpers'
import { Invitation } from 'db'
import useSWR from 'swr'
import { env } from 'utils'
export const useInvitations = ({
typebotId,
onError,
}: {
typebotId?: string
onError: (error: Error) => void
}) => {
const { data, error, mutate } = useSWR<{ invitations: Invitation[] }, Error>(
typebotId ? `/api/typebots/${typebotId}/invitations` : null,
fetcher,
{
dedupingInterval: env('E2E_TEST') === 'true' ? 0 : undefined,
}
)
if (error) onError(error)
return {
invitations: data?.invitations,
isLoading: !error && !data,
mutate,
}
}