2
0
Files
bot/apps/builder/components/share/ShareContent.tsx

117 lines
3.7 KiB
TypeScript
Raw Normal View History

2022-02-18 14:57:10 +01:00
import {
Flex,
Heading,
HStack,
IconButton,
Stack,
Tag,
Wrap,
Text,
} from '@chakra-ui/react'
import { TrashIcon } from 'assets/icons'
import { UpgradeButton } from 'components/shared/buttons/UpgradeButton'
2022-06-02 07:54:48 +02:00
import { useToast } from 'components/shared/hooks/useToast'
2022-01-06 09:40:56 +01:00
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
2022-05-13 15:22:44 -07:00
import { useWorkspace } from 'contexts/WorkspaceContext'
2021-12-23 15:20:21 +01:00
import React from 'react'
import { parseDefaultPublicId } from 'services/typebots'
2022-05-13 15:22:44 -07:00
import { isFreePlan } from 'services/workspace'
2022-08-08 08:21:36 +02:00
import { getViewerUrl, isDefined, isNotDefined } from 'utils'
2022-02-18 14:57:10 +01:00
import { CustomDomainsDropdown } from './customDomain/CustomDomainsDropdown'
2021-12-23 15:20:21 +01:00
import { EditableUrl } from './EditableUrl'
import { integrationsList } from './integrations/EmbedButton'
2021-12-23 15:20:21 +01:00
export const ShareContent = () => {
2022-05-13 15:22:44 -07:00
const { workspace } = useWorkspace()
const { typebot, updateTypebot } = useTypebot()
2022-06-02 07:54:48 +02:00
const { showToast } = useToast()
2021-12-23 15:20:21 +01:00
const handlePublicIdChange = (publicId: string) => {
if (publicId === typebot?.publicId) return
2022-02-18 14:57:10 +01:00
if (publicId.length < 4)
2022-06-02 07:54:48 +02:00
return showToast({ description: 'ID must be longer than 4 characters' })
updateTypebot({ publicId })
2021-12-23 15:20:21 +01:00
}
const publicId = typebot
? typebot?.publicId ?? parseDefaultPublicId(typebot.name, typebot.id)
: ''
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 | undefined) =>
updateTypebot({ customDomain })
2022-02-18 14:57:10 +01:00
2021-12-23 15:20:21 +01:00
return (
<Flex h="full" w="full" justifyContent="center" align="flex-start">
<Stack maxW="1000px" w="full" pt="10" spacing={10}>
2022-02-18 14:57:10 +01:00
<Stack spacing={4} align="flex-start">
<Heading fontSize="2xl" as="h1">
Your typebot link
</Heading>
{typebot && (
<EditableUrl
2022-08-08 08:21:36 +02:00
hostname={
getViewerUrl({ isBuilder: true }) ?? 'https://typebot.io'
}
2022-02-18 14:57:10 +01:00
pathname={publicId}
onPathnameChange={handlePublicIdChange}
/>
)}
2022-02-18 14:57:10 +01:00
{typebot?.customDomain && (
<HStack>
<EditableUrl
hostname={'https://' + typebot.customDomain.split('/')[0]}
pathname={typebot.customDomain.split('/')[1]}
onPathnameChange={handlePathnameChange}
2022-02-18 14:57:10 +01:00
/>
<IconButton
icon={<TrashIcon />}
aria-label="Remove custom domain"
size="xs"
onClick={() => handleCustomDomainChange(undefined)}
2022-02-18 14:57:10 +01:00
/>
</HStack>
)}
2022-05-13 15:22:44 -07:00
{isFreePlan(workspace) ? (
2022-02-18 14:57:10 +01:00
<UpgradeButton colorScheme="gray">
<Text mr="2">Add my domain</Text>{' '}
<Tag colorScheme="orange">Pro</Tag>
</UpgradeButton>
) : (
<>
{isNotDefined(typebot?.customDomain) && (
<CustomDomainsDropdown
onCustomDomainSelect={handleCustomDomainChange}
/>
)}
</>
)}
</Stack>
<Stack spacing={4}>
<Heading fontSize="2xl" as="h1">
Embed your typebot
</Heading>
<Wrap spacing={7}>
{integrationsList.map((IntegrationButton, idx) => (
<IntegrationButton
key={idx}
publicId={publicId}
isPublished={isPublished}
/>
))}
</Wrap>
</Stack>
2021-12-23 15:20:21 +01:00
</Stack>
</Flex>
)
}