import { useEffect } from "react"; import { ArrowLeft, BookOpen, Calendar, CheckCircle2, Globe, GraduationCap, Mail, MapPin, Phone, PlayCircle, RefreshCw, Target, UserPlus, } 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, CardHeader, CardTitle } from "../../components/ui/card"; import { Separator } from "../../components/ui/separator"; import { Avatar, AvatarFallback, AvatarImage } from "../../components/ui/avatar"; import { cn } from "../../lib/utils"; import { useUsersStore } from "../../zustand/userStore"; import { getUserById } from "../../api/users.api"; const activityIcons: Record = { completed: CheckCircle2, started: PlayCircle, joined: UserPlus, }; 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 not found
); } const user = userProfile; const fullName = `${user.first_name} ${user.last_name}`; const initials = `${user.first_name?.[0] ?? ""}${user.last_name?.[0] ?? ""}`.toUpperCase(); const recentActivities = [ { type: "completed", text: "Completed Unit 4: Business Emails", time: "Today, 10:27 AM" }, { type: "completed", text: "Completed Unit 3: Formal Writing", time: "Yesterday, 3:45 PM" }, { type: "started", text: "Started Learning Path: Business English", time: "Jan 15, 2025" }, { type: "joined", text: "Joined Yimaru", time: "Jan 10, 2025" }, ]; const infoFields = [ { icon: Phone, label: "Phone", value: user.phone_number }, { icon: Mail, label: "Email", value: user.email }, { icon: Globe, label: "Country", value: user.country || "Ethiopia" }, { icon: MapPin, label: "Region", value: user.region }, ]; return (
Back to Users
{/* ── Left column ── */}
{/* Profile card */}
{initials}

{fullName}

{user.status === "ACTIVE" ? "Active" : "Inactive"}
{infoFields.map(({ icon: Icon, label, value }) => (
{label}
{value || "—"}
))}
Joined
{user.created_at ? new Date(user.created_at).toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric", }) : "—"}
{/* Subscription card */}
Subscription {user.status === "ACTIVE" ? "Active" : "Inactive"}
Plan 6-Month
Expires
Nov 13, 2025 3 days left
{/* ── Right column ── */}
{/* Learning profile */}
Learning Profile
Proficiency
Intermediate B1
Primary Goal
{user.learning_goal || "Improve business communication skills for professional advancement"}
{/* Recent activity */}
Recent Activity
{recentActivities.map((activity, index) => { const Icon = activityIcons[activity.type] ?? CheckCircle2; const isLast = index === recentActivities.length - 1; return (
{!isLast && (
)}
{activity.text}
{activity.time}
); })}
); } function InfoItem({ label, value }: { label: string; value: string }) { return (
{label}
{value}
); } function TagItem({ label, value }: { label: string; value: string }) { return (
{label}
{value}
); }