Files
isletmem-kovakcrm/src/app/(dashboard)/dashboard/page.tsx
T
kovakmedya f11cd099f6 feat(dashboard): real data — metrics, charts, top customers, recent transactions
Dashboard is no longer mock data. Single getDashboardData(tenantId) server
query computes everything in one pass.

New aggregator (lib/appwrite/dashboard-queries.ts):
- Pulls customers, invoices, finance_entries, tasks, services in parallel.
- Derives:
  * metrics: totalCustomers, activeCustomers, monthIncome,
    prevMonthIncome (for delta), outstanding (unpaid invoice total),
    overdueCount, openTasks, urgentTasks
  * monthlyIncome: 12-month income+expense series for area chart
  * topCustomers: 5 highest-grossing customers by paid invoice total
  * recentTransactions: 8 newest finance entries
  * topServices: 5 services by aggregate unit price (placeholder, will
    refine when we have invoice line analytics)
  * newCustomersMonthly: 6-month new customer count for bar chart

Components (dashboard/components/):
- Metrics: 4 cards with trend indicator on income (delta vs previous
  month), warning tone on overdue invoices and urgent tasks.
- IncomeChart: Recharts Area chart, dual income/expense series with
  gradient fills, Turkish month labels.
- TopCustomers: ranked list with progress bars relative to top earner.
- RecentTransactions: list with type badge, signed amount, link to
  /finance for full list.
- CustomerGrowth: BarChart of new customers per month (last 6).
- QuickActions: 4 buttons linking to /customers, /invoices, /calendar,
  /tasks (replaced template's New User/Add Product/etc).

Layout: 4 metric cards row, then income chart + top customers (2-col),
then recent transactions + customer growth (2-col).

Removed:
- src/app/(dashboard)/dashboard-2/ (was the demo page; same components
  re-exported into the real /dashboard from there. Now /dashboard owns
  its components.)
- 'Dashboard 2' entry from CommandSearch; replaced with our actual
  module list (Müşteriler / Hizmetler / Yazılımlarımız / Takvim /
  Görevler / Gelir-Gider / Faturalar).
2026-04-30 06:19:44 +03:00

53 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { redirect } from "next/navigation";
import { getActiveContext } from "@/lib/appwrite/active-context";
import { getDashboardData } from "@/lib/appwrite/dashboard-queries";
import { CustomerGrowth } from "./components/customer-growth";
import { IncomeChart } from "./components/income-chart";
import { Metrics } from "./components/metrics";
import { QuickActions } from "./components/quick-actions";
import { RecentTransactions } from "./components/recent-transactions";
import { TopCustomers } from "./components/top-customers";
export default async function DashboardPage() {
const ctx = await getActiveContext();
if (!ctx) redirect("/onboarding");
const data = await getDashboardData(ctx.tenantId);
const firstName = ctx.user.name?.split(" ")[0] ?? "";
const companyName = ctx.settings?.companyName ?? "Çalışma alanı";
return (
<div className="flex-1 space-y-6 px-6 pt-0">
<div className="flex flex-col justify-between gap-4 md:flex-row md:items-center md:gap-6">
<div className="flex flex-col gap-1">
<p className="text-muted-foreground text-sm">{companyName}</p>
<h1 className="text-2xl font-bold tracking-tight">
{firstName ? `Hoş geldiniz, ${firstName}` : "Genel bakış"}
</h1>
<p className="text-muted-foreground text-sm">
İşletmenizin temel metriklerini ve son hareketleri buradan takip edin.
</p>
</div>
<QuickActions />
</div>
<div className="@container/main space-y-6">
<Metrics data={data.metrics} />
<div className="grid grid-cols-1 gap-6 @5xl:grid-cols-2">
<IncomeChart data={data.monthlyIncome} />
<TopCustomers data={data.topCustomers} />
</div>
<div className="grid grid-cols-1 gap-6 @5xl:grid-cols-2">
<RecentTransactions data={data.recentTransactions} />
<CustomerGrowth data={data.newCustomersMonthly} />
</div>
</div>
</div>
);
}