Skip to content

Commit

Permalink
fix(dashboard): 🐛 Import from file button
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 14, 2022
1 parent 80c15f9 commit 5a060c7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
26 changes: 13 additions & 13 deletions apps/builder/components/templates/ImportFileMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
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',
})

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 {
Expand All @@ -26,7 +25,6 @@ export const ImportFromFileMenuItem = ({ onNewTypebot, ...props }: Props) => {
console.error(err)
toast({ description: 'Failed to parse the file' })
}
setIsLoading(false)
}

return (
Expand All @@ -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>
</>
)
}
9 changes: 2 additions & 7 deletions apps/builder/layouts/dashboard/TemplatesContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 0 additions & 2 deletions apps/builder/playwright/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
NEXT_PUBLIC_AUTH_MOCKING=enabled

PLAYWRIGHT_BUILDER_TEST_BASE_URL=http://localhost:3000

# SMTP Credentials (Generated on https://ethereal.email/)
Expand Down
13 changes: 9 additions & 4 deletions apps/builder/playwright/services/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

3 comments on commit 5a060c7

@vercel
Copy link

@vercel vercel bot commented on 5a060c7 Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

viewer-v2-typebot-io.vercel.app
typebot-viewer.vercel.app
viewer-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 5a060c7 Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

landing-page-v2 – ./apps/landing-page

landing-page-v2-git-main-typebot-io.vercel.app
landing-page-v2-jade.vercel.app
landing-page-v2-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 5a060c7 Feb 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
next.typebot.io
builder-v2-git-main-typebot-io.vercel.app

Please sign in to comment.