"use client"; import { useEffect } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useAuth } from "@/components/AuthProvider"; import { useCachedFetch } from "@/hooks/useCachedFetch"; import { Smartphone, FileText, MapPin } from "lucide-react"; import { Skeleton } from "@/components/ui/Skeleton"; interface Issue { id: string; description: string; priority: number | null; state: string; city: string | null; locality: string | null; full_address: string | null; created_at: string; category: string | null; confidence: number | null; image_urls: string[]; annotated_urls: string[]; sla_deadline: string | null; } interface IssuesResponse { items: Issue[]; } export default function UserDashboard() { const { user, role, signOut, loading: authLoading } = useAuth(); const router = useRouter(); useEffect(() => { if (!authLoading) { if (role !== "user") { router.push("/signin"); } } }, [authLoading, role, router]); // Only fetch if user ID is available const fetchUrl = user?.id ? `/issues?user_id=${user.id}` : ""; const { data: issuesResponse, loading: issuesLoading } = useCachedFetch(fetchUrl); const issues = issuesResponse?.items || []; const contentLoading = issuesLoading && !issuesResponse; const getStateBadge = (state: string) => { const styles: Record = { reported: "bg-blue-100 text-blue-800", assigned: "bg-yellow-100 text-yellow-800", in_progress: "bg-orange-100 text-orange-800", resolved: "bg-green-100 text-green-800", closed: "bg-slate-100 text-slate-600", escalated: "bg-red-100 text-red-800", validated: "bg-emerald-100 text-emerald-800", pending_confirmation: "bg-slate-200 text-slate-700", pending_verification: "bg-indigo-100 text-indigo-800", }; return ( {state.replace("_", " ").toUpperCase()} ); }; if (authLoading) { return (
Loading Dashboard...
); } return (

Report an Issue

Notice something wrong in your neighborhood? Use our mobile app to report issues with instant GPS tagging and AI verification.

Available for

Android & iOS

Total Reports

{contentLoading ? ( ) : (

{issues.length}

)}

Resolved

{contentLoading ? ( ) : (

{issues.filter((i) => i.state === "resolved").length}

)}

Active Cases

{contentLoading ? ( ) : (

{ issues.filter((i) => [ "reported", "assigned", "in_progress", "pending_verification", ].includes(i.state), ).length }

)}

Efficiency

{contentLoading ? ( ) : (

{issues.length > 0 ? Math.round( (issues.filter((i) => i.state === "resolved").length / issues.length) * 100, ) : 0} %

)}

My Activity

List of all reports submitted by you

{contentLoading ? (
{Array.from({ length: 4 }).map((_, idx) => (
))}
) : issues.length === 0 ? (

No reports found

Your report history will appear here once you submit an issue through the app.

) : (
{issues.map((issue) => (
{getStateBadge(issue.state)} {issue.category || "General"}
{new Date(issue.created_at).toLocaleDateString(undefined, { month: "short", day: "numeric", year: "numeric", })}

{issue.description || "No description provided"}

{issue.full_address || [issue.locality, issue.city] .filter(Boolean) .join(", ") || "Location pending"}
{issue.image_urls?.[0] && (
Issue
)}
))}
)}
); }