import { Button, HStack, IconButton, Stack, Tooltip, Text, Menu, MenuButton, MenuList, MenuItem, useDisclosure, ButtonProps, } from '@chakra-ui/react' import { ChevronLeftIcon, CloudOffIcon, LockedIcon, UnlockedIcon, } from 'assets/icons' import { useTypebot } from 'contexts/TypebotContext/TypebotContext' import { useWorkspace } from 'contexts/WorkspaceContext' import { InputBlockType } from 'models' import { useRouter } from 'next/router' import { timeSince } from 'services/utils' import { isFreePlan } from 'services/workspace' import { isNotDefined } from 'utils' import { LimitReached, ChangePlanModal } from '../modals/ChangePlanModal' export const PublishButton = (props: ButtonProps) => { const { workspace } = useWorkspace() const { push, query } = useRouter() const { isOpen, onOpen, onClose } = useDisclosure() const { isPublishing, isPublished, publishTypebot, publishedTypebot, restorePublishedTypebot, typebot, isSavingLoading, updateTypebot, unpublishTypebot, save, } = useTypebot() const hasInputFile = typebot?.groups .flatMap((g) => g.blocks) .some((b) => b.type === InputBlockType.FILE) const handlePublishClick = () => { if (isFreePlan(workspace) && hasInputFile) return onOpen() publishTypebot() if (!publishedTypebot) push(`/typebots/${query.typebotId}/share`) } const closeTypebot = async () => { updateTypebot({ isClosed: true }) await save() } const openTypebot = async () => { updateTypebot({ isClosed: false }) await save() } return ( There are non published changes. Published version from{' '} {publishedTypebot && timeSince(publishedTypebot.updatedAt.toString())}{' '} ago } isDisabled={isNotDefined(publishedTypebot) || isPublished} > {publishedTypebot && ( } aria-label="Show published typebot menu" size="sm" isDisabled={isPublishing || isSavingLoading} /> {!isPublished && ( Restore published version )} {!typebot?.isClosed ? ( }> Close typebot to new responses ) : ( }> Reopen typebot to new responses )} }> Unpublish typebot )} ) }