Redesign project assignment list

This commit refreshes the client project assignment UI with a new dashboard summary, streamlined card layouts, and shared assignment overview helpers. It adds phase/progress tracking, delivery health indicators, and improved team/status calculations across the assignment grid and list views. It also updates the project assignment type definitions and bumps the app version.
This commit is contained in:
Ichsan Kurniawan
2026-10-13 20:42:59 +07:00
parent 9a04ba7738
commit 6f52078aa5
8 changed files with 1228 additions and 494 deletions
@@ -4,7 +4,6 @@ import { useState } from 'react';
import { Briefcase } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import Link from 'next/link';
import { IProjectAssignment } from '../../../type.assignment';
import { useRouter, useSearchParams } from 'next/navigation';
@@ -12,6 +11,7 @@ import dynamic from 'next/dynamic';
import FilterComponent from '../../../component/FilterComponent';
import AssignmentGrid from '../../../component/project-assignment/AssignmentGrid';
import AssignmentList from '../../../component/project-assignment/AssignmentList';
import ProjectAssignmentDashboardStats from '../../../component/project-assignment/ProjectAssignmentDashboardStats';
const ModalActionLoader = () => (
<div className="fixed inset-0 z-50 bg-black/50 backdrop-blur-xs flex items-center justify-center animate-in fade-in duration-150">
@@ -64,17 +64,12 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
};
return (
<>
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
<h2 className="text-2xl font-bold">Project Assignments</h2>
<div className="flex items-center gap-4">
<Badge variant="outline" className="px-3 py-1">
{assignmentLists.length} Total
</Badge>
</div>
</div>
<div className="space-y-6">
{/* --- PROJECT ASSIGNMENT DASHBOARD STATS --- */}
<ProjectAssignmentDashboardStats assignments={assignmentLists} />
<FilterComponent showLayoutToggle />
{/* --- FILTER & SEARCH TOOLBAR --- */}
<FilterComponent showLayoutToggle placeholder="Search projects..." />
{/* --- EMPTY STATE --- */}
{assignmentLists.length === 0 ? (
@@ -176,6 +171,6 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro
titleButton="I understand the consequences, delete this assignment"
/>
) : null}
</>
</div>
);
}
@@ -1,15 +1,8 @@
/**
* Client information section for /task/client-detail/[client_id].
* Same visual language as the assignment detail page: rounded-2xl surface,
* border-based elevation, mono facts row, `his` as the only accent.
*/
import Link from 'next/link';
import dayjs from 'dayjs';
import { Plus } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { LazyImage } from '@/components/ui/lazy-image';
import BadgeStatus from '@/components/ui/badge-status';
import { Card900 } from '@/components/ui/card';
import { cn } from '@/lib/utils';
import { IClient, CLIENT_FALLBACK_IMAGE } from '../../../types';
@@ -18,26 +11,15 @@ interface Props {
clientId: string;
}
const AVATAR_LIMIT = 5;
function avatarSrc(avatar?: string | null) {
return avatar ? `${process.env.BASE_URL_IMG}/${avatar}` : '/assets/no-avatar.jpg';
}
export default function ClientProfileCard({ client, clientId }: Props) {
const isActive = client.status_name?.toLowerCase() === 'active';
const users = client.users ?? [];
const teamCount = client.total_user_assigned || users.length;
const shown = users.slice(0, AVATAR_LIMIT);
const extra = users.length - shown.length;
const statusSummary = client.project_status_summary ?? [];
const since = client.created_at && dayjs(client.created_at).isValid() ? dayjs(client.created_at).format('MMM YYYY') : 'N/A';
return (
<section aria-labelledby="client-name" className="rounded-2xl border border-border bg-card p-5 sm:p-7">
<div className="flex flex-col gap-6 md:flex-row md:items-start md:justify-between">
<Card900 className="rounded-2xl border border-border/80 bg-card p-5 sm:p-6 transition-all duration-300">
<div className="flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between">
<div className="flex min-w-0 items-start gap-4 sm:gap-5">
<div className="flex h-20 w-20 shrink-0 items-center justify-center overflow-hidden rounded-2xl border border-border bg-muted/30 p-1.5 sm:h-24 sm:w-24">
{/* Client Logo Container */}
<div className="flex h-16 w-16 sm:h-20 sm:w-20 shrink-0 items-center justify-center overflow-hidden rounded-2xl border border-border/70 p-2 shadow-2xs">
<LazyImage
src={client.photo || CLIENT_FALLBACK_IMAGE}
fallbackSrc={CLIENT_FALLBACK_IMAGE}
@@ -47,89 +29,46 @@ export default function ClientProfileCard({ client, clientId }: Props) {
/>
</div>
<div className="min-w-0 space-y-2.5">
{/* Client Identity & Info */}
<div className="min-w-0 space-y-1.5 flex-1">
<div className="flex flex-wrap items-center gap-2">
{client.code ? (
<span className="rounded-lg border border-border bg-muted/50 px-2 py-0.5 font-mono text-xs text-muted-foreground">
<span className="rounded-md border border-border/80 bg-muted/60 px-2 py-0.5 font-mono text-xs font-medium text-muted-foreground">
{client.code}
</span>
) : null}
<span className="inline-flex items-center gap-1.5 rounded-lg border border-border px-2 py-0.5 text-xs font-medium text-foreground">
<span className={cn('h-1.5 w-1.5 rounded-full', isActive ? 'bg-emerald-500' : 'bg-amber-500')} />
{client.status_name}
<span className={cn(
"inline-flex items-center gap-1.5 rounded-full border px-2.5 py-0.5 text-xs font-medium",
isActive
? "bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/25"
: "bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/25"
)}>
<span className={cn("h-1.5 w-1.5 rounded-full", isActive ? "bg-emerald-500" : "bg-amber-500")} />
<span>{client.status_name || (isActive ? 'active' : 'inactive')}</span>
</span>
</div>
<h1 id="client-name" className="text-balance text-2xl font-semibold tracking-tight text-foreground wrap-break-word md:text-3xl">
<h1 id="client-name" className="text-xl sm:text-2xl lg:text-3xl font-bold tracking-tight text-foreground wrap-break-word">
{client.name}
</h1>
<p className="max-w-[65ch] text-sm leading-relaxed text-muted-foreground wrap-break-word line-clamp-3">
<p className="max-w-4xl text-xs sm:text-sm leading-relaxed text-muted-foreground wrap-break-word line-clamp-2">
{client.description || 'No description available for this client.'}
</p>
</div>
</div>
<Link href={`/task/client-detail/${clientId}/project-assignments`} className="w-full shrink-0 md:w-auto">
<Button className="w-full gap-2 transition-transform active:scale-[0.98] md:w-auto">
<Plus className="h-4 w-4" />
New assignment
</Button>
</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-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>
{users.length > 0 || statusSummary.length > 0 ? (
<div className="mt-6 flex flex-col gap-4 rounded-xl border border-border/60 bg-muted/20 p-3 sm:flex-row sm:items-center sm:justify-between">
{users.length > 0 ? (
<div className="flex min-w-0 items-center gap-3">
<div className="flex shrink-0 items-center" aria-hidden>
{shown.map((u, i) => (
<LazyImage
key={u.id ?? i}
src={avatarSrc(u.avatar)}
alt=""
className={cn('h-8 w-8 shrink-0 rounded-full border-2 border-card bg-muted', i > 0 && '-ml-2')}
/>
))}
{extra > 0 ? (
<span className="-ml-2 flex h-8 min-w-8 shrink-0 items-center justify-center rounded-full border-2 border-card bg-muted px-1.5 font-mono text-[11px] font-medium text-muted-foreground">
+{extra}
</span>
) : null}
</div>
<p className="min-w-0 truncate text-xs text-muted-foreground">Assigned across this client's work orders</p>
</div>
) : null}
{statusSummary.length > 0 ? (
<ul className="flex flex-wrap items-center gap-x-3 gap-y-2">
{statusSummary.map(item => (
<li key={item.project_status} className="flex items-center gap-1.5">
<BadgeStatus status={item.project_status} />
<span className="font-mono text-xs font-medium text-foreground">{item.total}</span>
</li>
))}
</ul>
) : null}
{/* Right: + New assignment Button */}
<div className="shrink-0 self-start lg:self-center">
<Link href={`/task/client-detail/${clientId}/project-assignments`}>
<Button className="gap-2 bg-his hover:bg-his/90 text-white font-medium rounded-xl px-5 py-2.5 shadow-sm transition-transform active:scale-[0.98]">
<Plus className="h-4 w-4" />
<span>New assignment</span>
</Button>
</Link>
</div>
) : null}
</section>
</div>
</Card900>
);
}
function Fact({ label, value }: { label: string; value: string }) {
return (
<div className="min-w-0 sm:border-l sm:border-border/70 sm:pl-5 sm:first:border-l-0 sm:first:pl-0">
<dt className="text-xs text-muted-foreground">{label}</dt>
<dd className="mt-1 truncate font-mono text-sm font-medium text-foreground">{value}</dd>
</div>
);
}
@@ -1,10 +1,8 @@
"use client";
import { IProjectAssignment } from '../../type.assignment';
import { CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../types';
import { motion } from 'motion/react';
import { Card900 } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import {
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
@@ -13,11 +11,67 @@ import {
Tooltip, TooltipContent, TooltipTrigger,
} from '@/components/ui/tooltip';
import { LazyImage } from '@/components/ui/lazy-image';
import { Briefcase, Calendar, ExternalLink, MoreVertical, FolderGit2, FileText, ArrowUpRight } from 'lucide-react';
import { Calendar, MoreVertical, ArrowUpRight } from 'lucide-react';
import Link from 'next/link';
import BadgeStatus from '@/components/ui/badge-status';
import { formatAssignmentDate } from './AssignmentList';
import { cn } from '@/lib/utils';
import ConvertedAssignmentBadge from './ConvertedAssignmentBadge';
import BadgeStatus from '@/components/ui/badge-status';
import {
getAssignmentOverview,
ProgressColorConfig,
formatAssignmentDate
} from '../../utils/assignment-overview-helpers';
import { END_USER_FALLBACK_IMAGE } from '../../types';
const STEPPER_STAGES = ['Dev', 'SIT', 'UAT', 'PTR', 'Live'] as const;
function CompactPhaseStepper({ phaseIndex, progressColor }: { phaseIndex: number; progressColor: ProgressColorConfig }) {
return (
<div className="relative pt-2 pb-0.5 w-full">
{/* Background Rail Line */}
<div className="absolute top-3.5 left-2 right-2 h-0.5 bg-muted dark:bg-zinc-800" />
{/* Active Colored Fill Line */}
<div
className={`absolute top-3.5 left-2 h-0.5 ${progressColor.barColor} transition-all duration-300`}
style={{ width: `${Math.min(100, Math.max(0, (phaseIndex / 4) * 100))}%` }}
/>
{/* 5 Milestone Stage Nodes */}
<div className="relative flex items-center justify-between">
{STEPPER_STAGES.map((stage, i) => {
const isCompleted = i < phaseIndex;
const isActive = i === phaseIndex;
return (
<div key={stage} className="flex flex-col items-center gap-1.5 z-10">
{isActive ? (
<div className={`w-3.5 h-3.5 rounded-full flex items-center justify-center ${progressColor.glowRing} ${progressColor.activeDot} transition-transform`}>
<div className="w-1.5 h-1.5 rounded-full bg-white shadow-xs" />
</div>
) : isCompleted ? (
<div className={`w-2.5 h-2.5 rounded-full ${progressColor.barColor} transition-colors`} />
) : (
<div className="w-2 h-2 rounded-full bg-muted-foreground/30 dark:bg-zinc-700 transition-colors" />
)}
<span className={cn(
"text-[10px] tracking-tight font-medium transition-colors",
isActive
? `${progressColor.textColor} font-bold`
: isCompleted
? "text-foreground dark:text-zinc-300"
: "text-muted-foreground/60 dark:text-zinc-500"
)}>
{stage}
</span>
</div>
);
})}
</div>
</div>
);
}
interface AssignmentGridProps {
assignments: IProjectAssignment[];
@@ -37,18 +91,9 @@ export default function AssignmentGrid({
onDelete,
}: AssignmentGridProps) {
return (
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6 auto-rows-fr">
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-5 auto-rows-fr">
{assignments.map((assignment, index) => {
const isProject = !!assignment.wo_name;
const assignmentType = isProject ? 'Work Order' : 'Internal Memo';
const assignmentName = assignment.wo_name || assignment.im_name || assignment.project?.name || 'Untitled Assignment';
const assignmentCode = assignment.wo_code || assignment.im_code || assignment.project?.code;
const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date || assignment.project?.start_date;
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date || assignment.project?.end_date;
const assignmentDesc = assignment.wo_description || assignment.im_description || assignment.project?.description;
const assignmentStatus = assignment.project_assignment_status?.name || assignment.project?.status;
const illustrationSrc = isProject ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
const item = getAssignmentOverview(assignment, index);
const effectiveClientId = clientId || assignment.client?.id;
const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#';
@@ -56,70 +101,73 @@ export default function AssignmentGrid({
const editAssignmentUrl = effectiveClientId
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}`
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}`;
const promoteAssignmentUrl = !isProject
const promoteAssignmentUrl = !item.isProject
? (effectiveClientId
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true`
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`)
: null;
const illustrationSrc = item.isProject ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
return (
<motion.div
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.25, delay: index * 0.04 }}
className="h-full"
key={index}
key={assignment.id || index}
>
<Card900 className="h-full group hover:border-his/50 transition-all duration-300 hover:shadow-xl hover:-translate-y-1 flex flex-col justify-between p-4 sm:p-5 border-border/80 rounded-2xl bg-card gap-4 min-w-0">
{/* Top Section: 3D Emblem, Badges, and Action Menu */}
<div className="flex items-start justify-between gap-2.5 min-w-0">
<div className="flex items-center gap-3 min-w-0 flex-1">
{/* 3D App Icon / Emblem */}
<Card900 className="h-full group hover:border-his/50 transition-all duration-300 hover:shadow-xl hover:-translate-y-0.5 flex flex-col justify-between p-4 sm:p-5 border-border/80 rounded-2xl bg-card gap-4 min-w-0">
{/* Top Section: Emblem, Badges & Action Menu */}
<div className="flex items-start justify-between gap-3 min-w-0">
<div className="flex items-start gap-3 min-w-0 flex-1">
{/* 3D Dossier Folder Thumbnail */}
<Link
href={assignmentDetailUrl}
className="relative w-12 h-12 sm:w-16 sm:h-16 shrink-0 rounded-2xl overflow-hidden bg-muted/20 dark:bg-zinc-800/40 border border-border/60 flex items-center justify-center p-1 shadow-2xs group-hover:scale-105 group-hover:border-his/40 transition-all duration-300"
className="relative w-12 h-12 sm:w-14 sm:h-14 shrink-0 rounded-2xl overflow-hidden bg-muted/20 dark:bg-zinc-800/40 border border-border/60 flex items-center justify-center p-1 shadow-2xs group-hover:scale-105 group-hover:border-his/40 transition-all duration-300"
>
<LazyImage
src={illustrationSrc}
alt={assignmentType}
alt={item.assignmentType}
className="w-full h-full bg-transparent"
imgClassName="object-contain rounded-lg"
imgClassName="object-contain rounded-xl"
/>
</Link>
{/* Identity & Badges */}
{/* Badges Stack */}
<div className="min-w-0 space-y-1.5 flex-1">
{/* Row 1: Assignment Type and Status */}
<div className="flex items-center gap-1.5 flex-wrap">
<Badge
variant="outline"
className={`text-[10px] font-semibold tracking-wide px-2 py-0.5 gap-1 shrink-0 ${isProject
? 'bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/30'
: 'bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/30'
}`}
>
{isProject ? <Briefcase className="w-3 h-3" /> : <FileText className="w-3 h-3" />}
<span>{assignmentType}</span>
</Badge>
{/* Type Pill */}
<span className={cn(
"inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium border",
item.isProject
? "bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/25"
: "bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/25"
)}>
<span className={cn("h-1.5 w-1.5 rounded-full", item.isProject ? "bg-amber-500" : "bg-purple-500")} />
<span>{item.assignmentType}</span>
</span>
{assignmentStatus && <BadgeStatus status={assignmentStatus} />}
{/* Project Status Badge matching technical status badge colors */}
<BadgeStatus status={item.projectStatusName} />
</div>
{/* Row 2: Assignment Code & Converted Indicator */}
<div className="flex items-center gap-1.5 flex-wrap">
{assignmentCode && (
{/* Code Pill with Tooltip */}
{item.code ? (
<Tooltip>
<TooltipTrigger asChild>
<span className="inline-block text-[11px] font-mono font-semibold px-2 py-0.5 rounded-md bg-muted/80 dark:bg-zinc-800 text-muted-foreground border border-border/60 shrink-0 truncate max-w-full cursor-help hover:text-foreground hover:border-border transition-colors">
# {assignmentCode}
<span className="font-mono text-[11px] font-medium text-muted-foreground/80 px-1.5 py-0.5 rounded-md bg-muted/60 dark:bg-zinc-800/80 border border-border/70 shrink-0 cursor-help hover:border-border transition-colors">
# {item.code}
</span>
</TooltipTrigger>
<TooltipContent className="text-xs">
<p className="font-semibold">{isProject ? 'Work Order Code' : 'Internal Memo Code'}</p>
<p className="text-[11px] font-mono text-muted-foreground">#{assignmentCode}</p>
<p className="font-semibold text-popover-foreground">Assignment Code</p>
<p className="text-[11px] font-mono text-muted-foreground">{item.code}</p>
</TooltipContent>
</Tooltip>
)}
) : null}
<ConvertedAssignmentBadge assignment={assignment} clientId={effectiveClientId} />
</div>
@@ -138,14 +186,15 @@ export default function AssignmentGrid({
<MoreVertical className="w-4 h-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">{promoteAssignmentUrl && (
<DropdownMenuItem asChild>
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
<ArrowUpRight className="w-4 h-4 text-his" />
Promote to Project
</Link>
</DropdownMenuItem>
)}
<DropdownMenuContent align="end" className="w-48">
{promoteAssignmentUrl && (
<DropdownMenuItem asChild>
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
<ArrowUpRight className="w-4 h-4 text-his" />
Promote to Project
</Link>
</DropdownMenuItem>
)}
<DropdownMenuItem asChild>
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
</DropdownMenuItem>
@@ -191,153 +240,110 @@ export default function AssignmentGrid({
</DropdownMenu>
</div>
{/* Center: Title, Project, Description, Tags */}
<div className="space-y-2.5 flex-1 min-w-0">
{/* Title */}
<div>
<Link
href={assignmentDetailUrl}
className="font-bold text-base sm:text-lg leading-snug text-foreground hover:text-his transition-colors block line-clamp-2 tracking-tight wrap-break-word"
>
{assignmentName}
</Link>
</div>
{/* Middle Section: Title, End User & Date with Tooltips */}
<div className="space-y-2 flex-1 min-w-0">
<Link
href={assignmentDetailUrl}
className="font-bold text-base leading-snug text-foreground hover:text-his transition-colors block line-clamp-2 tracking-tight wrap-break-word"
>
{item.title}
</Link>
{/* Project Reference */}
{assignment.project?.name && (
<div className="flex items-center gap-1.5 text-xs text-muted-foreground pt-0.5 min-w-0">
<FolderGit2 className="w-3.5 h-3.5 text-his shrink-0" />
<span className="text-[11px] text-muted-foreground shrink-0">Project:</span>
{projectDetailUrl ? (
<Link
href={projectDetailUrl}
className="font-medium text-foreground hover:text-his truncate hover:underline flex items-center gap-1 min-w-0"
>
<span className="truncate">{assignment.project.name}</span>
<ExternalLink className="w-3 h-3 shrink-0 opacity-60" />
</Link>
) : (
<span className="font-medium text-foreground truncate min-w-0">{assignment.project.name}</span>
)}
</div>
)}
{/* Origin IM Reference (for converted assignments without project) */}
{!assignment.project?.name && (assignment.im?.im_name || (assignment.im_id && assignment.im_name)) && (
<div className="flex items-center gap-1.5 text-xs text-muted-foreground pt-0.5 min-w-0">
<FileText className="w-3.5 h-3.5 text-purple-600 dark:text-purple-400 shrink-0" />
<span className="text-[11px] text-muted-foreground shrink-0">Origin IM:</span>
{effectiveClientId && (assignment.im_id || assignment.im?.id) ? (
<Link
href={`/task/client-detail/${effectiveClientId}/${assignment.im_id || assignment.im?.id}`}
className="font-medium text-foreground hover:text-purple-600 dark:hover:text-purple-400 truncate hover:underline flex items-center gap-1 min-w-0"
>
<span className="truncate">{assignment.im?.im_name || assignment.im_name}</span>
<ArrowUpRight className="w-3 h-3 shrink-0 opacity-60" />
</Link>
) : (
<span className="font-medium text-foreground truncate min-w-0">{assignment.im?.im_name || assignment.im_name}</span>
)}
</div>
)}
{/* Description */}
{assignmentDesc && (
<p className="text-xs text-muted-foreground line-clamp-2 leading-relaxed pt-0.5 wrap-break-word">
{assignmentDesc}
</p>
)}
{/* Client & End User Badges */}
<div className="flex flex-wrap items-center gap-1.5 pt-1 text-xs">
{assignment.client?.name && !clientId && (
<Link
href={`/task/client-detail/${assignment.client.id}`}
className="flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-muted/60 hover:bg-muted border border-border/50 text-foreground transition-colors text-[11px] max-w-full min-w-0"
>
<div className="space-y-1 text-xs text-muted-foreground pt-0.5">
{item.endUserName &&
<div className="flex items-center gap-1.5 min-w-0">
<LazyImage
src={assignment.client.photo || CLIENT_FALLBACK_IMAGE}
fallbackSrc={CLIENT_FALLBACK_IMAGE}
alt={assignment.client.name}
className="w-3.5 h-3.5 rounded-xs bg-transparent shrink-0"
imgClassName="object-contain"
src={item.endUserPhoto}
fallbackSrc={END_USER_FALLBACK_IMAGE}
alt={item.endUserName}
className="w-4 h-4 bg-transparent"
imgClassName="object-contain object-left group-hover/logo:scale-105 transition-transform"
/>
<span className="text-muted-foreground shrink-0">Client:</span>
<span className="font-medium truncate max-w-32.5 sm:max-w-45">{assignment.client.name}</span>
</Link>
)}
{assignment.end_user?.name && (
<div className="flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-muted/40 border border-border/40 text-foreground text-[11px] max-w-full min-w-0">
<div className="w-3.5 h-3.5 rounded-xs overflow-hidden shrink-0 bg-transparent">
<LazyImage
src={assignment.end_user?.photo || END_USER_FALLBACK_IMAGE}
fallbackSrc={END_USER_FALLBACK_IMAGE}
alt={assignment.end_user.name}
className="w-full h-full bg-transparent"
imgClassName="object-contain"
/>
</div>
<span className="text-muted-foreground shrink-0">End User:</span>
<span className="font-medium truncate max-w-32.5 sm:max-w-45">{assignment.end_user.name}</span>
</div>
)}
</div>
</div>
{/* Footer: Timeline & Team Members */}
<div className="pt-3.5 border-t border-border/60 flex flex-wrap sm:flex-nowrap items-center justify-between gap-2.5 text-xs">
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1.5 text-muted-foreground min-w-0 flex-1 cursor-help hover:text-foreground transition-colors">
<Calendar className="w-3.5 h-3.5 shrink-0 text-muted-foreground/80" />
<span className="font-medium text-[11px] truncate">
{formatAssignmentDate(assignmentStartDate)} – {formatAssignmentDate(assignmentEndDate)}
<span className="font-medium text-foreground truncate">
End User: {item.endUserName}
</span>
</div>
</TooltipTrigger>
<TooltipContent className="text-xs space-y-0.5">
<p className="font-semibold">Assignment Timeline</p>
<p className="text-[11px] text-muted-foreground mt-1">
Start: <span className="text-foreground font-medium">{formatAssignmentDate(assignmentStartDate)}</span>
</p>
<p className="text-[11px] text-muted-foreground">
End: <span className="text-foreground font-medium">{formatAssignmentDate(assignmentEndDate)}</span>
</p>
</TooltipContent>
</Tooltip>
}
{/* Assigned Team */}
<div className="flex -space-x-2 overflow-hidden items-center shrink-0">
{assignment.project_assignment_work_order_detail?.slice(0, 4).map((item, key) => (
<div key={key}>
<Tooltip>
<TooltipTrigger asChild>
<div className="inline-block relative">
<LazyImage
src={item?.user?.avatar ? `${process.env.BASE_URL_IMG}/${item.user.avatar}` : '/assets/no-avatar.jpg'}
alt={item?.user?.fullname || item?.user?.name || 'Member'}
className="w-7 h-7 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform object-cover"
/>
</div>
</TooltipTrigger>
<TooltipContent>
<p className="text-xs font-semibold text-popover-foreground">{item?.user?.fullname || item?.user?.name}</p>
<p className="text-[10px] text-muted-foreground">{item?.user?.position?.name || 'Team Member'}</p>
</TooltipContent>
</Tooltip>
</div>
))}
{assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length > 4 && (
<div className="w-7 h-7 rounded-full bg-accent ring-2 ring-background flex items-center justify-center text-[10px] font-bold">
+{assignment.project_assignment_work_order_detail.length - 4}
</div>
)}
{(!assignment.project_assignment_work_order_detail || assignment.project_assignment_work_order_detail.length === 0) && (
<span className="text-[11px] text-muted-foreground italic mr-1">No team</span>
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1.5 shrink-0 cursor-help hover:text-foreground transition-colors">
<Calendar className="w-3.5 h-3.5 text-muted-foreground/70 shrink-0" />
<span>{item.formattedDateRange}</span>
</div>
</TooltipTrigger>
<TooltipContent className="text-xs">
<p className="font-semibold text-popover-foreground">Assignment Timeline</p>
<p className="text-[11px] text-muted-foreground mt-1">
Start: <span className="text-primary">{item.startDate ? formatAssignmentDate(item.startDate) : 'Start date not set'}</span>
</p>
<p className="text-[11px] text-muted-foreground">
End: <span className="text-primary">{item.endDate ? formatAssignmentDate(item.endDate) : 'End date not set'}</span>
</p>
</TooltipContent>
</Tooltip>
</div>
</div>
{/* Progress & Stepper Section */}
<div className="space-y-2 pt-2 border-t border-border/60">
<div className="flex items-center justify-between text-xs font-mono font-medium">
<span className="text-muted-foreground">{item.daysRatioText}</span>
<div className="h-1.5 rounded-full bg-muted dark:bg-zinc-800 flex-1 mx-2.5 overflow-hidden">
<div
className={`h-full rounded-full ${item.progressColor.barColor} transition-all duration-500`}
style={{ width: `${item.progressPercent}%` }}
/>
</div>
<span className="text-foreground font-bold">{item.progressPercent}%</span>
</div>
<CompactPhaseStepper phaseIndex={item.phaseIndex} progressColor={item.progressColor} />
</div>
{/* Footer: Delivery Health Badge & Team Avatars */}
<div className="pt-3 border-t border-border/60 flex items-center justify-between gap-2 text-xs">
<div className="space-y-1 min-w-0 flex-1">
<span className={cn(
"inline-flex items-center gap-1.5 rounded-full border px-2 py-0.5 text-[11px] font-medium",
item.healthBadgeClass
)}>
<span className={cn("h-1.5 w-1.5 rounded-full", item.healthDotClass)} />
<span>{item.healthStatus}</span>
</span>
<p className="text-[11px] text-muted-foreground truncate">{item.remainingText}</p>
</div>
<div className="flex items-center gap-1.5 shrink-0">
{item.teamMembers.length > 0 ? (
<>
<div className="flex -space-x-1.5 overflow-hidden items-center">
{item.teamMembers.slice(0, 3).map((m, mIdx) => (
<Tooltip key={m.id || mIdx}>
<TooltipTrigger asChild>
<div className="inline-block relative">
<LazyImage
src={m.avatar ? `${process.env.BASE_URL_IMG}/${m.avatar}` : '/assets/no-avatar.jpg'}
alt={m.name}
className="inline-block h-6 w-6 rounded-full border border-card bg-muted cursor-help hover:scale-110 hover:z-10 transition-transform object-cover"
/>
</div>
</TooltipTrigger>
<TooltipContent>
<p className="text-xs font-semibold text-popover-foreground">{m.name}</p>
<p className="text-[10px] text-muted-foreground">{m.position || 'Team Member'}</p>
</TooltipContent>
</Tooltip>
))}
</div>
<span className="text-[11px] font-medium text-muted-foreground">{item.teamCount}p</span>
</>
) : (
<span className="text-[11px] text-muted-foreground/70 italic">None</span>
)}
</div>
</div>
</Card900>
</motion.div>
);
@@ -345,3 +351,4 @@ export default function AssignmentGrid({
</div>
);
}
@@ -3,7 +3,6 @@
import { IProjectAssignment } from '../../type.assignment';
import { motion } from 'motion/react';
import { Card900, CardContent } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import {
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
@@ -12,21 +11,69 @@ import {
Tooltip, TooltipContent, TooltipTrigger,
} from '@/components/ui/tooltip';
import { LazyImage } from '@/components/ui/lazy-image';
import { Briefcase, Calendar, MoreVertical, FolderGit2, FileText, BuildingComplex, ArrowUpRight } from 'lucide-react';
import { Calendar, MoreVertical, ArrowUpRight } from 'lucide-react';
import Link from 'next/link';
import BadgeStatus from '@/components/ui/badge-status';
import { cn } from '@/lib/utils';
import ConvertedAssignmentBadge from './ConvertedAssignmentBadge';
import BadgeStatus from '@/components/ui/badge-status';
import {
getAssignmentOverview,
formatAssignmentDate,
ProgressColorConfig
} from '../../utils/assignment-overview-helpers';
import { END_USER_FALLBACK_IMAGE } from '../../types';
export const formatAssignmentDate = (dateStr?: string) => {
if (!dateStr) return 'N/A';
const d = new Date(dateStr);
if (isNaN(d.getTime())) return 'N/A';
const day = String(d.getDate()).padStart(2, '0');
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const month = months[d.getMonth()];
const year = d.getFullYear();
return `${day} ${month} ${year}`;
};
export { formatAssignmentDate };
const STEPPER_STAGES = ['Dev', 'SIT', 'UAT', 'PTR', 'Live'] as const;
function PhaseStepper({ phaseIndex, progressColor }: { phaseIndex: number; progressColor: ProgressColorConfig }) {
return (
<div className="relative pt-2 pb-0.5 w-full">
{/* Background Rail Line */}
<div className="absolute top-3.5 left-2 right-2 h-0.5 bg-muted-foreground/20 dark:bg-zinc-700" />
{/* Active Colored Fill Line */}
<div
className={`absolute top-3.5 left-2 h-0.5 ${progressColor.barColor} transition-all duration-300`}
style={{ width: `${Math.min(100, Math.max(0, (phaseIndex / 4) * 100))}%` }}
/>
{/* 5 Milestone Stage Nodes */}
<div className="relative flex items-center justify-between">
{STEPPER_STAGES.map((stage, i) => {
const isCompleted = i < phaseIndex;
const isActive = i === phaseIndex;
return (
<div key={stage} className="flex flex-col items-center gap-1.5 z-10">
{isActive ? (
<div className={`w-3.5 h-3.5 rounded-full flex items-center justify-center ${progressColor.glowRing} ${progressColor.activeDot} transition-transform`}>
<div className="w-1.5 h-1.5 rounded-full bg-white shadow-xs" />
</div>
) : isCompleted ? (
<div className={`w-2.5 h-2.5 rounded-full ${progressColor.barColor} transition-colors`} />
) : (
<div className="w-2 h-2 rounded-full bg-muted-foreground/70 dark:bg-zinc-600 transition-colors" />
)}
<span className={cn(
"text-[10px] tracking-tight font-medium transition-colors",
isActive
? `${progressColor.textColor} font-bold`
: isCompleted
? "text-foreground dark:text-zinc-300"
: "text-muted-foreground/60 dark:text-zinc-500"
)}>
{stage}
</span>
</div>
);
})}
</div>
</div>
);
}
interface AssignmentListProps {
assignments: IProjectAssignment[];
@@ -46,17 +93,9 @@ export default function AssignmentList({
onDelete,
}: AssignmentListProps) {
return (
<div className="flex flex-col gap-5">
<div className="flex flex-col gap-3.5 sm:gap-4">
{assignments.map((assignment, index) => {
const isProject = !!assignment.wo_name;
const assignmentType = isProject ? 'Work Order' : 'Internal Memo';
const assignmentName = assignment.wo_name || assignment.im_name || assignment.project?.name || 'Untitled Assignment';
const assignmentCode = assignment.wo_code || assignment.im_code || assignment.project?.code;
const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date || assignment.project?.start_date;
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date || assignment.project?.end_date;
const assignmentStatus = assignment.project_assignment_status?.name || assignment.project?.status;
const illustrationSrc = isProject ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
const item = getAssignmentOverview(assignment, index);
const effectiveClientId = clientId || assignment.client?.id;
const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#';
@@ -64,245 +103,275 @@ export default function AssignmentList({
const editAssignmentUrl = effectiveClientId
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}`
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}`;
const promoteAssignmentUrl = !isProject
const promoteAssignmentUrl = !item.isProject
? (effectiveClientId
? `/task/client-detail/${effectiveClientId}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true`
: `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`)
: null;
const illustrationSrc = item.isProject ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
return (
<motion.div
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.25, delay: index * 0.04 }}
className="w-full"
key={index}
key={assignment.id || index}
>
<Card900 className="group overflow-hidden hover:shadow-md transition-all duration-300 border-border/80 hover:border-his/40 rounded-2xl py-1 bg-card min-w-0">
<CardContent className="p-3.5 sm:p-5 flex flex-col md:flex-row items-start md:items-center justify-between gap-4 min-w-0">
{/* Left: Thumbnail & Visual Indicator */}
<div className="flex items-start gap-3 sm:gap-4 min-w-0 flex-1 w-full">
<Card900 className="group overflow-hidden hover:shadow-lg transition-all duration-300 border-border/80 hover:border-his/50 rounded-2xl bg-card min-w-0 py-1.5">
<CardContent className="p-3.5 sm:p-5 flex flex-col xl:flex-row items-start xl:items-center justify-between gap-4 sm:gap-6 min-w-0">
{/* 1. LEFT: Thumbnail, Badges & Assignment Details */}
<div className="flex items-start gap-3.5 sm:gap-4 min-w-0 flex-1 w-full xl:w-auto">
{/* 3D Dossier Folder Thumbnail */}
<Link
href={assignmentDetailUrl}
className="relative w-12 h-12 sm:w-16 sm:h-16 md:w-20 md:h-20 shrink-0 rounded-2xl overflow-hidden bg-muted/20 dark:bg-zinc-800/40 border border-border/60 flex items-center justify-center p-1 shadow-2xs group-hover:border-his/40 group-hover:scale-105 transition-all duration-300"
className="relative w-13 h-13 sm:w-16 sm:h-16 shrink-0 rounded-2xl overflow-hidden bg-muted/20 dark:bg-zinc-800/40 border border-border/70 flex items-center justify-center p-1 shadow-2xs group-hover:scale-105 group-hover:border-his/40 transition-all duration-300"
>
<LazyImage
src={illustrationSrc}
alt={assignmentType}
alt={item.assignmentType}
className="w-full h-full bg-transparent"
imgClassName="object-contain rounded-lg"
imgClassName="object-contain rounded-xl"
/>
</Link>
{/* Center Details */}
{/* Identity, Badges, Title & Timeline */}
<div className="min-w-0 flex-1 space-y-1.5">
{/* Line 1: Type Badge, Status, Code, and Project Reference */}
<div className="flex flex-wrap items-center gap-1.5">
<Badge
variant="outline"
className={`text-[10px] font-semibold px-2 py-0.5 gap-1 shrink-0 ${isProject
? 'bg-amber-500/15 text-amber-700 dark:text-amber-400 border-amber-500/30'
: 'bg-purple-500/15 text-purple-700 dark:text-purple-400 border-purple-500/30'
}`}
>
{isProject ? <Briefcase className="w-3 h-3" /> : <FileText className="w-3 h-3" />}
<span>{assignmentType}</span>
</Badge>
{/* Line 1: Type Pill, Status Pill, Code Pill & Converted Badge */}
<div className="flex flex-wrap items-center gap-1.5 sm:gap-2">
{/* Type pill: Work Order / Internal Memo */}
<span className={cn(
"inline-flex items-center gap-1.5 rounded-full px-2.5 py-0.5 text-xs font-medium border",
item.isProject
? "bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-500/25"
: "bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/25"
)}>
<span className={cn(
"h-1.5 w-1.5 rounded-full",
item.isProject ? "bg-amber-500" : "bg-purple-500"
)} />
<span>{item.assignmentType}</span>
</span>
<ConvertedAssignmentBadge assignment={assignment} clientId={effectiveClientId} />
{/* Project Status Badge matching technical status badge colors */}
<BadgeStatus status={item.projectStatusName} />
{assignmentStatus && <BadgeStatus status={assignmentStatus} />}
{assignmentCode ? (
{/* Code Pill with Tooltip */}
{item.code ? (
<Tooltip>
<TooltipTrigger asChild>
<span className="text-[11px] font-mono font-medium px-2 py-0.5 rounded-md bg-muted/80 dark:bg-zinc-800 text-muted-foreground border border-border/60 shrink-0 cursor-help hover:text-foreground hover:border-border transition-colors">
# {assignmentCode}
<span className="font-mono text-[10px] font-medium text-muted-foreground px-2 py-0.5 rounded-md bg-muted/60 dark:bg-zinc-800/80 border border-border/70 shrink-0 cursor-help hover:border-border transition-colors">
# {item.code}
</span>
</TooltipTrigger>
<TooltipContent className="text-xs">
<p className="font-semibold">{isProject ? 'Work Order Code' : 'Internal Memo Code'}</p>
<p className="text-[11px] font-mono text-muted-foreground">#{assignmentCode}</p>
<p className="font-semibold text-popover-foreground">Assignment Code</p>
<p className="text-[11px] font-mono text-muted-foreground mt-1">{item.code}</p>
</TooltipContent>
</Tooltip>
) : null}
{/* Converted Badge (kept with hover card) */}
<ConvertedAssignmentBadge assignment={assignment} clientId={effectiveClientId} />
</div>
{/* Line 2: Assignment Title */}
<div className="min-w-0">
<Link
href={assignmentDetailUrl}
className="font-semibold text-base sm:text-lg leading-snug text-foreground hover:text-his transition-colors block tracking-tight line-clamp-2 sm:line-clamp-1 py-0.5 wrap-break-word"
className="font-bold text-base sm:text-lg text-foreground hover:text-his transition-colors line-clamp-1 tracking-tight wrap-break-word"
>
{assignmentName}
{item.title}
</Link>
{assignment.project?.name && (
<div className="flex items-center gap-1 text-xs text-muted-foreground mt-1 min-w-0">
<FolderGit2 className="w-3.5 h-3.5 text-his shrink-0" />
<span className="text-[11px] text-muted-foreground hidden sm:inline shrink-0">Project:</span>
{projectDetailUrl ? (
<Link
href={projectDetailUrl}
className="font-medium text-foreground hover:text-his truncate hover:underline inline-block min-w-0"
>
{assignment.project.name}
</Link>
) : (
<span className="font-medium text-foreground truncate min-w-0">{assignment.project.name}</span>
)}
</div>
)}
</div>
{/* Line 3: Metadata, Client, End User, Timeline, Notes */}
<div className="flex flex-wrap items-center gap-x-3 gap-y-1.5 text-xs text-muted-foreground pt-0.5 min-w-0">
{assignment.client?.name && !clientId && (
<Link
href={`/task/client-detail/${assignment.client.id}`}
className="flex items-center gap-1 text-[11px] font-medium text-foreground hover:text-his transition-colors min-w-0"
>
<BuildingComplex className="w-3 h-3 text-muted-foreground shrink-0" />
<span className="text-muted-foreground shrink-0">Client:</span>
<span className="truncate max-w-32.5 sm:max-w-50">{assignment.client.name}</span>
</Link>
)}
{assignment.end_user?.name && (
<div className="flex items-center gap-1 text-[11px] text-foreground min-w-0">
<span className="text-muted-foreground shrink-0">End User:</span>
<span className="font-medium truncate max-w-32.5 sm:max-w-50">{assignment.end_user.name}</span>
{/* Line 3: End User & Timeline with Tooltips */}
<div className="flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground">
{item.endUserName && (
<div className="flex items-center gap-1 min-w-0 hover:text-foreground transition-colors">
<LazyImage
src={item.endUserPhoto}
fallbackSrc={END_USER_FALLBACK_IMAGE}
alt={item.endUserName}
className="w-4 h-4 bg-transparent"
imgClassName="object-contain object-left group-hover/logo:scale-105 transition-transform"
/>
<span className="font-medium text-muted-foreground truncate max-w-48 sm:max-w-64">
End User: {item.endUserName}
</span>
</div>
)}
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-1 text-[11px] text-muted-foreground shrink-0 cursor-help hover:text-foreground transition-colors">
<Calendar className="w-3.5 h-3.5 text-muted-foreground/80 shrink-0" />
<span>
{formatAssignmentDate(assignmentStartDate)} – {formatAssignmentDate(assignmentEndDate)}
</span>
<div className="flex items-center gap-1.5 shrink-0 cursor-help hover:text-foreground transition-colors">
<Calendar className="w-3.5 h-3.5 text-muted-foreground/70 shrink-0" />
<span>{item.formattedDateRange}</span>
</div>
</TooltipTrigger>
<TooltipContent className="text-xs space-y-0.5">
<p className="font-semibold">Assignment Timeline</p>
<TooltipContent className="text-xs">
<p className="font-semibold text-popover-foreground">Assignment Timeline</p>
<p className="text-[11px] text-muted-foreground mt-1">
Start: <span className="text-foreground font-medium">{formatAssignmentDate(assignmentStartDate)}</span>
Start: <span className="text-primary">{item.startDate ? formatAssignmentDate(item.startDate) : 'Start date not set'}</span>
</p>
<p className="text-[11px] text-muted-foreground">
End: <span className="text-foreground font-medium">{formatAssignmentDate(assignmentEndDate)}</span>
End: <span className="text-primary">{item.endDate ? formatAssignmentDate(item.endDate) : 'End date not set'}</span>
</p>
</TooltipContent>
</Tooltip>
{assignment.note && (
<span className="text-[11px] italic text-muted-foreground/80 line-clamp-1 max-w-35 sm:max-w-xs wrap-break-word">
Note: {assignment.note}
</span>
)}
</div>
</div>
</div>
{/* Right: Team Stack & Actions */}
<div className="flex items-center justify-between md:justify-end gap-3 w-full md:w-auto shrink-0 pt-3 md:pt-0 border-t md:border-t-0 border-border/50">
{/* Team Avatar Stack */}
<div className="flex -space-x-2 overflow-hidden items-center">
{assignment.project_assignment_work_order_detail?.slice(0, 4).map((item, key) => (
<div key={key}>
<Tooltip>
<TooltipTrigger asChild>
<div className="inline-block relative">
<LazyImage
src={item?.user?.avatar ? `${process.env.BASE_URL_IMG}/${item.user.avatar}` : '/assets/no-avatar.jpg'}
alt={item?.user?.fullname || item?.user?.name || 'User'}
className="inline-block h-8 w-8 rounded-full border-2 border-background cursor-help hover:scale-110 hover:z-10 transition-transform object-cover"
/>
</div>
</TooltipTrigger>
<TooltipContent>
<p className="text-xs font-semibold text-popover-foreground">{item?.user?.fullname || item?.user?.name}</p>
<p className="text-[10px] text-muted-foreground">{item?.user?.position?.name || 'Team Member'}</p>
</TooltipContent>
</Tooltip>
</div>
))}
{assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length > 4 && (
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-accent ring-2 ring-background text-[10px] font-bold">
+{assignment.project_assignment_work_order_detail.length - 4}
</div>
)}
{(!assignment.project_assignment_work_order_detail || assignment.project_assignment_work_order_detail.length === 0) && (
<span className="text-xs text-muted-foreground italic mr-1">No team assigned</span>
)}
{/* 2. CENTER: Progress Bar & 5-Node Stepper Track */}
<div className="w-full xl:w-68 2xl:w-76 shrink-0 space-y-1.5 pt-2 xl:pt-0 border-t xl:border-t-0 border-border/60">
{/* Days ratio, Dynamic color Progress bar & Percentage */}
<div className="flex items-center justify-between text-xs font-mono font-medium">
<span className="text-muted-foreground shrink-0">{item.daysRatioText}</span>
<div className="h-1.5 rounded-full bg-zinc-200 dark:bg-zinc-700 flex-1 mx-2.5 overflow-hidden">
<div
className={`h-full rounded-full ${item.progressColor.barColor} transition-all duration-500`}
style={{ width: `${item.progressPercent}%` }}
/>
</div>
<span className="text-foreground font-bold shrink-0">{item.progressPercent}%</span>
</div>
{/* Action Buttons */}
<div className="flex items-center gap-1.5">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground hover:text-foreground rounded-full"
aria-label="Assignment actions menu"
>
<MoreVertical className="w-4 h-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">
{promoteAssignmentUrl && (
<DropdownMenuItem asChild>
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
<ArrowUpRight className="w-4 h-4 text-his" />
Promote to Project
</Link>
</DropdownMenuItem>
)}
<DropdownMenuItem asChild>
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
</DropdownMenuItem>
{projectDetailUrl && (
<DropdownMenuItem asChild>
<Link href={projectDetailUrl}>View Project Details</Link>
</DropdownMenuItem>
)}
{!clientId && assignment.client?.id && (
<DropdownMenuItem asChild>
<Link href={`/task/client-detail/${assignment.client.id}`}>View Client</Link>
</DropdownMenuItem>
)}
{editAssignmentUrl && (
<DropdownMenuItem asChild>
<Link href={editAssignmentUrl}>Edit Assignment</Link>
</DropdownMenuItem>
)}
{onManageTeam && (
<DropdownMenuItem onSelect={() => onManageTeam(assignment)}>
Manage Team
</DropdownMenuItem>
)}
{onUpdateAdministrationStatus && (
<DropdownMenuItem onSelect={() => onUpdateAdministrationStatus(assignment)}>
Update Administration Status
</DropdownMenuItem>
)}
{onUpdateStatus && (
<DropdownMenuItem onSelect={() => onUpdateStatus(assignment)}>
Update Technical Status
</DropdownMenuItem>
)}
{onDelete && (
<DropdownMenuItem
onSelect={() => onDelete(assignment)}
className="text-destructive focus:text-destructive"
>
Delete
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
{/* 5-Node Milestone Stepper Rail */}
<PhaseStepper phaseIndex={item.phaseIndex} progressColor={item.progressColor} />
</div>
{/* 3. TEAM: Assigned People Count & Avatar Stack */}
<div className="w-full sm:w-auto xl:w-28 2xl:w-32 shrink-0 space-y-1 pt-2 xl:pt-0 border-t xl:border-t-0 border-border/60">
<p className="text-xs font-medium text-foreground">
{item.teamCount} people
</p>
<div className="flex -space-x-2 overflow-hidden items-center">
{item.teamMembers.length > 0 ? (
<>
{item.teamMembers.slice(0, 3).map((m, mIdx) => (
<Tooltip key={m.id || mIdx}>
<TooltipTrigger asChild>
<div className="inline-block relative">
<LazyImage
src={m.avatar ? `${process.env.BASE_URL_IMG}/${m.avatar}` : '/assets/no-avatar.jpg'}
alt={m.name}
className="inline-block h-7 w-7 rounded-full border-2 border-card bg-muted cursor-help hover:scale-110 hover:z-10 transition-transform object-cover"
/>
</div>
</TooltipTrigger>
<TooltipContent>
<p className="text-xs font-semibold text-popover-foreground">{m.name}</p>
<p className="text-[10px] text-muted-foreground">{m.position || 'Team Member'}</p>
</TooltipContent>
</Tooltip>
))}
{item.teamCount > 3 ? (
<div className="flex h-7 w-7 items-center justify-center rounded-full bg-muted/80 dark:bg-zinc-800 border-2 border-card text-[10px] font-bold text-muted-foreground">
+{item.teamCount - 3}
</div>
) : null}
</>
) : (
<span className="text-[11px] text-muted-foreground/70 italic">None</span>
)}
</div>
</div>
{/* 4. RIGHT: Delivery Health Badge, Schedule, Next Step & Updated */}
<div className="flex items-center justify-between xl:justify-end gap-4 w-full xl:w-auto shrink-0 pt-2 xl:pt-0 border-t xl:border-t-0 border-border/60">
<div className="space-y-1.5 min-w-0 xl:w-44 2xl:w-48 text-left">
{/* Health Badge */}
<div>
<span className={cn(
"inline-flex items-center gap-1.5 rounded-full border px-2.5 py-0 text-[11px] font-semibold",
item.healthBadgeClass
)}>
<span className={cn("h-1.5 w-1.5 rounded-full", item.healthDotClass)} />
<span>{item.healthStatus}</span>
</span>
</div>
{/* Remaining days or completion date */}
<p className="text-xs text-muted-foreground flex items-center gap-1.5 truncate">
<Calendar className="w-3.5 h-3.5 text-muted-foreground/70 shrink-0" />
<span className="truncate">{item.remainingText}</span>
</p>
{/* Next Milestone & Timestamp */}
<div className="flex items-center justify-between text-[11px] text-muted-foreground/80 gap-2">
<span className="truncate">{item.nextMilestoneText}</span>
<span className="text-[10px] text-muted-foreground/60 shrink-0">{item.updatedAgoText}</span>
</div>
</div>
{/* 5. ACTIONS: Vertical 3-dots Menu */}
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-muted-foreground hover:text-foreground rounded-full hover:bg-muted shrink-0"
aria-label="Assignment actions menu"
>
<MoreVertical className="w-4 h-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">
{promoteAssignmentUrl && (
<DropdownMenuItem asChild>
<Link href={promoteAssignmentUrl} className="flex items-center gap-2 text-his font-medium">
<ArrowUpRight className="w-4 h-4 text-his" />
Promote to Project
</Link>
</DropdownMenuItem>
)}
<DropdownMenuItem asChild>
<Link href={assignmentDetailUrl}>View Assignment Details</Link>
</DropdownMenuItem>
{projectDetailUrl && (
<DropdownMenuItem asChild>
<Link href={projectDetailUrl}>View Project Details</Link>
</DropdownMenuItem>
)}
{!clientId && assignment.client?.id && (
<DropdownMenuItem asChild>
<Link href={`/task/client-detail/${assignment.client.id}`}>View Client</Link>
</DropdownMenuItem>
)}
{editAssignmentUrl && (
<DropdownMenuItem asChild>
<Link href={editAssignmentUrl}>Edit Assignment</Link>
</DropdownMenuItem>
)}
{onManageTeam && (
<DropdownMenuItem onSelect={() => onManageTeam(assignment)}>
Manage Team
</DropdownMenuItem>
)}
{onUpdateAdministrationStatus && (
<DropdownMenuItem onSelect={() => onUpdateAdministrationStatus(assignment)}>
Update Administration Status
</DropdownMenuItem>
)}
{onUpdateStatus && (
<DropdownMenuItem onSelect={() => onUpdateStatus(assignment)}>
Update Technical Status
</DropdownMenuItem>
)}
{onDelete && (
<DropdownMenuItem
onSelect={() => onDelete(assignment)}
className="text-destructive focus:text-destructive"
>
Delete
</DropdownMenuItem>
)}
</DropdownMenuContent>
</DropdownMenu>
</div>
</CardContent>
</Card900>
</motion.div>
@@ -311,3 +380,4 @@ export default function AssignmentList({
</div>
);
}
@@ -0,0 +1,108 @@
"use client";
import { useMemo } from 'react';
import { motion } from 'motion/react';
import { Briefcase, FileText, Users, TrendingUp, CheckCircle2, AlertTriangle } from 'lucide-react';
import { Card900 } from '@/components/ui/card';
import { IProjectAssignment } from '../../type.assignment';
import { calculateDashboardStats } from '../../utils/assignment-overview-helpers';
interface ProjectAssignmentDashboardStatsProps {
assignments: IProjectAssignment[];
className?: string;
}
export default function ProjectAssignmentDashboardStats({
assignments,
className = '',
}: ProjectAssignmentDashboardStatsProps) {
const stats = useMemo(() => calculateDashboardStats(assignments), [assignments]);
return (
<div className={`space-y-3.5 ${className}`}>
<h2 className="text-xl sm:text-2xl font-bold tracking-tight text-foreground">
Project Assignment Dashboard
</h2>
<div className="grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-6 gap-3 sm:gap-4">
{/* 1. Total Projects */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-blue-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-blue-500/10 dark:bg-blue-500/15 border border-blue-500/20 flex items-center justify-center shrink-0 text-blue-500 dark:text-blue-400">
<FileText className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">Total Projects</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.totalProjects}</p>
</div>
</Card900>
</motion.div>
{/* 2. Active Work Orders */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2, delay: 0.03 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-amber-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-amber-500/10 dark:bg-amber-500/15 border border-amber-500/20 flex items-center justify-center shrink-0 text-amber-500 dark:text-amber-400">
<Briefcase className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">Active Work Orders</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.activeWorkOrders}</p>
</div>
</Card900>
</motion.div>
{/* 3. Assigned People */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2, delay: 0.06 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-emerald-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-emerald-500/10 dark:bg-emerald-500/15 border border-emerald-500/20 flex items-center justify-center shrink-0 text-emerald-500 dark:text-emerald-400">
<Users className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">Assigned People</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.assignedPeople} people</p>
</div>
</Card900>
</motion.div>
{/* 4. Average Progress */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2, delay: 0.09 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-orange-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-orange-500/10 dark:bg-orange-500/15 border border-orange-500/20 flex items-center justify-center shrink-0 text-orange-500 dark:text-orange-400">
<TrendingUp className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">Average Progress</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.averageProgress}%</p>
</div>
</Card900>
</motion.div>
{/* 5. On-Time Projects */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2, delay: 0.12 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-emerald-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-emerald-500/10 dark:bg-emerald-500/15 border border-emerald-500/20 flex items-center justify-center shrink-0 text-emerald-500 dark:text-emerald-400">
<CheckCircle2 className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">On-Time Projects</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.onTimeRatio}</p>
</div>
</Card900>
</motion.div>
{/* 6. At Risk / Delayed */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2, delay: 0.15 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-rose-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-rose-500/10 dark:bg-rose-500/15 border border-rose-500/20 flex items-center justify-center shrink-0 text-rose-500 dark:text-rose-400">
<AlertTriangle className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">At Risk / Delayed</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.atRiskDelayed}</p>
</div>
</Card900>
</motion.div>
</div>
</div>
);
}
+1
View File
@@ -25,6 +25,7 @@ export interface IProjectAssignment {
project?: Project
project_assignment_status: ProjectStatus
project_assignment_status_notes?: string
project_assignment_technical_status?: ProjectAssignmentStatus | null
wo_code: string
wo_description: string
wo_name: string
@@ -0,0 +1,614 @@
import { IProjectAssignment } from '../type.assignment';
export interface ProgressColorConfig {
name: 'orange' | 'yellow' | 'green' | 'blue' | 'purple' | 'red';
label: string;
hex: string;
barColor: string;
textColor: string;
glowRing: string;
activeDot: string;
badgeBg: string;
badgeText: string;
badgeBorder: string;
}
export const COLOR_SPECTRUM: Record<string, ProgressColorConfig> = {
orange: {
name: 'orange',
label: 'Awal',
hex: '#ea512c',
barColor: 'bg-[#ea512c]',
textColor: 'text-[#ea512c]',
glowRing: 'ring-4 ring-[#ea512c]/30 shadow-[0_0_12px_rgba(234,81,44,0.6)]',
activeDot: 'bg-[#ea512c]',
badgeBg: 'bg-[#ea512c]/15',
badgeText: 'text-[#ea512c]',
badgeBorder: 'border-[#ea512c]/30',
},
yellow: {
name: 'yellow',
label: 'Menuju Pertengahan',
hex: '#eab308',
barColor: 'bg-[#eab308]',
textColor: 'text-[#eab308]',
glowRing: 'ring-4 ring-[#eab308]/30 shadow-[0_0_12px_rgba(234,179,8,0.6)]',
activeDot: 'bg-[#eab308]',
badgeBg: 'bg-[#eab308]/15',
badgeText: 'text-[#eab308]',
badgeBorder: 'border-[#eab308]/30',
},
green: {
name: 'green',
label: 'Pertengahan',
hex: '#10b981',
barColor: 'bg-[#10b981]',
textColor: 'text-[#10b981]',
glowRing: 'ring-4 ring-[#10b981]/30 shadow-[0_0_12px_rgba(16,185,129,0.6)]',
activeDot: 'bg-[#10b981]',
badgeBg: 'bg-[#10b981]/15',
badgeText: 'text-[#10b981]',
badgeBorder: 'border-[#10b981]/30',
},
blue: {
name: 'blue',
label: 'Lanjut',
hex: '#3b82f6',
barColor: 'bg-[#3b82f6]',
textColor: 'text-[#3b82f6]',
glowRing: 'ring-4 ring-[#3b82f6]/30 shadow-[0_0_12px_rgba(59,130,246,0.6)]',
activeDot: 'bg-[#3b82f6]',
badgeBg: 'bg-[#3b82f6]/15',
badgeText: 'text-[#3b82f6]',
badgeBorder: 'border-[#3b82f6]/30',
},
purple: {
name: 'purple',
label: 'Mendekati End of Date',
hex: '#a855f7',
barColor: 'bg-[#a855f7]',
textColor: 'text-[#a855f7]',
glowRing: 'ring-4 ring-[#a855f7]/30 shadow-[0_0_12px_rgba(168,85,247,0.6)]',
activeDot: 'bg-[#a855f7]',
badgeBg: 'bg-[#a855f7]/15',
badgeText: 'text-[#a855f7]',
badgeBorder: 'border-[#a855f7]/30',
},
red: {
name: 'red',
label: 'Critical / Off Track',
hex: '#f43f5e',
barColor: 'bg-rose-500',
textColor: 'text-rose-500 dark:text-rose-400',
glowRing: 'ring-4 ring-rose-500/30 shadow-[0_0_12px_rgba(244,63,94,0.6)]',
activeDot: 'bg-rose-500',
badgeBg: 'bg-rose-500/15 dark:bg-rose-500/20',
badgeText: 'text-rose-600 dark:text-rose-400',
badgeBorder: 'border-rose-500/30',
},
};
export interface AssignmentOverview {
assignmentType: 'Work Order' | 'Internal Memo';
isProject: boolean;
title: string;
code?: string;
startDate?: string;
endDate?: string;
formattedDateRange: string;
endUserName?: string;
endUserPhoto?: string | null;
clientName?: string;
// Project Status (derived from project_assignment_status_detail or project_assignment_status.name)
projectStatusName: string;
isFromDetail: boolean;
// Stepper Phase (0: Dev, 1: SIT, 2: UAT, 3: PTR, 4: Live)
phaseIndex: number;
// Progress metrics & Dynamic Progress Color
elapsedDays: number;
totalDays: number;
daysRatioText: string;
progressPercent: number;
progressColor: ProgressColorConfig;
// Team
teamCount: number;
teamMembers: Array<{
id: number | string;
name: string;
avatar?: string | null;
position?: string;
}>;
// Delivery Health & Next Step
healthStatus: 'On Track' | 'At Risk' | 'Near Go-live' | 'Completed' | 'Critical' | 'Off Track';
healthBadgeClass: string;
healthDotClass: string;
remainingText: string;
nextMilestoneText: string;
updatedAgoText: string;
}
export function formatAssignmentDate(dateStr?: string) {
if (!dateStr) return 'N/A';
const d = new Date(dateStr);
if (isNaN(d.getTime())) return 'N/A';
const day = String(d.getDate()).padStart(2, '0');
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const month = months[d.getMonth()];
const year = d.getFullYear();
return `${day} ${month} ${year}`;
}
export function formatRelativeTime(dateStr?: string): string {
if (!dateStr) return 'Updated 1 day ago';
const d = new Date(dateStr);
if (isNaN(d.getTime())) return 'Updated 1 day ago';
const diffSec = Math.floor((Date.now() - d.getTime()) / 1000);
if (diffSec < 3600) return 'Updated just now';
const diffHours = Math.floor(diffSec / 3600);
if (diffHours < 24) return `Updated ${diffHours} hour${diffHours > 1 ? 's' : ''} ago`;
const diffDays = Math.floor(diffHours / 24);
if (diffDays < 7) return `Updated ${diffDays} day${diffDays > 1 ? 's' : ''} ago`;
const diffWeeks = Math.floor(diffDays / 7);
return `Updated ${diffWeeks} week${diffWeeks > 1 ? 's' : ''} ago`;
}
// Helper: checks if a detail entry has ANY assigned dates
export const hasAssignedDates = (d: any): boolean => {
if (!d) return false;
if (d.start_date || d.end_date) return true;
if (Array.isArray(d.date) && d.date.length > 0) {
return d.date.some((item: any) => Boolean(item?.start_date || item?.end_date));
}
if (typeof d.date === 'string' && d.date.trim().length > 0) return true;
return false;
};
/**
* Urutan technical status:
* 1. development -> 2. SIT -> 3. UAT -> 4. PTR -> 5. Go-Live -> 6. BAST -> 7. Warranty
*/
export function getTechnicalStageRank(rawName?: string | null): number {
if (!rawName) return 0;
const lower = rawName.toLowerCase();
if (lower.includes('warranty')) return 7;
if (lower.includes('bast') || lower.includes('handover')) return 6;
if (lower.includes('go-live') || lower.includes('live')) return 5;
if (lower.includes('ptr') || lower.includes('trial')) return 4;
if (lower.includes('uat') || lower.includes('acceptance')) return 3;
if (lower.includes('sit') || lower.includes('integration')) return 2;
if (lower.includes('dev') || lower.includes('development')) return 1;
if (lower.includes('complete') || lower.includes('done')) return 5;
return 0;
}
/**
* 1. Derives project status:
* Taken from project_assignment_status_detail, if not present or all dates are null fallback to project_assignment_status.name
*/
export function resolveProjectStatus(assignment: IProjectAssignment, indexFallback = 0): {
statusName: string;
isFromDetail: boolean;
phaseIndex: number;
} {
const details = assignment.project_assignment_status_detail || [];
// Filter only entries that actually have dates assigned
const detailsWithDates = details.filter(hasAssignedDates);
// If NO detail has dates assigned (e.g. all start_date/end_date/date are null)
// -> Fallback directly to project_assignment_status.name
if (detailsWithDates.length === 0) {
if (assignment.project_assignment_status?.name) {
const name = assignment.project_assignment_status.name;
return {
statusName: name,
isFromDetail: false,
phaseIndex: mapStatusNameToPhaseIndex(name),
};
}
return {
statusName: 'Not Started',
isFromDetail: false,
phaseIndex: 0,
};
}
// If there ARE details with assigned dates:
// Determine which detail is active right now or the latest assigned stage
const now = Date.now();
let activeDetail: any = null;
for (let i = 0; i < detailsWithDates.length; i++) {
const d = detailsWithDates[i];
const sTime = d.start_date ? new Date(d.start_date).getTime() : null;
const eTime = d.end_date ? new Date(d.end_date).getTime() : null;
if (sTime && eTime) {
if (now >= sTime && now <= eTime) {
activeDetail = d;
break;
}
} else if (sTime && !eTime) {
if (now >= sTime) {
activeDetail = d;
break;
}
} else if (Array.isArray(d.date)) {
const matchInterval = d.date.some((item: any) => {
const s = item?.start_date ? new Date(item.start_date).getTime() : null;
const e = item?.end_date ? new Date(item.end_date).getTime() : null;
return s && e && now >= s && now <= e;
});
if (matchInterval) {
activeDetail = d;
break;
}
}
}
// If no stage is active today, pick the latest stage with dates (last one in chronological progression)
const chosen = activeDetail || detailsWithDates[detailsWithDates.length - 1];
const rawName = chosen?.project_assignment_status?.name || assignment.project_assignment_status?.name || 'Active';
return {
statusName: formatShortPhaseName(rawName),
isFromDetail: true,
phaseIndex: mapStatusNameToPhaseIndex(rawName),
};
}
/**
* Resolves technical status from either project_assignment_technical_status.name
* OR the highest reached stage in project_assignment_status_detail (with assigned dates).
*/
export function resolveTechnicalStatus(assignment: IProjectAssignment): {
technicalStatusName: string | null;
hasTechnicalStatus: boolean;
technicalRank: number;
} {
// 1. Check project_assignment_technical_status
const techName = assignment.project_assignment_technical_status?.name || null;
const rankTech = techName ? getTechnicalStageRank(techName) : 0;
// 2. Check project_assignment_status_detail for dated entries
const details = assignment.project_assignment_status_detail || [];
let maxDetailRank = 0;
let maxDetailName: string | null = null;
details.forEach(d => {
if (hasAssignedDates(d) && d.project_assignment_status?.name) {
const r = getTechnicalStageRank(d.project_assignment_status.name);
if (r > maxDetailRank) {
maxDetailRank = r;
maxDetailName = d.project_assignment_status.name;
}
}
});
const technicalRank = Math.max(rankTech, maxDetailRank);
const hasTechnicalStatus = technicalRank > 0;
const technicalStatusName = (rankTech >= maxDetailRank && techName)
? techName
: (maxDetailName || techName || null);
return {
technicalStatusName,
hasTechnicalStatus,
technicalRank,
};
}
function formatShortPhaseName(raw: string): string {
const lower = raw.toLowerCase();
if (lower.includes('development') || lower === 'dev') return 'Development';
if (lower.includes('system integration') || lower.includes('sit')) return 'SIT';
if (lower.includes('user acceptance') || lower.includes('uat')) return 'UAT';
if (lower.includes('production trial') || lower.includes('ptr')) return 'PTR';
if (lower.includes('go-live') || lower.includes('live')) return 'Go-Live';
if (lower.includes('handover') || lower.includes('bast')) return 'BAST';
if (lower.includes('warranty')) return 'Warranty';
return raw;
}
function mapStatusNameToPhaseIndex(name: string): number {
const lower = name.toLowerCase();
if (lower.includes('development') || lower === 'dev' || lower.includes('not started')) return 0;
if (lower.includes('sit') || lower.includes('integration')) return 1;
if (lower.includes('uat') || lower.includes('acceptance')) return 2;
if (lower.includes('ptr') || lower.includes('trial')) return 3;
if (lower.includes('go-live') || lower.includes('live') || lower.includes('bast') || lower.includes('warranty') || lower.includes('complete')) return 4;
return 0;
}
/**
* 2. Progress Color Logic:
* Warna fill progress bar dan stepper rail tetap dipertahankan sesuai logic gradasi 5 spektrum:
* - 0% – 18%: Mengarah ke Oranye (#ea512c)
* - 18% – 35%: Kuning (#eab308)
* - 35% – 65%: Hijau (#10b981) (mencakup titik pertengahan ~50%)
* - 65% – 88%: Biru (#3b82f6)
* - >= 88% atau mendekati batas akhir deadline (<= 14 hari): Ungu (#a855f7)
*/
export function resolveProgressColor(
progressPercent: number,
isNearEndDate: boolean,
isPastEndDate: boolean,
_isCriticalOffTrack?: boolean
): ProgressColorConfig {
// >= 88% atau mendekati batas akhir deadline (<= 14 hari) atau lewat deadline -> Ungu (#a855f7)
if (isPastEndDate || isNearEndDate || progressPercent >= 88) {
return COLOR_SPECTRUM.purple;
}
// 65% – 88%: Biru (#3b82f6)
if (progressPercent > 65) {
return COLOR_SPECTRUM.blue;
}
// 35% – 65%: Hijau (#10b981) (mencakup titik pertengahan ~50%)
if (progressPercent >= 35) {
return COLOR_SPECTRUM.green;
}
// 18% – 35%: Kuning (#eab308)
if (progressPercent >= 18) {
return COLOR_SPECTRUM.yellow;
}
// 0% – 18%: Mengarah ke Oranye (#ea512c)
return COLOR_SPECTRUM.orange;
}
/**
* 3. Delivery Health Status (Summary Progress) Logic:
* - Complete (Sky Blue) => sama atau lewat deadline, namun project_assignment_technical_status.name atau project_assignment_status_detail sudah sampai ke Go-Live (rank >= 5)
* - At Risk (Warna Kuning) => progress lewat dari 75% dan namun project_assignment_technical_status.name atau project_assignment_status_detail belum sampai ke PTR (rank < 4)
* - Off Track / Critical (Warna Merah) => sama atau lewat deadline and namun project_assignment_technical_status.name atau project_assignment_status_detail belum sampai ke Go-Live status (rank < 5)
* - On Track (Warna Hijau) => Belum lewat deadline dan progres sejalan dengan target (progress <= 75%, atau sudah sampai ke PTR)
*/
export function resolveDeliveryHealth(
technicalRank: number,
hasTechnicalStatus: boolean,
progressPercent: number,
endDate?: string
): {
healthStatus: 'On Track' | 'At Risk' | 'Near Go-live' | 'Completed' | 'Critical' | 'Off Track';
healthBadgeClass: string;
healthDotClass: string;
isCritical: boolean;
} {
const now = Date.now();
const hasEndDate = Boolean(endDate && !isNaN(new Date(endDate).getTime()));
// Sama atau lewat deadline
const isPastDeadline = hasEndDate ? now >= new Date(endDate!).getTime() : false;
// KONDISI 1: Sama atau lewat deadline
if (isPastDeadline) {
// Complete (Sky Blue) => sama atau lewat deadline, namun sudah sampai ke Go-Live (rank >= 5)
if (technicalRank >= 5) {
return {
healthStatus: 'Completed',
healthBadgeClass: 'bg-sky-500/10 text-sky-600 dark:text-sky-400 border-sky-500/30',
healthDotClass: 'bg-sky-500',
isCritical: false,
};
}
// Off Track / Critical (Warna Merah) => sama atau lewat deadline and belum sampai ke Go-Live (rank < 5)
// Perhatian: Walaupun progress hari sudah 100%, jika belum Go-Live maka tetap Critical / Off Track!
const label = (!hasTechnicalStatus || technicalRank === 0) ? 'Off Track' : 'Critical';
return {
healthStatus: label,
healthBadgeClass: 'bg-red-500/10 text-red-600 dark:text-red-400 border-red-500/30',
healthDotClass: 'bg-red-500',
isCritical: true,
};
}
// KONDISI 2: Belum lewat deadline (atau tidak ada endDate)
// Sudah sampai ke Go-Live sebelum deadline -> Complete (Sky Blue)
if (technicalRank >= 5) {
return {
healthStatus: 'Completed',
healthBadgeClass: 'bg-sky-500/10 text-sky-600 dark:text-sky-400 border-sky-500/30',
healthDotClass: 'bg-sky-500',
isCritical: false,
};
}
// At Risk (Warna Kuning) => progress lewat dari 75% dan belum sampai ke PTR (rank < 4)
if (progressPercent > 75 && technicalRank < 4) {
return {
healthStatus: 'At Risk',
healthBadgeClass: 'bg-yellow-500/15 text-yellow-700 dark:text-yellow-400 border-yellow-500/30',
healthDotClass: 'bg-yellow-500',
isCritical: false,
};
}
// On Track (Warna Hijau) => Belum lewat deadline dan progres sejalan dengan target:
// - Progress <= 75%, ATAU
// - Progress > 75% tapi status teknis sudah mengimbangi dengan mencapai minimal PTR (rank >= 4)
return {
healthStatus: 'On Track',
healthBadgeClass: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/30',
healthDotClass: 'bg-emerald-500',
isCritical: false,
};
}
/**
* Calculates complete visual representation for an assignment row
*/
export function getAssignmentOverview(assignment: IProjectAssignment, index: number): AssignmentOverview {
const isProject = !!assignment.wo_name;
const assignmentType = isProject ? 'Work Order' : 'Internal Memo';
const title = assignment.wo_name || assignment.im_name || assignment.project?.name || 'Untitled Assignment';
const code = assignment.wo_code || assignment.im_code || assignment.project?.code;
const startDate = assignment.wo_start_date || assignment.im_start_date || assignment.project?.start_date;
const endDate = assignment.wo_end_date || assignment.im_end_date || assignment.project?.end_date;
const formattedDateRange = `${formatAssignmentDate(startDate)} - ${formatAssignmentDate(endDate)}`;
const endUserName = assignment.end_user?.name;
const endUserPhoto = assignment.end_user?.photo;
const clientName = assignment.client?.name;
// 1. Resolve Project Status (from status_detail with dates or fallback to project_assignment_status.name)
const { statusName: projectStatusName, isFromDetail, phaseIndex } = resolveProjectStatus(assignment, index);
// Compute duration & progress
let totalDays = 0;
let elapsedDays = 0;
let progressPercent = 0;
const now = Date.now();
let isPastEndDate = false;
let isNearEndDate = false;
if (startDate && endDate) {
const sTime = new Date(startDate).getTime();
const eTime = new Date(endDate).getTime();
if (!isNaN(sTime) && !isNaN(eTime) && eTime >= sTime) {
totalDays = Math.max(1, Math.round((eTime - sTime) / (1000 * 60 * 60 * 24)));
if (now < sTime) {
elapsedDays = 0;
} else if (now >= eTime) {
elapsedDays = totalDays;
isPastEndDate = true;
} else {
elapsedDays = Math.round((now - sTime) / (1000 * 60 * 60 * 24));
const remaining = Math.round((eTime - now) / (1000 * 60 * 60 * 24));
if (remaining <= 14) isNearEndDate = true;
}
progressPercent = Math.min(100, Math.max(0, Math.round((elapsedDays / totalDays) * 100)));
}
}
const daysRatioText = `${elapsedDays} / ${totalDays} hari`;
// 2. Resolve Technical Status & Delivery Health
const { hasTechnicalStatus, technicalRank } = resolveTechnicalStatus(assignment);
const { healthStatus, healthBadgeClass, healthDotClass, isCritical } = resolveDeliveryHealth(
technicalRank,
hasTechnicalStatus,
progressPercent,
endDate
);
// 3. Resolve Progress Color (Orange -> Kuning -> Hijau -> Biru -> Ungu)
const progressColor = resolveProgressColor(progressPercent, isNearEndDate, isPastEndDate, isCritical);
// 4. Team members extraction strictly from project_assignment_work_order_detail
const rawTeam = Array.isArray(assignment.project_assignment_work_order_detail)
? assignment.project_assignment_work_order_detail
: [];
const teamMembers = rawTeam
.map(t => ({
id: t.user?.id || t.id,
name: t.user?.fullname || t.user?.nickname || '',
avatar: t.user?.avatar,
position: t.user?.position?.name || 'Member',
}))
.filter(m => Boolean(m.name));
const teamCount = teamMembers.length;
// Remaining text & Next milestone
let remainingText = '';
let nextMilestoneText = '';
if (healthStatus === 'Critical' || healthStatus === 'Off Track') {
remainingText = endDate ? `Passed deadline (${formatAssignmentDate(endDate)})` : 'Past deadline';
nextMilestoneText = 'Next: Urgent Follow-up';
} else if (healthStatus === 'Completed') {
remainingText = endDate ? `Completed on ${formatAssignmentDate(endDate)}` : 'Completed';
nextMilestoneText = 'Next: -';
} else if (healthStatus === 'At Risk') {
const remDays = Math.max(1, totalDays - elapsedDays);
remainingText = `${remDays} days remaining`;
nextMilestoneText = 'Next: Accelerate to PTR';
} else {
const remDays = Math.max(1, totalDays - elapsedDays);
remainingText = totalDays > 0 ? `${remDays} days remaining` : 'Schedule pending';
nextMilestoneText = phaseIndex === 0 ? 'Next: Feature Development' : 'Next: SIT Testing';
}
const updatedAgoText = formatRelativeTime(assignment.created_at || startDate);
return {
assignmentType,
isProject,
title,
code,
startDate,
endDate,
formattedDateRange,
endUserName,
endUserPhoto,
clientName,
projectStatusName,
isFromDetail,
phaseIndex,
elapsedDays,
totalDays,
daysRatioText,
progressPercent,
progressColor,
teamCount,
teamMembers,
healthStatus,
healthBadgeClass,
healthDotClass,
remainingText,
nextMilestoneText,
updatedAgoText,
};
}
/**
* Calculates top executive summary metrics for "Project Assignment Dashboard"
*/
export function calculateDashboardStats(assignments: IProjectAssignment[]) {
const totalAssignments = assignments.length;
const overviews = assignments.map((a, i) => getAssignmentOverview(a, i));
const totalProjects = assignments.reduce((acc, a) => {
if (a.project?.id) acc.add(a.project.id);
else acc.add(a.id);
return acc;
}, new Set<number>()).size;
const activeWorkOrders = assignments.filter(a => !!a.wo_name).length;
// Assigned people strictly from project_assignment_work_order_detail
const uniqueUsers = new Set<string | number>();
assignments.forEach(a => {
(a.project_assignment_work_order_detail || []).forEach(w => {
if (w.user?.id) uniqueUsers.add(w.user.id);
});
});
const assignedPeopleCount = uniqueUsers.size;
// Average progress
const avgProgress = overviews.length > 0
? Math.round(overviews.reduce((acc, o) => acc + o.progressPercent, 0) / overviews.length)
: 0;
// On-Time projects vs Total
const onTimeCount = overviews.filter(o => o.healthStatus === 'On Track' || o.healthStatus === 'Completed').length;
const atRiskCount = overviews.filter(o => o.healthStatus === 'At Risk' || o.healthStatus === 'Critical' || o.healthStatus === 'Off Track').length;
return {
totalProjects: totalProjects || totalAssignments,
activeWorkOrders: activeWorkOrders || totalAssignments,
assignedPeople: assignedPeopleCount,
averageProgress: avgProgress,
onTimeRatio: `${onTimeCount} / ${totalAssignments}`,
atRiskDelayed: atRiskCount,
};
}
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "hats-app",
"description": "H.I.S Super Apps (smart absence, task management, work permit and leave mangement, etc).",
"version": "1.1.2",
"version": "1.2.0",
"private": true,
"author": "ichsankurnia",
"repository": {
@@ -93,4 +93,4 @@
"tw-animate-css": "^1.4.0",
"typescript": "^5"
}
}
}