Changes
Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
co-authored by
renee-png
parent
5489371d45
commit
cbea663981
@@ -125,7 +125,13 @@ function FormFillDialog({ formId, onClose, isAdmin }: { formId: string; onClose:
|
|||||||
|
|
||||||
const { data: responses } = useQuery({
|
const { data: responses } = useQuery({
|
||||||
queryKey: ["form-responses", formId],
|
queryKey: ["form-responses", formId],
|
||||||
queryFn: async () => (await supabase.from("form_responses").select("*, students(first_name, last_name), profiles!form_responses_submitted_by_fkey(full_name)").eq("form_id", formId).order("submitted_at", { ascending: false })).data ?? [],
|
queryFn: async () => {
|
||||||
|
const { data } = await supabase.from("form_responses").select("*, students(first_name, last_name)").eq("form_id", formId).order("submitted_at", { ascending: false });
|
||||||
|
const ids = Array.from(new Set((data ?? []).map((r) => r.submitted_by)));
|
||||||
|
const { data: profs } = ids.length ? await supabase.from("profiles").select("id, full_name").in("id", ids) : { data: [] };
|
||||||
|
const map = Object.fromEntries((profs ?? []).map((p) => [p.id, p.full_name]));
|
||||||
|
return (data ?? []).map((r) => ({ ...r, submitter_name: map[r.submitted_by] ?? "—" }));
|
||||||
|
},
|
||||||
enabled: isAdmin,
|
enabled: isAdmin,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user