Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
002f4d00f0
commit
79d124e188
@@ -162,13 +162,22 @@ function LinksTab() {
|
|||||||
|
|
||||||
const { data: links } = useQuery({
|
const { data: links } = useQuery({
|
||||||
queryKey: ["admin-links"],
|
queryKey: ["admin-links"],
|
||||||
queryFn: async () => (await supabase.from("parent_students").select("id, profiles!parent_students_parent_id_fkey(full_name, email), students(first_name, last_name)")).data ?? [],
|
queryFn: async () => {
|
||||||
|
const { data } = await supabase.from("parent_students").select("id, parent_id, students(first_name, last_name)");
|
||||||
|
const ids = (data ?? []).map((d) => d.parent_id);
|
||||||
|
const { data: profs } = ids.length ? await supabase.from("profiles").select("id, full_name, email").in("id", ids) : { data: [] };
|
||||||
|
const map = Object.fromEntries((profs ?? []).map((p) => [p.id, p]));
|
||||||
|
return (data ?? []).map((d) => ({ ...d, profile: map[d.parent_id] }));
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const { data: parents } = useQuery({
|
const { data: parents } = useQuery({
|
||||||
queryKey: ["all-parents"],
|
queryKey: ["all-parents"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const { data } = await supabase.from("user_roles").select("profiles(id, full_name, email)").eq("role", "parent");
|
const { data: r } = await supabase.from("user_roles").select("user_id").eq("role", "parent");
|
||||||
return (data ?? []).map((d) => d.profiles as { id: string; full_name: string; email: string }).filter(Boolean);
|
const ids = (r ?? []).map((x) => x.user_id);
|
||||||
|
if (ids.length === 0) return [];
|
||||||
|
const { data } = await supabase.from("profiles").select("id, full_name, email").in("id", ids);
|
||||||
|
return data ?? [];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { data: students } = useQuery({
|
const { data: students } = useQuery({
|
||||||
|
|||||||
Reference in New Issue
Block a user