From b4a6e427ad5a4713089f310b573752b179f4b597 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 16 Aug 2024 15:41:14 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20input=20answer=20empty=20i?= =?UTF-8?q?f=20filled=20from=20set=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1700 --- .../editor/providers/TypebotProvider.tsx | 18 +++++++++++------- .../publish/components/PublishButton.tsx | 14 ++++++-------- .../src/features/typebot/helpers/sanitizers.ts | 3 +-- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/apps/builder/src/features/editor/providers/TypebotProvider.tsx b/apps/builder/src/features/editor/providers/TypebotProvider.tsx index 27c4865223..dd99bc1ab4 100644 --- a/apps/builder/src/features/editor/providers/TypebotProvider.tsx +++ b/apps/builder/src/features/editor/providers/TypebotProvider.tsx @@ -64,7 +64,7 @@ const typebotContext = createContext< is404: boolean isPublished: boolean isSavingLoading: boolean - save: () => Promise + save: (updates?: Partial, overwrite?: boolean) => Promise undo: () => void redo: () => void canRedo: boolean @@ -72,6 +72,7 @@ const typebotContext = createContext< updateTypebot: (props: { updates: UpdateTypebotPayload save?: boolean + overwrite?: boolean }) => Promise restorePublishedTypebot: () => void } & GroupsActions & @@ -219,7 +220,7 @@ export const TypebotProvider = ({ ]) const saveTypebot = useCallback( - async (updates?: Partial) => { + async (updates?: Partial, overwrite?: boolean) => { if (!localTypebot || !typebot || isReadOnly) return const typebotToSave = { ...localTypebot, @@ -235,13 +236,14 @@ export const TypebotProvider = ({ const newParsedTypebot = typebotV6Schema.parse({ ...typebotToSave }) setLocalTypebot(newParsedTypebot) try { - const { - typebot: { updatedAt }, - } = await updateTypebot({ + const { typebot } = await updateTypebot({ typebotId: newParsedTypebot.id, typebot: newParsedTypebot, }) - setUpdateDate(updatedAt) + setUpdateDate(typebot.updatedAt) + if (overwrite) { + setLocalTypebot(typebot) + } } catch { setLocalTypebot({ ...localTypebot, @@ -300,14 +302,16 @@ export const TypebotProvider = ({ const updateLocalTypebot = async ({ updates, save, + overwrite, }: { updates: UpdateTypebotPayload save?: boolean + overwrite?: boolean }) => { if (!localTypebot || isReadOnly) return const newTypebot = { ...localTypebot, ...updates } setLocalTypebot(newTypebot) - if (save) await saveTypebot(newTypebot) + if (save) await saveTypebot(newTypebot, overwrite) return newTypebot } diff --git a/apps/builder/src/features/publish/components/PublishButton.tsx b/apps/builder/src/features/publish/components/PublishButton.tsx index 48a893e8a7..9474830177 100644 --- a/apps/builder/src/features/publish/components/PublishButton.tsx +++ b/apps/builder/src/features/publish/components/PublishButton.tsx @@ -111,14 +111,12 @@ export const PublishButton = ({ const handlePublishClick = async () => { if (!typebot?.id) return if (isFreePlan(workspace) && hasInputFile) return onOpen() - if (!typebot.publicId) { - await updateTypebot({ - updates: { - publicId: parseDefaultPublicId(typebot.name, typebot.id), - }, - save: true, - }) - } else await save() + await save( + !typebot.publicId + ? { publicId: parseDefaultPublicId(typebot.name, typebot.id) } + : undefined, + true + ) publishTypebotMutate({ typebotId: typebot.id, }) diff --git a/apps/builder/src/features/typebot/helpers/sanitizers.ts b/apps/builder/src/features/typebot/helpers/sanitizers.ts index 10d6722654..84672cf290 100644 --- a/apps/builder/src/features/typebot/helpers/sanitizers.ts +++ b/apps/builder/src/features/typebot/helpers/sanitizers.ts @@ -172,7 +172,6 @@ export const sanitizeVariables = ({ .flatMap((group) => group.blocks as Block[]) .filter((b) => isInputBlock(b) || b.type === LogicBlockType.SET_VARIABLE) return variables.map((variable) => { - if (variable.isSessionVariable) return variable const isVariableLinkedToInputBlock = blocks.some( (block) => isInputBlock(block) && block.options?.variableId === variable.id @@ -180,7 +179,7 @@ export const sanitizeVariables = ({ if (isVariableLinkedToInputBlock) return { ...variable, - isSessionVariable: true, + isSessionVariable: false, } const isVariableSetToForbiddenResultVar = blocks.some( (block) =>