Fix admin consulting page query
Change from relationship query to manual join to avoid foreign key issues with profiles table 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -74,16 +74,38 @@ export default function AdminConsulting() {
|
||||
}, [user, isAdmin, authLoading]);
|
||||
|
||||
const fetchSlots = async () => {
|
||||
const { data, error } = await supabase
|
||||
// First fetch slots
|
||||
const { data: slotsData, error: slotsError } = await supabase
|
||||
.from('consulting_slots')
|
||||
.select(`
|
||||
*,
|
||||
profiles:user_id (name, email)
|
||||
`)
|
||||
.select('*')
|
||||
.order('date', { ascending: false })
|
||||
.order('start_time', { ascending: true });
|
||||
|
||||
if (!error && data) setSlots(data);
|
||||
if (slotsError || !slotsData) {
|
||||
console.error('Error fetching slots:', slotsError);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Then fetch profiles for each user_id
|
||||
const userIds = [...new Set(slotsData.map(s => s.user_id))];
|
||||
const { data: profilesData } = await supabase
|
||||
.from('profiles')
|
||||
.select('id, name, email')
|
||||
.in('id', userIds);
|
||||
|
||||
// Create a map for quick lookup
|
||||
const profilesMap = new Map(
|
||||
(profilesData || []).map(p => [p.id, { name: p.name, email: p.email }])
|
||||
);
|
||||
|
||||
// Combine slots with profile data
|
||||
const slotsWithProfiles = slotsData.map(slot => ({
|
||||
...slot,
|
||||
profiles: profilesMap.get(slot.user_id) || null
|
||||
}));
|
||||
|
||||
setSlots(slotsWithProfiles);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user