2
0

🐛 Fix input answer empty if filled from set variable

Closes #1700
This commit is contained in:
Baptiste Arnaud
2024-08-16 15:41:14 +02:00
parent 86263f0722
commit b4a6e427ad
3 changed files with 18 additions and 17 deletions

View File

@ -64,7 +64,7 @@ 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
@ -72,6 +72,7 @@ const typebotContext = createContext<
updateTypebot: (props: {
updates: UpdateTypebotPayload
save?: boolean
overwrite?: boolean
}) => Promise<TypebotV6 | undefined>
restorePublishedTypebot: () => void
} & GroupsActions &
@ -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,
@ -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
}

View File

@ -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,
})

View File

@ -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) =>