Skip to content

Commit

Permalink
fix(viewer): 🐛 Result creation fail
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 9, 2022
1 parent 0c23f2d commit 82446c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions apps/viewer/layouts/TypebotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export const TypebotPage = ({
url,
}: TypebotPageProps & { typebot: PublicTypebot }) => {
const [showTypebot, setShowTypebot] = useState(false)
const [predefinedVariables, setPredefinedVariables] =
useState<{ [key: string]: string }>()
const [predefinedVariables, setPredefinedVariables] = useState<{
[key: string]: string
}>()
const [error, setError] = useState<Error | undefined>(
isIE ? new Error('Internet explorer is not supported') : undefined
)
Expand All @@ -44,7 +45,7 @@ export const TypebotPage = ({
if (resultIdFromSession) setResultId(resultIdFromSession)
else {
const { error, data: result } = await createResult(typebot.typebotId)
if (error) setError(error)
if (error) return setError(error)
if (result) {
setResultId(result.id)
if (typebot.settings.general.isNewResultOnRefreshEnabled !== true)
Expand All @@ -56,6 +57,7 @@ export const TypebotPage = ({

const handleNewVariables = async (variables: VariableWithValue[]) => {
if (!resultId) return setError(new Error('Result was not created'))
if (variables.length === 0) return
const { error } = await updateResult(resultId, { variables })
if (error) setError(error)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { withSentry } from '@sentry/nextjs'
import prisma from 'libs/prisma'
import { Result } from 'models'
import { NextApiRequest, NextApiResponse } from 'next'
import { methodNotAllowed } from 'utils'

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (req.method === 'PATCH') {
const data = (
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
) as { isCompleted: true }
) as Result
const resultId = req.query.resultId as string
const result = await prisma.result.update({
where: { id: resultId },
Expand Down

4 comments on commit 82446c4

@vercel
Copy link

@vercel vercel bot commented on 82446c4 Apr 9, 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 82446c4 Apr 9, 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 82446c4 Apr 9, 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 82446c4 Apr 9, 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.