fix(results): 🐛 useLogs returns nothing
This commit is contained in:
@ -21,14 +21,13 @@ import { Log } from 'db'
|
|||||||
import { useLogs } from 'services/typebots/logs'
|
import { useLogs } from 'services/typebots/logs'
|
||||||
import { isDefined } from 'utils'
|
import { isDefined } from 'utils'
|
||||||
|
|
||||||
export const LogsModal = ({
|
type Props = {
|
||||||
resultId,
|
typebotId: string
|
||||||
onClose,
|
|
||||||
}: {
|
|
||||||
resultId?: string
|
resultId?: string
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
}) => {
|
}
|
||||||
const { isLoading, logs } = useLogs(resultId)
|
export const LogsModal = ({ typebotId, resultId, onClose }: Props) => {
|
||||||
|
const { isLoading, logs } = useLogs(typebotId, resultId)
|
||||||
return (
|
return (
|
||||||
<Modal isOpen={isDefined(resultId)} onClose={onClose} size="xl">
|
<Modal isOpen={isDefined(resultId)} onClose={onClose} size="xl">
|
||||||
<ModalOverlay />
|
<ModalOverlay />
|
||||||
|
@ -152,10 +152,13 @@ export const SubmissionsContent = ({
|
|||||||
contentLabel="You are seeing complete submissions only."
|
contentLabel="You are seeing complete submissions only."
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<LogsModal
|
{publishedTypebot && (
|
||||||
resultId={inspectingLogsResultId}
|
<LogsModal
|
||||||
onClose={handleLogsModalClose}
|
typebotId={publishedTypebot?.typebotId}
|
||||||
/>
|
resultId={inspectingLogsResultId}
|
||||||
|
onClose={handleLogsModalClose}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<Flex w="full" justifyContent="flex-end">
|
<Flex w="full" justifyContent="flex-end">
|
||||||
<ResultsActionButtons
|
<ResultsActionButtons
|
||||||
isDeleteLoading={isDeleteLoading}
|
isDeleteLoading={isDeleteLoading}
|
||||||
|
@ -12,7 +12,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const typebotId = req.query.typebotId as string
|
const typebotId = req.query.typebotId as string
|
||||||
const resultId = req.query.resultId as string
|
const resultId = req.query.resultId as string
|
||||||
const logs = await prisma.log.findMany({
|
const logs = await prisma.log.findMany({
|
||||||
where: { resultId, result: { typebot: canReadTypebot(typebotId, user) } },
|
where: {
|
||||||
|
result: { id: resultId, typebot: canReadTypebot(typebotId, user) },
|
||||||
|
},
|
||||||
})
|
})
|
||||||
return res.send({ logs })
|
return res.send({ logs })
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,13 @@ import { Log } from 'db'
|
|||||||
import { fetcher } from 'services/utils'
|
import { fetcher } from 'services/utils'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
|
|
||||||
export const useLogs = (resultId?: string, onError?: (e: Error) => void) => {
|
export const useLogs = (
|
||||||
|
typebotId: string,
|
||||||
|
resultId?: string,
|
||||||
|
onError?: (e: Error) => void
|
||||||
|
) => {
|
||||||
const { data, error } = useSWR<{ logs: Log[] }>(
|
const { data, error } = useSWR<{ logs: Log[] }>(
|
||||||
resultId ? `/api/typebots/t/results/${resultId}/logs` : null,
|
resultId ? `/api/typebots/${typebotId}/results/${resultId}/logs` : null,
|
||||||
fetcher
|
fetcher
|
||||||
)
|
)
|
||||||
if (error && onError) onError(error)
|
if (error && onError) onError(error)
|
||||||
|
Reference in New Issue
Block a user