2
0

fix: 🚑️ Webhook and instant updates

This commit is contained in:
Baptiste Arnaud
2022-02-22 10:16:35 +01:00
parent 642a42779b
commit d49461cde6
36 changed files with 317 additions and 204 deletions

View File

@ -94,9 +94,14 @@ export const TypebotContext = ({
})
useEffect(() => {
if (!typebot || !localTypebot || deepEqual(typebot, localTypebot)) return
if (typebot?.blocks.length === localTypebot?.blocks.length)
setLocalTypebot({ ...typebot })
if (
!typebot ||
!localTypebot ||
typebot.updatedAt <= localTypebot.updatedAt ||
deepEqual(typebot, localTypebot)
)
return
setLocalTypebot({ ...typebot })
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [typebot])
@ -113,8 +118,8 @@ export const TypebotContext = ({
] = useUndo<Typebot | undefined>(undefined)
const saveTypebot = async () => {
if (deepEqual(typebot, localTypebot)) return
const typebotToSave = currentTypebotRef.current
if (deepEqual(typebot, typebotToSave)) return
if (!typebotToSave) return
setIsSavingLoading(true)
const { error } = await updateTypebot(typebotToSave.id, typebotToSave)