mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 16:56:29 +00:00
dcb74c0f2b
Introduce a reusable HoverCard component (components/ui/hover-card.tsx) and integrate it into the client grid to show a status summary with badges. Import the cn helper and BadgeStatus in ClientGrid, add a status pill trigger with animated indicator, and switch displayed client reference from end_user_name to client.name. In ManageTeam, include id in draftData, replace BadgeStatus rendering with a Badge variant and adjust the edit button colors to teal; the same teal edit-button color change was applied to UpdateTimelineStatus. Remove an unnecessary comment line in the task page. These changes improve status visibility and unify UI affordances.
228 lines
18 KiB
TypeScript
228 lines
18 KiB
TypeScript
// app/clients/components/client-grid.tsx
|
|
"use client" // Keep as client component if using motion/react animations
|
|
|
|
import { motion } from 'motion/react';
|
|
import { Card, Card900, CardContent } from '@/components/ui/card';
|
|
import { Button } from '@/components/ui/button';
|
|
import { ExternalLink, MoreHorizontal, Users } 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 { IClient } from '../types';
|
|
import { useState } from 'react';
|
|
import { useRouter } from 'next/navigation';
|
|
import FormClient from './FormClient';
|
|
import { ConfirmDeleteWithInput } from '@/components/modal/ConfirmDeleteWithInput';
|
|
import {
|
|
HoverCard, HoverCardContent, HoverCardTrigger,
|
|
} from "@/components/ui/hover-card"
|
|
import { cn } from '@/lib/utils';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
|
|
export default function ClientGrid({ clients }: { clients: IClient[] }) {
|
|
const router = useRouter();
|
|
const [action, setAction] = useState<'EDIT' | 'DELETE' | undefined>(undefined)
|
|
const [selectedData, setShowSelectedData] = useState<IClient>()
|
|
|
|
const handleClose = () => {
|
|
setAction(undefined)
|
|
setShowSelectedData(undefined)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{clients.length === 0 ?
|
|
<div className="py-12 text-center border-2 border-dashed rounded-xl">
|
|
<Users className="w-12 h-12 mx-auto text-muted-foreground mb-4 opacity-20" />
|
|
<div className="text-center">
|
|
<h3 className="text-xl font-semibold">No Client Found</h3>
|
|
<p className="text-muted-foreground max-w-sm mx-auto mt-2">
|
|
Try to change the filter or create one to get started.
|
|
</p>
|
|
<Button variant="outline" className="mt-4" onClick={() => { setAction('EDIT'); setShowSelectedData(undefined) }}>Create New Client</Button>
|
|
</div>
|
|
</div> : null
|
|
}
|
|
|
|
{clients.length > 0 ?
|
|
<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
|
|
|
|
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"
|
|
>
|
|
<Link href={`/task/client-detail/${client.id}`} className="h-full">
|
|
<Card900 className="h-full group overflow-hidden hover:shadow-lg transition-all duration-300 border-primary/5 hover:border-primary/20 flex flex-col py-0">
|
|
<CardContent className="p-0 flex flex-col h-full">
|
|
<div className="relative h-32 bg-accent/50 overflow-hidden">
|
|
<LazyImage
|
|
src={client.photo!}
|
|
alt={client.name}
|
|
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
|
|
/>
|
|
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/40 to-transparent" />
|
|
<div className="absolute top-3 right-3 z-20">
|
|
<HoverCard openDelay={10} closeDelay={100}>
|
|
<HoverCardTrigger>
|
|
<div className="group/pill flex items-center gap-2 bg-black/40 hover:bg-black/60 backdrop-blur-md border border-white/20 rounded-full py-1 px-3 transition-all duration-300 cursor-help hover:scale-105 active:scale-95 shadow-xl">
|
|
<div className="relative flex items-center justify-center">
|
|
{client.status_name.toLowerCase() === 'active' &&
|
|
<span className="absolute inset-0 rounded-full bg-green-400 animate-ping opacity-40 scale-150" />
|
|
}
|
|
<div className={cn(
|
|
"w-2.5 h-2.5 rounded-full ring-2 ring-black/40 relative z-10",
|
|
client.status_name.toLowerCase() === 'active' ? 'bg-green-400' : 'bg-orange-400'
|
|
)} />
|
|
</div>
|
|
<span className="text-[10px] font-black text-white/90 uppercase tracking-widest whitespace-nowrap">
|
|
{client.status_name}
|
|
</span>
|
|
</div>
|
|
|
|
</HoverCardTrigger>
|
|
<HoverCardContent side="bottom" align='end' className="flex flex-col gap-0.5 text-sm">
|
|
<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-2.5 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></div>
|
|
</div>
|
|
</HoverCardContent>
|
|
</HoverCard>
|
|
</div>
|
|
<div className="absolute bottom-4 left-4 right-4 flex items-end justify-between">
|
|
<div className="text-white">
|
|
<h3 className="font-bold text-lg leading-tight">{client.name}</h3>
|
|
{/* <p className="text-xs opacity-80">{client.end_user_name}</p> */}
|
|
</div>
|
|
<Link href={`/task/client-detail/${client.id}`}>
|
|
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity">
|
|
<ExternalLink className="w-4 h-4" />
|
|
</Button>
|
|
</Link>
|
|
</div>
|
|
</div>
|
|
<div className="p-5 flex flex-col flex-1 justify-between gap-4">
|
|
<div className="space-y-2">
|
|
{/* <p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
|
Currently managing a portfolio of <span className="font-bold text-foreground">{projectCount} projects</span> and <span className="font-bold text-foreground">{imCount} internal memos</span>.
|
|
A dedicated team of <span className="font-bold text-foreground">{assignedEmployeeIds.length} experts</span> is handling <span className="font-bold text-foreground">{woCount} work orders</span> to ensure successful delivery for <span className="italic">{client.endUser}</span>.
|
|
</p> */}
|
|
<p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
|
{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) => {
|
|
return (
|
|
<div key={key}>
|
|
<Tooltip>
|
|
<TooltipTrigger>
|
|
<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" />
|
|
</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">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={() => { setShowSelectedData(client); setAction('EDIT') }} onClick={(e) => e.stopPropagation()}>
|
|
Edit Client
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}>
|
|
Delete Client
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</CardContent>
|
|
</Card900>
|
|
</Link>
|
|
</motion.div>
|
|
);
|
|
})}
|
|
</div> : null
|
|
}
|
|
|
|
{action === 'EDIT' && <FormClient data={selectedData} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }} />}
|
|
|
|
{action === 'DELETE' ? <ConfirmDeleteWithInput endpoint={`/client/${selectedData?.id}`} onCancel={handleClose} onSuccess={() => { router.refresh(); handleClose() }}
|
|
title={selectedData?.name!} description={`This action cannot be undone. This will permanently delete and remove client ${selectedData?.name} from our servers.`}
|
|
titleButton={`I understand the consequences, delete this client`}
|
|
/> : null}
|
|
</>
|
|
);
|
|
} |