generated from muhtadeetaron/nextjs-template
feat(zustand): add zustand stores for exam, timer and auth
This commit is contained in:
@ -8,6 +8,7 @@ import BackgroundWrapper from "@/components/BackgroundWrapper";
|
||||
import { API_URL, getToken } from "@/lib/auth";
|
||||
import { Loader, RefreshCw } from "lucide-react";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { useAuthStore } from "@/stores/authStore";
|
||||
|
||||
type Mock = {
|
||||
test_id: string;
|
||||
@ -22,7 +23,7 @@ type Mock = {
|
||||
|
||||
export default function MockScreen() {
|
||||
const router = useRouter();
|
||||
const { user } = useAuth();
|
||||
const { user } = useAuthStore();
|
||||
|
||||
const [mocks, setMocks] = useState<Mock[]>([]);
|
||||
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||
|
||||
@ -10,6 +10,7 @@ import { API_URL, getToken } from "@/lib/auth";
|
||||
import { Loader, RefreshCw } from "lucide-react";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { Question } from "@/types/exam";
|
||||
import { useAuthStore } from "@/stores/authStore";
|
||||
|
||||
type Subject = {
|
||||
subject_id: string;
|
||||
@ -19,7 +20,7 @@ type Subject = {
|
||||
|
||||
export default function PaperScreen() {
|
||||
const router = useRouter();
|
||||
const { user } = useAuth();
|
||||
const { user } = useAuthStore();
|
||||
|
||||
const [subjects, setSubjects] = useState<Subject[]>([]);
|
||||
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||
@ -70,7 +71,7 @@ export default function PaperScreen() {
|
||||
<Header displayTabTitle="Subjects" />
|
||||
<div className="overflow-y-auto">
|
||||
<div className="mt-5 px-5">
|
||||
<DestructibleAlert text={errorMsg} extraStyles="" />
|
||||
<DestructibleAlert text={errorMsg} />
|
||||
</div>
|
||||
<div className="flex justify-center mt-4">
|
||||
<button
|
||||
|
||||
@ -8,6 +8,7 @@ import BackgroundWrapper from "@/components/BackgroundWrapper";
|
||||
import { API_URL, getToken } from "@/lib/auth";
|
||||
import { Loader, RefreshCw } from "lucide-react";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { useAuthStore } from "@/stores/authStore";
|
||||
|
||||
type Topic = {
|
||||
topic_id: string;
|
||||
@ -21,7 +22,7 @@ type Topic = {
|
||||
|
||||
export default function TopicScreen() {
|
||||
const router = useRouter();
|
||||
const { user } = useAuth();
|
||||
const { user } = useAuthStore();
|
||||
|
||||
const [topics, setTopics] = useState<Topic[]>([]);
|
||||
const [errorMsg, setErrorMsg] = useState<string | null>(null);
|
||||
@ -72,7 +73,7 @@ export default function TopicScreen() {
|
||||
<Header displayTabTitle="Subjects" />
|
||||
<div className="overflow-y-auto">
|
||||
<div className="mt-5 px-5">
|
||||
<DestructibleAlert text={errorMsg} extraStyles="" />
|
||||
<DestructibleAlert text={errorMsg} />
|
||||
</div>
|
||||
<div className="flex justify-center mt-4">
|
||||
<button
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
import BackgroundWrapper from "@/components/BackgroundWrapper";
|
||||
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
|
||||
import { useAuth } from "@/context/AuthContext";
|
||||
import { clearAuthToken } from "@/lib/auth";
|
||||
import { useAuthStore } from "@/stores/authStore";
|
||||
import {
|
||||
Bookmark,
|
||||
ChartColumn,
|
||||
@ -23,10 +23,10 @@ import React from "react";
|
||||
|
||||
const SettingsPage = () => {
|
||||
const router = useRouter();
|
||||
const { user, isLoading } = useAuth();
|
||||
const { user, logout } = useAuthStore();
|
||||
|
||||
function handleLogout() {
|
||||
clearAuthToken();
|
||||
logout();
|
||||
router.replace("/");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user