feat(dashboard): 💅 Show when the bot is published
This commit is contained in:
@@ -129,7 +129,7 @@ export const TypebotButton = ({
|
|||||||
color="white"
|
color="white"
|
||||||
>
|
>
|
||||||
{typebot.publishedTypebotId ? (
|
{typebot.publishedTypebotId ? (
|
||||||
<GlobeIcon fill="white" fontSize="20px" />
|
<GlobeIcon fontSize="20px" />
|
||||||
) : (
|
) : (
|
||||||
<ToolIcon fill="white" fontSize="20px" />
|
<ToolIcon fill="white" fontSize="20px" />
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import {
|
|||||||
parseDefaultPublicId,
|
parseDefaultPublicId,
|
||||||
updateTypebot,
|
updateTypebot,
|
||||||
} from 'services/typebots'
|
} from 'services/typebots'
|
||||||
import { fetcher, omit, preventUserFromRefreshing } from 'services/utils'
|
import { fetcher, preventUserFromRefreshing } from 'services/utils'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import { isDefined } from 'utils'
|
import { isDefined } from 'utils'
|
||||||
import { BlocksActions, blocksActions } from './actions/blocks'
|
import { BlocksActions, blocksActions } from './actions/blocks'
|
||||||
@@ -31,6 +31,7 @@ import { useRegisterActions } from 'kbar'
|
|||||||
import useUndo from 'services/utils/useUndo'
|
import useUndo from 'services/utils/useUndo'
|
||||||
import { useDebounce } from 'use-debounce'
|
import { useDebounce } from 'use-debounce'
|
||||||
import { itemsAction, ItemsActions } from './actions/items'
|
import { itemsAction, ItemsActions } from './actions/items'
|
||||||
|
import { generate } from 'short-uuid'
|
||||||
const autoSaveTimeout = 40000
|
const autoSaveTimeout = 40000
|
||||||
|
|
||||||
type UpdateTypebotPayload = Partial<{
|
type UpdateTypebotPayload = Partial<{
|
||||||
@@ -38,6 +39,7 @@ type UpdateTypebotPayload = Partial<{
|
|||||||
settings: Settings
|
settings: Settings
|
||||||
publicId: string
|
publicId: string
|
||||||
name: string
|
name: string
|
||||||
|
publishedTypebotId: string
|
||||||
}>
|
}>
|
||||||
|
|
||||||
export type SetTypebot = (typebot: Typebot | undefined) => void
|
export type SetTypebot = (typebot: Typebot | undefined) => void
|
||||||
@@ -213,13 +215,14 @@ export const TypebotContext = ({
|
|||||||
|
|
||||||
const publishTypebot = async () => {
|
const publishTypebot = async () => {
|
||||||
if (!localTypebot) return
|
if (!localTypebot) return
|
||||||
|
const publishedTypebotId = generate()
|
||||||
const newLocalTypebot = { ...localTypebot }
|
const newLocalTypebot = { ...localTypebot }
|
||||||
if (!localPublishedTypebot) {
|
if (!localPublishedTypebot) {
|
||||||
const newPublicId = parseDefaultPublicId(
|
const newPublicId = parseDefaultPublicId(
|
||||||
localTypebot.name,
|
localTypebot.name,
|
||||||
localTypebot.id
|
localTypebot.id
|
||||||
)
|
)
|
||||||
updateLocalTypebot({ publicId: newPublicId })
|
updateLocalTypebot({ publicId: newPublicId, publishedTypebotId })
|
||||||
newLocalTypebot.publicId = newPublicId
|
newLocalTypebot.publicId = newPublicId
|
||||||
}
|
}
|
||||||
if (hasUnsavedChanges || !localPublishedTypebot) await saveTypebot()
|
if (hasUnsavedChanges || !localPublishedTypebot) await saveTypebot()
|
||||||
@@ -230,9 +233,10 @@ export const TypebotContext = ({
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
setIsPublishing(true)
|
setIsPublishing(true)
|
||||||
const { data, error } = await createPublishedTypebot(
|
const { data, error } = await createPublishedTypebot({
|
||||||
omit(parseTypebotToPublicTypebot(newLocalTypebot), 'id')
|
...parseTypebotToPublicTypebot(newLocalTypebot),
|
||||||
)
|
id: publishedTypebotId,
|
||||||
|
})
|
||||||
setLocalPublishedTypebot(data)
|
setLocalPublishedTypebot(data)
|
||||||
setIsPublishing(false)
|
setIsPublishing(false)
|
||||||
if (error) return toast({ title: error.name, description: error.message })
|
if (error) return toast({ title: error.name, description: error.message })
|
||||||
|
|||||||
@@ -1,11 +1,4 @@
|
|||||||
import {
|
import { Block, PublicBlock, PublicStep, PublicTypebot, Typebot } from 'models'
|
||||||
Block,
|
|
||||||
InputStep,
|
|
||||||
PublicBlock,
|
|
||||||
PublicStep,
|
|
||||||
PublicTypebot,
|
|
||||||
Typebot,
|
|
||||||
} from 'models'
|
|
||||||
import shortId from 'short-uuid'
|
import shortId from 'short-uuid'
|
||||||
import { HStack, Text } from '@chakra-ui/react'
|
import { HStack, Text } from '@chakra-ui/react'
|
||||||
import { CalendarIcon } from 'assets/icons'
|
import { CalendarIcon } from 'assets/icons'
|
||||||
@@ -38,9 +31,7 @@ const parseBlocksToPublicBlocks = (blocks: Block[]): PublicBlock[] =>
|
|||||||
),
|
),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
export const createPublishedTypebot = async (
|
export const createPublishedTypebot = async (typebot: PublicTypebot) =>
|
||||||
typebot: Omit<PublicTypebot, 'id'>
|
|
||||||
) =>
|
|
||||||
sendRequest<PublicTypebot>({
|
sendRequest<PublicTypebot>({
|
||||||
url: `/api/publicTypebots`,
|
url: `/api/publicTypebots`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
Reference in New Issue
Block a user