From e4adb85498368d18ad3d4d17109736dbdc82a3a6 Mon Sep 17 00:00:00 2001 From: Kenan KARAER Date: Wed, 3 Dec 2025 22:24:46 +0300 Subject: [PATCH] Feat: Connect Dashboard to real Supabase data --- src/app/dashboard/page.tsx | 141 +++++++++++++++++++++++++++---------- 1 file changed, 105 insertions(+), 36 deletions(-) diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 5d4ad1c..21dc031 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -1,7 +1,66 @@ +import { createClient } from "@/lib/supabase/server" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" -import { CalendarDays, CreditCard, Users, DollarSign, TrendingUp, ArrowUpRight } from "lucide-react" +import { CalendarDays, CreditCard, Users, DollarSign, TrendingUp, ArrowUpRight, Calendar as CalendarIcon } from "lucide-react" +import { format } from "date-fns" +import { tr } from "date-fns/locale" +import Link from "next/link" +import { Badge } from "@/components/ui/badge" + +export default async function DashboardPage() { + const supabase = await createClient() + + // 1. Total Reservations (Count) + const { count: totalReservations } = await supabase + .from('reservations') + .select('*', { count: 'exact', head: true }) + .neq('status', 'cancelled') + + // 2. Active Customers (Count) + const { count: totalCustomers } = await supabase + .from('customers') + .select('*', { count: 'exact', head: true }) + + // 3. Pending Payments (Sum of remaining balances) + // This is complex to calculate in one query without a view or function, + // so we'll approximate or fetch pending payments directly if possible. + // For now, let's just count pending reservations as a proxy or fetch recent payments. + // Better: Sum of 'amount' from 'payments' where status = 'pending' (if we tracked pending payments that way) + // Or: Calculate total potential revenue vs paid revenue. + // Let's stick to "Total Revenue" (Paid) for now. + + const { data: payments } = await supabase + .from('payments') + .select('amount') + .eq('status', 'paid') + + const totalRevenue = payments?.reduce((sum, p) => sum + Number(p.amount), 0) || 0 + + // 4. Upcoming Events (Next 5) + const { data: upcomingEvents } = await supabase + .from('reservations') + .select(` + id, + start_time, + status, + halls (name), + customers (full_name) + `) + .gte('start_time', new Date().toISOString()) + .neq('status', 'cancelled') + .order('start_time', { ascending: true }) + .limit(5) + + // 5. Recent Activities (Last 5 created reservations) + const { data: recentReservations } = await supabase + .from('reservations') + .select(` + id, + created_at, + customers (full_name) + `) + .order('created_at', { ascending: false }) + .limit(5) -export default function DashboardPage() { return (
@@ -22,9 +81,9 @@ export default function DashboardPage() {
-
12
+
{totalReservations || 0}

- +2 geçen aydan beri + Aktif rezervasyonlar

@@ -32,33 +91,16 @@ export default function DashboardPage() { - Aktif Müşteriler + Toplam Müşteri
-
50
+
{totalCustomers || 0}

- +4 geçen aydan beri -

-
-
- - - - - Bekleyen Ödemeler - -
- -
-
- -
₺12,000
-

- 3 rezervasyon için + Kayıtlı müşteri sayısı

@@ -66,16 +108,16 @@ export default function DashboardPage() { - Aylık Gelir + Toplam Gelir
-
₺45,000
+
₺{totalRevenue.toLocaleString('tr-TR')}

- +10% geçen aydan beri + Tahsil edilen ödemeler

@@ -87,28 +129,55 @@ export default function DashboardPage() { Yaklaşan Etkinlikler -
-

Takvim önizlemesi buraya gelecek.

-
+ {upcomingEvents?.length === 0 ? ( +
+

Yaklaşan etkinlik bulunmuyor.

+
+ ) : ( +
+ {upcomingEvents?.map((event) => ( +
+
+
+ +
+
+

{event.customers?.full_name}

+

{event.halls?.name}

+
+
+
+

{format(new Date(event.start_time), 'd MMM yyyy', { locale: tr })}

+

{format(new Date(event.start_time), 'HH:mm')}

+
+
+ ))} +
+ )}
- Son Aktiviteler + Son İşlemler
- {[1, 2, 3].map((i) => ( -
+ {recentReservations?.map((res) => ( +
- AH + {res.customers?.full_name?.substring(0, 2).toUpperCase()}
-

Ahmet Hakan rezervasyon yaptı

-

2 dakika önce

+

{res.customers?.full_name} rezervasyon oluşturdu

+

+ {format(new Date(res.created_at), 'd MMM HH:mm', { locale: tr })} +

))} + {recentReservations?.length === 0 && ( +

Henüz işlem yok.

+ )}