import { TrashIcon } from '@/components/icons' import { Seo } from '@/components/Seo' import { isProPlan, LimitReached, LockTag, UpgradeButton, } from '@/features/billing' import { CustomDomainsDropdown } from '@/features/customDomains' import { TypebotHeader, useTypebot } from '@/features/editor' import { useWorkspace } from '@/features/workspace' import { useToast } from '@/hooks/useToast' import { isCloudProdInstance } from '@/utils/helpers' import { Flex, Heading, HStack, IconButton, Stack, Wrap, Text, } from '@chakra-ui/react' import { Plan } from 'db' import { isDefined, getViewerUrl, isNotDefined, env } from 'utils' import { isPublicDomainAvailableQuery } from '../queries/isPublicDomainAvailableQuery' import { parseDefaultPublicId } from '../utils' import { EditableUrl } from './EditableUrl' import { integrationsList } from './embeds/EmbedButton' export const SharePage = () => { const { workspace } = useWorkspace() const { typebot, updateTypebot, publishedTypebot } = useTypebot() const { showToast } = useToast() const handlePublicIdChange = async (publicId: string) => { updateTypebot({ publicId }) } const publicId = typebot ? typebot?.publicId ?? parseDefaultPublicId(typebot.name, typebot.id) : '' const isPublished = isDefined(publishedTypebot) 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) => updateTypebot({ customDomain }) const checkIfPathnameIsValid = (pathname: string) => { const isCorrectlyFormatted = /^([a-z0-9]+-[a-z0-9]+)*$/.test(pathname) || /^[a-z0-9]*$/.test(pathname) if (!isCorrectlyFormatted) { showToast({ description: 'Should contain only contain letters, numbers. Words can be separated by dashes.', }) return false } return true } const checkIfPublicIdIsValid = async (publicId: string) => { const isLongerThanAllowed = publicId.length >= 4 if (!isLongerThanAllowed && isCloudProdInstance) { showToast({ description: 'Should be longer than 4 characters', }) return false } if (!checkIfPathnameIsValid(publicId)) return false const { data } = await isPublicDomainAvailableQuery(publicId) if (!data?.isAvailable) { showToast({ description: 'ID is already taken' }) return false } return true } return ( Your typebot link {typebot && ( )} {typebot?.customDomain && ( } aria-label="Remove custom domain" size="xs" onClick={() => handleCustomDomainChange(null)} /> )} {isNotDefined(typebot?.customDomain) && env('VERCEL_VIEWER_PROJECT_NAME') ? ( <> {isProPlan(workspace) ? ( ) : ( Add my domain{' '} )} ) : null} Embed your typebot {integrationsList.map((IntegrationButton, idx) => ( ))} ) }