@ -64,7 +64,7 @@ const typebotContext = createContext<
|
|||||||
is404: boolean
|
is404: boolean
|
||||||
isPublished: boolean
|
isPublished: boolean
|
||||||
isSavingLoading: boolean
|
isSavingLoading: boolean
|
||||||
save: () => Promise<void>
|
save: (updates?: Partial<TypebotV6>, overwrite?: boolean) => Promise<void>
|
||||||
undo: () => void
|
undo: () => void
|
||||||
redo: () => void
|
redo: () => void
|
||||||
canRedo: boolean
|
canRedo: boolean
|
||||||
@ -72,6 +72,7 @@ const typebotContext = createContext<
|
|||||||
updateTypebot: (props: {
|
updateTypebot: (props: {
|
||||||
updates: UpdateTypebotPayload
|
updates: UpdateTypebotPayload
|
||||||
save?: boolean
|
save?: boolean
|
||||||
|
overwrite?: boolean
|
||||||
}) => Promise<TypebotV6 | undefined>
|
}) => Promise<TypebotV6 | undefined>
|
||||||
restorePublishedTypebot: () => void
|
restorePublishedTypebot: () => void
|
||||||
} & GroupsActions &
|
} & GroupsActions &
|
||||||
@ -219,7 +220,7 @@ export const TypebotProvider = ({
|
|||||||
])
|
])
|
||||||
|
|
||||||
const saveTypebot = useCallback(
|
const saveTypebot = useCallback(
|
||||||
async (updates?: Partial<TypebotV6>) => {
|
async (updates?: Partial<TypebotV6>, overwrite?: boolean) => {
|
||||||
if (!localTypebot || !typebot || isReadOnly) return
|
if (!localTypebot || !typebot || isReadOnly) return
|
||||||
const typebotToSave = {
|
const typebotToSave = {
|
||||||
...localTypebot,
|
...localTypebot,
|
||||||
@ -235,13 +236,14 @@ export const TypebotProvider = ({
|
|||||||
const newParsedTypebot = typebotV6Schema.parse({ ...typebotToSave })
|
const newParsedTypebot = typebotV6Schema.parse({ ...typebotToSave })
|
||||||
setLocalTypebot(newParsedTypebot)
|
setLocalTypebot(newParsedTypebot)
|
||||||
try {
|
try {
|
||||||
const {
|
const { typebot } = await updateTypebot({
|
||||||
typebot: { updatedAt },
|
|
||||||
} = await updateTypebot({
|
|
||||||
typebotId: newParsedTypebot.id,
|
typebotId: newParsedTypebot.id,
|
||||||
typebot: newParsedTypebot,
|
typebot: newParsedTypebot,
|
||||||
})
|
})
|
||||||
setUpdateDate(updatedAt)
|
setUpdateDate(typebot.updatedAt)
|
||||||
|
if (overwrite) {
|
||||||
|
setLocalTypebot(typebot)
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
setLocalTypebot({
|
setLocalTypebot({
|
||||||
...localTypebot,
|
...localTypebot,
|
||||||
@ -300,14 +302,16 @@ export const TypebotProvider = ({
|
|||||||
const updateLocalTypebot = async ({
|
const updateLocalTypebot = async ({
|
||||||
updates,
|
updates,
|
||||||
save,
|
save,
|
||||||
|
overwrite,
|
||||||
}: {
|
}: {
|
||||||
updates: UpdateTypebotPayload
|
updates: UpdateTypebotPayload
|
||||||
save?: boolean
|
save?: boolean
|
||||||
|
overwrite?: boolean
|
||||||
}) => {
|
}) => {
|
||||||
if (!localTypebot || isReadOnly) return
|
if (!localTypebot || isReadOnly) return
|
||||||
const newTypebot = { ...localTypebot, ...updates }
|
const newTypebot = { ...localTypebot, ...updates }
|
||||||
setLocalTypebot(newTypebot)
|
setLocalTypebot(newTypebot)
|
||||||
if (save) await saveTypebot(newTypebot)
|
if (save) await saveTypebot(newTypebot, overwrite)
|
||||||
return newTypebot
|
return newTypebot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,14 +111,12 @@ export const PublishButton = ({
|
|||||||
const handlePublishClick = async () => {
|
const handlePublishClick = async () => {
|
||||||
if (!typebot?.id) return
|
if (!typebot?.id) return
|
||||||
if (isFreePlan(workspace) && hasInputFile) return onOpen()
|
if (isFreePlan(workspace) && hasInputFile) return onOpen()
|
||||||
if (!typebot.publicId) {
|
await save(
|
||||||
await updateTypebot({
|
!typebot.publicId
|
||||||
updates: {
|
? { publicId: parseDefaultPublicId(typebot.name, typebot.id) }
|
||||||
publicId: parseDefaultPublicId(typebot.name, typebot.id),
|
: undefined,
|
||||||
},
|
true
|
||||||
save: true,
|
)
|
||||||
})
|
|
||||||
} else await save()
|
|
||||||
publishTypebotMutate({
|
publishTypebotMutate({
|
||||||
typebotId: typebot.id,
|
typebotId: typebot.id,
|
||||||
})
|
})
|
||||||
|
@ -172,7 +172,6 @@ export const sanitizeVariables = ({
|
|||||||
.flatMap((group) => group.blocks as Block[])
|
.flatMap((group) => group.blocks as Block[])
|
||||||
.filter((b) => isInputBlock(b) || b.type === LogicBlockType.SET_VARIABLE)
|
.filter((b) => isInputBlock(b) || b.type === LogicBlockType.SET_VARIABLE)
|
||||||
return variables.map((variable) => {
|
return variables.map((variable) => {
|
||||||
if (variable.isSessionVariable) return variable
|
|
||||||
const isVariableLinkedToInputBlock = blocks.some(
|
const isVariableLinkedToInputBlock = blocks.some(
|
||||||
(block) =>
|
(block) =>
|
||||||
isInputBlock(block) && block.options?.variableId === variable.id
|
isInputBlock(block) && block.options?.variableId === variable.id
|
||||||
@ -180,7 +179,7 @@ export const sanitizeVariables = ({
|
|||||||
if (isVariableLinkedToInputBlock)
|
if (isVariableLinkedToInputBlock)
|
||||||
return {
|
return {
|
||||||
...variable,
|
...variable,
|
||||||
isSessionVariable: true,
|
isSessionVariable: false,
|
||||||
}
|
}
|
||||||
const isVariableSetToForbiddenResultVar = blocks.some(
|
const isVariableSetToForbiddenResultVar = blocks.some(
|
||||||
(block) =>
|
(block) =>
|
||||||
|
Reference in New Issue
Block a user