import { createFileRoute, Link } from "@tanstack/react-router"; import { useQuery } from "@tanstack/react-query"; import { supabase } from "@/integrations/supabase/client"; import { useAuth } from "@/hooks/use-auth"; import { Button } from "@/components/ui/button"; import { Plus, ChevronRight } from "lucide-react"; export const Route = createFileRoute("/_authenticated/students/")({ head: () => ({ meta: [{ title: "Students — School Portal" }] }), component: StudentsIndexPage, }); function StudentsIndexPage() { const { roles } = useAuth(); const isAdmin = roles.includes("admin"); const { data: students } = useQuery({ queryKey: ["students"], queryFn: async () => { const { data, error } = await supabase .from("students") .select("id, first_name, last_name, dob, allergies, photo_release, class_id, classes(name)") .order("last_name"); if (error) throw error; return data ?? []; }, }); return (

Students

{students?.length ?? 0} students visible to you

{isAdmin && ( )}
{(students ?? []).map((s) => (
{s.last_name}, {s.first_name}
{(s.classes as { name: string } | null)?.name ?? "No class"} · {s.allergies ? `Allergies: ${s.allergies}` : "No allergies"}
))} {students?.length === 0 &&
No students yet.
}
); }