-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(results): ✨ Add logs in results
- Loading branch information
1 parent
4630512
commit ebf92b5
Showing
27 changed files
with
408 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalHeader, | ||
ModalCloseButton, | ||
ModalBody, | ||
Stack, | ||
Spinner, | ||
ModalFooter, | ||
Accordion, | ||
AccordionItem, | ||
AccordionButton, | ||
HStack, | ||
AccordionIcon, | ||
AccordionPanel, | ||
Text, | ||
Tag, | ||
} from '@chakra-ui/react' | ||
import { Log } from 'db' | ||
import { useLogs } from 'services/typebots/logs' | ||
import { isDefined } from 'utils' | ||
|
||
export const LogsModal = ({ | ||
resultId, | ||
onClose, | ||
}: { | ||
resultId?: string | ||
onClose: () => void | ||
}) => { | ||
const { isLoading, logs } = useLogs(resultId) | ||
return ( | ||
<Modal isOpen={isDefined(resultId)} onClose={onClose} size="xl"> | ||
<ModalOverlay /> | ||
<ModalContent> | ||
<ModalHeader>Logs</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody as={Stack}> | ||
{logs?.map((log, idx) => ( | ||
<LogCard key={idx} log={log} /> | ||
))} | ||
{isLoading && <Spinner />} | ||
</ModalBody> | ||
|
||
<ModalFooter /> | ||
</ModalContent> | ||
</Modal> | ||
) | ||
} | ||
|
||
const LogCard = ({ log }: { log: Log }) => { | ||
if (log.details) | ||
return ( | ||
<Accordion allowToggle> | ||
<AccordionItem style={{ borderBottomWidth: 0, borderWidth: 0 }}> | ||
<AccordionButton | ||
as={HStack} | ||
p="4" | ||
cursor="pointer" | ||
justifyContent="space-between" | ||
borderRadius="md" | ||
> | ||
<HStack> | ||
<StatusTag status={log.status} /> | ||
<Text>{log.description}</Text> | ||
</HStack> | ||
<AccordionIcon /> | ||
</AccordionButton> | ||
<AccordionPanel | ||
as="pre" | ||
overflow="scroll" | ||
borderWidth="1px" | ||
borderRadius="md" | ||
> | ||
{log.details} | ||
</AccordionPanel> | ||
</AccordionItem> | ||
</Accordion> | ||
) | ||
return ( | ||
<HStack p="4"> | ||
<StatusTag status={log.status} /> | ||
<Text>{log.description}</Text> | ||
</HStack> | ||
) | ||
} | ||
|
||
const StatusTag = ({ status }: { status: string }) => { | ||
switch (status) { | ||
case 'error': | ||
return <Tag colorScheme={'red'}>Fail</Tag> | ||
case 'warning': | ||
return <Tag colorScheme={'orange'}>Warn</Tag> | ||
case 'info': | ||
return <Tag colorScheme={'blue'}>Info</Tag> | ||
default: | ||
return <Tag colorScheme={'green'}>Ok</Tag> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
apps/builder/pages/api/typebots/[typebotId]/results/[resultId]/logs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { withSentry } from '@sentry/nextjs' | ||
import prisma from 'libs/prisma' | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import { getAuthenticatedUser } from 'services/api/utils' | ||
import { methodNotAllowed, notAuthenticated } from 'utils' | ||
|
||
const handler = async (req: NextApiRequest, res: NextApiResponse) => { | ||
const user = await getAuthenticatedUser(req) | ||
if (!user) return notAuthenticated(res) | ||
if (req.method === 'GET') { | ||
const resultId = req.query.resultId as string | ||
const logs = await prisma.log.findMany({ where: { resultId } }) | ||
return res.send({ logs }) | ||
} | ||
methodNotAllowed(res) | ||
} | ||
|
||
export default withSentry(handler) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Log } from 'db' | ||
import { fetcher } from 'services/utils' | ||
import useSWR from 'swr' | ||
|
||
export const useLogs = (resultId?: string, onError?: (e: Error) => void) => { | ||
const { data, error } = useSWR<{ logs: Log[] }>( | ||
resultId ? `/api/typebots/t/results/${resultId}/logs` : null, | ||
fetcher | ||
) | ||
if (error && onError) onError(error) | ||
return { | ||
logs: data?.logs, | ||
isLoading: !error && !data, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
ebf92b5
There was a problem hiding this comment.
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:
viewer-v2 – ./apps/viewer
zap.fundviser.in
bot.matthesv.de
app.yvon.earth
viewer.typebot.io
bot.outstandbrand.com
chat.hayuri.id
88584434.therpm.club
chat.matthesv.de
demo.wemakebots.xyz
92109660.therpm.club
criar.somaperuzzo.com
bot.pratikmandalia.com
typebot-viewer.vercel.app
chat.atlasoutfittersk9.com
link.venturasuceder.com
chat.thehomebuyersusa.com
bot.pinpointinteractive.com
bot.adventureconsulting.hu
viewer-v2-typebot-io.vercel.app
tarian.theiofoundation.org
viewer-v2-git-main-typebot-io.vercel.app
ebf92b5
There was a problem hiding this comment.
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
app.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app