mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
93a9b489d0
This commit updates the task dashboard and assignment views for smaller screens by tightening spacing, improving text wrapping, and making filter/search controls responsive. It also refreshes the assignment detail layout with clearer date spans, team summaries, and switchable grid/list member views, while polishing client and assignment cards for better readability on mobile.
287 lines
21 KiB
TypeScript
287 lines
21 KiB
TypeScript
import { IClient } from '../../types';
|
|
import { motion } from 'motion/react';
|
|
import { Card900, CardContent } from '@/components/ui/card';
|
|
import Link from 'next/link';
|
|
import { LazyImage } from '@/components/ui/lazy-image';
|
|
import { ExternalLink, MoreHorizontal, FolderGit2, FileText, Users } from 'lucide-react';
|
|
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 { cn } from '@/lib/utils';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
|
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 imCount = 0;
|
|
const projectCount = client.total_project || 0;
|
|
const woCount = client.total_work_order || 0;
|
|
const userCount = client.total_user_assigned || client.users?.length || 0;
|
|
const isActive = client.status_name?.toLowerCase() === 'active';
|
|
|
|
const hasDescription = typeof client.description === 'string' && client.description.trim().length > 0;
|
|
|
|
return (
|
|
<motion.div
|
|
initial={{ opacity: 0, y: 8 }}
|
|
animate={{ opacity: 1, y: 0 }}
|
|
transition={{ duration: 0.25, delay: index * 0.04 }}
|
|
className="w-full"
|
|
key={index}
|
|
>
|
|
<Card900 className="group overflow-hidden hover:shadow-md transition-all duration-300 border-border/80 hover:border-primary/30 flex flex-col lg:flex-row py-1.5">
|
|
<CardContent className="p-0 flex flex-col lg:flex-row w-full items-stretch">
|
|
{/* Left Column: Photo / Thumbnail (uncropped) */}
|
|
<div className="relative w-full lg:w-56 xl:w-64 h-48 lg:h-auto min-h-40 bg-muted/20 dark:bg-zinc-800/20 shrink-0 overflow-hidden flex items-center justify-center p-3 border-b lg:border-b-0 lg:border-r border-border/50">
|
|
<Link href={`/task/client-detail/${client.id}`} className="w-full h-full flex items-center justify-center">
|
|
<LazyImage
|
|
src={client.photo!}
|
|
alt={client.name}
|
|
className="w-full h-full max-h-36 bg-transparent"
|
|
imgClassName="object-contain p-1 group-hover:scale-105 transition-transform duration-500"
|
|
/>
|
|
</Link>
|
|
</div>
|
|
|
|
{/* Middle Column: Details, Description, Metrics & Breakdown */}
|
|
<div className="p-4 sm:p-5 flex-1 flex flex-col justify-between gap-3 min-w-0">
|
|
{/* Header Row: Code + Name + Status */}
|
|
<div className="flex flex-wrap sm:flex-nowrap items-center justify-between gap-2.5 min-w-0">
|
|
<div className="flex items-center gap-2 min-w-0 flex-1">
|
|
{client.code && (
|
|
<span className="text-xs font-mono font-medium px-2 py-0.5 rounded-md bg-accent text-accent-foreground border border-border/60 shrink-0">
|
|
{client.code}
|
|
</span>
|
|
)}
|
|
<Link
|
|
href={`/task/client-detail/${client.id}`}
|
|
className="font-semibold text-base sm:text-lg text-foreground hover:text-primary transition-colors tracking-tight truncate min-w-0"
|
|
>
|
|
{client.name}
|
|
</Link>
|
|
</div>
|
|
|
|
{/* Status Pill with HoverCard */}
|
|
<div className="shrink-0">
|
|
<HoverCard openDelay={10} closeDelay={100}>
|
|
<HoverCardTrigger asChild>
|
|
<button
|
|
type="button"
|
|
className="group/pill inline-flex items-center gap-2 bg-muted/60 dark:bg-zinc-800/80 hover:bg-muted dark:hover:bg-zinc-800 border border-border/80 rounded-full py-1 px-3 transition-colors text-xs font-medium cursor-help"
|
|
>
|
|
<span className={cn(
|
|
"w-2 h-2 rounded-full",
|
|
isActive ? 'bg-emerald-500' : 'bg-amber-500'
|
|
)} />
|
|
<span className="uppercase tracking-wider text-[10px] font-bold text-foreground">
|
|
{client.status_name}
|
|
</span>
|
|
</button>
|
|
</HoverCardTrigger>
|
|
<HoverCardContent side="bottom" align="end" 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?.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">{item.total}</span>
|
|
</div>
|
|
))
|
|
) : (
|
|
<span className="italic text-muted-foreground">No status summary recorded.</span>
|
|
)}
|
|
</div>
|
|
</HoverCardContent>
|
|
</HoverCard>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Description & Narrative */}
|
|
<div className="space-y-1.5 min-w-0">
|
|
{hasDescription && (
|
|
<p className="text-xs sm:text-sm text-foreground/90 line-clamp-2 leading-relaxed wrap-break-word">
|
|
{client.description}
|
|
</p>
|
|
)}
|
|
|
|
<p className="text-xs leading-relaxed text-muted-foreground line-clamp-2 pt-0.5 wrap-break-word">
|
|
{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-semibold text-foreground">
|
|
{projectCount} project{projectCount > 1 ? 's' : ''}
|
|
</span>
|
|
)}
|
|
{projectCount > 0 && imCount > 0 && " and "}
|
|
{imCount > 0 && (
|
|
<span className="font-semibold text-foreground">
|
|
{imCount} internal memo{imCount > 1 ? 's' : ''}
|
|
</span>
|
|
)}
|
|
.{" "}
|
|
</>
|
|
)}
|
|
{woCount > 0 && (
|
|
<>
|
|
A dedicated team of{" "}
|
|
<span className="font-semibold text-foreground">{userCount} experts</span> is handling{" "}
|
|
<span className="font-semibold text-foreground">
|
|
{woCount} work order{woCount > 1 ? 's' : ''}
|
|
</span>{" "}
|
|
to ensure successful delivery for <span className="italic">{client.name}</span>.
|
|
</>
|
|
)}
|
|
</>
|
|
)}
|
|
</p>
|
|
</div>
|
|
|
|
{/* Metrics Bar & Status Breakdown */}
|
|
<div className="flex flex-wrap items-center gap-2 pt-2 border-t border-border/50">
|
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground bg-accent/40 dark:bg-zinc-800/60 px-2.5 py-1 rounded-md border border-border/40">
|
|
<FolderGit2 className="w-3.5 h-3.5 text-muted-foreground" />
|
|
<span className="font-semibold text-foreground">{projectCount}</span>
|
|
<span>Projects</span>
|
|
</div>
|
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground bg-accent/40 dark:bg-zinc-800/60 px-2.5 py-1 rounded-md border border-border/40">
|
|
<FileText className="w-3.5 h-3.5 text-muted-foreground" />
|
|
<span className="font-semibold text-foreground">{woCount}</span>
|
|
<span>Work Orders</span>
|
|
</div>
|
|
<div className="flex items-center gap-1.5 text-xs text-muted-foreground bg-accent/40 dark:bg-zinc-800/60 px-2.5 py-1 rounded-md border border-border/40">
|
|
<Users className="w-3.5 h-3.5 text-muted-foreground" />
|
|
<span className="font-semibold text-foreground">{userCount}</span>
|
|
<span>Assigned</span>
|
|
</div>
|
|
|
|
{/* Project Status Summary items inline */}
|
|
{client.project_status_summary && client.project_status_summary.length > 0 && (
|
|
<div className="hidden sm:flex items-center gap-1.5 ml-auto">
|
|
{client.project_status_summary.slice(0, 3).map((item, key) => (
|
|
<div key={key} className="flex items-center gap-1">
|
|
<BadgeStatus status={item.project_status} />
|
|
<span className="text-[11px] font-semibold text-muted-foreground">({item.total})</span>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Right Column: Assigned Team & Action Buttons */}
|
|
<div className="p-4 sm:p-5 lg:w-72 shrink-0 flex flex-col justify-between border-t lg:border-t-0 lg:border-l border-border/60 bg-muted/15 dark:bg-zinc-900/30 gap-4">
|
|
{/* Assigned Team */}
|
|
<div className="space-y-2">
|
|
<div className="flex items-center justify-between">
|
|
<span className="text-[10px] uppercase tracking-wider font-semibold text-muted-foreground">
|
|
Assigned Team
|
|
</span>
|
|
<span className="text-xs font-semibold text-foreground">
|
|
{client.users?.length || 0}
|
|
</span>
|
|
</div>
|
|
|
|
<div className="flex -space-x-2 overflow-hidden items-center">
|
|
{client.users?.slice(0, 5).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 || 'User'}
|
|
className="inline-block h-8 w-8 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-bold">{user?.name || user?.fullname}</p>
|
|
<p className="text-[10px] opacity-80">{user?.position?.name || 'Team Member'}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
))}
|
|
{client.users?.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">
|
|
+{client.users.length - 5}
|
|
</div>
|
|
)}
|
|
{(!client.users || client.users.length === 0) && (
|
|
<span className="text-xs text-muted-foreground italic mr-1">No team assigned</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Action buttons */}
|
|
<div className="flex items-center justify-between sm:justify-end lg:justify-between gap-2 pt-3 border-t border-border/40">
|
|
<Link href={`/task/client-detail/${client.id}`} className="flex-1 sm:flex-none">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="w-full sm:w-auto 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 menu"
|
|
>
|
|
<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>
|
|
</CardContent>
|
|
</Card900>
|
|
</motion.div>
|
|
);
|
|
})
|
|
}
|
|
</div>
|
|
);
|
|
}
|