🐛 (editor) Fix lost changes when typebot takes a long time to update
Closes #1231
This commit is contained in:
@ -208,7 +208,11 @@ export const TypebotProvider = ({
|
||||
const saveTypebot = useCallback(
|
||||
async (updates?: Partial<TypebotV6>) => {
|
||||
if (!localTypebot || !typebot || isReadOnly) return
|
||||
const typebotToSave = { ...localTypebot, ...updates }
|
||||
const typebotToSave = {
|
||||
...localTypebot,
|
||||
...updates,
|
||||
updatedAt: new Date(),
|
||||
}
|
||||
if (dequal(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt')))
|
||||
return
|
||||
setLocalTypebot({ ...typebotToSave })
|
||||
|
@ -37,6 +37,7 @@ const typebotUpdateSchemaPick = {
|
||||
whatsAppCredentialsId: true,
|
||||
riskLevel: true,
|
||||
events: true,
|
||||
updatedAt: true,
|
||||
} as const
|
||||
|
||||
export const updateTypebot = authenticatedProcedure
|
||||
@ -67,12 +68,6 @@ export const updateTypebot = authenticatedProcedure
|
||||
title: 'Typebot V5',
|
||||
}),
|
||||
]),
|
||||
updatedAt: z
|
||||
.date()
|
||||
.optional()
|
||||
.describe(
|
||||
'Used for checking if there is a newer version of the typebot in the database'
|
||||
),
|
||||
})
|
||||
)
|
||||
.output(
|
||||
@ -80,8 +75,7 @@ export const updateTypebot = authenticatedProcedure
|
||||
typebot: typebotV6Schema,
|
||||
})
|
||||
)
|
||||
.mutation(
|
||||
async ({ input: { typebotId, typebot, updatedAt }, ctx: { user } }) => {
|
||||
.mutation(async ({ input: { typebotId, typebot }, ctx: { user } }) => {
|
||||
const existingTypebot = await prisma.typebot.findFirst({
|
||||
where: {
|
||||
id: typebotId,
|
||||
@ -125,8 +119,9 @@ export const updateTypebot = authenticatedProcedure
|
||||
})
|
||||
|
||||
if (
|
||||
updatedAt &&
|
||||
updatedAt.getTime() > new Date(existingTypebot?.updatedAt).getTime()
|
||||
typebot.updatedAt &&
|
||||
new Date(existingTypebot?.updatedAt).getTime() >
|
||||
typebot.updatedAt.getTime()
|
||||
)
|
||||
throw new TRPCError({
|
||||
code: 'CONFLICT',
|
||||
@ -207,6 +202,7 @@ export const updateTypebot = authenticatedProcedure
|
||||
typebot.customDomain === null ? null : typebot.customDomain,
|
||||
isClosed: typebot.isClosed,
|
||||
whatsAppCredentialsId: typebot.whatsAppCredentialsId ?? undefined,
|
||||
updatedAt: typebot.updatedAt,
|
||||
},
|
||||
})
|
||||
|
||||
@ -215,8 +211,7 @@ export const updateTypebot = authenticatedProcedure
|
||||
)
|
||||
|
||||
return { typebot: migratedTypebot }
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
const isPublicIdValid = (str: string) =>
|
||||
/^([a-z0-9]+-[a-z0-9]*)*$/.test(str) || /^[a-z0-9]*$/.test(str)
|
||||
|
@ -4401,6 +4401,9 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"updatedAt": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "Typebot V6"
|
||||
@ -7003,15 +7006,14 @@
|
||||
},
|
||||
"events": {
|
||||
"type": "array"
|
||||
},
|
||||
"updatedAt": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "Typebot V5"
|
||||
}
|
||||
]
|
||||
},
|
||||
"updatedAt": {
|
||||
"type": "string",
|
||||
"description": "Used for checking if there is a newer version of the typebot in the database"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
Reference in New Issue
Block a user