Files
hats-app/app/(dashboard)/task/component/HomeTask.tsx
T
Ichsan Kurniawan 9a04ba7738 Revamp client overview dashboard
This update redesigns the task dashboard around client overview metrics, adding summary cards, project status breakdowns, and milestone timelines for each client. It also adds an active-first sort option, supports customizable search placeholders, and passes the full client list into the dashboard while wrapping the client views in Suspense for smoother loading.
2026-10-13 18:36:38 +07:00

129 lines
5.5 KiB
TypeScript

"use client";
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { Plus, Building2, FolderGit2, Users, FileText, TrendingUp } from 'lucide-react';
import { motion } from 'motion/react';
import { Button } from '@/components/ui/button';
import { Card900 } from '@/components/ui/card';
import FormClient from './client/FormClient';
import FilterComponent from './FilterComponent';
import { IClient } from '../types';
import { calculateOverviewStats } from '../utils/client-overview-helpers';
interface HomeTaskProps {
clients?: IClient[];
}
export default function HomeTask({ clients = [] }: HomeTaskProps) {
const router = useRouter();
const [showForm, setShowForm] = useState(false);
const stats = calculateOverviewStats(clients);
const statCards = [
{
title: 'Total Clients',
value: stats.totalClients,
icon: Building2,
trend: null,
},
{
title: 'Active Projects',
value: stats.activeProjects,
icon: FolderGit2,
trend: stats.projectsTrend,
},
{
title: 'Assigned Personnel',
value: stats.assignedPersonnel,
icon: Users,
trend: stats.personnelTrend,
},
{
title: 'Active Work Orders',
value: stats.activeWorkOrders,
icon: FileText,
trend: stats.workOrdersTrend,
},
];
return (
<div className="space-y-6">
{/* Header: Title + Subtitle + Action Button */}
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
<div>
<h1 className="text-2xl sm:text-3xl font-bold tracking-tight text-foreground">Client Overview</h1>
<p className="text-xs sm:text-sm text-muted-foreground mt-1 max-w-2xl">
Complete overview of all clients, projects, personnel and work orders in one place.
</p>
</div>
<div className="flex items-center gap-3 shrink-0">
<Button
className="gap-2 w-full sm:w-auto shrink-0 font-medium"
onClick={() => setShowForm(true)}
>
<Plus className="w-4 h-4" /> Add Client
</Button>
</div>
</div>
{/* Top Stat Cards (4 Cards Grid) */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-3 md:gap-4">
{statCards.map((card, idx) => {
const IconComponent = card.icon;
return (
<motion.div
key={card.title}
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.25, delay: idx * 0.05 }}
>
<Card900 className="relative overflow-hidden p-4 sm:p-5 shadow-xs hover:border-his transition-all duration-300 flex flex-row items-center gap-3.5 sm:gap-4">
<div className="w-8 h-8 md:w-12 md:h-12 rounded-xl bg-orange-500/10 dark:bg-orange-950/40 border border-orange-500/30 dark:border-orange-700/40 flex items-center justify-center shrink-0 text-orange-600 dark:text-orange-500 shadow-xs">
<IconComponent className="size-4 md:size-6" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs sm:text-[13px] font-medium text-muted-foreground truncate">{card.title}</p>
<div className="flex items-center gap-2.5 mt-0.5">
<span className="text-xl md:text-3xl font-extrabold tracking-tight text-foreground">
{card.value}
</span>
{card.trend && (
<div className="flex flex-col text-[10px] leading-tight font-medium pl-0.5">
<span className="text-emerald-600 dark:text-emerald-400 font-bold flex items-center gap-0.5 whitespace-nowrap">
↑ {card.trend}
</span>
<span className="text-muted-foreground text-[9px] sm:text-[10px] whitespace-nowrap">
vs last month
</span>
</div>
)}
</div>
</div>
</Card900>
</motion.div>
);
})}
</div>
{/* Filter and View Toggle */}
<FilterComponent
hideFilterModal
showLayoutToggle={true}
/>
{showForm && (
<FormClient
isRedirectToDetail
onCancel={() => setShowForm(false)}
onSuccess={() => {
setShowForm(false);
router.refresh();
}}
/>
)}
</div>
);
}