Skip to content

Commit

Permalink
🐛 Fix input answer empty if filled from set variable
Browse files Browse the repository at this point in the history
Closes #1700
  • Loading branch information
baptisteArno committed Aug 16, 2024
1 parent 86263f0 commit b4a6e42
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
18 changes: 11 additions & 7 deletions apps/builder/src/features/editor/providers/TypebotProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ const typebotContext = createContext<
is404: boolean
isPublished: boolean
isSavingLoading: boolean
save: () => Promise<void>
save: (updates?: Partial<TypebotV6>, overwrite?: boolean) => Promise<void>
undo: () => void
redo: () => void
canRedo: boolean
canUndo: boolean
updateTypebot: (props: {
updates: UpdateTypebotPayload
save?: boolean
overwrite?: boolean
}) => Promise<TypebotV6 | undefined>
restorePublishedTypebot: () => void
} & GroupsActions &
Expand Down Expand Up @@ -219,7 +220,7 @@ export const TypebotProvider = ({
])

const saveTypebot = useCallback(
async (updates?: Partial<TypebotV6>) => {
async (updates?: Partial<TypebotV6>, overwrite?: boolean) => {
if (!localTypebot || !typebot || isReadOnly) return
const typebotToSave = {
...localTypebot,
Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
14 changes: 6 additions & 8 deletions apps/builder/src/features/publish/components/PublishButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
3 changes: 1 addition & 2 deletions apps/builder/src/features/typebot/helpers/sanitizers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,14 @@ 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
)
if (isVariableLinkedToInputBlock)
return {
...variable,
isSessionVariable: true,
isSessionVariable: false,
}
const isVariableSetToForbiddenResultVar = blocks.some(
(block) =>
Expand Down

0 comments on commit b4a6e42

Please sign in to comment.