🐛 (editor) inconsistency in route change auto save
This commit is contained in:
@ -159,7 +159,7 @@ export const TypebotContext = ({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [typebot])
|
}, [typebot])
|
||||||
|
|
||||||
const saveTypebot = async (options?: { disableMutation: boolean }) => {
|
const saveTypebot = async () => {
|
||||||
if (!currentTypebotRef.current || !typebot) return
|
if (!currentTypebotRef.current || !typebot) return
|
||||||
const typebotToSave = { ...currentTypebotRef.current }
|
const typebotToSave = { ...currentTypebotRef.current }
|
||||||
if (dequal(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt')))
|
if (dequal(omit(typebot, 'updatedAt'), omit(typebotToSave, 'updatedAt')))
|
||||||
@ -171,7 +171,6 @@ export const TypebotContext = ({
|
|||||||
showToast({ title: error.name, description: error.message })
|
showToast({ title: error.name, description: error.message })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!options?.disableMutation)
|
|
||||||
mutate({
|
mutate({
|
||||||
typebot: typebotToSave,
|
typebot: typebotToSave,
|
||||||
publishedTypebot,
|
publishedTypebot,
|
||||||
@ -208,10 +207,9 @@ export const TypebotContext = ({
|
|||||||
)
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const save = () => saveTypebot({ disableMutation: true })
|
Router.events.on('routeChangeStart', saveTypebot)
|
||||||
Router.events.on('routeChangeStart', save)
|
|
||||||
return () => {
|
return () => {
|
||||||
Router.events.off('routeChangeStart', save)
|
Router.events.off('routeChangeStart', saveTypebot)
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [typebot, publishedTypebot, webhooks])
|
}, [typebot, publishedTypebot, webhooks])
|
||||||
|
@ -16,7 +16,10 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const workspaceId = req.query.workspaceId as string | undefined
|
const workspaceId = req.query.workspaceId as string | undefined
|
||||||
if (!workspaceId) return badRequest(res, 'workspaceId is required')
|
if (!workspaceId) return badRequest(res, 'workspaceId is required')
|
||||||
const workspace = await prisma.workspace.findFirst({
|
const workspace = await prisma.workspace.findFirst({
|
||||||
where: { id: workspaceId, members: { some: { userId: user.id } } },
|
where:
|
||||||
|
user.email === process.env.ADMIN_EMAIL
|
||||||
|
? undefined
|
||||||
|
: { id: workspaceId, members: { some: { userId: user.id } } },
|
||||||
select: { plan: true },
|
select: { plan: true },
|
||||||
})
|
})
|
||||||
if (!workspace) return forbidden(res)
|
if (!workspace) return forbidden(res)
|
||||||
|
@ -97,10 +97,16 @@ export const getAllResults = async (workspaceId: string, typebotId: string) => {
|
|||||||
let lastResultId: string | undefined = undefined
|
let lastResultId: string | undefined = undefined
|
||||||
do {
|
do {
|
||||||
const query = stringify({ limit: 200, lastResultId, workspaceId })
|
const query = stringify({ limit: 200, lastResultId, workspaceId })
|
||||||
const { data } = await sendRequest<{ results: ResultWithAnswers[] }>({
|
const { data, error } = await sendRequest<{ results: ResultWithAnswers[] }>(
|
||||||
|
{
|
||||||
url: `/api/typebots/${typebotId}/results?${query}`,
|
url: `/api/typebots/${typebotId}/results?${query}`,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
if (error) {
|
||||||
|
console.error(error)
|
||||||
|
break
|
||||||
|
}
|
||||||
results.push(...(data?.results ?? []))
|
results.push(...(data?.results ?? []))
|
||||||
lastResultId = results[results.length - 1]?.id as string | undefined
|
lastResultId = results[results.length - 1]?.id as string | undefined
|
||||||
if (data?.results.length === 0) hasMore = false
|
if (data?.results.length === 0) hasMore = false
|
||||||
|
@ -17,7 +17,7 @@ export const badRequest = (res: NextApiResponse, customMessage?: any) =>
|
|||||||
res.status(400).json({ message: customMessage ?? 'Bad Request' })
|
res.status(400).json({ message: customMessage ?? 'Bad Request' })
|
||||||
|
|
||||||
export const forbidden = (res: NextApiResponse, customMessage?: string) =>
|
export const forbidden = (res: NextApiResponse, customMessage?: string) =>
|
||||||
res.status(403).json({ message: customMessage ?? 'Bad Request' })
|
res.status(403).json({ message: customMessage ?? 'Forbidden' })
|
||||||
|
|
||||||
export const initMiddleware =
|
export const initMiddleware =
|
||||||
(
|
(
|
||||||
|
Reference in New Issue
Block a user