2
0

fix(viewer): 🐛 Make custom domain fetching more predictable

This commit is contained in:
Baptiste Arnaud
2022-05-02 07:24:24 -07:00
parent 28710dddc7
commit 8fdfda6482
2 changed files with 10 additions and 6 deletions

View File

@ -41,6 +41,14 @@ export const ShareContent = () => {
: ''
const isPublished = isDefined(typebot?.publishedTypebotId)
const handlePathnameChange = (pathname: string) => {
if (!typebot?.customDomain) return
const existingHost = typebot.customDomain?.split('/')[0]
const newDomain =
pathname === '' ? existingHost : existingHost + '/' + pathname
handleCustomDomainChange(newDomain)
}
const handleCustomDomainChange = (customDomain: string | null) =>
updateOnBothTypebots({ customDomain })
@ -65,11 +73,7 @@ export const ShareContent = () => {
<EditableUrl
hostname={'https://' + typebot.customDomain.split('/')[0]}
pathname={typebot.customDomain.split('/')[1]}
onPathnameChange={(pathname) =>
handleCustomDomainChange(
typebot.customDomain?.split('/')[0] + '/' + pathname
)
}
onPathnameChange={handlePathnameChange}
/>
<IconButton
icon={<TrashIcon />}

View File

@ -50,7 +50,7 @@ const getTypebotFromPublicId = async (publicId?: string) => {
const getTypebotFromCustomDomain = async (customDomain: string) => {
const typebot = await prisma.publicTypebot.findFirst({
where: { customDomain: { contains: customDomain } },
where: { customDomain },
})
if (isNotDefined(typebot)) return null
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')