Files
fabrikanabytok/apps/fabrikanabytok/app/(platform)/admin/customers/page.tsx
2025-11-28 20:47:59 +01:00

125 lines
4.4 KiB
TypeScript

import { getAllCustomers } from "@/lib/actions/customer.actions"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
import { Users, Building, UserPlus, TrendingUp } from "lucide-react"
import { CustomersTable } from "@/components/admin/customers-table"
import Link from "next/link"
export const dynamic = "force-dynamic"
export const metadata = {
title: "Ügyfelek - Admin - FABRIKA NABYTOK",
description: "Ügyfél és partner kezelés",
}
interface PageProps {
searchParams: Promise<{
type?: string
category?: string
status?: string
search?: string
}>
}
export default async function CustomersPage({ searchParams }: PageProps) {
const params = await searchParams
const result = await getAllCustomers(params)
const customers = result.success ? result.customers : []
// Calculate stats
const totalCustomers = customers.length
const activeCustomers = customers.filter((c: any) => c.status === "active").length
const companies = customers.filter((c: any) => c.type === "company").length
const individuals = customers.filter((c: any) => c.type === "individual").length
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold">Ügyfelek & Partnerek</h1>
<p className="text-muted-foreground mt-2">Kezelje az ügyfeleket és partnereket</p>
</div>
<Button asChild>
<Link href="/admin/customers/new">
<UserPlus className="w-4 h-4 mr-2" />
Új ügyfél
</Link>
</Button>
</div>
{/* Stats */}
<div className="grid gap-6 md:grid-cols-4">
<Card>
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium">Összes ügyfél</CardTitle>
<Users className="w-4 h-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{totalCustomers}</div>
<p className="text-xs text-muted-foreground mt-1">
{activeCustomers} aktív
</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium">Cégek</CardTitle>
<Building className="w-4 h-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{companies}</div>
<p className="text-xs text-muted-foreground mt-1">
{((companies / totalCustomers) * 100 || 0).toFixed(0)}% az összes ügyf élből
</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium">Magánszemélyek</CardTitle>
<Users className="w-4 h-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{individuals}</div>
<p className="text-xs text-muted-foreground mt-1">
{((individuals / totalCustomers) * 100 || 0).toFixed(0)}% az összes ügyf élből
</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium">Átlag rendelésérték</CardTitle>
<TrendingUp className="w-4 h-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">
{customers
.reduce((sum: number, c: any) => sum + (c.averageOrderValue || 0), 0)
.toLocaleString("hu-HU")}{" "}
Ft
</div>
<p className="text-xs text-muted-foreground mt-1">
Összes ügyfél alapján
</p>
</CardContent>
</Card>
</div>
{/* Customers Table */}
<Card>
<CardHeader>
<CardTitle>Összes ügyfél</CardTitle>
<CardDescription>Kezelje és kövesse nyomon az ügyfeleit</CardDescription>
</CardHeader>
<CardContent>
<CustomersTable customers={customers} />
</CardContent>
</Card>
</div>
)
}