fix(viewer): 🐛 Make custom domain fetching more predictable
This commit is contained in:
@ -41,6 +41,14 @@ export const ShareContent = () => {
|
|||||||
: ''
|
: ''
|
||||||
const isPublished = isDefined(typebot?.publishedTypebotId)
|
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) =>
|
const handleCustomDomainChange = (customDomain: string | null) =>
|
||||||
updateOnBothTypebots({ customDomain })
|
updateOnBothTypebots({ customDomain })
|
||||||
|
|
||||||
@ -65,11 +73,7 @@ export const ShareContent = () => {
|
|||||||
<EditableUrl
|
<EditableUrl
|
||||||
hostname={'https://' + typebot.customDomain.split('/')[0]}
|
hostname={'https://' + typebot.customDomain.split('/')[0]}
|
||||||
pathname={typebot.customDomain.split('/')[1]}
|
pathname={typebot.customDomain.split('/')[1]}
|
||||||
onPathnameChange={(pathname) =>
|
onPathnameChange={handlePathnameChange}
|
||||||
handleCustomDomainChange(
|
|
||||||
typebot.customDomain?.split('/')[0] + '/' + pathname
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={<TrashIcon />}
|
icon={<TrashIcon />}
|
||||||
|
@ -50,7 +50,7 @@ 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: { contains: customDomain } },
|
where: { customDomain },
|
||||||
})
|
})
|
||||||
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')
|
||||||
|
Reference in New Issue
Block a user