fix(nav): fix exam flow navigation

chore(zustand): refactor auth code for zustand store
This commit is contained in:
shafin-r
2025-09-09 20:45:30 +06:00
parent c3ead879ad
commit 108d34988d
11 changed files with 172 additions and 126 deletions

View File

@ -13,7 +13,6 @@ import {
import DestructibleAlert from "@/components/DestructibleAlert";
import BackgroundWrapper from "@/components/BackgroundWrapper";
import { API_URL, getToken } from "@/lib/auth";
import { Test } from "@/types/exam";
import { Metadata } from "@/types/exam";
import { useExamStore } from "@/stores/examStore";
@ -21,15 +20,9 @@ function PretestPageContent() {
const router = useRouter();
const searchParams = useSearchParams();
const [examData, setExamData] = useState<Test>();
// Get params from URL search params
const id = searchParams.get("test_id") || "";
const typeParam = searchParams.get("type");
const type =
typeParam === "mock" || typeParam === "subject" || typeParam === "topic"
? typeParam
: null;
const type = searchParams.get("type");
const [metadata, setMetadata] = useState<Metadata | null>(null);
const [loading, setLoading] = useState(true);
@ -56,10 +49,8 @@ function PretestPageContent() {
const data = await questionResponse.json();
const fetchedMetadata: Metadata = data.metadata;
const fetchedQuestions: Test = data.questions;
setMetadata(fetchedMetadata);
setExamData(fetchedQuestions);
} catch (error) {
console.error(error);
setError(error instanceof Error ? error.message : "An error occurred");
@ -122,7 +113,7 @@ function PretestPageContent() {
}
function handleStartExam() {
if (!examData) return;
if (!metadata) return;
setStatus("in-progress");
router.push(
@ -135,7 +126,7 @@ function PretestPageContent() {
<div className="flex-1 overflow-y-auto mb-20">
{metadata ? (
<div className="mx-10 mt-10 gap-6 pb-6 space-y-6">
<button onClick={() => router.back()}>
<button onClick={() => router.replace(`/categories/${type}s`)}>
<ArrowLeft size={30} color="black" />
</button>