): Typebot => ({
diff --git a/apps/builder/services/publicTypebot.tsx b/apps/builder/services/publicTypebot.tsx
index e6931d46d..33e58e31b 100644
--- a/apps/builder/services/publicTypebot.tsx
+++ b/apps/builder/services/publicTypebot.tsx
@@ -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,
diff --git a/apps/viewer/layouts/TypebotPage.tsx b/apps/viewer/layouts/TypebotPage.tsx
index 9ecaca0a0..2deb0eafb 100644
--- a/apps/viewer/layouts/TypebotPage.tsx
+++ b/apps/viewer/layouts/TypebotPage.tsx
@@ -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 = ({
{showTypebot && (
diff --git a/apps/viewer/pages/[[...publicId]].tsx b/apps/viewer/pages/[[...publicId]].tsx
index 3ce15a1af..9c205f30f 100644
--- a/apps/viewer/pages/[[...publicId]].tsx
+++ b/apps/viewer/pages/[[...publicId]].tsx
@@ -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')
diff --git a/apps/viewer/playwright/services/database.ts b/apps/viewer/playwright/services/database.ts
index 5037c775a..cd79bbc7c 100644
--- a/apps/viewer/playwright/services/database.ts
+++ b/apps/viewer/playwright/services/database.ts
@@ -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,
})
diff --git a/packages/db/prisma/migrations/20220604084638_remove_public_typebot_duplicates/migration.sql b/packages/db/prisma/migrations/20220604084638_remove_public_typebot_duplicates/migration.sql
new file mode 100644
index 000000000..88297df0c
--- /dev/null
+++ b/packages/db/prisma/migrations/20220604084638_remove_public_typebot_duplicates/migration.sql
@@ -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";
diff --git a/packages/db/prisma/schema.prisma b/packages/db/prisma/schema.prisma
index b7400b957..ff0392d2f 100644
--- a/packages/db/prisma/schema.prisma
+++ b/packages/db/prisma/schema.prisma
@@ -215,14 +215,11 @@ model PublicTypebot {
updatedAt DateTime @default(now()) @updatedAt
typebotId String @unique
typebot Typebot @relation(fields: [typebotId], references: [id], onDelete: Cascade)
- name String
blocks Json[]
variables Json[]
edges Json[]
theme Json
settings Json
- publicId String? @unique
- customDomain String? @unique
}
model Result {