fix(dashboard): 🐛 Import from file button
This commit is contained in:
@ -1,15 +1,15 @@
|
||||
import { chakra, MenuItem, MenuItemProps, useToast } from '@chakra-ui/react'
|
||||
import { FileIcon } from 'assets/icons'
|
||||
import { MoreButton } from 'components/dashboard/FolderContent/MoreButton'
|
||||
import { Typebot } from 'models'
|
||||
import React, { ChangeEvent, useState } from 'react'
|
||||
import React, { ChangeEvent } from 'react'
|
||||
import { readFile } from 'services/utils'
|
||||
|
||||
type Props = {
|
||||
onNewTypebot: (typebot: Typebot) => void
|
||||
} & MenuItemProps
|
||||
|
||||
export const ImportFromFileMenuItem = ({ onNewTypebot, ...props }: Props) => {
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
export const CreateTypebotMoreButton = ({ onNewTypebot }: Props) => {
|
||||
const toast = useToast({
|
||||
position: 'top-right',
|
||||
status: 'error',
|
||||
@ -17,7 +17,6 @@ export const ImportFromFileMenuItem = ({ onNewTypebot, ...props }: Props) => {
|
||||
|
||||
const handleInputChange = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||
if (!e.target?.files) return
|
||||
setIsLoading(true)
|
||||
const file = e.target.files[0]
|
||||
const fileContent = await readFile(file)
|
||||
try {
|
||||
@ -26,7 +25,6 @@ export const ImportFromFileMenuItem = ({ onNewTypebot, ...props }: Props) => {
|
||||
console.error(err)
|
||||
toast({ description: 'Failed to parse the file' })
|
||||
}
|
||||
setIsLoading(false)
|
||||
}
|
||||
|
||||
return (
|
||||
@ -38,14 +36,16 @@ export const ImportFromFileMenuItem = ({ onNewTypebot, ...props }: Props) => {
|
||||
onChange={handleInputChange}
|
||||
accept=".json"
|
||||
/>
|
||||
<MenuItem
|
||||
icon={<FileIcon />}
|
||||
id="file-input"
|
||||
isLoading={isLoading}
|
||||
{...props}
|
||||
>
|
||||
{props.children}
|
||||
</MenuItem>
|
||||
<MoreButton>
|
||||
<MenuItem
|
||||
as="label"
|
||||
cursor="pointer"
|
||||
icon={<FileIcon />}
|
||||
htmlFor="file-input"
|
||||
>
|
||||
Import from file
|
||||
</MenuItem>
|
||||
</MoreButton>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
@ -7,8 +7,7 @@ import {
|
||||
Stack,
|
||||
useToast,
|
||||
} from '@chakra-ui/react'
|
||||
import { MoreButton } from 'components/dashboard/FolderContent/MoreButton'
|
||||
import { ImportFromFileMenuItem } from 'components/templates/ImportFileMenuItem'
|
||||
import { CreateTypebotMoreButton } from 'components/templates/ImportFileMenuItem'
|
||||
import { TemplateButton } from 'components/templates/TemplateButton'
|
||||
import { useUser } from 'contexts/UserContext'
|
||||
import { Typebot } from 'models'
|
||||
@ -63,11 +62,7 @@ export const TemplatesContent = () => {
|
||||
>
|
||||
Start from scratch
|
||||
</Button>
|
||||
<MoreButton>
|
||||
<ImportFromFileMenuItem onNewTypebot={handleCreateSubmit}>
|
||||
Import from file
|
||||
</ImportFromFileMenuItem>
|
||||
</MoreButton>
|
||||
<CreateTypebotMoreButton onNewTypebot={handleCreateSubmit} />
|
||||
</Flex>
|
||||
<Divider />
|
||||
<Text>Or start from a template</Text>
|
||||
|
@ -1,5 +1,3 @@
|
||||
NEXT_PUBLIC_AUTH_MOCKING=enabled
|
||||
|
||||
PLAYWRIGHT_BUILDER_TEST_BASE_URL=http://localhost:3000
|
||||
|
||||
# SMTP Credentials (Generated on https://ethereal.email/)
|
||||
|
@ -15,10 +15,15 @@ import { encrypt } from 'utils'
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
export const teardownDatabase = async () => {
|
||||
await prisma.user.deleteMany()
|
||||
await prisma.credentials.deleteMany()
|
||||
await prisma.dashboardFolder.deleteMany()
|
||||
return prisma.typebot.deleteMany()
|
||||
const ownerFilter = {
|
||||
where: { ownerId: { in: ['freeUser', 'proUser'] } },
|
||||
}
|
||||
await prisma.user.deleteMany({
|
||||
where: { id: { in: ['freeUser', 'proUser'] } },
|
||||
})
|
||||
await prisma.credentials.deleteMany(ownerFilter)
|
||||
await prisma.dashboardFolder.deleteMany(ownerFilter)
|
||||
return prisma.typebot.deleteMany(ownerFilter)
|
||||
}
|
||||
|
||||
export const setupDatabase = async () => {
|
||||
|
Reference in New Issue
Block a user