// 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() const handleClose = () => { setAction(undefined) setShowSelectedData(undefined) } return ( <> {clients.length === 0 ?

No Client Found

Try to change the filter or create one to get started.

: null } {clients.length > 0 ?
{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 (
{client.status_name.toLowerCase() === 'active' && }
{client.status_name}
Status Summary
This is status summary information from WO or IM related to this client.
{client.project_status_summary.map((item, key) =>
{item.total}
)}

{client.name}

{/*

{client.end_user_name}

*/}
{/*

Currently managing a portfolio of {projectCount} projects and {imCount} internal memos. A dedicated team of {assignedEmployeeIds.length} experts is handling {woCount} work orders to ensure successful delivery for {client.endUser}.

*/}

{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 && {projectCount} project{projectCount! > 1 ? 's' : ''} } {projectCount! > 0 && imCount > 0 && " and "} {imCount > 0 && {imCount} internal memo{imCount > 1 ? 's' : ''} } .{" "} )} {woCount! > 0 && ( <> A dedicated team of{" "} {userCount} experts is handling{" "} {woCount} work order{woCount! > 1 ? 's' : ''}{" "}to ensure successful delivery for {client.name}. )} }

Assigned Team
{client.users?.slice(0, 5).map((user, key) => { return (

{user?.name}

{user?.position?.name}

); })} {client.users?.length! > 5 &&
+{client.users?.length! - 5}
} {client.users?.length === 0 && No team assigned }
e.stopPropagation()}> View Client Detail { setShowSelectedData(client); setAction('EDIT') }} onClick={(e) => e.stopPropagation()}> Edit Client { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive" onClick={(e) => e.stopPropagation()}> Delete Client
); })}
: null } {action === 'EDIT' && { router.refresh(); handleClose() }} />} {action === 'DELETE' ? { 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} ); }