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