From 82446c41af903e450469084267647b5837a26cee Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Sat, 9 Apr 2022 11:18:38 -0500 Subject: [PATCH] =?UTF-8?q?fix(viewer):=20=F0=9F=90=9B=20Result=20creation?= =?UTF-8?q?=20fail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/viewer/layouts/TypebotPage.tsx | 8 +++++--- .../pages/api/typebots/[typebotId]/results/[resultId].ts | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/viewer/layouts/TypebotPage.tsx b/apps/viewer/layouts/TypebotPage.tsx index 641509c128..6df44e4111 100644 --- a/apps/viewer/layouts/TypebotPage.tsx +++ b/apps/viewer/layouts/TypebotPage.tsx @@ -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( isIE ? new Error('Internet explorer is not supported') : undefined ) @@ -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) @@ -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) } diff --git a/apps/viewer/pages/api/typebots/[typebotId]/results/[resultId].ts b/apps/viewer/pages/api/typebots/[typebotId]/results/[resultId].ts index d2d3839097..d1f289c385 100644 --- a/apps/viewer/pages/api/typebots/[typebotId]/results/[resultId].ts +++ b/apps/viewer/pages/api/typebots/[typebotId]/results/[resultId].ts @@ -1,5 +1,6 @@ import { withSentry } from '@sentry/nextjs' import prisma from 'libs/prisma' +import { Result } from 'models' import { NextApiRequest, NextApiResponse } from 'next' import { methodNotAllowed } from 'utils' @@ -7,7 +8,7 @@ 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 },