From c6e996a220eaa0184bfa8251963e3dd80e99cfd1 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 7 Aug 2026 04:15:42 +0000 Subject: [PATCH] Modified by www.SourceFiles.app --- src/routes/_authenticated/students.index.tsx | 59 ++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/routes/_authenticated/students.index.tsx diff --git a/src/routes/_authenticated/students.index.tsx b/src/routes/_authenticated/students.index.tsx new file mode 100644 index 0000000..6a54276 --- /dev/null +++ b/src/routes/_authenticated/students.index.tsx @@ -0,0 +1,59 @@ +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.
} +
+
+ ); +}