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?.length ?? 0} students visible to you
+