Files
hats-app/app/(dashboard)/task/component/ClientGrid.tsx
T
Ichsan Kurniawan 80cb73f7fa Add FilterModal and DatePickerMultiMode; UI fixes
Introduce a FilterModal component and a DatePickerMultiMode UI component; refactor FilterComponent to use the modal and expose new hide* props for finer control. Update HomeTask to use a Select for view switching and remove unused props. Improve client and assignment UIs: ClientGrid empty state, client card actions, AssignmentTable empty state, and various text/label adjustments. Fix PieChart null-safety with optional chaining and remove a stray console.log in ClientDetailComponent. Update assignment field mappings to prefer wo_* values where appropriate and pass hideCategory to project detail page. Also update .env.development API/IMG URLs.
2026-04-23 21:01:12 +07:00

184 lines
14 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';
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"
>
<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 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.end_user_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">
<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={() => { setShowSelectedData(client); setAction('EDIT') }}>Edit Client</DropdownMenuItem>
<DropdownMenuItem onSelect={() => { setShowSelectedData(client); setAction('DELETE') }} className="text-destructive">Delete Client</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
</div>
</CardContent>
</Card900>
</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}
</>
);
}