-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79aede1
commit 9a78a34
Showing
12 changed files
with
217 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
HStack, | ||
Tooltip, | ||
EditablePreview, | ||
EditableInput, | ||
Text, | ||
Editable, | ||
Button, | ||
ButtonProps, | ||
useEditableControls, | ||
} from '@chakra-ui/react' | ||
import { EditIcon } from 'assets/icons' | ||
import { CopyButton } from 'components/shared/buttons/CopyButton' | ||
import React from 'react' | ||
|
||
type EditableUrlProps = { | ||
publicId?: string | ||
onPublicIdChange: (publicId: string) => void | ||
} | ||
|
||
export const EditableUrl = ({ | ||
publicId, | ||
onPublicIdChange, | ||
}: EditableUrlProps) => { | ||
return ( | ||
<Editable | ||
as={HStack} | ||
spacing={3} | ||
defaultValue={publicId} | ||
onSubmit={onPublicIdChange} | ||
> | ||
<HStack spacing={1}> | ||
<Text>https://</Text> | ||
<Tooltip label="Edit"> | ||
<EditablePreview | ||
mx={1} | ||
bgColor="blue.500" | ||
color="white" | ||
px={3} | ||
rounded="md" | ||
cursor="pointer" | ||
display="flex" | ||
fontWeight="semibold" | ||
/> | ||
</Tooltip> | ||
|
||
<EditableInput px={2} /> | ||
|
||
<Text>.typebot.io/</Text> | ||
</HStack> | ||
|
||
<HStack> | ||
<EditButton size="xs" /> | ||
<CopyButton size="xs" textToCopy={`https://${publicId}.typebot.io/`} /> | ||
</HStack> | ||
</Editable> | ||
) | ||
} | ||
|
||
const EditButton = (props: ButtonProps) => { | ||
const { isEditing, getEditButtonProps } = useEditableControls() | ||
|
||
return isEditing ? ( | ||
<></> | ||
) : ( | ||
<Button leftIcon={<EditIcon />} {...props} {...getEditButtonProps()}> | ||
Edit | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Flex, Heading, Stack } from '@chakra-ui/react' | ||
import { useTypebot } from 'contexts/TypebotContext' | ||
import React from 'react' | ||
import { parseDefaultPublicId } from 'services/typebots' | ||
import { EditableUrl } from './EditableUrl' | ||
|
||
export const ShareContent = () => { | ||
const { typebot, updatePublicId } = useTypebot() | ||
|
||
const handlePublicIdChange = (publicId: string) => { | ||
if (publicId === typebot?.publicId) return | ||
updatePublicId(publicId) | ||
} | ||
return ( | ||
<Flex h="full" w="full" justifyContent="center" align="flex-start"> | ||
<Stack maxW="1000px" w="full" pt="10" spacing={6}> | ||
<Heading fontSize="2xl" as="h1"> | ||
Your typebot link | ||
</Heading> | ||
{typebot && ( | ||
<EditableUrl | ||
publicId={ | ||
typebot?.publicId ?? | ||
parseDefaultPublicId(typebot.name, typebot.id) | ||
} | ||
onPublicIdChange={handlePublicIdChange} | ||
/> | ||
)} | ||
<Heading fontSize="2xl" as="h1"> | ||
Embed your typebot | ||
</Heading> | ||
</Stack> | ||
</Flex> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react' | ||
import { ButtonProps, Button, useClipboard } from '@chakra-ui/react' | ||
|
||
interface CopyButtonProps extends ButtonProps { | ||
textToCopy: string | ||
onCopied?: () => void | ||
} | ||
|
||
export const CopyButton = (props: CopyButtonProps) => { | ||
const { textToCopy, onCopied, ...buttonProps } = props | ||
const { hasCopied, onCopy } = useClipboard(textToCopy) | ||
|
||
return ( | ||
<Button | ||
isDisabled={hasCopied} | ||
onClick={() => { | ||
onCopy() | ||
if (onCopied) onCopied() | ||
}} | ||
{...buttonProps} | ||
> | ||
{!hasCopied ? 'Copy' : 'Copied'} | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Flex } from '@chakra-ui/layout' | ||
import withAuth from 'components/HOC/withUser' | ||
import { Seo } from 'components/Seo' | ||
import { ShareContent } from 'components/share/ShareContent' | ||
import { TypebotHeader } from 'components/shared/TypebotHeader' | ||
import { TypebotContext } from 'contexts/TypebotContext' | ||
import { useRouter } from 'next/router' | ||
import React from 'react' | ||
|
||
const SharePage = () => { | ||
const { query } = useRouter() | ||
return ( | ||
<TypebotContext typebotId={query.id?.toString()}> | ||
<Seo title="Share" /> | ||
<Flex overflow="hidden" h="100vh" flexDir="column"> | ||
<TypebotHeader /> | ||
<ShareContent /> | ||
</Flex> | ||
</TypebotContext> | ||
) | ||
} | ||
|
||
export default withAuth(SharePage) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/db/prisma/migrations/20211223141944_add_public_id/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[publicId]` on the table `PublicTypebot` will be added. If there are existing duplicate values, this will fail. | ||
- A unique constraint covering the columns `[publicId]` on the table `Typebot` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "PublicTypebot" ADD COLUMN "publicId" TEXT; | ||
|
||
-- AlterTable | ||
ALTER TABLE "Typebot" ADD COLUMN "publicId" TEXT; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "PublicTypebot_publicId_key" ON "PublicTypebot"("publicId"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Typebot_publicId_key" ON "Typebot"("publicId"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9a78a34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: