mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
78f48d783f
Introduce client and assignment detail pages and client-side components for the Task dashboard. Adds interactive ClientDetailComponent, AssignmentDetailComponent, page entries (server + dummy variants), project-assignment form, various UI components (AssignmentTable, ClientGrid, ManageEmployee, FormUpdateStatus, ConfirmDelete, LazyImage helper), types and a dummy data hook. Update app/(dashboard)/task/page.tsx to use the new components. Update .env.development to point to dev API endpoints, bump NEXT_PUBLIC_APP_VERSION to v1.2.0 and add NEXT_PUBLIC_S3_IMAGE_URL.
340 lines
24 KiB
TypeScript
340 lines
24 KiB
TypeScript
"use client"
|
|
|
|
import { motion } from 'motion/react';
|
|
import { Plus, Search, MoreHorizontal, ExternalLink, Users, LayoutGrid, List } from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Card, CardContent } from '@/components/ui/card';
|
|
import {
|
|
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
|
} from '@/components/ui/dropdown-menu';
|
|
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|
import {
|
|
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
|
} from '@/components/ui/table';
|
|
import {
|
|
Tooltip, TooltipContent, TooltipTrigger,
|
|
} from '@/components/ui/tooltip';
|
|
import { useState } from 'react';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { cn } from '@/lib/utils';
|
|
import { useAppState } from '@/hooks/useDummyTaskData';
|
|
import Link from 'next/link';
|
|
import { LazyImage } from '@/components/ui/lazy-image';
|
|
import { DUMMY_EMPLOYEES, IClient } from './types';
|
|
import ClientForm from './component/FormClient';
|
|
|
|
export default function Clients() {
|
|
const [search, setSearch] = useState('');
|
|
const [view, setView] = useState<'grid' | 'table'>('grid');
|
|
const [selectedData, setSelectedData] = useState<IClient | undefined>()
|
|
const [showForm, setShowForm] = useState(false)
|
|
|
|
const { clients, assignments } = useAppState();
|
|
|
|
const filteredClients = clients.filter((c) =>
|
|
c.name.toLowerCase().includes(search.toLowerCase()) ||
|
|
c.endUser.toLowerCase().includes(search.toLowerCase())
|
|
);
|
|
|
|
// Flatten data for table view
|
|
const masterData = assignments.flatMap((assignment: any) => {
|
|
const client = clients.find(c => c.id === assignment.clientId);
|
|
if (!client) return [];
|
|
|
|
// If no work orders, still show the assignment?
|
|
// The user image shows WO details, so usually it's WO based.
|
|
if (assignment.workOrder) {
|
|
return [{
|
|
client,
|
|
assignment,
|
|
wo: null
|
|
}];
|
|
}
|
|
|
|
return assignment.workOrder.map((wo: any) => ({
|
|
client,
|
|
assignment,
|
|
wo
|
|
}));
|
|
}).filter((item: any) =>
|
|
item.client.name.toLowerCase().includes(search.toLowerCase()) ||
|
|
item.assignment.name.toLowerCase().includes(search.toLowerCase()) ||
|
|
(item.wo?.name.toLowerCase().includes(search.toLowerCase()) ?? false)
|
|
);
|
|
|
|
const handleClose = () => {
|
|
setSelectedData(undefined)
|
|
setShowForm(false)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<motion.div
|
|
initial={{ opacity: 0, x: 20 }}
|
|
animate={{ opacity: 1, x: 0 }}
|
|
exit={{ opacity: 0, x: -20 }}
|
|
className="flex-1 space-y-8 p-6 sm:p-8 pt-6"
|
|
>
|
|
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
|
<div>
|
|
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">My Task & Projects</h1>
|
|
<p className="text-xs md:text-base text-muted-foreground w-full lg:w-1/2 xl:w-3/4 mt-2">Something that can be done at any time is often done at no time. Do it now, or decide when you'll do it.</p>
|
|
</div>
|
|
<div className="flex items-center gap-3">
|
|
<Tabs value={view} onValueChange={(v) => setView(v as 'grid' | 'table')} className="w-auto">
|
|
<TabsList>
|
|
<TabsTrigger value="grid" className="gap-2">
|
|
<LayoutGrid className="w-4 h-4" />
|
|
Grid
|
|
</TabsTrigger>
|
|
<TabsTrigger value="table" className="gap-2">
|
|
<List className="w-4 h-4" />
|
|
Table
|
|
</TabsTrigger>
|
|
</TabsList>
|
|
</Tabs>
|
|
<Button className="gap-2" onClick={() => setShowForm(true)}><Plus className="w-4 h-4" />Add Client</Button>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="relative">
|
|
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
|
<Input
|
|
placeholder="Search clients, projects, or work orders..."
|
|
className="pl-10"
|
|
value={search}
|
|
onChange={(e) => setSearch(e.target.value)}
|
|
/>
|
|
</div>
|
|
|
|
{view === 'grid' ? (
|
|
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
{filteredClients.map((client, i) => {
|
|
const clientAssignments = assignments.filter(a => a.clientId === client.id);
|
|
const imCount = clientAssignments.filter(a => a.type === 'IM').length;
|
|
const projectCount = clientAssignments.filter(a => a.type === 'Project').length;
|
|
// const woCount = clientAssignments.reduce((acc, a) => acc + a.workOrders.length, 0);
|
|
const woCount = 1
|
|
const assignedEmployeeIds = Array.from(new Set(clientAssignments.flatMap(a => a.assignedEmployees)));
|
|
|
|
return (
|
|
<motion.div
|
|
key={client.id}
|
|
initial={{ opacity: 0, scale: 0.95 }}
|
|
animate={{ opacity: 1, scale: 1 }}
|
|
transition={{ delay: i * 0.05 }}
|
|
className="h-full"
|
|
>
|
|
<Card className="h-full group overflow-hidden hover:shadow-lg transition-all duration-300 border-primary/5 hover:border-primary/20 flex flex-col py-0">
|
|
<CardContent className="p-0 flex flex-col h-full">
|
|
<div className="relative h-32 bg-accent/50 overflow-hidden">
|
|
<LazyImage
|
|
src={client.imageUrl}
|
|
alt={client.name}
|
|
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
|
|
/>
|
|
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/40 to-transparent" />
|
|
<div className="absolute bottom-4 left-4 right-4 flex items-end justify-between">
|
|
<div className="text-white">
|
|
<h3 className="font-bold text-lg leading-tight">{client.name}</h3>
|
|
<p className="text-xs opacity-80">{client.endUser}</p>
|
|
</div>
|
|
<Link href={`/task/client-detail/${client.id}`}>
|
|
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity">
|
|
<ExternalLink className="w-4 h-4" />
|
|
</Button>
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
<div className="p-5 flex flex-col flex-1 justify-between gap-4">
|
|
<div className="space-y-2">
|
|
{/* <p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
|
Currently managing a portfolio of <span className="font-bold text-foreground">{projectCount} projects</span> and <span className="font-bold text-foreground">{imCount} internal memos</span>.
|
|
A dedicated team of <span className="font-bold text-foreground">{assignedEmployeeIds.length} experts</span> is handling <span className="font-bold text-foreground">{woCount} work orders</span> to ensure successful delivery for <span className="italic">{client.endUser}</span>.
|
|
</p> */}
|
|
<p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
|
{projectCount === 0 && imCount === 0 && woCount === 0 ?
|
|
"No active projects, internal memos, or work orders recorded for this client yet."
|
|
:
|
|
<>
|
|
{(projectCount > 0 || imCount > 0) && (
|
|
<>
|
|
Currently managing a portfolio of{" "}
|
|
{projectCount > 0 &&
|
|
<span className="font-bold text-foreground">{projectCount} project{projectCount > 1 ? 's' : ''}</span>
|
|
}
|
|
{projectCount > 0 && imCount > 0 && " and "}
|
|
{imCount > 0 &&
|
|
<span className="font-bold text-foreground">{imCount} internal memo{imCount > 1 ? 's' : ''}</span>
|
|
}
|
|
.{" "}
|
|
</>
|
|
)}
|
|
{woCount > 0 && (
|
|
<>
|
|
A dedicated team of{" "}
|
|
<span className="font-bold text-foreground">{assignedEmployeeIds.length} experts</span> is handling{" "}
|
|
<span className="font-bold text-foreground">{woCount} work order{woCount > 1 ? 's' : ''}</span>{" "}to ensure successful delivery for <span className="italic">{client.endUser}</span>.
|
|
</>
|
|
)}
|
|
</>
|
|
}
|
|
</p>
|
|
</div>
|
|
|
|
<div className="flex items-center justify-between pt-4 pb-2 border-t border-border">
|
|
<div className="flex flex-col gap-1">
|
|
<span className="text-[10px] uppercase tracking-wider font-semibold text-muted-foreground">Assigned Team</span>
|
|
<div className="flex -space-x-2 overflow-hidden">
|
|
{assignedEmployeeIds.slice(0, 5).map((empId) => {
|
|
const emp = DUMMY_EMPLOYEES.find(e => e.id === empId);
|
|
return (
|
|
<div key={empId}>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<LazyImage
|
|
className="inline-block h-8 w-8 rounded-full ring-2 ring-background object-cover"
|
|
src={emp?.avatar!}
|
|
alt={emp?.name!}
|
|
/>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p className="text-xs font-bold">{emp?.name}</p>
|
|
<p className="text-[10px] opacity-80">{emp?.role}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
);
|
|
})}
|
|
{assignedEmployeeIds.length > 5 && (
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-accent ring-2 ring-background text-[10px] font-bold">
|
|
+{assignedEmployeeIds.length - 5}
|
|
</div>
|
|
)}
|
|
{assignedEmployeeIds.length === 0 && (
|
|
<span className="text-[10px] text-muted-foreground italic">No team assigned</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-2 self-end">
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button variant="ghost" size="icon" className="h-8 w-8">
|
|
<MoreHorizontal className="w-4 h-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem asChild>
|
|
<Link href={`/task/client-detail/${client.id}`}>View Client Detail</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onSelect={() => { setShowForm(true); setSelectedData(client) }}>Edit Client</DropdownMenuItem>
|
|
<DropdownMenuItem className="text-destructive">Delete Client</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</div>
|
|
) : (
|
|
<Card className="overflow-hidden">
|
|
<div className="overflow-x-auto">
|
|
<Table>
|
|
<TableHeader className="bg-accent/50">
|
|
<TableRow>
|
|
<TableHead className="min-w-[150px]">Client</TableHead>
|
|
<TableHead className="min-w-[120px]">End User</TableHead>
|
|
<TableHead className="min-w-[200px]">Project Name</TableHead>
|
|
<TableHead>Project Code</TableHead>
|
|
<TableHead className="min-w-[200px]">Description</TableHead>
|
|
<TableHead>Year</TableHead>
|
|
<TableHead>Proj Start</TableHead>
|
|
<TableHead>Proj End</TableHead>
|
|
<TableHead className="min-w-[180px]">Work Order</TableHead>
|
|
<TableHead>WO Code</TableHead>
|
|
<TableHead>WO Start</TableHead>
|
|
<TableHead>WO End</TableHead>
|
|
<TableHead>Last Status</TableHead>
|
|
<TableHead>Date Status Changed</TableHead>
|
|
<TableHead className="min-w-[200px]">Status Remarks</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{masterData.map((item, idx) => {
|
|
const { client, assignment, wo } = item;
|
|
const latestStatus = wo?.statusHistory?.[0] || assignment.statusHistory?.[0];
|
|
|
|
return (
|
|
<TableRow key={`${assignment.id}-${wo?.id || idx}`} className="hover:bg-accent/30">
|
|
<TableCell className="font-bold text-primary">{client.name}</TableCell>
|
|
<TableCell>{client.endUser}</TableCell>
|
|
<TableCell className="font-medium">
|
|
<Link href={`/assignments/${assignment.id}`} className="hover:underline text-blue-600 dark:text-blue-400">
|
|
{assignment.name}
|
|
</Link>
|
|
</TableCell>
|
|
<TableCell className="font-mono text-xs">{assignment.code || '-'}</TableCell>
|
|
<TableCell className="max-w-[250px] truncate text-xs" title={assignment.description}>
|
|
{assignment.description}
|
|
</TableCell>
|
|
<TableCell>{assignment.year || '-'}</TableCell>
|
|
<TableCell className="whitespace-nowrap text-xs">
|
|
{assignment.startDate ? new Date(assignment.startDate).toLocaleDateString() : '-'}
|
|
</TableCell>
|
|
<TableCell className="whitespace-nowrap text-xs">
|
|
{assignment.endDate ? new Date(assignment.endDate).toLocaleDateString() : '-'}
|
|
</TableCell>
|
|
<TableCell className="font-medium">{wo?.name || '-'}</TableCell>
|
|
<TableCell className="font-mono text-xs">{wo?.code || '-'}</TableCell>
|
|
<TableCell className="whitespace-nowrap text-xs">
|
|
{wo?.startDate ? new Date(wo.startDate).toLocaleDateString() : '-'}
|
|
</TableCell>
|
|
<TableCell className="whitespace-nowrap text-xs">
|
|
{wo?.endDate ? new Date(wo.endDate).toLocaleDateString() : '-'}
|
|
</TableCell>
|
|
<TableCell>
|
|
<Badge variant="outline" className={cn(
|
|
"text-[10px] px-2 py-0 h-5",
|
|
(wo?.status || assignment.status) === 'Active' ? 'text-green-600 border-green-200 bg-green-50' :
|
|
(wo?.status || assignment.status) === 'Completed' ? 'text-blue-600 border-blue-200 bg-blue-50' :
|
|
'text-orange-600 border-orange-200 bg-orange-50'
|
|
)}>
|
|
{wo?.status || assignment.status}
|
|
</Badge>
|
|
</TableCell>
|
|
<TableCell className="whitespace-nowrap text-xs">
|
|
{latestStatus ? new Date(latestStatus.date).toLocaleDateString() : '-'}
|
|
</TableCell>
|
|
<TableCell className="text-xs italic text-muted-foreground">
|
|
{latestStatus?.note || '-'}
|
|
</TableCell>
|
|
</TableRow>
|
|
);
|
|
})}
|
|
</TableBody>
|
|
</Table>
|
|
</div>
|
|
</Card>
|
|
)}
|
|
|
|
{(view === 'grid' ? filteredClients : masterData).length === 0 && (
|
|
<div className="py-12 text-center border-2 border-dashed rounded-xl">
|
|
<Users className="w-12 h-12 mx-auto text-muted-foreground mb-4 opacity-20" />
|
|
<h3 className="text-lg font-medium">No data found</h3>
|
|
<p className="text-muted-foreground">Try adjusting your search or add new entries.</p>
|
|
</div>
|
|
)}
|
|
</motion.div>
|
|
|
|
{showForm ?
|
|
<ClientForm data={selectedData} onCancel={handleClose} onSuccess={handleClose} /> : null
|
|
}
|
|
</>
|
|
);
|
|
}
|