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