fix(api): fix api endpoint logic #1

This commit is contained in:
shafin-r
2025-08-10 19:25:25 +06:00
parent 0bca09f8ef
commit 713696760e
8 changed files with 138 additions and 84 deletions

View File

@ -22,13 +22,17 @@ export default function RegisterPage() {
const { setToken } = useAuth();
const router = useRouter();
const [form, setForm] = useState<RegisterForm>({
name: "",
institution: "",
sscRoll: "",
hscRoll: "",
full_name: "",
username: "",
email: "",
phone: "",
password: "",
phone_number: "",
ssc_roll: 0,
ssc_board: "",
hsc_roll: 0,
hsc_board: "",
college: "",
preparation_unit: "",
});
const [error, setError] = useState<string | null>(null);
@ -44,8 +48,8 @@ export default function RegisterPage() {
};
const validateForm = () => {
const { sscRoll, hscRoll, password } = form;
if (sscRoll === hscRoll) {
const { ssc_roll, hsc_roll, password } = form;
if (ssc_roll === hsc_roll) {
return "SSC Roll and HSC Roll must be unique.";
}
const passwordRegex =
@ -93,11 +97,11 @@ export default function RegisterPage() {
return (
<BackgroundWrapper>
<div className="min-h-screen flex flex-col items-center justify-center px-4 py-10">
<div className="w-full max-w-md space-y-6">
<div className="w-full space-y-6">
<div className="w-full aspect-[368/89] mx-auto">
<Image
src="/images/logo/logo.png"
alt="Logo"
alt="logo"
width={368}
height={89}
className="w-full h-auto"
@ -106,48 +110,34 @@ export default function RegisterPage() {
<div className="space-y-10">
<div className="space-y-6">
<h1 className="text-2xl font-semibold">Personal Info</h1>
<FormField
title="Full name"
value={form.name}
handleChangeText={(value) => setForm({ ...form, name: value })}
/>
<FormField
title="Institution"
value={form.institution}
value={form.full_name}
handleChangeText={(value) =>
setForm({ ...form, institution: value })
setForm({ ...form, full_name: value })
}
/>
<FormField
title="SSC Roll No."
value={form.sscRoll}
title="User name"
value={form.username}
handleChangeText={(value) =>
setForm({ ...form, sscRoll: value })
setForm({ ...form, username: value })
}
/>
<FormField
title="HSC Roll No."
value={form.hscRoll}
title="Phone Number"
value={form.phone_number}
handleChangeText={(value) =>
setForm({ ...form, hscRoll: value })
setForm({ ...form, phone_number: value })
}
/>
<FormField
title="Email Address"
value={form.email}
handleChangeText={(value) => setForm({ ...form, email: value })}
/>
<FormField
title="Phone Number"
value={form.phone}
handleChangeText={(value) => setForm({ ...form, phone: value })}
/>
<FormField
title="Password"
value={form.password}
@ -156,6 +146,58 @@ export default function RegisterPage() {
}
placeholder={undefined}
/>
<h1 className="text-2xl font-semibold">Educational Background</h1>
<FormField
title="College"
value={form.college}
handleChangeText={(value) =>
setForm({ ...form, college: value })
}
/>
<FormField
title="Preparation Unit"
value={form.preparation_unit}
handleChangeText={(value) =>
setForm({ ...form, preparation_unit: value })
}
/>
<div className="w-full flex gap-4">
<FormField
title="SSC Board"
value={form.ssc_board}
handleChangeText={(value) =>
setForm({ ...form, ssc_board: value })
}
/>
<FormField
title="SSC Roll No."
value={form.ssc_roll}
handleChangeText={(value: string) =>
setForm({ ...form, ssc_roll: Number(value) })
}
className="max-w-26"
/>
</div>
<div className="w-full flex gap-4">
<FormField
title="HSC Board"
value={form.hsc_board}
handleChangeText={(value) =>
setForm({ ...form, hsc_board: value })
}
/>
<FormField
title="HSC Roll No."
value={form.hsc_roll}
handleChangeText={(value: string) =>
setForm({ ...form, hsc_roll: Number(value) })
}
className="max-w-26"
/>
</div>
</div>
{error && <DestructibleAlert text={error} />}

View File

@ -2,7 +2,7 @@
import { useSearchParams } from "next/navigation";
import { useRouter } from "next/navigation";
import { Suspense, useEffect, useState } from "react";
import { useEffect, useState } from "react";
import Header from "@/components/Header";
import DestructibleAlert from "@/components/DestructibleAlert";
import BackgroundWrapper from "@/components/BackgroundWrapper";
@ -14,8 +14,7 @@ interface Mock {
title: string;
rating: number;
}
function PaperPageContent() {
export default function PaperScreen() {
const router = useRouter();
const searchParams = useSearchParams();
const name = searchParams.get("name") || "";
@ -23,6 +22,7 @@ function PaperPageContent() {
const [questions, setQuestions] = useState<Mock[] | null>(null);
const [errorMsg, setErrorMsg] = useState<string | null>(null);
const [refreshing, setRefreshing] = useState<boolean>(false);
const [componentKey, setComponentKey] = useState<number>(0);
async function fetchMocks() {
try {
@ -44,29 +44,31 @@ function PaperPageContent() {
const onRefresh = async () => {
setRefreshing(true);
await fetchMocks();
setComponentKey((prevKey) => prevKey + 1);
setTimeout(() => {
setRefreshing(false);
}, 1000);
};
if (errorMsg) {
return (
<BackgroundWrapper>
<div className="min-h-screen">
<Header displayTabTitle={name} />
<div className="overflow-y-auto">
<div className="mt-5 px-5">
<DestructibleAlert text={errorMsg} extraStyles="" />
</div>
<div className="flex justify-center mt-4">
<button
onClick={onRefresh}
disabled={refreshing}
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 disabled:opacity-50"
>
{refreshing ? <Loader /> : <RefreshCw />}
</button>
</div>
<Header displayTabTitle={name} />
<div className="overflow-y-auto">
<div className="mt-5 px-5">
<DestructibleAlert text={errorMsg} extraStyles="" />
</div>
<div className="flex justify-center mt-4">
<button
onClick={onRefresh}
disabled={refreshing}
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 disabled:opacity-50"
>
{refreshing ? <Loader /> : <RefreshCw />}
</button>
</div>
{/* <CustomBackHandler fallbackRoute="unit" /> */}
</div>
</BackgroundWrapper>
);
@ -118,20 +120,3 @@ function PaperPageContent() {
</BackgroundWrapper>
);
}
export default function PaperScreen() {
<Suspense
fallback={
<BackgroundWrapper>
<div className="min-h-screen">
<div className="mx-10 mt-10 flex flex-col justify-center items-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-900 mb-4"></div>
<p className="text-lg font-medium text-gray-900">Loading...</p>
</div>
</div>
</BackgroundWrapper>
}
>
<PaperPageContent />
</Suspense>;
}