2
0

(editor) Add unpublish and close typebot options

Introducing more menu items on the "Publised" button in the editor. You can now unpublish a typebot and close it to new
responses
This commit is contained in:
Baptiste Arnaud
2022-10-06 08:33:46 +02:00
parent 7ca97d4606
commit bfed599695
80 changed files with 1112 additions and 961 deletions

View File

@ -12,7 +12,12 @@ import {
useDisclosure,
ButtonProps,
} from '@chakra-ui/react'
import { ChevronLeftIcon } from 'assets/icons'
import {
ChevronLeftIcon,
CloudOffIcon,
LockedIcon,
UnlockedIcon,
} from 'assets/icons'
import { useTypebot } from 'contexts/TypebotContext/TypebotContext'
import { useWorkspace } from 'contexts/WorkspaceContext'
import { InputBlockType } from 'models'
@ -34,6 +39,9 @@ export const PublishButton = (props: ButtonProps) => {
restorePublishedTypebot,
typebot,
isSavingLoading,
updateTypebot,
unpublishTypebot,
save,
} = useTypebot()
const hasInputFile = typebot?.groups
@ -46,6 +54,16 @@ export const PublishButton = (props: ButtonProps) => {
if (!publishedTypebot) push(`/typebots/${query.typebotId}/share`)
}
const closeTypebot = async () => {
updateTypebot({ isClosed: true })
await save()
}
const openTypebot = async () => {
updateTypebot({ isClosed: false })
await save()
}
return (
<HStack spacing="1px">
<ChangePlanModal
@ -68,33 +86,52 @@ export const PublishButton = (props: ButtonProps) => {
</Text>
</Stack>
}
isDisabled={isNotDefined(publishedTypebot)}
isDisabled={isNotDefined(publishedTypebot) || isPublished}
>
<Button
colorScheme="blue"
isLoading={isPublishing || isSavingLoading}
isDisabled={isPublished}
onClick={handlePublishClick}
borderRightRadius={publishedTypebot && !isPublished ? 0 : undefined}
borderRightRadius={publishedTypebot ? 0 : undefined}
{...props}
>
{isPublished ? 'Published' : 'Publish'}
{isPublished
? typebot?.isClosed
? 'Closed'
: 'Published'
: 'Publish'}
</Button>
</Tooltip>
{publishedTypebot && !isPublished && (
{publishedTypebot && (
<Menu>
<MenuButton
as={IconButton}
colorScheme="blue"
colorScheme={'blue'}
borderLeftRadius={0}
icon={<ChevronLeftIcon transform="rotate(-90deg)" />}
aria-label="Show published version"
aria-label="Show published typebot menu"
size="sm"
isDisabled={isPublishing || isSavingLoading}
/>
<MenuList>
<MenuItem onClick={restorePublishedTypebot}>
Restore published version
{!isPublished && (
<MenuItem onClick={restorePublishedTypebot}>
Restore published version
</MenuItem>
)}
{!typebot?.isClosed ? (
<MenuItem onClick={closeTypebot} icon={<LockedIcon />}>
Close typebot to new responses
</MenuItem>
) : (
<MenuItem onClick={openTypebot} icon={<UnlockedIcon />}>
Reopen typebot to new responses
</MenuItem>
)}
<MenuItem onClick={unpublishTypebot} icon={<CloudOffIcon />}>
Unpublish typebot
</MenuItem>
</MenuList>
</Menu>