Files
hats-app/app/(dashboard)/task/component/project-assignment/AssignmentList.tsx
T
Ichsan Kurniawan a991f114ef Show assignment progress and latest activity
Add actual progress and latest activity details to assignment grid and list views, and show linked project names in the list. Remove a debug log from the assignment detail page.
2026-10-17 21:26:05 +07:00

421 lines
28 KiB
TypeScript

"use client";
import { IProjectAssignment } from '../../type.assignment';
import { motion } from 'motion/react';
import { Card900, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import {
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import {
Tooltip, TooltipContent, TooltipTrigger,
} from '@/components/ui/tooltip';
import { LazyImage } from '@/components/ui/lazy-image';
import { Calendar, MoreVertical, ArrowUpRight, Clock, FolderGit2 } from 'lucide-react';
import Link from 'next/link';
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 { 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[];
clientId?: string;
onManageTeam?: (assignment: IProjectAssignment) => void;
onUpdateStatus?: (assignment: IProjectAssignment) => void;
onUpdateAdministrationStatus?: (assignment: IProjectAssignment) => void;
onDelete?: (assignment: IProjectAssignment) => void;
}
export default function AssignmentList({
assignments,
clientId,
onManageTeam,
onUpdateStatus,
onUpdateAdministrationStatus,
onDelete,
}: AssignmentListProps) {
return (
<div className="flex flex-col gap-3.5 sm:gap-4">
{assignments.map((assignment, index) => {
const item = getAssignmentOverview(assignment, index);
const effectiveClientId = clientId || assignment.client?.id;
const assignmentDetailUrl = effectiveClientId ? `/task/client-detail/${effectiveClientId}/${assignment.id}` : '#';
const projectDetailUrl = effectiveClientId && assignment.project?.id ? `/task/client-detail/${effectiveClientId}/project-detail/${assignment.project.id}` : null;
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 = !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={assignment.id || index}
>
<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-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={item.assignmentType}
className="w-full h-full bg-transparent"
imgClassName="object-contain rounded-xl"
/>
</Link>
{/* Identity, Badges, Title & Timeline */}
<div className="min-w-0 flex-1 space-y-1.5">
{/* 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>
{/* Project Status Badge matching technical status badge colors */}
<BadgeStatus status={assignment.project_assignment_status.name} />
{/* Code Pill with Tooltip */}
{item.code ? (
<Tooltip>
<TooltipTrigger asChild>
<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 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-bold text-base sm:text-lg text-foreground hover:text-his transition-colors line-clamp-1 tracking-tight wrap-break-word"
>
{item.title}
</Link>
</div>
{assignment.project?.name && (
<div className="flex items-center gap-1.5 text-xs text-muted-foreground mt-1 min-w-0 font-medium">
<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="text-foreground hover:text-his truncate hover:underline inline-block min-w-0"
>
{assignment.project.name}
</Link>
) : (
<span className="text-foreground truncate min-w-0">{assignment.project.name}</span>
)}
</div>
)}
{/* 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.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>
</div>
{/* 2. CENTER: Progress Bars (Actual Progress & Timeline) & 5-Node Stepper Track */}
<div className="w-full xl:w-72 2xl:w-80 shrink-0 space-y-2 pt-2 xl:pt-0 border-t xl:border-t-0 border-border/60">
{/* Actual Progress (Real Work) matching detail page styling */}
<div className="flex items-center justify-between text-xs font-mono font-medium">
<span className="text-[10px] tracking-wider font-semibold text-his bg-his/10 px-1.5 py-0.5 rounded font-sans shrink-0">
Actual
</span>
<div className="h-1.5 rounded-full bg-zinc-200 dark:bg-zinc-700/60 flex-1 mx-2.5 overflow-hidden">
<div
className="h-full rounded-full bg-his transition-all duration-700 ease-out"
style={{
width: `${item.actualProgress}%`,
boxShadow: '0 0 8px rgba(234, 81, 44, 0.45)',
}}
/>
</div>
<span className="text-foreground font-bold shrink-0">{item.actualProgress}%</span>
</div>
{/* 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 text-[11px] shrink-0">{item.daysRatioText}</span>
<div className="h-1.5 rounded-full bg-zinc-200 dark:bg-zinc-700/60 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-muted-foreground font-semibold shrink-0">{item.progressPercent}%</span>
</div>
{/* 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-48 2xl:w-56 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>
{/* Latest Activity Wording */}
<p
className="text-[11px] text-muted-foreground/80 truncate flex items-center gap-1.5"
title={item.latestActivityText}
>
<Clock className="w-3 h-3 text-muted-foreground/60 shrink-0" />
<span className="truncate">{item.latestActivityText}</span>
</p>
</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>
);
})}
</div>
);
}