import React from 'react'; import { Users, Search, Plus, Mail, Phone, MoreHorizontal, ArrowUpRight } from 'lucide-react'; import { supabaseAdmin } from '@/lib/supabase'; async function getCustomers() { const { data: transactions, error } = await supabaseAdmin .from('transactions') .select('*'); if (error || !transactions) return null; // Group transactions by name or phone const customerMap = new Map(); transactions.forEach(t => { const key = t.customer_name || t.customer_phone || 'Unknown'; if (!customerMap.has(key)) { customerMap.set(key, { id: t.id, name: t.customer_name || 'İsimsiz Müşteri', phone: t.customer_phone || 'Telefon Yok', spent: 0, orders: 0, status: 'New' }); } const c = customerMap.get(key); c.orders += 1; if (t.status === 'succeeded') { c.spent += Number(t.amount); } }); const customers = Array.from(customerMap.values()).map(c => { if (c.orders > 5) c.status = 'High Value'; else if (c.orders > 1) c.status = 'Active'; return c; }); return customers; } export default async function CustomersPage() { const customers = await getCustomers(); if (!customers) return
Müşteri portföyünüzü yönetin
{customers.length.toLocaleString('tr-TR')}
Toplam Müşteri
Gerçek
Canlı Veri
{customers.filter(c => c.phone !== 'Telefon Yok').length}
Telefon Kayıtlı
| Müşteri Bilgileri | Segment | Sipariş | Toplam Harcama | Aksiyonlar |
|---|---|---|---|---|
|
{customer.name.slice(0, 2).toUpperCase()}
{customer.name}
{customer.phone}
|
{customer.status === 'Active' ? 'Aktif' : customer.status === 'High Value' ? 'VIP' : customer.status === 'New' ? 'Yeni Üye' : 'İnaktif'} | {customer.orders} | {customer.spent.toLocaleString('tr-TR', { minimumFractionDigits: 2 })} ₺ |
|