From 491e60a815dddb4400259b8183e7a8a980cde6ec Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Sat, 14 Jan 2023 15:49:36 +0100 Subject: [PATCH] :children_crossing: (dashboard) Improve invalid typebot import feedback --- .../components/ImportTypebotFromFileButton.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/builder/src/features/templates/components/ImportTypebotFromFileButton.tsx b/apps/builder/src/features/templates/components/ImportTypebotFromFileButton.tsx index 7d2c2e0b41..bcc0bb3c0d 100644 --- a/apps/builder/src/features/templates/components/ImportTypebotFromFileButton.tsx +++ b/apps/builder/src/features/templates/components/ImportTypebotFromFileButton.tsx @@ -1,7 +1,7 @@ import { useToast } from '@/hooks/useToast' import { readFile } from '@/utils/helpers' import { Button, ButtonProps, chakra } from '@chakra-ui/react' -import { Typebot } from 'models' +import { Typebot, typebotSchema } from 'models' import React, { ChangeEvent } from 'react' type Props = { @@ -19,10 +19,18 @@ export const ImportTypebotFromFileButton = ({ const file = e.target.files[0] const fileContent = await readFile(file) try { - onNewTypebot(JSON.parse(fileContent)) + const typebot = JSON.parse(fileContent) + typebotSchema.parse({ + ...typebot, + createdAt: new Date(), + updatedAt: new Date(), + }) + onNewTypebot(typebot) } catch (err) { console.error(err) - showToast({ description: 'Failed to parse the file' }) + showToast({ + description: "Failed to parse the file. Are you sure it's a typebot?", + }) } }