Add Graph draft
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import { StartBlock, StepType } from 'bot-engine'
|
||||
import { Typebot, User } from 'db'
|
||||
import prisma from 'libs/prisma'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
@ -23,8 +24,21 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
}
|
||||
if (req.method === 'POST') {
|
||||
const data = JSON.parse(req.body) as Typebot
|
||||
const startBlock: StartBlock = {
|
||||
id: 'start-block',
|
||||
title: 'Start',
|
||||
graphCoordinates: { x: 0, y: 0 },
|
||||
steps: [
|
||||
{
|
||||
id: 'start-step',
|
||||
blockId: 'start-block',
|
||||
label: 'Form starts here',
|
||||
type: StepType.START,
|
||||
},
|
||||
],
|
||||
}
|
||||
const typebot = await prisma.typebot.create({
|
||||
data: { ...data, ownerId: user.id },
|
||||
data: { ...data, ownerId: user.id, startBlock },
|
||||
})
|
||||
return res.send(typebot)
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Typebot } from '.prisma/client'
|
||||
import prisma from 'libs/prisma'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getSession } from 'next-auth/react'
|
||||
@ -11,6 +10,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.status(401).json({ message: 'Not authenticated' })
|
||||
|
||||
const id = req.query.id.toString()
|
||||
if (req.method === 'GET') {
|
||||
const typebot = await prisma.typebot.findUnique({
|
||||
where: { id },
|
||||
})
|
||||
return res.send({ typebot })
|
||||
}
|
||||
if (req.method === 'DELETE') {
|
||||
const typebots = await prisma.typebot.delete({
|
||||
where: { id },
|
||||
@ -18,7 +23,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.send({ typebots })
|
||||
}
|
||||
if (req.method === 'PATCH') {
|
||||
const data = JSON.parse(req.body) as Partial<Typebot>
|
||||
const data = JSON.parse(req.body)
|
||||
const typebots = await prisma.typebot.update({
|
||||
where: { id },
|
||||
data,
|
||||
|
@ -1,19 +1,24 @@
|
||||
import { Flex } from '@chakra-ui/layout'
|
||||
import { Board } from 'components/board/Board'
|
||||
import withAuth from 'components/HOC/withUser'
|
||||
import { Seo } from 'components/Seo'
|
||||
import { GraphProvider } from 'contexts/BoardContext'
|
||||
import { GraphProvider } from 'contexts/GraphContext'
|
||||
import { TypebotContext } from 'contexts/TypebotContext'
|
||||
import { useRouter } from 'next/router'
|
||||
import React from 'react'
|
||||
|
||||
const TypebotEditPage = () => {
|
||||
const { query } = useRouter()
|
||||
return (
|
||||
<>
|
||||
<TypebotContext typebotId={query.id?.toString()}>
|
||||
<Seo title="Editor" />
|
||||
<Flex overflow="hidden" h="100vh">
|
||||
<GraphProvider>
|
||||
<></>
|
||||
<Board />
|
||||
</GraphProvider>
|
||||
</Flex>
|
||||
</>
|
||||
</TypebotContext>
|
||||
)
|
||||
}
|
||||
|
||||
export default TypebotEditPage
|
||||
export default withAuth(TypebotEditPage)
|
||||
|
Reference in New Issue
Block a user