mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 17:56:28 +00:00
38f21de78a
Derive assignment status from scheduled phases that have started, map milestone colors to delivery health, and refine client timeline spacing and contrast.
289 lines
21 KiB
TypeScript
289 lines
21 KiB
TypeScript
"use client";
|
|
|
|
import { motion } from 'motion/react';
|
|
import Link from 'next/link';
|
|
import { FileText, Users, ClipboardList, MoreHorizontal, ExternalLink } from 'lucide-react';
|
|
import { Card900 } from '@/components/ui/card';
|
|
import { LazyImage } from '@/components/ui/lazy-image';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
|
} from '@/components/ui/dropdown-menu';
|
|
import {
|
|
Tooltip, TooltipContent, TooltipTrigger,
|
|
} from '@/components/ui/tooltip';
|
|
import {
|
|
HoverCard, HoverCardContent, HoverCardTrigger,
|
|
} from '@/components/ui/hover-card';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import { cn } from '@/lib/utils';
|
|
import { IClient, CLIENT_FALLBACK_IMAGE } from '../../types';
|
|
import { getProjectStatusBreakdown } from '../../utils/client-overview-helpers';
|
|
import ClientMilestoneTimeline from './ClientMilestoneTimeline';
|
|
|
|
interface ClientListProps {
|
|
clients: IClient[];
|
|
onEdit: (client: IClient) => void;
|
|
onDelete: (client: IClient) => void;
|
|
}
|
|
|
|
export default function ClientList({ clients, onEdit, onDelete }: ClientListProps) {
|
|
return (
|
|
<div className="flex flex-col gap-6">
|
|
{clients.map((client, index) => {
|
|
const isActive = (client.status_name || '').toLowerCase() === 'active';
|
|
const stages = getProjectStatusBreakdown(client);
|
|
const maxStageCount = 10;
|
|
|
|
const totalProjects = client.total_project ?? 0;
|
|
const assignedPeople = client.total_user_assigned || client.users?.length || 0;
|
|
const activeWorkOrders = client.total_work_order ?? 0;
|
|
|
|
return (
|
|
<motion.div
|
|
key={client.id || index}
|
|
initial={{ opacity: 0, y: 10 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
transition={{ duration: 0.25, delay: index * 0.04 }}
|
|
className="w-full"
|
|
>
|
|
<Card900 className="group overflow-hidden rounded-2xl border border-border/80 hover:border-his transition-all duration-300 p-5 sm:p-6 pb-0 sm:pb-0 shadow-xs flex flex-col gap-6">
|
|
{/* Top Section: 3-column layout (Identity | Status Breakdown | Quick Stats) */}
|
|
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6 items-start">
|
|
{/* Left Column: Client Identity & Team (col-span-3) */}
|
|
<div className="lg:col-span-3 flex flex-col justify-between h-full gap-4 min-w-0">
|
|
<div className="space-y-3 min-w-0">
|
|
{/* Code Badge + Status Pill with HoverCard */}
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
{client.code && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="text-xs font-mono font-semibold px-2.5 py-0.5 rounded-md bg-muted/80 dark:bg-zinc-800/80 text-foreground border border-border/70 shrink-0 cursor-help">
|
|
{client.code}
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="text-xs">
|
|
<p className="font-semibold text-popover-foreground">Client Code</p>
|
|
<p className="text-[11px] font-mono text-muted-foreground">{client.code}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
|
|
{/* Status Pill with Hover Content Summary Status */}
|
|
<HoverCard openDelay={10} closeDelay={100}>
|
|
<HoverCardTrigger asChild>
|
|
<button
|
|
type="button"
|
|
className={cn(
|
|
"group/pill inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-[11px] font-bold uppercase tracking-wider border shrink-0 cursor-help transition-all duration-200",
|
|
isActive
|
|
? "bg-teal-500/10 text-teal-500 border-teal-500/30 hover:bg-teal-500/20 dark:bg-teal-950/60 dark:text-teal-300 dark:border-teal-700/50 dark:hover:bg-teal-950/80"
|
|
: "bg-amber-500/10 text-amber-700 border-amber-500/30 hover:bg-amber-500/20 dark:bg-amber-950/60 dark:text-amber-300 dark:border-amber-700/50 dark:hover:bg-amber-950/80"
|
|
)}
|
|
>
|
|
<span
|
|
className={cn(
|
|
"w-1.5 h-1.5 rounded-full animate-pulse",
|
|
isActive ? "bg-teal-600 dark:bg-teal-400" : "bg-amber-600 dark:bg-amber-400"
|
|
)}
|
|
/>
|
|
<span>{client.status_name || (isActive ? 'ACTIVE' : 'INACTIVE')}</span>
|
|
</button>
|
|
</HoverCardTrigger>
|
|
<HoverCardContent side="bottom" align="start" className="w-[calc(100vw-3rem)] max-w-xs sm:w-72 p-3 text-xs">
|
|
<div className="font-semibold text-foreground">Status Summary</div>
|
|
<p className="text-muted-foreground mt-0.5">Status summary from WO or IM related to this client.</p>
|
|
<div className="flex flex-col mt-3 gap-2">
|
|
{client.project_status_summary && client.project_status_summary.length > 0 ? (
|
|
client.project_status_summary.map((item, key) => (
|
|
<div className="flex justify-between items-center gap-2" key={key}>
|
|
<BadgeStatus status={item.project_status} />
|
|
<span className="font-bold text-foreground">{item.total}</span>
|
|
</div>
|
|
))
|
|
) : (
|
|
<span className="italic text-muted-foreground">No status summary recorded.</span>
|
|
)}
|
|
</div>
|
|
</HoverCardContent>
|
|
</HoverCard>
|
|
</div>
|
|
|
|
{/* Brand Logo Presentation */}
|
|
<div className="pt-1">
|
|
<Link
|
|
href={`/task/client-detail/${client.id}`}
|
|
className="max-w-55 h-12 relative flex items-center group/logo"
|
|
>
|
|
<LazyImage
|
|
src={client.photo}
|
|
fallbackSrc={CLIENT_FALLBACK_IMAGE}
|
|
alt={client.name}
|
|
className="h-full w-auto bg-transparent max-h-12"
|
|
imgClassName="object-contain object-left max-h-12 group-hover/logo:scale-105 transition-transform"
|
|
/>
|
|
</Link>
|
|
</div>
|
|
|
|
{/* Client Full Corporate Name */}
|
|
<Link
|
|
href={`/task/client-detail/${client.id}`}
|
|
className="text-xs sm:text-sm font-semibold uppercase tracking-tight text-foreground/90 hover:text-primary transition-colors block line-clamp-2"
|
|
title={client.name}
|
|
>
|
|
{client.name}
|
|
</Link>
|
|
|
|
{/* Team Avatars */}
|
|
<div className="flex -space-x-2 overflow-hidden items-center pt-1">
|
|
{client.users?.slice(0, 5).map((user, uKey) => (
|
|
<div key={user.id || uKey}>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div className="inline-block relative">
|
|
<LazyImage
|
|
src={user?.avatar ? `${process.env.BASE_URL_IMG}/${user?.avatar}` : '/assets/no-avatar.jpg'}
|
|
alt={user?.fullname || user?.name || 'Team Member'}
|
|
className="w-7 h-7 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform object-cover"
|
|
/>
|
|
</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="text-xs">
|
|
<p className="font-semibold text-popover-foreground">{user?.name || user?.fullname}</p>
|
|
<p className="text-[10px] text-muted-foreground">{user?.position?.name || 'Team Member'}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
))}
|
|
{client.users && client.users.length > 5 && (
|
|
<div className="w-7 h-7 rounded-full bg-accent ring-2 ring-background flex items-center justify-center text-[10px] font-bold text-foreground shrink-0">
|
|
+{client.users.length - 5}
|
|
</div>
|
|
)}
|
|
{(!client.users || client.users.length === 0) && (
|
|
<span className="text-[11px] text-muted-foreground italic">No team assigned</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Middle Column: Project Status Breakdown (col-span-6) */}
|
|
<div className="lg:col-span-6 flex flex-col justify-start space-y-2.5 lg:px-4 lg:border-l lg:border-border/60 min-w-0 pt-4 lg:pt-0 border-t lg:border-t-0 border-border/50">
|
|
<h4 className="text-xs sm:text-sm font-bold text-foreground tracking-tight">
|
|
Project Status
|
|
</h4>
|
|
|
|
<div className="space-y-1.5 pt-0.5">
|
|
{stages.map((stage) => {
|
|
const barPercent = Math.min(100, (stage.count / maxStageCount) * 100);
|
|
return (
|
|
<div key={stage.id} className="flex items-center gap-2 sm:gap-3 text-xs">
|
|
{/* Stage Name + Dot matching technical status */}
|
|
<div className="flex items-center gap-2 w-48 sm:w-56 shrink-0 min-w-0">
|
|
<span className={cn("w-2 h-2 rounded-full shrink-0", stage.colorDot)} />
|
|
<span className="text-muted-foreground text-[11px] sm:text-xs truncate font-medium">
|
|
{stage.name}
|
|
</span>
|
|
</div>
|
|
|
|
{/* Progress Bar Container */}
|
|
<div className="flex-1 max-w-50 sm:max-w-60 bg-muted dark:bg-zinc-800 rounded-full h-2 overflow-hidden shrink-0">
|
|
<div
|
|
className={cn("h-full rounded-full transition-all duration-500", stage.colorBar)}
|
|
style={{ width: `${barPercent}%` }}
|
|
/>
|
|
</div>
|
|
|
|
{/* Count Number */}
|
|
<span className="text-[11px] sm:text-xs font-semibold text-foreground w-4 text-right shrink-0">
|
|
{stage.count}
|
|
</span>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Right Column: Quick Stats & Actions (col-span-3) */}
|
|
<div className="lg:col-span-3 flex flex-col justify-between h-full lg:border-l lg:border-border/60 lg:pl-5 space-y-4 pt-4 lg:pt-0 border-t lg:border-t-0 border-border/50">
|
|
<div className="space-y-3">
|
|
<div className="flex items-center justify-between text-xs py-1 border-b border-border/30">
|
|
<div className="flex items-center gap-2 text-muted-foreground">
|
|
<FileText className="w-4 h-4 text-muted-foreground" />
|
|
<span>Total Projects</span>
|
|
</div>
|
|
<span className="font-bold text-foreground text-sm">{totalProjects}</span>
|
|
</div>
|
|
|
|
<div className="flex items-center justify-between text-xs py-1 border-b border-border/30">
|
|
<div className="flex items-center gap-2 text-muted-foreground">
|
|
<Users className="w-4 h-4 text-muted-foreground" />
|
|
<span>Assigned People</span>
|
|
</div>
|
|
<span className="font-bold text-foreground text-sm">{assignedPeople}</span>
|
|
</div>
|
|
|
|
<div className="flex items-center justify-between text-xs py-1 border-b border-border/30">
|
|
<div className="flex items-center gap-2 text-muted-foreground">
|
|
<ClipboardList className="w-4 h-4 text-muted-foreground" />
|
|
<span>Active Work Orders</span>
|
|
</div>
|
|
<span className="font-bold text-foreground text-sm">{activeWorkOrders}</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Action Buttons: View Detail + More Actions Dropdown */}
|
|
<div className="flex items-center justify-end gap-2 pt-2">
|
|
<Link href={`/task/client-detail/${client.id}`} className="flex-1">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="w-full text-xs h-8 gap-1.5 hover:bg-accent"
|
|
>
|
|
<span>View Detail</span>
|
|
<ExternalLink className="w-3.5 h-3.5" />
|
|
</Button>
|
|
</Link>
|
|
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
|
aria-label="Client actions"
|
|
>
|
|
<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={() => onEdit(client)}>
|
|
Edit Client
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
onSelect={() => onDelete(client)}
|
|
className="text-destructive focus:text-destructive"
|
|
>
|
|
Delete Client
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Bottom Section: 2-Month Milestone Timeline */}
|
|
<div className="pt-3 border-t border-border/50">
|
|
<ClientMilestoneTimeline client={client} variant="list" />
|
|
</div>
|
|
</Card900>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|