Skip to content

Commit

Permalink
feat(dashboard): 💅 Show when the bot is published
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 15, 2022
1 parent 2eee226 commit 8583e2a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const TypebotButton = ({
color="white"
>
{typebot.publishedTypebotId ? (
<GlobeIcon fill="white" fontSize="20px" />
<GlobeIcon fontSize="20px" />
) : (
<ToolIcon fill="white" fontSize="20px" />
)}
Expand Down
14 changes: 9 additions & 5 deletions apps/builder/contexts/TypebotContext/TypebotContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
parseDefaultPublicId,
updateTypebot,
} from 'services/typebots'
import { fetcher, omit, preventUserFromRefreshing } from 'services/utils'
import { fetcher, preventUserFromRefreshing } from 'services/utils'
import useSWR from 'swr'
import { isDefined } from 'utils'
import { BlocksActions, blocksActions } from './actions/blocks'
Expand All @@ -31,13 +31,15 @@ import { useRegisterActions } from 'kbar'
import useUndo from 'services/utils/useUndo'
import { useDebounce } from 'use-debounce'
import { itemsAction, ItemsActions } from './actions/items'
import { generate } from 'short-uuid'
const autoSaveTimeout = 40000

type UpdateTypebotPayload = Partial<{
theme: Theme
settings: Settings
publicId: string
name: string
publishedTypebotId: string
}>

export type SetTypebot = (typebot: Typebot | undefined) => void
Expand Down Expand Up @@ -213,13 +215,14 @@ export const TypebotContext = ({

const publishTypebot = async () => {
if (!localTypebot) return
const publishedTypebotId = generate()
const newLocalTypebot = { ...localTypebot }
if (!localPublishedTypebot) {
const newPublicId = parseDefaultPublicId(
localTypebot.name,
localTypebot.id
)
updateLocalTypebot({ publicId: newPublicId })
updateLocalTypebot({ publicId: newPublicId, publishedTypebotId })
newLocalTypebot.publicId = newPublicId
}
if (hasUnsavedChanges || !localPublishedTypebot) await saveTypebot()
Expand All @@ -230,9 +233,10 @@ export const TypebotContext = ({
})
} else {
setIsPublishing(true)
const { data, error } = await createPublishedTypebot(
omit(parseTypebotToPublicTypebot(newLocalTypebot), 'id')
)
const { data, error } = await createPublishedTypebot({
...parseTypebotToPublicTypebot(newLocalTypebot),
id: publishedTypebotId,
})
setLocalPublishedTypebot(data)
setIsPublishing(false)
if (error) return toast({ title: error.name, description: error.message })
Expand Down
13 changes: 2 additions & 11 deletions apps/builder/services/publicTypebot.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
Block,
InputStep,
PublicBlock,
PublicStep,
PublicTypebot,
Typebot,
} from 'models'
import { Block, PublicBlock, PublicStep, PublicTypebot, Typebot } from 'models'
import shortId from 'short-uuid'
import { HStack, Text } from '@chakra-ui/react'
import { CalendarIcon } from 'assets/icons'
Expand Down Expand Up @@ -38,9 +31,7 @@ const parseBlocksToPublicBlocks = (blocks: Block[]): PublicBlock[] =>
),
}))

export const createPublishedTypebot = async (
typebot: Omit<PublicTypebot, 'id'>
) =>
export const createPublishedTypebot = async (typebot: PublicTypebot) =>
sendRequest<PublicTypebot>({
url: `/api/publicTypebots`,
method: 'POST',
Expand Down

3 comments on commit 8583e2a

@vercel
Copy link

@vercel vercel bot commented on 8583e2a Feb 15, 2022

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:

builder-v2 – ./apps/builder

next.typebot.io
builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 8583e2a Feb 15, 2022

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:

viewer-v2 – ./apps/viewer

viewer-v2-git-main-typebot-io.vercel.app
viewer-v2-typebot-io.vercel.app
typebot-viewer.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 8583e2a Feb 15, 2022

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:

landing-page-v2 – ./apps/landing-page

landing-page-v2-typebot-io.vercel.app
landing-page-v2-jade.vercel.app
landing-page-v2-git-main-typebot-io.vercel.app

Please sign in to comment.