Files
hats-app/app/(dashboard)/task/component/HomeTask.tsx
T
Ichsan Kurniawan f0cc469d24 Update client actions and dashboard labels
Show client edit and delete actions directly in grid and list views, simplify work-order and dashboard metric labels, and adjust spacing for milestone timelines without upcoming milestones.
2026-11-04 14:34:58 +07:00

131 lines
5.6 KiB
TypeScript

"use client";
import { useState } from 'react';
import { useRouter } from 'next/navigation';
import { Plus, Building2, FolderGit2, FileText, ClipboardClock } from 'lucide-react';
import { motion } from 'motion/react';
import { Button } from '@/components/ui/button';
import { Card900 } from '@/components/ui/card';
import dynamic from 'next/dynamic';
import FilterComponent from './FilterComponent';
const FormClient = dynamic(() => import('./client/FormClient'), { ssr: false });
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: 'Projects',
value: stats.activeProjects,
icon: FolderGit2,
trend: stats.projectsTrend,
},
{
title: 'Internal Memos',
value: stats.activeInternalMemos,
icon: ClipboardClock,
trend: stats.personnelTrend,
},
{
title: '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>
);
}