2
0

🚸 (dashboard) Add unpublish menu item in dashboard

Also remove the useless publishedTypebotId field in Typebot

Closes #232
This commit is contained in:
Baptiste Arnaud
2023-01-27 17:11:26 +01:00
parent a842f57297
commit f93bc2fcb2
59 changed files with 212 additions and 90 deletions

View File

@ -18,7 +18,7 @@ import { RightPanel, useEditor } from '../../providers/EditorProvider'
import { useTypebot } from '../../providers/TypebotProvider'
import { useRouter } from 'next/router'
import React, { useState } from 'react'
import { isNotDefined } from 'utils'
import { isDefined, isNotDefined } from 'utils'
import { EditableTypebotName } from './EditableTypebotName'
import { getBubbleActions } from 'typebot-js'
import Link from 'next/link'
@ -34,6 +34,7 @@ export const TypebotHeader = () => {
const router = useRouter()
const {
typebot,
publishedTypebot,
updateTypebot,
save,
undo,
@ -126,7 +127,7 @@ export const TypebotHeader = () => {
>
Share
</Button>
{typebot?.publishedTypebotId && (
{isDefined(publishedTypebot) && (
<Button
as={Link}
href={`/typebots/${typebot?.id}/results`}

View File

@ -16,14 +16,13 @@ import {
useMemo,
useState,
} from 'react'
import { isDefined, isNotDefined, omit } from 'utils'
import { isDefined, omit } from 'utils'
import { edgesAction, EdgesActions } from './actions/edges'
import { itemsAction, ItemsActions } from './actions/items'
import { GroupsActions, groupsActions } from './actions/groups'
import { blocksAction, BlocksActions } from './actions/blocks'
import { variablesAction, VariablesActions } from './actions/variables'
import { dequal } from 'dequal'
import cuid from 'cuid'
import { useToast } from '@/hooks/useToast'
import { useTypebotQuery } from '@/hooks/useTypebotQuery'
import useUndo from '../../hooks/useUndo'
@ -52,7 +51,6 @@ type UpdateTypebotPayload = Partial<{
settings: Settings
publicId: string
name: string
publishedTypebotId: string
icon: string
customDomain: string
resultsTablePreferences: ResultsTablePreferences
@ -254,17 +252,12 @@ export const TypebotProvider = ({
const publishTypebot = async () => {
if (!localTypebot) return
const publishedTypebotId = cuid()
const newLocalTypebot = { ...localTypebot }
if (publishedTypebot && isNotDefined(localTypebot.publishedTypebotId)) {
updateLocalTypebot({ publishedTypebotId: publishedTypebot.id })
await saveTypebot()
}
if (!publishedTypebot) {
const newPublicId =
localTypebot.publicId ??
parseDefaultPublicId(localTypebot.name, localTypebot.id)
updateLocalTypebot({ publicId: newPublicId, publishedTypebotId })
updateLocalTypebot({ publicId: newPublicId })
newLocalTypebot.publicId = newPublicId
await saveTypebot()
}
@ -277,8 +270,7 @@ export const TypebotProvider = ({
setIsPublishing(true)
const { data, error } = await createPublishedTypebotQuery(
{
...parseTypebotToPublicTypebot(newLocalTypebot),
id: publishedTypebotId,
...omit(parseTypebotToPublicTypebot(newLocalTypebot), 'id'),
},
localTypebot.workspaceId
)