2
0

🚸 Loosen file import parsing strictness

This commit is contained in:
Baptiste Arnaud
2023-08-18 09:27:14 +02:00
parent e2075d6135
commit 19fc576957
7 changed files with 35 additions and 47 deletions

View File

@@ -4,7 +4,6 @@ import {
Fade,
Flex,
HStack,
useColorMode,
useColorModeValue,
VStack,
} from '@chakra-ui/react'
@@ -20,7 +19,6 @@ import { useDrag } from '@use-gesture/react'
import { ResizeHandle } from './ResizeHandle'
export const PreviewDrawer = () => {
const isDark = useColorMode().colorMode === 'dark'
const { save, isSavingLoading } = useTypebot()
const { setRightPanel } = useEditor()
const { setPreviewingBlock } = useGraph()
@@ -69,7 +67,6 @@ export const PreviewDrawer = () => {
<Fade in={isResizeHandleVisible}>
<ResizeHandle
{...useResizeHandleDrag()}
isDark={isDark}
pos="absolute"
left="-7.5px"
top={`calc(50% - ${headerHeight}px)`}

View File

@@ -1,6 +1,6 @@
import { FlexProps, Flex, useColorModeValue, Box } from '@chakra-ui/react'
export const ResizeHandle = (props: { isDark: boolean } & FlexProps) => {
export const ResizeHandle = (props: FlexProps) => {
return (
<Flex
w="15px"

View File

@@ -63,8 +63,10 @@ export const PublishButton = (props: ButtonProps) => {
description: error.message,
}),
onSuccess: () => {
refetchPublishedTypebot({
typebotId: typebot?.id as string,
})
if (!publishedTypebot) push(`/typebots/${query.typebotId}/share`)
refetchPublishedTypebot()
},
})
@@ -76,7 +78,6 @@ export const PublishButton = (props: ButtonProps) => {
description: error.message,
}),
onSuccess: () => {
if (!publishedTypebot) push(`/typebots/${query.typebotId}/share`)
refetchPublishedTypebot()
},
})

View File

@@ -1,7 +1,7 @@
import { parseInvalidTypebot } from '@/features/typebot/helpers/parseInvalidTypebot'
import { useToast } from '@/hooks/useToast'
import { Button, ButtonProps, chakra } from '@chakra-ui/react'
import { Typebot, typebotSchema } from '@typebot.io/schemas'
import { Typebot, typebotCreateSchema } from '@typebot.io/schemas'
import React, { ChangeEvent } from 'react'
type Props = {
@@ -19,12 +19,9 @@ export const ImportTypebotFromFileButton = ({
const file = e.target.files[0]
const fileContent = await readFile(file)
try {
const typebot = typebotSchema
.omit({
createdAt: true,
updatedAt: true,
})
.parse(parseInvalidTypebot(JSON.parse(fileContent)))
const typebot = typebotCreateSchema.parse(
parseInvalidTypebot(JSON.parse(fileContent))
)
onNewTypebot(typebot as Typebot)
} catch (err) {
console.error(err)

View File

@@ -5,6 +5,7 @@ import { Plan, WorkspaceRole } from '@typebot.io/prisma'
import {
defaultSettings,
defaultTheme,
typebotCreateSchema,
typebotSchema,
} from '@typebot.io/schemas'
import { z } from 'zod'
@@ -31,22 +32,7 @@ export const createTypebot = authenticatedProcedure
.input(
z.object({
workspaceId: z.string(),
typebot: typebotSchema
.pick({
name: true,
icon: true,
selectedThemeTemplateId: true,
groups: true,
theme: true,
settings: true,
folderId: true,
variables: true,
edges: true,
resultsTablePreferences: true,
publicId: true,
customDomain: true,
})
.partial(),
typebot: typebotCreateSchema,
})
)
.output(

View File

@@ -1,7 +1,7 @@
import prisma from '@/lib/prisma'
import { authenticatedProcedure } from '@/helpers/server/trpc'
import { TRPCError } from '@trpc/server'
import { typebotSchema } from '@typebot.io/schemas'
import { typebotCreateSchema, typebotSchema } from '@typebot.io/schemas'
import { z } from 'zod'
import {
isCustomDomainNotAvailable,
@@ -25,23 +25,13 @@ export const updateTypebot = authenticatedProcedure
.input(
z.object({
typebotId: z.string(),
typebot: typebotSchema
.pick({
name: true,
icon: true,
selectedThemeTemplateId: true,
groups: true,
theme: true,
settings: true,
folderId: true,
variables: true,
edges: true,
isClosed: true,
resultsTablePreferences: true,
publicId: true,
customDomain: true,
})
.partial(),
typebot: typebotCreateSchema.merge(
typebotSchema
.pick({
isClosed: true,
})
.partial()
),
updatedAt: z
.date()
.optional()

View File

@@ -71,6 +71,23 @@ export const typebotSchema = z.object({
isClosed: z.boolean(),
}) satisfies z.ZodType<TypebotPrisma>
export const typebotCreateSchema = typebotSchema
.pick({
name: true,
icon: true,
selectedThemeTemplateId: true,
groups: true,
theme: true,
settings: true,
folderId: true,
variables: true,
edges: true,
resultsTablePreferences: true,
publicId: true,
customDomain: true,
})
.partial()
export type Typebot = z.infer<typeof typebotSchema>
export type Target = z.infer<typeof targetSchema>
export type Source = z.infer<typeof sourceSchema>