feat(db): 🗃️ Remove duplicate fields in PublicTypebot
This commit is contained in:
@ -5,6 +5,7 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
HStack,
|
HStack,
|
||||||
Text,
|
Text,
|
||||||
|
Spinner,
|
||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
import React, { ChangeEvent, FormEvent, useEffect } from 'react'
|
import React, { ChangeEvent, FormEvent, useEffect } from 'react'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
@ -70,6 +71,7 @@ export const SignInForm = ({
|
|||||||
})
|
})
|
||||||
setAuthLoading(false)
|
setAuthLoading(false)
|
||||||
}
|
}
|
||||||
|
if (isLoadingProviders) return <Spinner />
|
||||||
if (hasNoAuthProvider)
|
if (hasNoAuthProvider)
|
||||||
return (
|
return (
|
||||||
<Text>
|
<Text>
|
||||||
|
@ -23,14 +23,14 @@ import { integrationsList } from './integrations/EmbedButton'
|
|||||||
|
|
||||||
export const ShareContent = () => {
|
export const ShareContent = () => {
|
||||||
const { workspace } = useWorkspace()
|
const { workspace } = useWorkspace()
|
||||||
const { typebot, updateOnBothTypebots } = useTypebot()
|
const { typebot, updateTypebot } = useTypebot()
|
||||||
const { showToast } = useToast()
|
const { showToast } = useToast()
|
||||||
|
|
||||||
const handlePublicIdChange = (publicId: string) => {
|
const handlePublicIdChange = (publicId: string) => {
|
||||||
if (publicId === typebot?.publicId) return
|
if (publicId === typebot?.publicId) return
|
||||||
if (publicId.length < 4)
|
if (publicId.length < 4)
|
||||||
return showToast({ description: 'ID must be longer than 4 characters' })
|
return showToast({ description: 'ID must be longer than 4 characters' })
|
||||||
updateOnBothTypebots({ publicId })
|
updateTypebot({ publicId })
|
||||||
}
|
}
|
||||||
|
|
||||||
const publicId = typebot
|
const publicId = typebot
|
||||||
@ -46,8 +46,8 @@ export const ShareContent = () => {
|
|||||||
handleCustomDomainChange(newDomain)
|
handleCustomDomainChange(newDomain)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCustomDomainChange = (customDomain: string | null) =>
|
const handleCustomDomainChange = (customDomain: string | undefined) =>
|
||||||
updateOnBothTypebots({ customDomain })
|
updateTypebot({ customDomain })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex h="full" w="full" justifyContent="center" align="flex-start">
|
<Flex h="full" w="full" justifyContent="center" align="flex-start">
|
||||||
@ -76,7 +76,7 @@ export const ShareContent = () => {
|
|||||||
icon={<TrashIcon />}
|
icon={<TrashIcon />}
|
||||||
aria-label="Remove custom domain"
|
aria-label="Remove custom domain"
|
||||||
size="xs"
|
size="xs"
|
||||||
onClick={() => handleCustomDomainChange(null)}
|
onClick={() => handleCustomDomainChange(undefined)}
|
||||||
/>
|
/>
|
||||||
</HStack>
|
</HStack>
|
||||||
)}
|
)}
|
||||||
|
@ -25,7 +25,6 @@ export const TypebotHeader = () => {
|
|||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const {
|
const {
|
||||||
typebot,
|
typebot,
|
||||||
updateOnBothTypebots,
|
|
||||||
updateTypebot,
|
updateTypebot,
|
||||||
save,
|
save,
|
||||||
undo,
|
undo,
|
||||||
@ -36,7 +35,7 @@ export const TypebotHeader = () => {
|
|||||||
} = useTypebot()
|
} = useTypebot()
|
||||||
const { setRightPanel, rightPanel, setStartPreviewAtBlock } = useEditor()
|
const { setRightPanel, rightPanel, setStartPreviewAtBlock } = useEditor()
|
||||||
|
|
||||||
const handleNameSubmit = (name: string) => updateOnBothTypebots({ name })
|
const handleNameSubmit = (name: string) => updateTypebot({ name })
|
||||||
|
|
||||||
const handleChangeIcon = (icon: string) => updateTypebot({ icon })
|
const handleChangeIcon = (icon: string) => updateTypebot({ icon })
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ type UpdateTypebotPayload = Partial<{
|
|||||||
name: string
|
name: string
|
||||||
publishedTypebotId: string
|
publishedTypebotId: string
|
||||||
icon: string
|
icon: string
|
||||||
|
customDomain: string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
export type SetTypebot = (
|
export type SetTypebot = (
|
||||||
@ -77,11 +78,6 @@ const typebotContext = createContext<
|
|||||||
webhook: Partial<Webhook>
|
webhook: Partial<Webhook>
|
||||||
) => Promise<void>
|
) => Promise<void>
|
||||||
updateTypebot: (updates: UpdateTypebotPayload) => void
|
updateTypebot: (updates: UpdateTypebotPayload) => void
|
||||||
updateOnBothTypebots: (updates: {
|
|
||||||
publicId?: string
|
|
||||||
name?: string
|
|
||||||
customDomain?: string | null
|
|
||||||
}) => void
|
|
||||||
publishTypebot: () => void
|
publishTypebot: () => void
|
||||||
restorePublishedTypebot: () => void
|
restorePublishedTypebot: () => void
|
||||||
} & BlocksActions &
|
} & BlocksActions &
|
||||||
@ -322,20 +318,6 @@ export const TypebotContext = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateOnBothTypebots = async (updates: {
|
|
||||||
publicId?: string
|
|
||||||
name?: string
|
|
||||||
customDomain?: string | null
|
|
||||||
}) => {
|
|
||||||
updateLocalTypebot(updates)
|
|
||||||
await saveTypebot()
|
|
||||||
if (!publishedTypebot) return
|
|
||||||
await savePublishedTypebot({
|
|
||||||
...publishedTypebot,
|
|
||||||
...updates,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const restorePublishedTypebot = () => {
|
const restorePublishedTypebot = () => {
|
||||||
if (!publishedTypebot || !localTypebot) return
|
if (!publishedTypebot || !localTypebot) return
|
||||||
setLocalTypebot(parsePublicTypebotToTypebot(publishedTypebot, localTypebot))
|
setLocalTypebot(parsePublicTypebotToTypebot(publishedTypebot, localTypebot))
|
||||||
@ -377,7 +359,6 @@ export const TypebotContext = ({
|
|||||||
isPublished,
|
isPublished,
|
||||||
updateTypebot: updateLocalTypebot,
|
updateTypebot: updateLocalTypebot,
|
||||||
restorePublishedTypebot,
|
restorePublishedTypebot,
|
||||||
updateOnBothTypebots,
|
|
||||||
updateWebhook,
|
updateWebhook,
|
||||||
...blocksActions(setLocalTypebot as SetTypebot),
|
...blocksActions(setLocalTypebot as SetTypebot),
|
||||||
...stepsAction(setLocalTypebot as SetTypebot),
|
...stepsAction(setLocalTypebot as SetTypebot),
|
||||||
|
@ -260,15 +260,12 @@ const parseTypebotToPublicTypebot = (
|
|||||||
typebot: Typebot
|
typebot: Typebot
|
||||||
): Omit<PublicTypebot, 'createdAt' | 'updatedAt'> => ({
|
): Omit<PublicTypebot, 'createdAt' | 'updatedAt'> => ({
|
||||||
id,
|
id,
|
||||||
name: typebot.name,
|
|
||||||
blocks: typebot.blocks,
|
blocks: typebot.blocks,
|
||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
theme: typebot.theme,
|
theme: typebot.theme,
|
||||||
settings: typebot.settings,
|
settings: typebot.settings,
|
||||||
publicId: typebot.publicId,
|
|
||||||
variables: typebot.variables,
|
variables: typebot.variables,
|
||||||
edges: typebot.edges,
|
edges: typebot.edges,
|
||||||
customDomain: null,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({
|
const parseTestTypebot = (partialTypebot: Partial<Typebot>): Typebot => ({
|
||||||
|
@ -9,12 +9,9 @@ export const parseTypebotToPublicTypebot = (
|
|||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
blocks: typebot.blocks,
|
blocks: typebot.blocks,
|
||||||
edges: typebot.edges,
|
edges: typebot.edges,
|
||||||
name: typebot.name,
|
|
||||||
publicId: typebot.publicId,
|
|
||||||
settings: typebot.settings,
|
settings: typebot.settings,
|
||||||
theme: typebot.theme,
|
theme: typebot.theme,
|
||||||
variables: typebot.variables,
|
variables: typebot.variables,
|
||||||
customDomain: typebot.customDomain,
|
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
})
|
})
|
||||||
@ -26,12 +23,12 @@ export const parsePublicTypebotToTypebot = (
|
|||||||
id: typebot.typebotId,
|
id: typebot.typebotId,
|
||||||
blocks: typebot.blocks,
|
blocks: typebot.blocks,
|
||||||
edges: typebot.edges,
|
edges: typebot.edges,
|
||||||
name: typebot.name,
|
name: existingTypebot.name,
|
||||||
publicId: typebot.publicId,
|
publicId: existingTypebot.publicId,
|
||||||
settings: typebot.settings,
|
settings: typebot.settings,
|
||||||
theme: typebot.theme,
|
theme: typebot.theme,
|
||||||
variables: typebot.variables,
|
variables: typebot.variables,
|
||||||
customDomain: typebot.customDomain,
|
customDomain: existingTypebot.customDomain,
|
||||||
createdAt: existingTypebot.createdAt,
|
createdAt: existingTypebot.createdAt,
|
||||||
updatedAt: existingTypebot.updatedAt,
|
updatedAt: existingTypebot.updatedAt,
|
||||||
publishedTypebotId: typebot.id,
|
publishedTypebotId: typebot.id,
|
||||||
|
@ -9,7 +9,7 @@ import { createResult, updateResult } from '../services/result'
|
|||||||
import { ErrorPage } from './ErrorPage'
|
import { ErrorPage } from './ErrorPage'
|
||||||
|
|
||||||
export type TypebotPageProps = {
|
export type TypebotPageProps = {
|
||||||
typebot?: PublicTypebot
|
typebot?: PublicTypebot & { typebot: { name: string } }
|
||||||
url: string
|
url: string
|
||||||
isIE: boolean
|
isIE: boolean
|
||||||
customHeadCode: string | null
|
customHeadCode: string | null
|
||||||
@ -97,7 +97,7 @@ export const TypebotPage = ({
|
|||||||
<div style={{ height: '100vh' }}>
|
<div style={{ height: '100vh' }}>
|
||||||
<SEO
|
<SEO
|
||||||
url={url}
|
url={url}
|
||||||
typebotName={typebot.name}
|
typebotName={typebot.typebot.name}
|
||||||
metadata={typebot.settings.metadata}
|
metadata={typebot.settings.metadata}
|
||||||
/>
|
/>
|
||||||
{showTypebot && (
|
{showTypebot && (
|
||||||
|
@ -62,8 +62,9 @@ export const getServerSideProps: GetServerSideProps = async (
|
|||||||
|
|
||||||
const getTypebotFromPublicId = async (publicId?: string) => {
|
const getTypebotFromPublicId = async (publicId?: string) => {
|
||||||
if (!publicId) return null
|
if (!publicId) return null
|
||||||
const typebot = await prisma.publicTypebot.findUnique({
|
const typebot = await prisma.publicTypebot.findFirst({
|
||||||
where: { publicId },
|
where: { typebot: { publicId } },
|
||||||
|
include: { typebot: { select: { name: true } } },
|
||||||
})
|
})
|
||||||
if (isNotDefined(typebot)) return null
|
if (isNotDefined(typebot)) return null
|
||||||
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')
|
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')
|
||||||
@ -71,7 +72,8 @@ const getTypebotFromPublicId = async (publicId?: string) => {
|
|||||||
|
|
||||||
const getTypebotFromCustomDomain = async (customDomain: string) => {
|
const getTypebotFromCustomDomain = async (customDomain: string) => {
|
||||||
const typebot = await prisma.publicTypebot.findFirst({
|
const typebot = await prisma.publicTypebot.findFirst({
|
||||||
where: { customDomain },
|
where: { typebot: { customDomain } },
|
||||||
|
include: { typebot: { select: { name: true } } },
|
||||||
})
|
})
|
||||||
if (isNotDefined(typebot)) return null
|
if (isNotDefined(typebot)) return null
|
||||||
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')
|
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')
|
||||||
|
@ -92,15 +92,12 @@ const parseTypebotToPublicTypebot = (
|
|||||||
typebot: Typebot
|
typebot: Typebot
|
||||||
): PublicTypebot => ({
|
): PublicTypebot => ({
|
||||||
id,
|
id,
|
||||||
name: typebot.name,
|
|
||||||
blocks: typebot.blocks,
|
blocks: typebot.blocks,
|
||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
theme: typebot.theme,
|
theme: typebot.theme,
|
||||||
settings: typebot.settings,
|
settings: typebot.settings,
|
||||||
publicId: typebot.publicId,
|
|
||||||
variables: typebot.variables,
|
variables: typebot.variables,
|
||||||
edges: typebot.edges,
|
edges: typebot.edges,
|
||||||
customDomain: null,
|
|
||||||
createdAt: typebot.createdAt,
|
createdAt: typebot.createdAt,
|
||||||
updatedAt: typebot.updatedAt,
|
updatedAt: typebot.updatedAt,
|
||||||
})
|
})
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
-- DropIndex
|
||||||
|
DROP INDEX "PublicTypebot_customDomain_key";
|
||||||
|
|
||||||
|
-- DropIndex
|
||||||
|
DROP INDEX "PublicTypebot_publicId_key";
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "PublicTypebot" DROP COLUMN "customDomain",
|
||||||
|
DROP COLUMN "name",
|
||||||
|
DROP COLUMN "publicId";
|
@ -215,14 +215,11 @@ model PublicTypebot {
|
|||||||
updatedAt DateTime @default(now()) @updatedAt
|
updatedAt DateTime @default(now()) @updatedAt
|
||||||
typebotId String @unique
|
typebotId String @unique
|
||||||
typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
|
||||||
name String
|
|
||||||
blocks Json[]
|
blocks Json[]
|
||||||
variables Json[]
|
variables Json[]
|
||||||
edges Json[]
|
edges Json[]
|
||||||
theme Json
|
theme Json
|
||||||
settings Json
|
settings Json
|
||||||
publicId String? @unique
|
|
||||||
customDomain String? @unique
|
|
||||||
}
|
}
|
||||||
|
|
||||||
model Result {
|
model Result {
|
||||||
|
Reference in New Issue
Block a user