import { useEffect } from "react";
import { ArrowLeft, UserCircle2 } from "lucide-react";
import { Link, useParams } from "react-router-dom";
import { Badge } from "../../components/ui/badge";
import { Button } from "../../components/ui/button";
import { Card, CardContent } from "../../components/ui/card";
import { cn } from "../../lib/utils";
import { useUsersStore } from "../../zustand/userStore";
import { getUserById } from "../../api/users.api";
export function UserDetailPage() {
const { id } = useParams();
const userProfile = useUsersStore((s) => s.userProfile);
const setUserProfile = useUsersStore((s) => s.setUserProfile);
useEffect(() => {
if (!id) return;
const fetchUser = async () => {
try {
const res = await getUserById(Number(id));
setUserProfile(res.data.data);
} catch (err) {
console.error("Failed to fetch user profile", err);
setUserProfile(null);
}
};
fetchUser();
}, [id, setUserProfile]);
if (!userProfile) {
return (
User Detail
User not found
);
}
const user = userProfile;
const fullName = `${user.first_name} ${user.last_name}`;
return (
{/* Back Link */}
User Detail
{/* Left Column */}
{/* Basic Information */}
{user.profile_picture_url ? (

) : (
)}
{fullName}
ID: {user.id}
{user.status === "ACTIVE" ? "Active" : "Inactive"}
Phone
{user.phone_number || "-"}
Email
{user.email || "-"}
Region
{user.region || "-"}
Joined Date
{user.created_at ? new Date(user.created_at).toLocaleDateString() : "-"}
{/* Subscription */}
Subscription
{user.status === "ACTIVE" ? "Active" : "Inactive"}
Profile Completed
{user.profile_completed ? "Yes" : "No"}
Preferred Language
{user.preferred_language || "-"}
{/* Right Column */}
{/* Learning Profile */}
Education Level
{user.education_level || "-"}
Nick Name
{user.nick_name || "-"}
Occupation
{user.occupation || "-"}
Learning Goal
{user.learning_goal || "-"}
Language Challenge
{user.language_challange || "-"}
Favourite Topic
{user.favoutite_topic || "-"}
{/* Status / Dates */}
Last Login
{user.last_login ? new Date(user.last_login).toLocaleString() : "-"}
Updated At
{user.updated_at ? new Date(user.updated_at).toLocaleString() : "-"}
);
}