Skip to content

Commit

Permalink
fix(results): 🐛 useLogs returns nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Mar 30, 2022
1 parent af9e08f commit 2461dd8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
11 changes: 5 additions & 6 deletions apps/builder/layouts/results/LogsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ import { Log } from 'db'
import { useLogs } from 'services/typebots/logs'
import { isDefined } from 'utils'

export const LogsModal = ({
resultId,
onClose,
}: {
type Props = {
typebotId: string
resultId?: string
onClose: () => void
}) => {
const { isLoading, logs } = useLogs(resultId)
}
export const LogsModal = ({ typebotId, resultId, onClose }: Props) => {
const { isLoading, logs } = useLogs(typebotId, resultId)
return (
<Modal isOpen={isDefined(resultId)} onClose={onClose} size="xl">
<ModalOverlay />
Expand Down
11 changes: 7 additions & 4 deletions apps/builder/layouts/results/SubmissionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ export const SubmissionsContent = ({
contentLabel="You are seeing complete submissions only."
/>
)}
<LogsModal
resultId={inspectingLogsResultId}
onClose={handleLogsModalClose}
/>
{publishedTypebot && (
<LogsModal
typebotId={publishedTypebot?.typebotId}
resultId={inspectingLogsResultId}
onClose={handleLogsModalClose}
/>
)}
<Flex w="full" justifyContent="flex-end">
<ResultsActionButtons
isDeleteLoading={isDeleteLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const typebotId = req.query.typebotId as string
const resultId = req.query.resultId as string
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 })
}
Expand Down
8 changes: 6 additions & 2 deletions apps/builder/services/typebots/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { Log } from 'db'
import { fetcher } from 'services/utils'
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[] }>(
resultId ? `/api/typebots/t/results/${resultId}/logs` : null,
resultId ? `/api/typebots/${typebotId}/results/${resultId}/logs` : null,
fetcher
)
if (error && onError) onError(error)
Expand Down

3 comments on commit 2461dd8

@vercel
Copy link

@vercel vercel bot commented on 2461dd8 Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 2461dd8 Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 2461dd8 Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.