mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
e7c6f1b17b
This commit updates the technical status flow to support the newer `data` payload format while preserving legacy `date` handling across timelines, overview helpers, and assignment detail views. It also adds per-interval descriptions for date ranges, improves schedule editing/deletion UX, and refreshes status badge colors and default work-order/client fallback values for a more consistent experience.
275 lines
19 KiB
TypeScript
275 lines
19 KiB
TypeScript
"use client";
|
|
|
|
import { motion } from 'motion/react';
|
|
import Link from 'next/link';
|
|
import { ExternalLink, MoreHorizontal, FileText, Users, ClipboardList } from 'lucide-react';
|
|
import { Card900 } from '@/components/ui/card';
|
|
import { Button } from '@/components/ui/button';
|
|
import { LazyImage } from '@/components/ui/lazy-image';
|
|
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, getClientMilestones } from '../../utils/client-overview-helpers';
|
|
|
|
interface ClientGridProps {
|
|
clients: IClient[];
|
|
onEdit: (client: IClient) => void;
|
|
onDelete: (client: IClient) => void;
|
|
}
|
|
|
|
export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProps) {
|
|
return (
|
|
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
{clients.map((client, i) => {
|
|
const isActive = (client.status_name || '').toLowerCase() === 'active';
|
|
const stages = getProjectStatusBreakdown(client);
|
|
const milestones = getClientMilestones(client);
|
|
const activeMilestone = milestones[1] || milestones[0];
|
|
|
|
const totalProjects = client.total_project ?? 0;
|
|
const assignedPeople = client.total_user_assigned || client.users?.length || 0;
|
|
const activeWorkOrders = client.total_work_order ?? 0;
|
|
|
|
// Pick top stages with activity (or top 3)
|
|
const topStages = stages.filter((s) => s.count > 0).slice(0, 7);
|
|
const displayStages = topStages.length > 0 ? topStages : stages.slice(0, 7);
|
|
const maxStageCount = Math.max(...displayStages.map((s) => s.count), 1);
|
|
|
|
return (
|
|
<motion.div
|
|
key={client.id || i}
|
|
initial={{ opacity: 0, scale: 0.96 }}
|
|
animate={{ opacity: 1, scale: 1 }}
|
|
transition={{ delay: i * 0.04 }}
|
|
className="h-full"
|
|
>
|
|
<Card900 className="group h-full overflow-hidden rounded-2xl border border-border/80 hover:border-his transition-all duration-300 p-5 shadow-xs flex flex-col justify-between gap-5">
|
|
{/* Card Top: Code + Status Pill with HoverCard + Actions Menu */}
|
|
<div className="space-y-4">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<div className="flex items-center gap-2 flex-wrap">
|
|
{client.code && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="text-xs font-mono font-semibold px-2 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-[10px] 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-950/40 text-amber-400 border-amber-700/50 hover:bg-amber-950/60 dark:bg-amber-950/60 dark:text-amber-300"
|
|
)}
|
|
>
|
|
<span
|
|
className={cn(
|
|
"w-1.5 h-1.5 rounded-full animate-pulse",
|
|
isActive ? "bg-teal-400" : "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>
|
|
|
|
{/* Dropdown Action Menu */}
|
|
<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>
|
|
|
|
{/* Client Brand Logo & Corporate Name */}
|
|
<div className="space-y-2">
|
|
<Link
|
|
href={`/task/client-detail/${client.id}`}
|
|
className="h-12 w-full 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>
|
|
|
|
<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>
|
|
</div>
|
|
|
|
{/* 3 Metrics Quick Strip */}
|
|
<div className="grid grid-cols-3 gap-2 p-2 rounded-xl bg-muted/30 dark:bg-zinc-800/50 border border-border/50 text-center">
|
|
<div className="flex flex-col items-center">
|
|
<div className="flex items-center gap-1 text-[10px] text-muted-foreground">
|
|
<FileText className="w-3 h-3" />
|
|
<span>Projects</span>
|
|
</div>
|
|
<span className="text-sm font-bold text-foreground mt-0.5">{totalProjects}</span>
|
|
</div>
|
|
<div className="flex flex-col items-center border-x border-border/40 px-1">
|
|
<div className="flex items-center gap-1 text-[10px] text-muted-foreground">
|
|
<Users className="w-3 h-3" />
|
|
<span>Personnel</span>
|
|
</div>
|
|
<span className="text-sm font-bold text-foreground mt-0.5">{assignedPeople}</span>
|
|
</div>
|
|
<div className="flex flex-col items-center">
|
|
<div className="flex items-center gap-1 text-[10px] text-muted-foreground">
|
|
<ClipboardList className="w-3 h-3" />
|
|
<span>Work Orders</span>
|
|
</div>
|
|
<span className="text-sm font-bold text-foreground mt-0.5">{activeWorkOrders}</span>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Project Status Breakdown (Mini bars matching technical status colors) */}
|
|
<div className="space-y-2 pt-1 border-t border-border/40">
|
|
<div className="flex items-center justify-between text-xs font-semibold text-foreground">
|
|
<span>Project Status</span>
|
|
<span className="text-[10px] text-muted-foreground font-normal">Active Stages</span>
|
|
</div>
|
|
<div className="space-y-1.5">
|
|
{displayStages.map((stage) => {
|
|
const barPercent = stage.count > 0 ? Math.max(16, (stage.count / maxStageCount) * 100) : 0;
|
|
return (
|
|
<div key={stage.id} className="flex items-center gap-2 text-xs">
|
|
<div className="flex items-center gap-1.5 w-32 shrink-0 truncate">
|
|
<span className={cn("w-1.5 h-1.5 rounded-full shrink-0", stage.colorDot)} />
|
|
<span className="text-muted-foreground text-[10px] truncate">{stage.name}</span>
|
|
</div>
|
|
<div className="flex-1 bg-muted dark:bg-zinc-800 rounded-full h-1.5 overflow-hidden">
|
|
<div
|
|
className={cn("h-full rounded-full transition-all duration-500", stage.colorBar)}
|
|
style={{ width: `${barPercent}%` }}
|
|
/>
|
|
</div>
|
|
<span className="text-[10px] font-semibold text-foreground w-3 text-right shrink-0">
|
|
{stage.count}
|
|
</span>
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* Card Bottom: Team Avatars & View Detail button */}
|
|
<div className="flex items-center justify-between gap-2 pt-3 border-t border-border/50">
|
|
{/* Team Avatars */}
|
|
<div className="flex -space-x-2 overflow-hidden items-center">
|
|
{client.users?.slice(0, 4).map((user, key) => (
|
|
<div key={key}>
|
|
<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 || '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>
|
|
<p className="text-xs 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 > 4 && (
|
|
<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 - 4}
|
|
</div>
|
|
)}
|
|
{(!client.users || client.users.length === 0) && (
|
|
<span className="text-[10px] text-muted-foreground italic">No team</span>
|
|
)}
|
|
</div>
|
|
|
|
<Link href={`/task/client-detail/${client.id}`}>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="text-xs h-7.5 px-2.5 gap-1 hover:bg-accent"
|
|
>
|
|
<span>Detail</span>
|
|
<ExternalLink className="w-3 h-3" />
|
|
</Button>
|
|
</Link>
|
|
</div>
|
|
</Card900>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
} |