From c30966a1baed444e4710d0fec114e0c2d69ade04 Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Tue, 7 May 2024 16:57:12 +0300 Subject: [PATCH] fix: copy quiz --- src/pages/createQuize/MyQuizzesFull.tsx | 8 +++----- src/stores/quizes/actions.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/pages/createQuize/MyQuizzesFull.tsx b/src/pages/createQuize/MyQuizzesFull.tsx index 2c6dc3f4..bd91e43b 100644 --- a/src/pages/createQuize/MyQuizzesFull.tsx +++ b/src/pages/createQuize/MyQuizzesFull.tsx @@ -13,6 +13,7 @@ import { resetEditConfig, updateQuiz, } from "@root/quizes/actions"; +import { mutate } from "swr"; import { useQuizes } from "@root/quizes/hooks"; import SectionWrapper from "@ui_kit/SectionWrapper"; import React from "react"; @@ -32,19 +33,16 @@ export default function MyQuizzesFull({ outerContainerSx: sx, children, }: Props) { - const { quizes, isValidating } = useQuizes(); + const { quizes } = useQuizes(); const navigate = useNavigate(); const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down(500)); const onClickCopy = (value: string) => { copyQuiz(value); + mutate("quizes"); }; - if (isValidating) { - return ; - } - return ( <> diff --git a/src/stores/quizes/actions.ts b/src/stores/quizes/actions.ts index d3b7edd0..ea864f6a 100644 --- a/src/stores/quizes/actions.ts +++ b/src/stores/quizes/actions.ts @@ -250,11 +250,16 @@ export const copyQuiz = async (quizId: string) => try { const { updated } = await quizApi.copy(quiz.backendId); - let newQuiz = { ...quiz, id: updated }; + let newQuiz: Quiz = { + ...quiz, + id: String(updated), + session_count: 0, + passed_count: 0, + }; setProducedState( (state) => { - state.quizes.unshift(quiz); + state.quizes.unshift(newQuiz); }, { type: "addQuiz",