diff --git a/app/(main)/quiz/[quiz_id]/results/page.tsx b/app/(main)/quiz/[quiz_id]/results/page.tsx index f78dcac..0c4588d 100644 --- a/app/(main)/quiz/[quiz_id]/results/page.tsx +++ b/app/(main)/quiz/[quiz_id]/results/page.tsx @@ -2,9 +2,11 @@ import { Queries } from "@/api/queries"; import QuizHeader from "@/components/quiz/QuizHeader"; import QuizResultsSearch from "@/components/quiz/QuizResultsSearch"; +import QuizResultsTabs from "@/components/quiz/QuizResultsTabs"; import QuizTapgyrResults from "@/components/quiz/QuizTapgyrResults"; import QuizTapgyrWinners from "@/components/quiz/QuizTapgyrWinners"; import { Data } from "@/models/quizQuestions.model"; +import { useQuizResults } from "@/store/store"; import { notFound } from "next/navigation"; import React, { useEffect, useState } from "react"; @@ -16,35 +18,46 @@ interface IParams { const Page = ({ params }: IParams) => { const [data, setData] = useState(); + const [tab, setTab] = useState(0); + const { resultData, error } = useQuizResults(); useEffect(() => { - Queries.getQuizById(params.quiz_id) - .then((res) => setData(res.data)) - .catch(() => notFound()); - }, []); + if (!resultData.length && !error) { + Queries.getQuizById(params.quiz_id) + .then((res) => setData(res.data)) + .catch(() => notFound()); + } + }, [resultData, error]); return (
- String(item.tapgyr)) : [] - } + + {tab === "results" && ( + String(item.tapgyr)) : [] + } + /> + )} {data?.has_steps && data.steps && data.steps?.length > 0 && - data.steps.map((step) => ( + tab !== "results" && ( - ))} + )}
); diff --git a/components/quiz/QuizQuestion.tsx b/components/quiz/QuizQuestion.tsx index 078c7be..548d829 100644 --- a/components/quiz/QuizQuestion.tsx +++ b/components/quiz/QuizQuestion.tsx @@ -1,8 +1,8 @@ -import React, { useContext } from 'react'; -import QuizAccordion from './QuizAccordion'; -import { Validator } from '@/utils/validator'; -import QuizContext from '@/context/QuizContext'; -import { v4 } from 'uuid'; +import React, { useContext } from "react"; +import QuizAccordion from "./QuizAccordion"; +import { Validator } from "@/utils/validator"; +import QuizContext from "@/context/QuizContext"; +import { v4 } from "uuid"; type TProps = { finished: string; @@ -15,26 +15,26 @@ type TProps = { }; const numbers = [ - 'Birinji sowal', - 'Ikinji sowal', - 'Üçünji sowal', - 'Dördünji sowal', - 'Bäşinji sowal', - 'Altynjy sowal', - 'Ýedinji sowal', - 'Sekizinji sowal', - 'Dokuzynjy sowal', - 'Onunjy sowal', - 'On Birinji sowal', - 'On Ikinji sowal', - 'On Üçünji sowal', - 'On Dördünji sowal', - 'On Bäşinji sowal', - 'On Altynji sowal', - 'On Ýeddi sowal', - 'On Sekiznji sowal', - 'On Dokuzunji sowal', - 'Ýigrinci sowal', + "Birinji sowal", + "Ikinji sowal", + "Üçünji sowal", + "Dördünji sowal", + "Bäşinji sowal", + "Altynjy sowal", + "Ýedinji sowal", + "Sekizinji sowal", + "Dokuzynjy sowal", + "Onunjy sowal", + "On Birinji sowal", + "On Ikinji sowal", + "On Üçünji sowal", + "On Dördünji sowal", + "On Bäşinji sowal", + "On Altynji sowal", + "On Ýeddi sowal", + "On Sekiznji sowal", + "On Dokuzunji sowal", + "Ýigrinci sowal", ]; const QuizQuestion = ({ @@ -51,20 +51,21 @@ const QuizQuestion = ({ Object.values(quizSearchData.data).map((userQuestion, id) => userQuestion.question_id === questionId ? (
-
+
-

- {numbers.map((number, id) => (id === questionNumber ? number : ''))}: +

+ {question}

+ finished === "closed" ? "bg-fillRed" : "bg-fillGreen" + } rounded-full`} + >
- {finished === 'closed' ? 'ýapyk' : 'açyk'} + {finished === "closed" ? "ýapyk" : "açyk"}
@@ -73,14 +74,16 @@ const QuizQuestion = ({ width="16" height="16" viewBox="0 0 16 16" - fill="none"> + fill="none" + > - {Validator.parseDate(startsAt)}-den {Validator.parseDate(endsAt)}-e çenli + {Validator.parseDate(startsAt)}-den{" "} + {Validator.parseDate(endsAt)}-e çenli
@@ -89,7 +92,8 @@ const QuizQuestion = ({ width="18" height="18" viewBox="0 0 18 18" - fill="none"> + fill="none" + >
-

- «{question}» -

- {finished === 'closed' ? ( + {finished === "closed" ? ( ) : null}
- ) : null, + ) : null ) ) : (
-
+
-

- {numbers.map((number, id) => (id === questionNumber ? number : ''))}: +

+ {question}

+ finished === "closed" ? "bg-fillRed" : "bg-fillGreen" + } rounded-full`} + >
- {finished === 'closed' ? 'ýapyk' : 'açyk'} + {finished === "closed" ? "ýapyk" : "açyk"}
@@ -136,14 +138,16 @@ const QuizQuestion = ({ width="16" height="16" viewBox="0 0 16 16" - fill="none"> + fill="none" + > - {Validator.parseDate(startsAt)}-den {Validator.parseDate(endsAt)}-e çenli + {Validator.parseDate(startsAt)}-den{" "} + {Validator.parseDate(endsAt)}-e çenli
@@ -152,7 +156,8 @@ const QuizQuestion = ({ width="18" height="18" viewBox="0 0 18 18" - fill="none"> + fill="none" + >
-

- «{question}» -

- {finished === 'closed' ? : null} + {finished === "closed" ? ( + + ) : null}
); }; diff --git a/components/quiz/QuizResultsSearch.tsx b/components/quiz/QuizResultsSearch.tsx index ec36529..31e8433 100644 --- a/components/quiz/QuizResultsSearch.tsx +++ b/components/quiz/QuizResultsSearch.tsx @@ -1,10 +1,11 @@ "use client"; import { useQuizResults, useResultsLoading } from "@/store/store"; +import { X } from "lucide-react"; import React, { useState } from "react"; const QuizResultsSearch = ({ id }: { id: string }) => { const [phone, setPhone] = useState(""); - const { setError, setResultData } = useQuizResults(); + const { setError, setResultData, error, resultData } = useQuizResults(); const { setLoading } = useResultsLoading(); const handleSearchSubmit = async (event: any) => { @@ -43,7 +44,7 @@ const QuizResultsSearch = ({ id }: { id: string }) => {

Öz jogaplaryňyzy görüň

-
+
{ maxLength={8} minLength={8} /> + {phone && ( + + )}
); diff --git a/components/quiz/QuizResultsTabs.tsx b/components/quiz/QuizResultsTabs.tsx new file mode 100644 index 0000000..6e69a5a --- /dev/null +++ b/components/quiz/QuizResultsTabs.tsx @@ -0,0 +1,47 @@ +import { Question } from "@/models/quizQuestions.model"; +import React from "react"; + +interface IQuizTabProps { + steps: { + tapgyr: number; + questions: Question[]; + }[]; + setStep: React.Dispatch>; + tab: number | string; +} + +function QuizResultsTabs({ steps, setStep, tab }: IQuizTabProps) { + return ( +
+ {steps.map((item) => ( + + ))} + +
+ ); +} + +export default QuizResultsTabs; diff --git a/components/quiz/QuizTapgyrResults.tsx b/components/quiz/QuizTapgyrResults.tsx index 2af5b79..d8ceb79 100644 --- a/components/quiz/QuizTapgyrResults.tsx +++ b/components/quiz/QuizTapgyrResults.tsx @@ -73,8 +73,8 @@ const QuizTapgyrResults = ({ id, steps }: { id: string; steps: string[] }) => { {data.length > 0 && !loading && !searchLoading ? ( - // Table Head -
+
+ {/* Table Head */}
{((data[0] as Datum).client?.id || (data[0] as ISearchNetije).place) && ( @@ -87,15 +87,6 @@ const QuizTapgyrResults = ({ id, steps }: { id: string; steps: string[] }) => { Telefon beligisi )} - {data[0]?.tapgyr_breakdown && - steps.map((item) => ( - - Tapgyr {item} - - ))} {((data[0] as Datum).correct_answers_time || (data[0] as ISearchNetije).total_nobat) && ( { )}
{/* Table body */} -
+
{data.map((winner, id) => (
{ ? (winner as ISearchNetije).place : id + 1} -
- - + - {(winner as Datum).client?.phone - ? (winner as Datum).client?.phone - : (winner as ISearchNetije).phone - ? (winner as ISearchNetije).phone - : "-"} - - {steps.map((step, i) => ( - - Tapgyr {step} - - ))} -
- {steps.map((step, i) => { - const tapgyr = winner.tapgyr_breakdown?.find( - (i) => i.tapgyr === Number(step) - ); - return ( -
-
- - {tapgyr && "tapgyr_correct_time" in tapgyr - ? tapgyr.tapgyr_correct_time - : tapgyr && "tapgyr_total_nobat" in tapgyr - ? tapgyr.tapgyr_total_nobat - : "-"} - -
-
- - {tapgyr && "tapgyr_score" in tapgyr - ? tapgyr.tapgyr_score - : tapgyr && "tapgyr_total_score" in tapgyr - ? tapgyr.tapgyr_total_score - : "-"} - -
-
- ); - })} + + + + {(winner as Datum).client?.phone + ? (winner as Datum).client?.phone + : (winner as ISearchNetije).phone + ? (winner as ISearchNetije).phone + : "-"} +
@@ -196,24 +145,6 @@ const QuizTapgyrResults = ({ id, steps }: { id: string; steps: string[] }) => { : "-"}
- {steps.map((step, i) => { - const tapgyr = winner.tapgyr_breakdown?.find( - (i) => i.tapgyr === Number(step) - ); - return ( -
-
- - {tapgyr && "tapgyr_correct_time" in tapgyr - ? tapgyr.tapgyr_correct_time - : tapgyr && "tapgyr_total_nobat" in tapgyr - ? tapgyr.tapgyr_total_nobat - : "-"} - -
-
- ); - })}
{ : "-"}
- {steps.map((step, i) => { - const tapgyr = winner.tapgyr_breakdown?.find( - (i) => i.tapgyr === Number(step) - ); - return ( -
-
- - {tapgyr && "tapgyr_correct_time" in tapgyr - ? tapgyr.tapgyr_correct_time - : tapgyr && "tapgyr_total_nobat" in tapgyr - ? tapgyr.tapgyr_total_nobat - : "-"} - -
-
- ); - })}
- {/* {steps.map((step, i) => { - const tapgyr = winner.tapgyr_breakdown?.find( - (i) => i.tapgyr === Number(step) - ); - return ( -
- - Tapgyr {step} - -
-
- - {tapgyr ? tapgyr.tapgyr_correct_time : "-"} - -
-
-
-
- - {tapgyr ? tapgyr.tapgyr_correct_time : "-"} - -
-
-
- ); - })} */} ))}