fix(ui): fix question item answer indexing in results page

This commit is contained in:
shafin-r
2025-07-25 19:09:06 +06:00
parent d57aa9b073
commit 0ea199c0fe
4 changed files with 82 additions and 43 deletions

View File

@ -2,8 +2,6 @@
import ProfileManager from "@/components/ProfileManager";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { getToken, API_URL } from "@/lib/auth";
import { ChevronLeft, Edit2, Lock, Save } from "lucide-react";
import { useRouter } from "next/navigation";
@ -49,8 +47,34 @@ const ProfilePage = () => {
fetchUser();
}, []);
const handleSave = async () => {
// try {
// const token = await getToken();
// if (!token || !userData) return;
// const response = await fetch(`${API_URL}/profile/edit`, {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// Authorization: `Bearer ${token}`,
// },
// body: JSON.stringify(userData),
// });
// if (response.ok) {
// setEditStatus(false);
// } else {
// console.error("Failed to save profile");
// }
// } catch (error) {
// console.error("Error saving profile:", error);
// }
console.log("Updated user data:", userData);
setEditStatus(false);
};
return (
<section className="min-h-screen mb-32 ">
<section className="min-h-screen mb-32">
<div className="h-48 bg-gradient-to-b from-[#113768] to-white w-full">
<button
onClick={() => router.push("/settings")}
@ -59,16 +83,26 @@ const ProfilePage = () => {
<ChevronLeft size={30} color="white" />
</button>
</div>
<div className="relative mx-10">
<Avatar className="bg-[#113768] w-32 h-32 absolute -top-20 left-1/2 transform -translate-x-1/2">
<AvatarFallback className="text-3xl text-white">
{userData?.name ? userData.name.charAt(0).toUpperCase() : ""}
</AvatarFallback>
</Avatar>
<div className="pt-14 space-y-8">
<ProfileManager userData={userData} edit={editStatus} />
<ProfileManager
userData={userData}
edit={editStatus}
setUserData={setUserData}
/>
<button
onClick={() => setEditStatus(!editStatus)}
onClick={() => {
if (editStatus) handleSave();
else setEditStatus(true);
}}
className={`p-3 ${
editStatus ? "bg-green-500" : "bg-[#113768]"
} w-full flex gap-3 justify-center items-center rounded-full`}
@ -78,11 +112,11 @@ const ProfilePage = () => {
) : (
<Edit2 size={20} color="white" />
)}
<p className="text-white">
{editStatus ? "Save Changes" : "Edit Profile"}
</p>
</button>
<button className="p-3 bg-[#113768] w-full flex gap-3 justify-center items-center rounded-full">
<Lock size={20} color="white" />
<p className="text-white">Change Password</p>

View File

@ -102,7 +102,7 @@ export default function ResultsPage() {
<QuestionItem
key={question.id}
question={question}
selectedAnswer={currentAttempt.answers[question.id]}
selectedAnswer={currentAttempt.answers[question.id - 1]}
mode="result"
/>
))}