mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 12:16:28 +00:00
3f0ed29f0c
This commit adds reusable client and end-user fallback assets and updates profile cards, lists, and assignment views to render graceful placeholders when images are missing or fail to load. It also hardens the shared LazyImage component with fallback handling and improves BadgeStatus so it accepts object-like status values and still renders clean labels. Minor UX fixes include dismissing upload toasts after completion and clarifying end-user form labels/copy.
213 lines
15 KiB
TypeScript
213 lines
15 KiB
TypeScript
"use client";
|
|
|
|
import { motion } from 'motion/react';
|
|
import { Card900, CardContent } from '@/components/ui/card';
|
|
import { Button } from '@/components/ui/button';
|
|
import { ExternalLink, MoreHorizontal } from 'lucide-react';
|
|
import Link from 'next/link';
|
|
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 { cn } from '@/lib/utils';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import { IClient, CLIENT_FALLBACK_IMAGE } from '../../types';
|
|
|
|
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 imCount = 0;
|
|
const projectCount = client.total_project;
|
|
const woCount = client.total_work_order;
|
|
const userCount = client.total_user_assigned;
|
|
const isActive = client.status_name.toLowerCase() === 'active';
|
|
|
|
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"
|
|
>
|
|
<Card900 className="h-full group overflow-hidden hover:shadow-lg transition-all duration-300 border-border/80 hover:border-primary/20 flex flex-col py-0">
|
|
<CardContent className="p-0 flex flex-col h-full">
|
|
{/* Uncropped Image banner */}
|
|
<div className="relative h-40 bg-muted/20 dark:bg-zinc-800/30 overflow-hidden flex items-center justify-center p-3 border-b border-border/50">
|
|
<Link href={`/task/client-detail/${client.id}`} className="w-full h-full flex items-center justify-center">
|
|
<LazyImage
|
|
src={client.photo || CLIENT_FALLBACK_IMAGE}
|
|
fallbackSrc={CLIENT_FALLBACK_IMAGE}
|
|
alt={client.name}
|
|
className="w-full h-full max-h-32 bg-transparent"
|
|
imgClassName="object-contain p-1 group-hover:scale-105 transition-transform duration-500"
|
|
/>
|
|
</Link>
|
|
<div className="absolute top-3 right-3 z-20">
|
|
<HoverCard openDelay={10} closeDelay={100}>
|
|
<HoverCardTrigger asChild>
|
|
<button
|
|
type="button"
|
|
className="group/pill flex items-center gap-2 bg-background/80 dark:bg-zinc-900/80 hover:bg-background border border-border/80 rounded-full py-1 px-3 transition-all duration-300 cursor-help shadow-xs"
|
|
>
|
|
<span className={cn(
|
|
"w-2 h-2 rounded-full",
|
|
isActive ? 'bg-emerald-500' : 'bg-amber-500'
|
|
)} />
|
|
<span className="text-[10px] font-bold text-foreground uppercase tracking-wider whitespace-nowrap">
|
|
{client.status_name}
|
|
</span>
|
|
</button>
|
|
</HoverCardTrigger>
|
|
<HoverCardContent side="bottom" align='end' className="flex flex-col gap-0.5 text-sm w-[calc(100vw-3rem)] max-w-xs sm:w-72">
|
|
<div className="font-semibold">Status Summary</div>
|
|
<div className="text-xs text-muted-foreground">This is status summary information from WO or IM related to this client.</div>
|
|
<div className='flex flex-col mt-4 gap-3 text-xs'>
|
|
{client.project_status_summary.map((item, key) => (
|
|
<div className='flex justify-between items-center gap-2' key={key}>
|
|
<BadgeStatus status={item.project_status} />
|
|
<div className='font-bold'>{item.total}</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</HoverCardContent>
|
|
</HoverCard>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="p-4 sm:p-5 flex flex-col flex-1 justify-between gap-4 min-w-0">
|
|
<div className="space-y-2 min-w-0">
|
|
<div className="flex items-start justify-between gap-2 min-w-0">
|
|
<div className="flex flex-wrap items-center gap-1.5 min-w-0 flex-1">
|
|
{client.code && (
|
|
<span className="text-[11px] font-mono font-medium px-2 py-0.5 rounded bg-accent text-accent-foreground border border-border/60 shrink-0">
|
|
{client.code}
|
|
</span>
|
|
)}
|
|
<Link
|
|
href={`/task/client-detail/${client.id}`}
|
|
className="font-bold text-base sm:text-lg leading-tight text-foreground hover:text-primary transition-colors truncate min-w-0 max-w-full block"
|
|
>
|
|
{client.name}
|
|
</Link>
|
|
</div>
|
|
<Link href={`/task/client-detail/${client.id}`} className="shrink-0">
|
|
<Button size="icon" variant="ghost" className="h-8 w-8 rounded-full text-muted-foreground hover:text-foreground">
|
|
<ExternalLink className="w-4 h-4" />
|
|
</Button>
|
|
</Link>
|
|
</div>
|
|
|
|
<p className="text-xs sm:text-sm leading-relaxed text-muted-foreground line-clamp-3 min-h-15 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-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">{userCount} 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.name}</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">
|
|
{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!}
|
|
className="inline-block h-8 w-8 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform"
|
|
/>
|
|
</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p className="text-xs font-bold">{user?.name}</p>
|
|
<p className="text-[10px] opacity-80">{user?.position?.name}</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?.length === 0 && (
|
|
<span className="text-[10px] text-muted-foreground italic mr-1">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" onClick={(e) => e.stopPropagation()}>
|
|
<MoreHorizontal className="w-4 h-4" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem asChild onClick={(e) => e.stopPropagation()}>
|
|
<Link href={`/task/client-detail/${client.id}`}>View Client Detail</Link>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onSelect={() => onEdit(client)} onClick={(e) => e.stopPropagation()}>
|
|
Edit Client
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onSelect={() => onDelete(client)} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
|
Delete Client
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card900>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
} |