Add internal memo metrics to client views

Default client detail view now opens in list mode. The client model and listing UI now include `total_im`, showing internal memo counts across grid and list cards, and the profile summary adds the new metric. This also improves the empty-state description behavior and keeps the client summary stats consistent across views.
This commit is contained in:
Ichsan Kurniawan
2026-10-08 13:19:41 +07:00
parent d3c4e21636
commit aa91f1ac4c
5 changed files with 39 additions and 54 deletions
@@ -25,7 +25,7 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
const searchParams = useSearchParams();
const urlLayout = searchParams?.get('layout') as 'grid' | 'list' | null;
const [viewMode] = useState<'grid' | 'list'>(urlLayout || 'grid');
const [viewMode] = useState<'grid' | 'list'>(urlLayout || 'list');
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'DELETE' | undefined>();
const [selectedData, setSelectedData] = useState<IProjectAssignment>();
@@ -78,9 +78,10 @@ export default function ClientProfileCard({ client, clientId }: Props) {
</Link>
</div>
<dl className="mt-7 grid grid-cols-2 gap-x-6 gap-y-5 border-t border-border/70 pt-6 sm:grid-cols-4">
<dl className="mt-7 grid grid-cols-2 gap-x-6 gap-y-5 border-t border-border/70 pt-6 sm:grid-cols-5">
<Fact label="Projects" value={String(client.total_project ?? 0)} />
<Fact label="Work orders" value={String(client.total_work_order ?? 0)} />
<Fact label="Internal memos" value={String(client.total_im ?? 0)} />
<Fact label="Team" value={teamCount === 1 ? '1 person' : `${teamCount} people`} />
<Fact label="Client since" value={since} />
</dl>
@@ -3,7 +3,7 @@
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 { ExternalLink, MoreHorizontal, FolderGit2, FileText, ScrollText } from 'lucide-react';
import Link from 'next/link';
import { LazyImage } from '@/components/ui/lazy-image';
import {
@@ -29,10 +29,9 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp
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 imCount = client.total_im || 0;
const projectCount = client.total_project || 0;
const woCount = client.total_work_order || 0;
const isActive = client.status_name.toLowerCase() === 'active';
return (
@@ -111,41 +110,32 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp
</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."
<p className="text-xs sm:text-sm leading-relaxed text-muted-foreground line-clamp-3 min-h-12 wrap-break-word">
{typeof client.description === 'string' && client.description.trim().length > 0 ? (
client.description
) : (
<>
{(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>.
</>
)}
</>
<span className="italic text-muted-foreground/70">No description provided.</span>
)}
</p>
{/* Metrics Summary Bar */}
<div className="flex flex-wrap items-center gap-1.5 pt-2 border-t border-border/50">
<div className="flex items-center gap-1 text-[11px] text-muted-foreground bg-accent/40 dark:bg-zinc-800/60 px-2 py-0.5 rounded-md border border-border/40">
<FolderGit2 className="w-3 h-3 text-muted-foreground" />
<span className="font-semibold text-foreground">{projectCount}</span>
<span>Projects</span>
</div>
<div className="flex items-center gap-1 text-[11px] text-muted-foreground bg-accent/40 dark:bg-zinc-800/60 px-2 py-0.5 rounded-md border border-border/40">
<FileText className="w-3 h-3 text-muted-foreground" />
<span className="font-semibold text-foreground">{woCount}</span>
<span>Work Orders</span>
</div>
<div className="flex items-center gap-1 text-[11px] text-muted-foreground bg-accent/40 dark:bg-zinc-800/60 px-2 py-0.5 rounded-md border border-border/40">
<ScrollText className="w-3 h-3 text-muted-foreground" />
<span className="font-semibold text-foreground">{imCount}</span>
<span>Internal Memos</span>
</div>
</div>
</div>
<div className="flex items-center justify-between pt-4 pb-2 border-t border-border">
@@ -3,7 +3,7 @@ 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 { ExternalLink, MoreHorizontal, FolderGit2, FileText, Users, ScrollText } from 'lucide-react';
import {
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
@@ -28,7 +28,7 @@ export default function ClientList({ clients, onEdit, onDelete }: ClientListProp
return (
<div className="flex flex-col gap-6">
{clients.map((client, index) => {
const imCount = 0;
const imCount = client.total_im || 0;
const projectCount = client.total_project || 0;
const woCount = client.total_work_order || 0;
const userCount = client.total_user_assigned || client.users?.length || 0;
@@ -159,7 +159,7 @@ export default function ClientList({ clients, onEdit, onDelete }: ClientListProp
</p>
</div>
{/* Metrics Bar & Status Breakdown */}
{/* Metrics Bar */}
<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" />
@@ -171,23 +171,16 @@ export default function ClientList({ clients, onEdit, onDelete }: ClientListProp
<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">
<ScrollText className="w-3.5 h-3.5 text-muted-foreground" />
<span className="font-semibold text-foreground">{imCount}</span>
<span>Internal Memos</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>
+1
View File
@@ -26,6 +26,7 @@ export type IClient = {
status_code: string
status_name: string
total_project: number
total_im?: number
total_work_order: number
total_user_assigned: number
users: IUser[]