🐛 Fix new typebot creation host bubble parsing
This commit is contained in:
@@ -7,6 +7,20 @@ import {
|
|||||||
Typebot,
|
Typebot,
|
||||||
} from 'models'
|
} from 'models'
|
||||||
|
|
||||||
|
export type NewTypebotProps = Omit<
|
||||||
|
Typebot,
|
||||||
|
| 'createdAt'
|
||||||
|
| 'updatedAt'
|
||||||
|
| 'id'
|
||||||
|
| 'publishedTypebotId'
|
||||||
|
| 'publicId'
|
||||||
|
| 'customDomain'
|
||||||
|
| 'icon'
|
||||||
|
| 'isArchived'
|
||||||
|
| 'isClosed'
|
||||||
|
| 'resultsTablePreferences'
|
||||||
|
>
|
||||||
|
|
||||||
export const parseNewTypebot = ({
|
export const parseNewTypebot = ({
|
||||||
folderId,
|
folderId,
|
||||||
name,
|
name,
|
||||||
@@ -19,19 +33,7 @@ export const parseNewTypebot = ({
|
|||||||
name: string
|
name: string
|
||||||
ownerAvatarUrl?: string
|
ownerAvatarUrl?: string
|
||||||
isBrandingEnabled?: boolean
|
isBrandingEnabled?: boolean
|
||||||
}): Omit<
|
}): NewTypebotProps => {
|
||||||
Typebot,
|
|
||||||
| 'createdAt'
|
|
||||||
| 'updatedAt'
|
|
||||||
| 'id'
|
|
||||||
| 'publishedTypebotId'
|
|
||||||
| 'publicId'
|
|
||||||
| 'customDomain'
|
|
||||||
| 'icon'
|
|
||||||
| 'isArchived'
|
|
||||||
| 'isClosed'
|
|
||||||
| 'resultsTablePreferences'
|
|
||||||
> => {
|
|
||||||
const startGroupId = cuid()
|
const startGroupId = cuid()
|
||||||
const startBlockId = cuid()
|
const startBlockId = cuid()
|
||||||
const startBlock: StartBlock = {
|
const startBlock: StartBlock = {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
} from 'utils/api'
|
} from 'utils/api'
|
||||||
import { getAuthenticatedUser } from '@/features/auth/api'
|
import { getAuthenticatedUser } from '@/features/auth/api'
|
||||||
import { parseNewTypebot } from '@/features/dashboard'
|
import { parseNewTypebot } from '@/features/dashboard'
|
||||||
|
import { NewTypebotProps } from '@/features/dashboard/api/parseNewTypebot'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const user = await getAuthenticatedUser(req)
|
const user = await getAuthenticatedUser(req)
|
||||||
@@ -86,14 +87,15 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
select: { plan: true },
|
select: { plan: true },
|
||||||
})
|
})
|
||||||
if (!workspace) return notFound(res, "Couldn't find workspace")
|
if (!workspace) return notFound(res, "Couldn't find workspace")
|
||||||
const data =
|
const data = (
|
||||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||||
|
) as NewTypebotProps | Omit<NewTypebotProps, 'groups'>
|
||||||
const typebot = await prisma.typebot.create({
|
const typebot = await prisma.typebot.create({
|
||||||
data:
|
data:
|
||||||
'groups' in data
|
'groups' in data
|
||||||
? data
|
? data
|
||||||
: parseNewTypebot({
|
: parseNewTypebot({
|
||||||
ownerAvatarUrl: user.image,
|
ownerAvatarUrl: user.image ?? undefined,
|
||||||
isBrandingEnabled: workspace.plan === Plan.FREE,
|
isBrandingEnabled: workspace.plan === Plan.FREE,
|
||||||
...data,
|
...data,
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user