From 9a4f4e8a6689aea5e42f2c21ea83d1bc5da8744d Mon Sep 17 00:00:00 2001 From: nflnkr Date: Mon, 26 Feb 2024 12:52:52 +0300 Subject: [PATCH] add questions state rollback on request error --- src/stores/questions/actions.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/stores/questions/actions.ts b/src/stores/questions/actions.ts index 9d577920..b8a7b6fe 100644 --- a/src/stores/questions/actions.ts +++ b/src/stores/questions/actions.ts @@ -267,6 +267,8 @@ export const updateQuestion = async ( ); const request = async () => { + const rollbackQuestions = useQuestionsStore.getState(); + const q = useQuestionsStore.getState().questions.find((q) => q.id === questionId) || useQuestionsStore @@ -300,6 +302,8 @@ export const updateQuestion = async ( } catch (error) { if (isAxiosCanceledError(error)) return; + useQuestionsStore.setState(rollbackQuestions); + devlog("Error editing question", { error, questionId }); enqueueSnackbar("Не удалось сохранить вопрос"); }