Changes
This commit is contained in:
@@ -42,11 +42,38 @@ export default function MemberDashboard() {
|
||||
}, [user, authLoading]);
|
||||
|
||||
const fetchData = async () => {
|
||||
const [accessRes, ordersRes] = await Promise.all([
|
||||
const [accessRes, ordersRes, paidOrdersRes] = await Promise.all([
|
||||
supabase.from('user_access').select(`id, product:products (id, title, slug, type, meeting_link, recording_url)`).eq('user_id', user!.id),
|
||||
supabase.from('orders').select('*').eq('user_id', user!.id).order('created_at', { ascending: false }).limit(3)
|
||||
supabase.from('orders').select('*').eq('user_id', user!.id).order('created_at', { ascending: false }).limit(3),
|
||||
// Also get products from paid orders (via order_items)
|
||||
supabase.from('orders')
|
||||
.select(`
|
||||
order_items (
|
||||
product:products (id, title, slug, type, meeting_link, recording_url)
|
||||
)
|
||||
`)
|
||||
.eq('user_id', user!.id)
|
||||
.eq('payment_status', 'paid')
|
||||
.eq('payment_provider', 'pakasir')
|
||||
]);
|
||||
if (accessRes.data) setAccess(accessRes.data as unknown as UserAccess[]);
|
||||
|
||||
// Combine access from user_access and paid orders
|
||||
const directAccess = accessRes.data as unknown as UserAccess[] || [];
|
||||
const paidProductAccess: UserAccess[] = [];
|
||||
|
||||
if (paidOrdersRes.data) {
|
||||
const existingIds = new Set(directAccess.map(a => a.product.id));
|
||||
paidOrdersRes.data.forEach((order: any) => {
|
||||
order.order_items?.forEach((item: any) => {
|
||||
if (item.product && !existingIds.has(item.product.id)) {
|
||||
existingIds.add(item.product.id);
|
||||
paidProductAccess.push({ id: `paid-${item.product.id}`, product: item.product });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
setAccess([...directAccess, ...paidProductAccess]);
|
||||
if (ordersRes.data) setRecentOrders(ordersRes.data);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user