@@ -156,13 +156,22 @@ export const TypebotHeader = () => {
|
||||
as={Link}
|
||||
aria-label="Navigate back"
|
||||
icon={<ChevronLeftIcon fontSize={25} />}
|
||||
href={
|
||||
router.query.parentId
|
||||
? `/typebots/${router.query.parentId}/edit`
|
||||
href={{
|
||||
pathname: router.query.parentId
|
||||
? '/typebots/[typebotId]/edit'
|
||||
: typebot?.folderId
|
||||
? `/typebots/folders/${typebot.folderId}`
|
||||
: '/typebots'
|
||||
}
|
||||
? '/typebots/folders/[folderId]'
|
||||
: '/typebots',
|
||||
query: {
|
||||
folderId: typebot?.folderId ?? [],
|
||||
parentId: Array.isArray(router.query.parentId)
|
||||
? router.query.parentId.slice(0, -1)
|
||||
: [],
|
||||
typebotId: Array.isArray(router.query.parentId)
|
||||
? [...router.query.parentId].pop()
|
||||
: router.query.parentId ?? [],
|
||||
},
|
||||
}}
|
||||
size="sm"
|
||||
/>
|
||||
<HStack spacing={1}>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LogicBlockType, PublicTypebot, Typebot } from '@typebot.io/schemas'
|
||||
import { PublicTypebot, Typebot } from '@typebot.io/schemas'
|
||||
import { Router, useRouter } from 'next/router'
|
||||
import {
|
||||
createContext,
|
||||
@@ -49,7 +49,6 @@ const typebotContext = createContext<
|
||||
{
|
||||
typebot?: Typebot
|
||||
publishedTypebot?: PublicTypebot
|
||||
linkedTypebots?: Pick<Typebot, 'id' | 'groups' | 'variables' | 'name'>[]
|
||||
isReadOnly?: boolean
|
||||
isPublished: boolean
|
||||
isSavingLoading: boolean
|
||||
@@ -132,36 +131,6 @@ export const TypebotProvider = ({
|
||||
{ redo, undo, flush, canRedo, canUndo, set: setLocalTypebot },
|
||||
] = useUndo<Typebot>(undefined)
|
||||
|
||||
const linkedTypebotIds = useMemo(
|
||||
() =>
|
||||
typebot?.groups
|
||||
.flatMap((group) => group.blocks)
|
||||
.reduce<string[]>(
|
||||
(typebotIds, block) =>
|
||||
block.type === LogicBlockType.TYPEBOT_LINK &&
|
||||
isDefined(block.options.typebotId) &&
|
||||
!typebotIds.includes(block.options.typebotId)
|
||||
? [...typebotIds, block.options.typebotId]
|
||||
: typebotIds,
|
||||
[]
|
||||
) ?? [],
|
||||
[typebot?.groups]
|
||||
)
|
||||
|
||||
const { data: linkedTypebotsData } = trpc.getLinkedTypebots.useQuery(
|
||||
{
|
||||
typebotId: typebot?.id as string,
|
||||
},
|
||||
{
|
||||
enabled: isDefined(typebot?.id) && linkedTypebotIds.length > 0,
|
||||
onError: (error) =>
|
||||
showToast({
|
||||
title: 'Error while fetching linkedTypebots',
|
||||
description: error.message,
|
||||
}),
|
||||
}
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!typebot && isDefined(localTypebot)) setLocalTypebot(undefined)
|
||||
if (isFetchingTypebot) return
|
||||
@@ -270,7 +239,6 @@ export const TypebotProvider = ({
|
||||
value={{
|
||||
typebot: localTypebot,
|
||||
publishedTypebot,
|
||||
linkedTypebots: linkedTypebotsData?.typebots ?? [],
|
||||
isReadOnly: typebotData?.isReadOnly,
|
||||
isSavingLoading: isSaving,
|
||||
save: saveTypebot,
|
||||
|
||||
Reference in New Issue
Block a user