2
0

🐛 (typebotLink) Fix linked typebot fetching error

Closes #429
This commit is contained in:
Baptiste Arnaud
2023-03-30 10:30:26 +02:00
parent 70416c0d14
commit 684e6338e2
25 changed files with 2716 additions and 605 deletions

View File

@@ -1,37 +0,0 @@
import { fetcher } from '@/helpers/fetcher'
import { Typebot } from '@typebot.io/schemas'
import { stringify } from 'qs'
import useSWR from 'swr'
export const useLinkedTypebots = ({
workspaceId,
typebotId,
typebotIds,
onError,
}: {
workspaceId?: string
typebotId?: string
typebotIds: string[]
onError: (error: Error) => void
}) => {
const params = stringify({ typebotIds, workspaceId }, { indices: false })
const { data, error, mutate } = useSWR<
{
typebots: Typebot[]
},
Error
>(
workspaceId && typebotIds.length > 0
? typebotIds.every((id) => typebotId === id)
? undefined
: `/api/typebots?${params}`
: null,
fetcher
)
if (error) onError(error)
return {
typebots: data?.typebots,
isLoading: !error && !data,
mutate,
}
}