mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
93d2c272f2
Dynamically import client and assignment lists, grids, forms, filters, and activity timelines to reduce initial bundle work, with loading placeholders for list and grid views. Also refine client logo corners and assignment activity accents.
291 lines
19 KiB
TypeScript
291 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 } from '../../utils/client-overview-helpers';
|
|
import dynamic from 'next/dynamic';
|
|
|
|
const ClientMilestoneTimeline = dynamic(
|
|
() => import('./ClientMilestoneTimeline'),
|
|
{
|
|
ssr: false,
|
|
loading: () => (
|
|
<div className="h-14 w-full rounded-lg bg-muted/20 border border-border/40 animate-pulse flex items-center justify-between px-3 my-1">
|
|
<div className="h-2 w-12 rounded bg-muted/60" />
|
|
<div className="h-1 flex-1 mx-3 rounded-full bg-muted/40" />
|
|
<div className="h-2 w-12 rounded bg-muted/60" />
|
|
</div>
|
|
),
|
|
}
|
|
);
|
|
|
|
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 totalProjects = client.total_project ?? 0;
|
|
const assignedPeople = client.total_user_assigned || client.users?.length || 0;
|
|
const activeWorkOrders = client.total_work_order ?? 0;
|
|
|
|
// Display all 7 stages
|
|
const maxStageCount = 10;
|
|
|
|
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 rounded 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">
|
|
{stages.map((stage) => {
|
|
const barPercent = Math.min(100, (stage.count / maxStageCount) * 100);
|
|
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-zinc-200/70 dark:bg-zinc-700/50 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>
|
|
|
|
{/* Next 2 Months Milestone Timeline */}
|
|
<div className="pt-2 border-t border-border/40">
|
|
<ClientMilestoneTimeline client={client} variant="grid" />
|
|
</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>
|
|
);
|
|
} |