2
0

refactor: ♻️ Rename step to block

This commit is contained in:
Baptiste Arnaud
2022-06-11 07:27:38 +02:00
parent 8751766d0e
commit 2df8338505
297 changed files with 4292 additions and 3989 deletions

View File

@ -12,7 +12,7 @@ import { getAuthenticatedUser } from 'services/api/utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
if (!user) return notAuthenticated(res)
const { redirectUrl, stepId, workspaceId } = JSON.parse(
const { redirectUrl, blockId, workspaceId } = JSON.parse(
Buffer.from(req.query.state.toString(), 'base64').toString()
)
if (req.method === 'GET') {
@ -49,7 +49,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const { id: credentialsId } = await prisma.credentials.create({
data: credentials,
})
const queryParams = stringify({ stepId, credentialsId })
const queryParams = stringify({ blockId, credentialsId })
res.redirect(
`${redirectUrl}?${queryParams}` ?? `${process.env.NEXTAUTH_URL}`
)

View File

@ -38,7 +38,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
],
},
orderBy: { createdAt: 'desc' },
select: { name: true, id: true, blocks: true },
select: { name: true, id: true, groups: true },
})
return res.send({ typebots })
}
@ -78,7 +78,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
const typebot = await prisma.typebot.create({
data:
'blocks' in data
'groups' in data
? data
: (parseNewTypebot({
ownerAvatarUrl: user.image,

View File

@ -14,7 +14,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
where: canReadTypebot(typebotId, user),
})
if (!typebot) return notFound(res)
return res.send({ blocks: typebot.blocks })
return res.send({ groups: typebot.groups })
}
methodNotAllowed(res)
}

View File

@ -16,14 +16,14 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
include: { publishedTypebot: true },
})
if (!typebot) return res.status(404).send({ answersCounts: [] })
const answersCounts: { blockId: string; totalAnswers: number }[] =
const answersCounts: { groupId: string; totalAnswers: number }[] =
await Promise.all(
(typebot.publishedTypebot as unknown as PublicTypebot).blocks.map(
(typebot.publishedTypebot as unknown as PublicTypebot).groups.map(
async (block) => {
const totalAnswers = await prisma.answer.count({
where: { blockId: block.id },
where: { groupId: block.id },
})
return { blockId: block.id, totalAnswers }
return { groupId: block.id, totalAnswers }
}
)
)

View File

@ -10,7 +10,7 @@ import React from 'react'
import { KBar } from 'components/shared/KBar'
import { BoardMenuButton } from 'components/editor/BoardMenuButton'
import { PreviewDrawer } from 'components/editor/preview/PreviewDrawer'
import { StepsSideBar } from 'components/editor/StepsSideBar'
import { BlocksSideBar } from 'components/editor/BlocksSideBar'
import { Graph } from 'components/shared/Graph'
import { GraphProvider } from 'contexts/GraphContext'
import { GraphDndContext } from 'contexts/GraphDndContext'
@ -37,9 +37,9 @@ const TypebotEditPage = () => {
backgroundPosition="-19px -19px"
>
<GraphDndContext>
<StepsSideBar />
<BlocksSideBar />
<GraphProvider
blocks={typebot?.blocks ?? []}
groups={typebot?.groups ?? []}
isReadOnly={isReadOnly}
>
{typebot && <Graph flex="1" typebot={typebot} />}