Add assignment timeline and activity log

This change adds a milestone timeline and development activity log for assignment detail pages, including a JSON comparison modal for activity history entries. It also extends assignment history types and overview helper logic to surface progress, delivery health, and milestone dates more accurately.
This commit is contained in:
Ichsan Kurniawan
2026-10-14 15:47:50 +07:00
parent 6f52078aa5
commit f0526e4096
7 changed files with 1278 additions and 299 deletions
@@ -0,0 +1,114 @@
"use client";
import { useState } from 'react';
import { IProjectAssignmentHistory } from '../../../type.assignment';
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Check, Copy, FileText } from 'lucide-react';
import dayjs from 'dayjs';
import { DialogDescription } from '@radix-ui/react-dialog';
interface ActivityHistoryModalProps {
historyItem: IProjectAssignmentHistory | null;
open: boolean;
onClose: () => void;
}
export function ActivityHistoryModal({ historyItem, open, onClose }: ActivityHistoryModalProps) {
const [copied, setCopied] = useState(false);
if (!historyItem) return null;
const oldData = historyItem.old_data;
const newData = historyItem.new_data;
const copyFullJson = () => {
const payload = {
id: historyItem.id,
description: historyItem.description,
created_at: historyItem.created_at,
user: historyItem.user,
old_data: oldData,
new_data: newData,
};
navigator.clipboard.writeText(JSON.stringify(payload, null, 2));
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
return (
<Dialog open={open} onOpenChange={(isOpen) => !isOpen && onClose()}>
<DialogContent className="sm:max-w-4xl max-h-[90vh] sm:max-h-[90vh] flex flex-col p-6 bg-zinc-950 border border-zinc-800 text-zinc-100 rounded-xl shadow-2xl">
{/* Header */}
<DialogHeader className="space-y-1 pb-4 border-b border-zinc-800">
<DialogTitle className="flex items-center gap-2">
<FileText className="h-5 w-5 text-his" />
Activity Log Details #{historyItem.id}
</DialogTitle>
<DialogDescription className="text-xs text-zinc-400 leading-relaxed">
{historyItem.description}
</DialogDescription>
<div className="flex items-center gap-3 pt-1 text-[11px] font-mono">
<span>By: {historyItem.user?.fullname || historyItem.user?.nickname || 'System'}</span>
<span>·</span>
<span>{dayjs(historyItem.created_at).format('DD MMM YYYY, HH:mm:ss')}</span>
</div>
</DialogHeader>
{/* Side-by-Side Comparison Panels */}
<div className="flex-1 overflow-y-auto py-4 space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* Old Data Panel */}
<div className="flex flex-col rounded-lg border border-zinc-800 bg-zinc-900/60 overflow-hidden">
<div className="px-3.5 py-2 border-b border-zinc-800 bg-zinc-900 text-xs font-mono font-medium text-zinc-400">
Old Data
</div>
<div className="p-3.5 font-mono text-xs text-zinc-300 max-h-[50vh] overflow-auto">
<pre className="whitespace-pre-wrap">
{oldData !== null && oldData !== undefined
? JSON.stringify(oldData, null, 2)
: 'null'}
</pre>
</div>
</div>
{/* New Data Panel */}
<div className="flex flex-col rounded-lg border border-zinc-800 bg-zinc-900/60 overflow-hidden">
<div className="px-3.5 py-2 border-b border-zinc-800 bg-zinc-900 text-xs font-mono font-medium text-zinc-400">
New Data
</div>
<div className="p-3.5 font-mono text-xs text-zinc-300 max-h-[50vh] overflow-auto">
<pre className="whitespace-pre-wrap">
{newData !== null && newData !== undefined
? JSON.stringify(newData, null, 2)
: 'null'}
</pre>
</div>
</div>
</div>
</div>
{/* Footer Actions */}
<div className="pt-4 border-t border-zinc-800 flex items-center justify-between">
<Button
variant="outline"
size="sm"
onClick={copyFullJson}
className="gap-1.5 text-xs border-zinc-700 bg-zinc-900 hover:bg-zinc-800 text-zinc-300"
>
{copied ? <Check className="w-3.5 h-3.5 text-emerald-400" /> : <Copy className="w-3.5 h-3.5" />}
<span>{copied ? 'Copied' : 'Copy JSON'}</span>
</Button>
<Button
variant="default"
size="sm"
onClick={onClose}
className="text-xs bg-zinc-800 hover:bg-zinc-700 text-zinc-100"
>
Close
</Button>
</div>
</DialogContent>
</Dialog>
);
}
@@ -1,14 +1,4 @@
"use client"
/**
* Design read: internal ops detail page for staff, calm Linear-style language,
* existing shadcn + Tailwind stack, brand orange (`his`) as the single accent.
* Dials: VARIANCE 5, MOTION 4, DENSITY 5.
*
* Shape lock: surfaces rounded-2xl, inner tiles rounded-xl, small chips rounded-lg.
* Elevation comes from borders, not shadows. Accent is used only for the current
* timeline node, link hovers and the primary action.
*/
"use client";
import { useState, type ReactNode } from 'react';
import Link from 'next/link';
@@ -19,6 +9,7 @@ import {
FolderGit2, History, LayoutGrid, List, Mail, Phone, UserPlus, Users,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card900 } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { LazyImage } from '@/components/ui/lazy-image';
import BadgeStatus from '@/components/ui/badge-status';
@@ -28,6 +19,18 @@ import { IClient, CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../.
import { IProjectAssignment, ProjectAssignmentWorkOrderDetail } from '../../../type.assignment';
import ConvertedAssignmentBadge from '../../../component/project-assignment/ConvertedAssignmentBadge';
import Reveal from '@/components/ui/reveal';
import { buildAssignmentOverview, formatAssignmentDate } from '../../../utils/assignment-overview-helpers';
// Dynamically imported heavy child components
const ProjectMilestoneTimeline = dynamic(
() => import('./ProjectMilestoneTimeline').then((mod) => mod.ProjectMilestoneTimeline),
{ ssr: false, loading: () => <div className="h-44 w-full animate-pulse rounded-2xl border border-border/80 bg-card p-6" /> }
);
const DevelopmentActivityLog = dynamic(
() => import('./DevelopmentActivityLog').then((mod) => mod.DevelopmentActivityLog),
{ ssr: false, loading: () => <div className="h-64 w-full animate-pulse rounded-2xl border border-border/80 bg-card p-6" /> }
);
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">
@@ -60,13 +63,7 @@ interface Props {
const TEAM_PREVIEW_LIMIT = 5;
function formatAssignmentDate(dateStr?: string | null) {
if (!dateStr) return 'N/A';
const d = dayjs(dateStr);
return d.isValid() ? d.format('DD MMM YYYY') : 'N/A';
}
/** Human span between two dates, e.g. "2 months 15 days". Null when either date is missing or invalid. */
/** Human span between two dates, e.g. "5 months" or "2 months 15 days". */
function formatSpan(start?: string | null, end?: string | null) {
if (!start || !end) return null;
const s = dayjs(start).startOf('day');
@@ -106,46 +103,56 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
const visibleTeam = showAllTeam ? team : team.slice(0, TEAM_PREVIEW_LIMIT);
const hiddenTeamCount = team.length - visibleTeam.length;
const statusHistory = assignment.project_assignment_status_detail?.filter(s => Boolean(s.start_date || (Array.isArray(s.date) && s.date.length > 0))) ?? [];
const currentEntry = statusHistory.find(s => !s.end_date && !(Array.isArray(s.date) && s.date[s.date.length - 1]?.end_date)) ?? statusHistory[0];
const duration = formatSpan(assignmentStartDate, assignmentEndDate);
const positionCount = new Set(team.map(m => m.user?.position?.name).filter(Boolean)).size;
const activeTeamCount = team.filter(m => !m.end_date || !dayjs(m.end_date).endOf('day').isBefore(dayjs())).length;
// Build assignment overview for progress metrics & dynamic 5-spectrum color
const overview = buildAssignmentOverview(assignment);
// Days metrics
const daysRemaining = assignmentEndDate ? dayjs(assignmentEndDate).diff(dayjs(), 'day') : 0;
const remainingText = daysRemaining >= 0 ? `${daysRemaining} hari sisa` : '0 hari sisa (Overdue)';
const totalDaysText = `${overview.totalDays} hari total / ${remainingText}`;
const dateRangeText = `${formatAssignmentDate(assignmentStartDate)} - ${formatAssignmentDate(assignmentEndDate)}`;
const handleClose = () => setAction(undefined);
return (
<>
<div className="mx-auto w-full max-w-7xl flex-1 space-y-6 p-4 pt-4 sm:p-8 sm:pt-6">
{/* Back to Client navigation */}
<Reveal>
<Link
href={clientHref}
className="group inline-flex items-center gap-1.5 text-sm text-muted-foreground transition-colors hover:text-foreground"
>
<ArrowLeft className="h-4 w-4 transition-transform duration-300 group-hover:-translate-x-0.5" />
<span>Back to {owner?.name ?? 'tasks'}</span>
<span>Back to: {owner?.name ?? 'PT. TELEKOMUNIKASI SELULAR'}</span>
</Link>
</Reveal>
{/* Header: identity, status, primary action, key facts */}
{/* 1. Header / Hero Card using Card900 */}
<Reveal delay={0.04}>
<section aria-labelledby="assignment-title" className="rounded-2xl border border-border bg-card p-5 sm:p-7">
<Card900 aria-labelledby="assignment-title" className="p-5 sm:p-7 gap-6">
{/* Top Area */}
<div className="flex flex-col gap-6 md:flex-row md:items-start md:justify-between">
<div className="flex min-w-0 items-start gap-4 sm:gap-5">
{/* Emblem */}
<div className="flex h-20 w-20 shrink-0 items-center justify-center overflow-hidden rounded-2xl border border-border bg-zinc-50 p-1 sm:h-24 sm:w-24 dark:bg-zinc-100">
<LazyImage
src={illustrationSrc}
alt={`${assignmentType} emblem`}
className="h-full w-full bg-transparent"
imgClassName="object-contain"
imgClassName="object-contain rounded-lg"
/>
</div>
<div className="min-w-0 space-y-2.5">
<div className="min-w-0 space-y-2">
{/* Top Pills */}
<div className="flex flex-wrap items-center gap-2">
<Badge variant="outline" className="gap-1 rounded-lg px-2 py-0.5 text-xs font-medium">
{isWorkOrder ? <Briefcase className="h-3 w-3" /> : <FileText className="h-3 w-3" />}
<Badge variant="outline" className="gap-1.5 rounded-lg px-2 py-0.5 text-xs font-medium">
{isWorkOrder ? <Briefcase className="h-3 w-3 text-his" /> : <FileText className="h-3 w-3 text-his" />}
{assignmentType}
</Badge>
<ConvertedAssignmentBadge assignment={assignment} clientId={owner?.id} />
@@ -157,24 +164,30 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
) : null}
</div>
<h1 id="assignment-title" className="text-balance text-2xl font-semibold tracking-tight text-foreground md:text-3xl wrap-break-word">
{/* Assignment Title */}
<h1
id="assignment-title"
className="text-balance text-2xl font-bold tracking-tight text-foreground md:text-3xl wrap-break-word"
>
{assignmentName}
</h1>
{/* Assignment Description */}
{assignmentDesc ? (
<p className="max-w-[65ch] text-sm leading-relaxed text-muted-foreground wrap-break-word">
<p className="max-w-[70ch] text-sm leading-relaxed text-muted-foreground wrap-break-word">
{assignmentDesc}
</p>
) : null}
</div>
</div>
<div className="flex flex-col sm:flex-row gap-2.5 w-full md:w-auto">
{/* Action Buttons: Keep Promote to Project (if IM), Update Technical Status, Update Admin Status */}
<div className="flex flex-wrap sm:flex-nowrap items-center gap-2.5 w-full md:w-auto shrink-0">
{!isWorkOrder && (
<Button
variant="outline"
asChild
className="w-full shrink-0 gap-2 border-his/40 text-his hover:bg-his/10 transition-transform active:scale-[0.98] md:w-auto"
className="w-full sm:w-auto shrink-0 gap-2 border-his/40 text-his hover:bg-his/10 transition-transform active:scale-[0.98]"
>
<Link href={owner?.id ? `/task/client-detail/${owner.id}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true` : `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`}>
<ArrowUpRight className="h-4 w-4 text-his" />
@@ -185,280 +198,288 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
<Button
variant="outline"
onClick={() => setAction('UPDATE_ADMIN_STATUS')}
className="w-full shrink-0 gap-2 transition-transform active:scale-[0.98] md:w-auto"
className="w-full sm:w-auto shrink-0 gap-2 transition-transform active:scale-[0.98]"
>
<ClipboardCheck className="h-4 w-4 text-his" />
Update Administration Status
</Button>
<Button
onClick={() => setAction('UPDATE_STATUS')}
className="w-full shrink-0 gap-2 transition-transform active:scale-[0.98] md:w-auto"
className="w-full sm:w-auto shrink-0 gap-2 bg-[#ea512c] hover:bg-[#ea512c]/90 text-white font-medium shadow-md shadow-[#ea512c]/20 transition-transform active:scale-[0.98]"
>
<History className="h-4 w-4" />
<Clock className="h-4 w-4" />
Update Technical Status
</Button>
</div>
</div>
<dl className="mt-7 grid grid-cols-2 gap-x-6 gap-y-5 border-t border-border/70 pt-6 sm:grid-cols-4">
{/* Progress Project Bar */}
<div className="space-y-2">
<div className="flex items-center justify-between gap-4">
<span className="text-xs font-semibold text-foreground tracking-wide">
Progress Project
</span>
<div className="flex items-center gap-3 flex-1 max-w-3xl">
<div className="relative h-2.5 w-full overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700/50">
<div
className="h-full rounded-full transition-all duration-700 ease-out"
style={{
width: `${overview.progressPercent}%`,
backgroundColor: overview.progressColor.hex,
boxShadow: `0 0 10px ${overview.progressColor.hex}88`,
}}
/>
</div>
<span className="font-mono text-sm font-bold text-foreground shrink-0 w-10 text-right">
{overview.progressPercent}%
</span>
</div>
</div>
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground pt-1">
<div className="flex items-center gap-1.5">
<Calendar className="h-3.5 w-3.5 text-muted-foreground/70" />
<span>{dateRangeText}</span>
</div>
<div className="flex items-center gap-1.5 font-mono text-[11px]">
<Clock className="h-3.5 w-3.5 text-muted-foreground/70" />
<span>{totalDaysText}</span>
</div>
</div>
</div>
{/* Quick Stats */}
<dl className="grid grid-cols-2 gap-x-6 gap-y-4 border-t border-border/70 pt-5 sm:grid-cols-4">
<Fact label="Start" value={formatAssignmentDate(assignmentStartDate)} />
<Fact label="End" value={formatAssignmentDate(assignmentEndDate)} />
<Fact label="Duration" value={duration ?? 'N/A'} />
<Fact label="Team" value={team.length === 1 ? '1 person' : `${team.length} people`} />
</dl>
</section>
</Card900>
</Reveal>
<div className="grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]">
{/* Main column */}
<div className="min-w-0 space-y-6">
<Reveal delay={0.08}>
<Surface title="Client and end user">
<div className="divide-y divide-border/70">
<PartyRow
role="Client"
party={owner}
href={owner?.id ? clientHref : undefined}
/>
<PartyRow role="End user" party={assignment.end_user} />
{/* 2. Project Milestone Timeline */}
<Reveal delay={0.08}>
<ProjectMilestoneTimeline
statusDetails={assignment.project_assignment_status_detail}
technicalStatus={assignment.project_assignment_technical_status}
startDate={assignmentStartDate}
endDate={assignmentEndDate}
warrantyDate={assignment.wo_warranty}
/>
</Reveal>
{/* 3. Development Activity Log (with pagination & clean modal) */}
<Reveal delay={0.12}>
<DevelopmentActivityLog history={assignment.project_assignment_history} />
</Reveal>
{/* 4. Client and End User + Project in 2-Column Grid (Preserving exact original card style) */}
<Reveal delay={0.16}>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6 items-stretch">
{/* Client and End User Card */}
<Surface title="Client and end user">
<div className="divide-y divide-border/70">
<PartyRow
role="Client"
party={owner}
href={owner?.id ? clientHref : undefined}
/>
<PartyRow role="End user" party={assignment.end_user} />
</div>
</Surface>
{/* Project Card */}
{assignment.project?.id ? (
<Surface title="Project">
<Link
href={`/task/client-detail/${owner?.id}/project-detail/${assignment.project.id}`}
className="group flex items-start gap-4 rounded-xl p-2 -m-2 transition-colors hover:bg-muted/40"
>
<div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl border border-border bg-muted/40 text-muted-foreground transition-colors group-hover:text-his">
<FolderGit2 className="h-5 w-5" />
</div>
<div className="min-w-0 flex-1 space-y-2">
<div className="flex items-center justify-between gap-2">
<p className="font-semibold text-foreground transition-colors group-hover:text-his">
{assignment.project.name}
</p>
<ExternalLink className="h-4 w-4 shrink-0 text-muted-foreground/60 transition-colors group-hover:text-his" />
</div>
<div className="flex flex-wrap items-center gap-2">
{assignment.project.code ? (
<span className="inline-flex items-center rounded-md border border-border/80 bg-muted/60 px-2 py-0.5 font-mono text-xs font-medium text-foreground/90">
<span className="mr-0.5 text-muted-foreground">#</span>
{assignment.project.code}
</span>
) : null}
{assignment.project.year ? (
<span className="inline-flex items-center gap-1 rounded-md border border-border/60 bg-muted/20 px-2 py-0.5 text-xs text-muted-foreground">
<Calendar className="h-3 w-3 text-muted-foreground/70" />
<span>Year {assignment.project.year}</span>
</span>
) : null}
{assignment.project.start_date || assignment.project.end_date ? (
<span className="inline-flex items-center gap-1.5 text-xs text-muted-foreground">
<span className="text-muted-foreground/40" aria-hidden>·</span>
<Clock className="h-3 w-3 text-muted-foreground/70" />
<span>
{formatAssignmentDate(assignment.project.start_date)} to {formatAssignmentDate(assignment.project.end_date)}
</span>
</span>
) : null}
</div>
<p className="line-clamp-3 max-w-[65ch] text-sm leading-relaxed text-muted-foreground">
{assignment.project.description || 'No description available.'}
</p>
</div>
</Link>
</Surface>
) : (
<Surface title="Project">
<div className="flex flex-col items-center justify-center py-8 text-center text-muted-foreground text-xs">
<FolderGit2 className="h-6 w-6 mb-1 text-muted-foreground/40" />
No project associated
</div>
</Surface>
</Reveal>
{assignment.project?.id ? (
<Reveal delay={0.12}>
<Surface title="Project">
<Link
href={`/task/client-detail/${owner?.id}/project-detail/${assignment.project.id}`}
className="group flex items-start gap-4 rounded-xl p-2 -m-2 transition-colors hover:bg-muted/40"
>
<div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl border border-border bg-muted/40 text-muted-foreground transition-colors group-hover:text-his">
<FolderGit2 className="h-5 w-5" />
</div>
<div className="min-w-0 flex-1 space-y-2">
<div className="flex items-center justify-between gap-2">
<p className="font-semibold text-foreground transition-colors group-hover:text-his">
{assignment.project.name}
</p>
<ExternalLink className="h-4 w-4 shrink-0 text-muted-foreground/60 transition-colors group-hover:text-his" />
</div>
<div className="flex flex-wrap items-center gap-2">
{assignment.project.code ? (
<span className="inline-flex items-center rounded-md border border-border/80 bg-muted/60 px-2 py-0.5 font-mono text-xs font-medium text-foreground/90">
<span className="mr-0.5 text-muted-foreground">#</span>
{assignment.project.code}
</span>
) : null}
{assignment.project.year ? (
<span className="inline-flex items-center gap-1 rounded-md border border-border/60 bg-muted/20 px-2 py-0.5 text-xs text-muted-foreground">
<Calendar className="h-3 w-3 text-muted-foreground/70" />
<span>Year {assignment.project.year}</span>
</span>
) : null}
{assignment.project.start_date || assignment.project.end_date ? (
<span className="inline-flex items-center gap-1.5 text-xs text-muted-foreground">
<span className="text-muted-foreground/40" aria-hidden>·</span>
<Clock className="h-3 w-3 text-muted-foreground/70" />
<span>
{formatAssignmentDate(assignment.project.start_date)} to {formatAssignmentDate(assignment.project.end_date)}
</span>
</span>
) : null}
</div>
<p className="line-clamp-3 max-w-[65ch] text-sm leading-relaxed text-muted-foreground">
{assignment.project.description || 'No description available.'}
</p>
</div>
</Link>
</Surface>
</Reveal>
) : null}
{assignment.note ? (
<Reveal delay={0.14}>
<Surface title="Notes">
<p className="max-w-[65ch] whitespace-pre-line text-sm leading-relaxed text-foreground/90">
{assignment.note}
</p>
</Surface>
</Reveal>
) : null}
<Reveal delay={0.16}>
<Surface
title="Team"
meta={team.length > 0 ? `${team.length}` : undefined}
action={
<div className="flex items-center gap-2">
{team.length > 0 ? (
<div className="flex items-center rounded-lg border border-border bg-muted/30 p-0.5 shadow-xs">
<button
type="button"
onClick={() => setTeamView('grid')}
className={cn(
'flex h-7 w-7 items-center justify-center rounded-md text-xs transition-colors',
teamView === 'grid'
? 'bg-his text-white shadow-xs'
: 'text-muted-foreground hover:text-foreground'
)}
title="Grid cards"
aria-label="Grid cards"
>
<LayoutGrid className="h-3.5 w-3.5" />
</button>
<button
type="button"
onClick={() => setTeamView('list')}
className={cn(
'flex h-7 w-7 items-center justify-center rounded-md text-xs transition-colors',
teamView === 'list'
? 'bg-his text-white shadow-xs'
: 'text-muted-foreground hover:text-foreground'
)}
title="Compact list"
aria-label="Compact list"
>
<List className="h-3.5 w-3.5" />
</button>
</div>
) : null}
<Button
onClick={() => setAction('MANAGE_EMPLOYEE')}
variant="outline"
size="sm"
className="gap-1.5 transition-transform active:scale-[0.98]"
>
<UserPlus className="h-4 w-4" />
Manage team
</Button>
</div>
}
>
{team.length === 0 ? (
<div className="flex flex-col items-center gap-3 rounded-xl border border-dashed border-border bg-muted/20 px-6 py-10 text-center">
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-muted text-muted-foreground">
<Users className="h-5 w-5" />
</div>
<div className="space-y-1">
<p className="text-sm font-medium text-foreground">Nobody is assigned yet</p>
<p className="max-w-xs text-sm text-muted-foreground">
Add people from the team directory to start tracking who works on this assignment.
</p>
</div>
<Button
onClick={() => setAction('MANAGE_EMPLOYEE')}
size="sm"
className="mt-2 gap-1.5 transition-transform active:scale-[0.98]"
>
<UserPlus className="h-4 w-4" />
Assign member
</Button>
</div>
) : (
<div className="space-y-4">
{/* Team Overview Bar */}
<div className="flex flex-col gap-2 rounded-xl border border-border/60 bg-muted/20 p-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex items-center gap-3">
<AvatarStack members={team} />
<div className="min-w-0">
<p className="text-xs font-medium text-foreground">
{team.length} {team.length === 1 ? 'member assigned' : 'members assigned'}
</p>
<p className="text-[11px] text-muted-foreground">
{activeTeamCount} active · {positionCount} {positionCount === 1 ? 'role' : 'roles'}
</p>
</div>
</div>
<span className="font-mono text-[11px] text-muted-foreground/80">
Viewing {visibleTeam.length} of {team.length}
</span>
</div>
{/* Member Roster Display: Grid or List */}
{teamView === 'grid' ? (
<ul className="grid gap-3 sm:grid-cols-2">
{visibleTeam.map(member => (
<TeamCard key={member.id} member={member} />
))}
</ul>
) : (
<ul className="divide-y divide-border/60 overflow-hidden rounded-xl border border-border/80 bg-card">
{visibleTeam.map(member => (
<TeamRow key={member.id} member={member} />
))}
</ul>
)}
{team.length > TEAM_PREVIEW_LIMIT ? (
<Button
variant="ghost"
size="sm"
onClick={() => setShowAllTeam(v => !v)}
className="gap-1.5 text-muted-foreground transition-colors hover:text-foreground"
aria-expanded={showAllTeam}
>
<ChevronDown className={cn('h-4 w-4 transition-transform duration-300', showAllTeam && 'rotate-180')} />
{showAllTeam ? 'Show fewer' : `Show ${hiddenTeamCount} more members`}
</Button>
) : null}
</div>
)}
</Surface>
</Reveal>
)}
</div>
</Reveal>
{/* Side rail: status history */}
<Reveal delay={0.12} className="lg:sticky lg:top-14">
<Surface title="Status history">
{statusHistory.length === 0 ? (
<p className="text-sm leading-relaxed text-muted-foreground">
No status changes recorded yet. Use Update Technical Status to log the first one.
</p>
) : (
<ol className="relative space-y-6 before:absolute before:bottom-2 before:left-1.75 before:top-2 before:w-px before:bg-border">
{statusHistory.map(entry => {
const isCurrent = entry.id === currentEntry?.id;
const span = formatSpan(entry.start_date, entry.end_date);
return (
<li key={entry.id} className="relative pl-7">
<span
aria-hidden
className={cn(
'absolute left-0 top-1 h-3.75 w-3.75 rounded-full border-[3px] border-card',
isCurrent ? 'bg-his' : 'bg-muted-foreground/40'
)}
/>
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
{isCurrent ? (
<BadgeStatus status={entry.project_assignment_status.name} />
) : (
<span className="text-sm font-medium text-foreground/80">
{entry.project_assignment_status.name}
</span>
)}
{isCurrent ? <span className="text-xs text-muted-foreground">Current</span> : null}
</div>
<p className="mt-1.5 font-mono text-xs text-muted-foreground">
{formatAssignmentDate(entry.start_date)} - {entry.end_date ? formatAssignmentDate(entry.end_date) : 'Present'}
</p>
{span ? (
<p className="mt-0.5 text-xs text-muted-foreground/80">{span}</p>
) : null}
{entry.description ? (
<p className="mt-1.5 rounded-lg border border-border/50 bg-muted/30 p-2 text-xs leading-relaxed text-foreground/90 italic">
{entry.description}
</p>
) : null}
</li>
);
})}
</ol>
)}
{/* Optional assignment note */}
{assignment.note ? (
<Reveal delay={0.18}>
<Surface title="Notes">
<p className="max-w-[70ch] whitespace-pre-line text-sm leading-relaxed text-foreground/90">
{assignment.note}
</p>
</Surface>
</Reveal>
</div>
) : null}
{/* 5. Team / Scope Section */}
<Reveal delay={0.20}>
<Surface
title="Team"
meta={team.length > 0 ? `${team.length}` : undefined}
action={
<div className="flex items-center gap-2">
{team.length > 0 ? (
<div className="flex items-center rounded-lg border border-border bg-muted/30 p-0.5 shadow-xs">
<button
type="button"
onClick={() => setTeamView('grid')}
className={cn(
'flex h-7 w-7 items-center justify-center rounded-md text-xs transition-colors',
teamView === 'grid'
? 'bg-his text-white shadow-xs'
: 'text-muted-foreground hover:text-foreground'
)}
title="Grid cards"
aria-label="Grid cards"
>
<LayoutGrid className="h-3.5 w-3.5" />
</button>
<button
type="button"
onClick={() => setTeamView('list')}
className={cn(
'flex h-7 w-7 items-center justify-center rounded-md text-xs transition-colors',
teamView === 'list'
? 'bg-his text-white shadow-xs'
: 'text-muted-foreground hover:text-foreground'
)}
title="Compact list"
aria-label="Compact list"
>
<List className="h-3.5 w-3.5" />
</button>
</div>
) : null}
<Button
onClick={() => setAction('MANAGE_EMPLOYEE')}
variant="outline"
size="sm"
className="gap-1.5 transition-transform active:scale-[0.98]"
>
<UserPlus className="h-4 w-4" />
Manage team
</Button>
</div>
}
>
{team.length === 0 ? (
<div className="flex flex-col items-center gap-3 rounded-xl border border-dashed border-border bg-muted/20 px-6 py-10 text-center">
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-muted text-muted-foreground">
<Users className="h-5 w-5" />
</div>
<div className="space-y-1">
<p className="text-sm font-medium text-foreground">Nobody is assigned yet</p>
<p className="max-w-xs text-sm text-muted-foreground">
Add people from the team directory to start tracking who works on this assignment.
</p>
</div>
<Button
onClick={() => setAction('MANAGE_EMPLOYEE')}
size="sm"
className="mt-2 gap-1.5 transition-transform active:scale-[0.98]"
>
<UserPlus className="h-4 w-4" />
Assign member
</Button>
</div>
) : (
<div className="space-y-4">
<div className="flex flex-col gap-2 rounded-xl border border-border/60 bg-muted/20 p-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex items-center gap-3">
<AvatarStack members={team} />
<div className="min-w-0">
<p className="text-xs font-medium text-foreground">
{team.length} {team.length === 1 ? 'member assigned' : 'members assigned'}
</p>
<p className="text-[11px] text-muted-foreground">
{activeTeamCount} active · {positionCount} {positionCount === 1 ? 'role' : 'roles'}
</p>
</div>
</div>
<span className="font-mono text-[11px] text-muted-foreground/80">
Viewing {visibleTeam.length} of {team.length}
</span>
</div>
{teamView === 'grid' ? (
<ul className="grid gap-3 sm:grid-cols-2">
{visibleTeam.map(member => (
<TeamCard key={member.id} member={member} />
))}
</ul>
) : (
<ul className="divide-y divide-border/60 overflow-hidden rounded-xl border border-border/80 bg-card">
{visibleTeam.map(member => (
<TeamRow key={member.id} member={member} />
))}
</ul>
)}
{team.length > TEAM_PREVIEW_LIMIT ? (
<Button
variant="ghost"
size="sm"
onClick={() => setShowAllTeam(v => !v)}
className="gap-1.5 text-muted-foreground transition-colors hover:text-foreground"
aria-expanded={showAllTeam}
>
<ChevronDown className={cn('h-4 w-4 transition-transform duration-300', showAllTeam && 'rotate-180')} />
{showAllTeam ? 'Show fewer' : `Show ${hiddenTeamCount} more members`}
</Button>
) : null}
</div>
)}
</Surface>
</Reveal>
</div>
{/* Modals */}
{action === 'UPDATE_ADMIN_STATUS' ? (
<UpdateAdministrationStatus
assignmentId={assignment.id}
@@ -489,7 +510,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
function Surface({ title, meta, action, children }: { title: string; meta?: string; action?: ReactNode; children: ReactNode }) {
return (
<section className="rounded-2xl border border-border bg-card p-5 sm:p-6">
<Card900 className="p-5 sm:p-6 gap-0">
<div className="mb-4 flex items-center justify-between gap-3">
<h2 className="flex items-center gap-2 text-base font-semibold tracking-tight text-foreground">
{title}
@@ -500,7 +521,7 @@ function Surface({ title, meta, action, children }: { title: string; meta?: stri
{action}
</div>
{children}
</section>
</Card900>
);
}
@@ -508,7 +529,7 @@ 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>
<dd className="mt-1 truncate font-mono text-sm font-semibold text-foreground">{value}</dd>
</div>
);
}
@@ -559,7 +580,6 @@ function memberName(member: ProjectAssignmentWorkOrderDetail) {
return member.user?.fullname || member.user?.name || 'Unnamed member';
}
/** Overlapping avatars used in the team summary. */
function AvatarStack({ members }: { members: ProjectAssignmentWorkOrderDetail[] }) {
const shown = members.slice(0, 5);
const extra = members.length - shown.length;
@@ -596,7 +616,6 @@ function ContactButton({ href, label, children }: { href: string; label: string;
);
}
/** Grid view card for a team member */
function TeamCard({ member }: { member: ProjectAssignmentWorkOrderDetail }) {
const user = member.user;
const name = memberName(member);
@@ -611,7 +630,6 @@ function TeamCard({ member }: { member: ProjectAssignmentWorkOrderDetail }) {
ended && 'bg-muted/10 opacity-75'
)}
>
{/* Top row: Avatar + Identity + Status */}
<div className="flex items-start gap-3">
<div className="relative shrink-0">
<LazyImage
@@ -654,7 +672,6 @@ function TeamCard({ member }: { member: ProjectAssignmentWorkOrderDetail }) {
</div>
</div>
{/* Middle row: Assignment Period & Duration pill */}
<div className="mt-3.5 rounded-lg border border-border/50 bg-muted/20 px-2.5 py-1.5 text-xs">
<div className="flex flex-wrap items-center justify-between gap-1.5">
<span className="inline-flex min-w-0 items-center gap-1.5 font-mono text-[11px] text-muted-foreground">
@@ -671,7 +688,6 @@ function TeamCard({ member }: { member: ProjectAssignmentWorkOrderDetail }) {
</div>
</div>
{/* Bottom row: Direct Actions & Contact */}
<div className="mt-3.5 flex items-center justify-between border-t border-border/60 pt-2.5 text-xs">
{user?.email ? (
<a
@@ -703,7 +719,6 @@ function TeamCard({ member }: { member: ProjectAssignmentWorkOrderDetail }) {
);
}
/** List view row for a team member */
function TeamRow({ member }: { member: ProjectAssignmentWorkOrderDetail }) {
const user = member.user;
const name = memberName(member);
@@ -0,0 +1,212 @@
"use client";
import { useState } from 'react';
import dynamic from 'next/dynamic';
import { IProjectAssignmentHistory } from '../../../type.assignment';
import { FileText, ChevronRight, ChevronLeft, History } from 'lucide-react';
import { Button } from '@/components/ui/button';
import dayjs from 'dayjs';
const ActivityHistoryModal = dynamic(
() => import('./ActivityHistoryModal').then((mod) => mod.ActivityHistoryModal),
{ ssr: false }
);
interface DevelopmentActivityLogProps {
history?: IProjectAssignmentHistory[];
}
export function DevelopmentActivityLog({ history = [] }: DevelopmentActivityLogProps) {
const [selectedItem, setSelectedItem] = useState<IProjectAssignmentHistory | null>(null);
const [currentPage, setCurrentPage] = useState(1);
const [itemsPerPage, setItemsPerPage] = useState(5);
// Sort newest first
const sortedHistory = [...history].sort((a, b) => {
return dayjs(b.created_at).valueOf() - dayjs(a.created_at).valueOf();
});
const totalItems = sortedHistory.length;
const totalPages = Math.max(1, Math.ceil(totalItems / itemsPerPage));
const safeCurrentPage = Math.min(currentPage, totalPages);
const startIndex = (safeCurrentPage - 1) * itemsPerPage;
const paginatedItems = sortedHistory.slice(startIndex, startIndex + itemsPerPage);
const getDotColor = (index: number, desc: string) => {
const lower = desc.toLowerCase();
if (lower.includes('create')) return 'bg-emerald-500';
if (lower.includes('assign')) return 'bg-sky-500';
if (lower.includes('status to active') || lower.includes('status to completed')) return 'bg-emerald-500';
if (lower.includes('on hold') || lower.includes('issue')) return 'bg-rose-500';
if (lower.includes('sit') || lower.includes('uat')) return 'bg-purple-500';
const colors = ['bg-emerald-500', 'bg-sky-500', 'bg-rose-500', 'bg-amber-500', 'bg-indigo-500'];
return colors[index % colors.length];
};
return (
<>
<section className="rounded-2xl border border-border/80 bg-card p-5 sm:p-6 transition-all duration-200">
<div className="mb-4 flex items-center justify-between gap-3">
<h2 className="flex items-center gap-2.5 text-base font-semibold tracking-tight text-foreground">
<span className="flex h-7 w-7 items-center justify-center rounded-lg bg-muted text-muted-foreground">
<FileText className="h-4 w-4" />
</span>
Development Activity Log
{totalItems > 0 && (
<span className="rounded-lg bg-muted px-2 py-0.5 font-mono text-xs font-medium text-muted-foreground">
{totalItems}
</span>
)}
</h2>
</div>
{totalItems === 0 ? (
<div className="flex flex-col items-center justify-center py-10 text-center rounded-xl border border-dashed border-border/70 bg-muted/10">
<History className="h-8 w-8 text-muted-foreground/50 mb-2" />
<p className="text-sm font-medium text-foreground">No development activity logs yet</p>
<p className="text-xs text-muted-foreground mt-0.5">
Status updates and assignment events will be logged here automatically.
</p>
</div>
) : (
<div className="space-y-3">
<div className="overflow-x-auto rounded-xl border border-border/70">
<table className="w-full text-left text-xs border-collapse">
<thead>
<tr className="border-b border-border/70 bg-muted/40 text-muted-foreground">
<th className="py-3 px-4 font-semibold w-40 sm:w-48">Date</th>
<th className="py-3 px-4 font-semibold w-24">Type</th>
<th className="py-3 px-4 font-semibold">Description</th>
<th className="py-3 px-3 w-8" aria-label="Action"></th>
</tr>
</thead>
<tbody className="divide-y divide-border/60">
{paginatedItems.map((item, idx) => {
const globalIndex = startIndex + idx;
const dotColor = getDotColor(globalIndex, item.description);
const formattedDate = dayjs(item.created_at).isValid()
? dayjs(item.created_at).format('D MMM YYYY')
: 'N/A';
return (
<tr
key={item.id}
onClick={() => setSelectedItem(item)}
className="group cursor-pointer hover:bg-muted/40 transition-colors"
title="Click to view JSON comparison"
>
{/* Date Column with dot */}
<td className="py-3.5 px-4 font-medium text-foreground whitespace-nowrap">
<div className="flex items-center gap-2.5">
<span className={`h-2.5 w-2.5 shrink-0 rounded-full ${dotColor}`} />
<span className="font-mono text-xs">{formattedDate}</span>
</div>
</td>
{/* Type Column: Left blank per instruction */}
<td className="py-3.5 px-4 text-muted-foreground/40 font-mono"></td>
{/* Description Column */}
<td className="py-3.5 px-4 text-foreground/90 font-normal leading-relaxed group-hover:text-foreground transition-colors">
<span className="line-clamp-2">{item.description}</span>
</td>
{/* Subtle Arrow Chevron */}
<td className="py-3.5 px-3 text-muted-foreground/40 group-hover:text-his transition-colors text-right">
<ChevronRight className="h-4 w-4 inline-block group-hover:translate-x-0.5 transition-transform" />
</td>
</tr>
);
})}
</tbody>
</table>
</div>
{/* Pagination Bar with Show per page selector */}
<div className="flex flex-col sm:flex-row items-center justify-between gap-3 pt-2 px-1 text-xs text-muted-foreground">
{/* Left: Show per page & count summary */}
<div className="flex items-center gap-3 font-mono text-[11px]">
<div className="flex items-center gap-1.5">
<span>Show</span>
<select
value={itemsPerPage}
onChange={(e) => {
setItemsPerPage(Number(e.target.value));
setCurrentPage(1);
}}
className="h-6.5 rounded-md border border-border bg-muted/40 px-2 py-0.5 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-his font-mono cursor-pointer"
>
<option value={5}>5</option>
<option value={10}>10</option>
<option value={20}>20</option>
<option value={50}>50</option>
</select>
<span>per page</span>
</div>
<span className="text-border">·</span>
<div>
Showing <span className="font-semibold text-foreground">{startIndex + 1}</span> to{' '}
<span className="font-semibold text-foreground">
{Math.min(startIndex + itemsPerPage, totalItems)}
</span>{' '}
of <span className="font-semibold text-foreground">{totalItems}</span> logs
</div>
</div>
{/* Right: Page navigation buttons */}
{totalPages > 1 && (
<div className="flex items-center gap-1.5">
<Button
variant="outline"
size="sm"
onClick={() => setCurrentPage((p) => Math.max(1, p - 1))}
disabled={safeCurrentPage <= 1}
className="h-7 px-2.5 text-xs gap-1"
>
<ChevronLeft className="h-3.5 w-3.5" />
<span>Prev</span>
</Button>
{Array.from({ length: totalPages }, (_, i) => i + 1).map((pageNum) => (
<Button
key={pageNum}
variant={pageNum === safeCurrentPage ? 'default' : 'outline'}
size="sm"
onClick={() => setCurrentPage(pageNum)}
className={`h-7 w-7 p-0 text-xs font-mono ${
pageNum === safeCurrentPage
? 'bg-his text-white hover:bg-his/90'
: 'text-muted-foreground hover:text-foreground'
}`}
>
{pageNum}
</Button>
))}
<Button
variant="outline"
size="sm"
onClick={() => setCurrentPage((p) => Math.min(totalPages, p + 1))}
disabled={safeCurrentPage >= totalPages}
className="h-7 px-2.5 text-xs gap-1"
>
<span>Next</span>
<ChevronRight className="h-3.5 w-3.5" />
</Button>
</div>
)}
</div>
</div>
)}
</section>
{/* Modal for JSON comparison on row click */}
<ActivityHistoryModal
historyItem={selectedItem}
open={!!selectedItem}
onClose={() => setSelectedItem(null)}
/>
</>
);
}
@@ -0,0 +1,565 @@
"use client";
import { useMemo } from 'react';
import { ProjectAssignmentStatusDetail, ProjectAssignmentStatus } from '../../../type.assignment';
import dayjs from 'dayjs';
import { TrendingUp, ChevronLeft, ChevronRight } from 'lucide-react';
interface ProjectMilestoneTimelineProps {
statusDetails?: ProjectAssignmentStatusDetail[];
technicalStatus?: ProjectAssignmentStatus | null;
startDate?: string | null;
endDate?: string | null;
warrantyDate?: string | null;
}
/** Formats date strictly if assigned; returns empty string if not set */
function formatDetailDate(detail?: ProjectAssignmentStatusDetail | null): string {
if (!detail) return '';
if (Array.isArray(detail.date) && detail.date.length > 0) {
const validDates = detail.date.filter((d) => Boolean(d?.start_date || d?.end_date));
if (validDates.length > 0) {
const first = validDates[0];
const last = validDates[validDates.length - 1];
const sStr = first?.start_date || first?.end_date;
const eStr = last?.end_date || last?.start_date;
const s = sStr ? dayjs(sStr) : null;
const e = eStr ? dayjs(eStr) : null;
if (s && s.isValid() && e && e.isValid()) {
if (s.isSame(e, 'day')) return s.format('D MMM YYYY');
if (s.isSame(e, 'month') && s.isSame(e, 'year')) {
return `${s.format('D')} - ${e.format('D MMM YYYY')}`;
}
if (s.isSame(e, 'year')) {
return `${s.format('D MMM')} - ${e.format('D MMM YYYY')}`;
}
return `${s.format('D MMM YYYY')} - ${e.format('D MMM YYYY')}`;
}
if (s && s.isValid()) return s.format('D MMM YYYY');
if (e && e.isValid()) return e.format('D MMM YYYY');
}
}
const s = detail.start_date ? dayjs(detail.start_date) : null;
const e = detail.end_date ? dayjs(detail.end_date) : null;
if (s && s.isValid() && e && e.isValid()) {
if (s.isSame(e, 'day')) return s.format('D MMM YYYY');
if (s.isSame(e, 'month') && s.isSame(e, 'year')) {
return `${s.format('D')} - ${e.format('D MMM YYYY')}`;
}
if (s.isSame(e, 'year')) {
return `${s.format('D MMM')} - ${e.format('D MMM YYYY')}`;
}
return `${s.format('D MMM YYYY')} - ${e.format('D MMM YYYY')}`;
}
if (s && s.isValid()) return s.format('D MMM YYYY');
if (e && e.isValid()) return e.format('D MMM YYYY');
return '';
}
export function ProjectMilestoneTimeline({
statusDetails = [],
technicalStatus,
startDate,
endDate,
warrantyDate,
}: ProjectMilestoneTimelineProps) {
const findDetail = (keyword: string, id?: number) => {
return statusDetails.find(
(d) =>
(id && d.project_assignment_status?.id === id) ||
(d.project_assignment_status?.name &&
d.project_assignment_status.name.toLowerCase().includes(keyword.toLowerCase()))
);
};
const devDetail = findDetail('dev', 6);
const sitDetail = findDetail('sit', 7);
const uatDetail = findDetail('uat', 8);
const ptrDetail = findDetail('ptr', 9);
const deployDetail = findDetail('deploy');
const goLiveDetail = findDetail('go-live', 10) || findDetail('live');
const bastDetail = findDetail('bast', 11) || findDetail('handover');
const warrantyDetail = findDetail('warranty', 12);
// Start date (empty if not set)
const effectiveStart = startDate || devDetail?.start_date;
const startFormatted = effectiveStart && dayjs(effectiveStart).isValid()
? dayjs(effectiveStart).format('D MMM YYYY')
: '';
// Development intermediate dates strictly from assigned data
const devDates = useMemo(() => {
const list: string[] = [];
if (devDetail) {
if (Array.isArray(devDetail.date) && devDetail.date.length > 0) {
devDetail.date.forEach((item) => {
if (item?.start_date && dayjs(item.start_date).isValid()) {
const f = dayjs(item.start_date).format('D MMM YYYY');
if (!list.includes(f)) list.push(f);
}
if (item?.end_date && item.end_date !== item.start_date && dayjs(item.end_date).isValid()) {
const f = dayjs(item.end_date).format('D MMM YYYY');
if (!list.includes(f)) list.push(f);
}
});
}
if (list.length === 0) {
if (devDetail.start_date && dayjs(devDetail.start_date).isValid()) {
list.push(dayjs(devDetail.start_date).format('D MMM YYYY'));
}
if (devDetail.end_date && devDetail.end_date !== devDetail.start_date && dayjs(devDetail.end_date).isValid()) {
list.push(dayjs(devDetail.end_date).format('D MMM YYYY'));
}
}
}
return list;
}, [devDetail]);
// Dates for subsequent phases (strictly empty if not set)
const sitDateFormatted = formatDetailDate(sitDetail);
const uatDateFormatted = formatDetailDate(uatDetail);
const ptrDateFormatted = formatDetailDate(ptrDetail);
const deployDateFormatted = formatDetailDate(deployDetail);
const goLiveDateFormatted = formatDetailDate(goLiveDetail);
const bastDateFormatted = formatDetailDate(bastDetail);
// Warranty dates (strictly empty if not set)
const warrantyStart = warrantyDetail?.start_date && dayjs(warrantyDetail.start_date).isValid()
? dayjs(warrantyDetail.start_date).format('D MMM YYYY')
: '';
const warrantyEnd = (warrantyDetail?.end_date || warrantyDate) && dayjs(warrantyDetail?.end_date || warrantyDate).isValid()
? dayjs(warrantyDetail?.end_date || warrantyDate).format('D MMM YYYY')
: '';
// Today's formatted date
const todayFormatted = dayjs().format('D MMM YYYY');
const todayVal = dayjs().valueOf();
// Technical status rank
const techName = technicalStatus?.name?.toLowerCase() || '';
const techId = technicalStatus?.id;
let techRank = 0;
if (techId === 6 || techName.includes('dev')) techRank = 1;
else if (techId === 7 || techName.includes('sit')) techRank = 2;
else if (techId === 8 || techName.includes('uat')) techRank = 3;
else if (techId === 9 || techName.includes('ptr')) techRank = 4;
else if (techName.includes('deploy')) techRank = 5;
else if (techId === 10 || techName.includes('go-live') || techName.includes('live')) techRank = 6;
else if (techId === 11 || techName.includes('bast') || techName.includes('handover')) techRank = 7;
else if (techId === 12 || techName.includes('warranty')) techRank = 8;
// Checkpoint dates
const sitEndTime = (sitDetail?.end_date || sitDetail?.start_date) ? dayjs(sitDetail?.end_date || sitDetail?.start_date).valueOf() : null;
const uatEndTime = (uatDetail?.end_date || uatDetail?.start_date) ? dayjs(uatDetail?.end_date || uatDetail?.start_date).valueOf() : null;
const ptrEndTime = (ptrDetail?.end_date || ptrDetail?.start_date) ? dayjs(ptrDetail?.end_date || ptrDetail?.start_date).valueOf() : null;
const deployEndTime = (deployDetail?.end_date || deployDetail?.start_date) ? dayjs(deployDetail?.end_date || deployDetail?.start_date).valueOf() : null;
const goLiveEndTime = (goLiveDetail?.end_date || goLiveDetail?.start_date) ? dayjs(goLiveDetail?.end_date || goLiveDetail?.start_date).valueOf() : null;
const bastEndTime = (bastDetail?.end_date || bastDetail?.start_date) ? dayjs(bastDetail?.end_date || bastDetail?.start_date).valueOf() : null;
/**
* Determine dynamic position of 'Today'
* For assignment 36: SIT ended 12 Oct, Today is 14 Oct, UAT starts 15 Oct -> insertAfter = 'sit'!
*/
const insertTodayAfter = useMemo<'start' | 'dev' | 'sit' | 'uat' | 'ptr' | 'deploy' | 'golive' | 'bast'>(() => {
if (bastEndTime && todayVal >= bastEndTime) return 'bast';
if (techRank >= 7) return 'golive';
if (goLiveEndTime && todayVal >= goLiveEndTime) return 'golive';
if (techRank >= 6) return 'deploy';
if (deployEndTime && todayVal >= deployEndTime) return 'deploy';
if (techRank >= 5) return 'ptr';
if (ptrEndTime && todayVal >= ptrEndTime) return 'ptr';
if (techRank >= 4) return 'uat';
if (uatEndTime && todayVal >= uatEndTime) return 'uat';
if (techRank >= 3 || (sitEndTime && todayVal >= sitEndTime)) return 'sit';
if (sitEndTime && todayVal >= sitEndTime) return 'sit';
if (techRank >= 2) return 'dev';
if (effectiveStart && todayVal < dayjs(effectiveStart).valueOf()) return 'start';
return 'dev';
}, [todayVal, techRank, bastEndTime, goLiveEndTime, deployEndTime, ptrEndTime, uatEndTime, sitEndTime, effectiveStart]);
// Active status highlights
const isDevActive = techRank === 1 || techName.includes('dev');
const isSitActive = techRank === 2;
const isUatActive = techRank === 3;
const isPtrActive = techRank === 4;
const isDeployActive = techRank === 5;
const isGoLiveActive = techRank === 6;
const isBastActive = techRank === 7;
return (
<section className="rounded-2xl border border-border/80 bg-card p-5 sm:p-6 transition-all duration-200">
{/* Header */}
<div className="mb-4 flex items-center justify-between gap-3">
<h2 className="flex items-center gap-2.5 text-base font-semibold tracking-tight text-foreground">
<TrendingUp className="h-4 w-4 text-muted-foreground" />
<span>Project Milestone Timeline</span>
</h2>
</div>
{/* Continuous Timeline Rail Container with Horizontal Scroll */}
<div className="overflow-x-auto pb-4 pt-4 scrollbar-thin">
<div className="min-w-255 px-4 py-8 flex items-center justify-between">
{/* 1. START NODE */}
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className="text-xs font-medium text-foreground whitespace-nowrap">Start</span>
</div>
<div className="h-4 w-4 rounded-full border-2 border-emerald-500 bg-emerald-500 z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono text-muted-foreground whitespace-nowrap">
{startFormatted}
</span>
</div>
</div>
{insertTodayAfter === 'start' && (
<>
<div className="flex-1 h-0.75 bg-[#ea512c]" />
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-10 flex flex-col items-center pointer-events-none z-20">
<div className="rounded-full bg-[#ea512c] px-2.5 py-0.5 text-[10px] font-bold text-white shadow-xs">
Today
</div>
<div className="w-0.5 h-3 bg-[#ea512c]" />
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-white bg-[#ea512c] z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono font-semibold text-foreground whitespace-nowrap">
{todayFormatted}
</span>
</div>
</div>
</>
)}
{/* Continuous Red Line connecting Start to Development */}
<div className="flex-1 h-0.75 bg-[#ea512c]" />
{/* 2. DEVELOPMENT SECTION */}
{devDates.length > 0 ? (
devDates.map((dStr, idx) => (
<div key={`dev-${idx}`} className="contents">
{idx > 0 && <div className="flex-1 h-0.75 bg-[#ea512c]" />}
<div className="relative shrink-0 flex flex-col items-center">
{idx === 0 && (
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className={`text-xs font-semibold whitespace-nowrap ${isDevActive ? 'text-[#ea512c]' : 'text-foreground/90'}`}>
Development
</span>
</div>
)}
<div className="h-3.5 w-3.5 rounded-full border-2 border-[#ea512c] bg-white z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono text-muted-foreground whitespace-nowrap">
{dStr}
</span>
</div>
</div>
</div>
))
) : (
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className={`text-xs font-semibold whitespace-nowrap ${isDevActive ? 'text-[#ea512c]' : 'text-foreground/90'}`}>
Development
</span>
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-[#ea512c] bg-white z-10 shadow-xs" />
</div>
)}
{insertTodayAfter === 'dev' && (
<>
<div className="flex-1 h-0.75 bg-[#ea512c]" />
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-10 flex flex-col items-center pointer-events-none z-20">
<div className="rounded-full bg-[#ea512c] px-2.5 py-0.5 text-[10px] font-bold text-white shadow-xs">
Today
</div>
<div className="w-0.5 h-3 bg-[#ea512c]" />
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-white bg-[#ea512c] z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono font-semibold text-foreground whitespace-nowrap">
{todayFormatted}
</span>
</div>
</div>
</>
)}
{/* Continuous Blue Line connecting to SIT */}
<div className="flex-1 h-0.75 bg-[#3b82f6]" />
{/* 3. SIT NODE */}
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className={`text-xs font-medium whitespace-nowrap ${isSitActive ? 'text-[#ea512c] font-semibold' : 'text-foreground'}`}>
SIT
</span>
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-[#3b82f6] bg-white z-10 shadow-xs" />
{sitDateFormatted && (
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono text-muted-foreground whitespace-nowrap">
{sitDateFormatted}
</span>
</div>
)}
</div>
{insertTodayAfter === 'sit' && (
<>
<div className="flex-1 h-0.75 bg-[#3b82f6]" />
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-10 flex flex-col items-center pointer-events-none z-20">
<div className="rounded-full bg-[#ea512c] px-2.5 py-0.5 text-[10px] font-bold text-white shadow-xs">
Today
</div>
<div className="w-0.5 h-3 bg-[#ea512c]" />
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-white bg-[#ea512c] z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono font-semibold text-foreground whitespace-nowrap">
{todayFormatted}
</span>
</div>
</div>
</>
)}
{/* Continuous Purple Line connecting to UAT */}
<div className="flex-1 h-0.75 bg-[#a855f7]" />
{/* 4. UAT NODE */}
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className={`text-xs font-medium whitespace-nowrap ${isUatActive ? 'text-[#ea512c] font-semibold' : 'text-foreground'}`}>
UAT
</span>
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-[#a855f7] bg-white z-10 shadow-xs" />
{uatDateFormatted && (
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono text-muted-foreground whitespace-nowrap">
{uatDateFormatted}
</span>
</div>
)}
</div>
{insertTodayAfter === 'uat' && (
<>
<div className="flex-1 h-0.75 bg-[#a855f7]" />
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-10 flex flex-col items-center pointer-events-none z-20">
<div className="rounded-full bg-[#ea512c] px-2.5 py-0.5 text-[10px] font-bold text-white shadow-xs">
Today
</div>
<div className="w-0.5 h-3 bg-[#ea512c]" />
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-white bg-[#ea512c] z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono font-semibold text-foreground whitespace-nowrap">
{todayFormatted}
</span>
</div>
</div>
</>
)}
{/* Continuous Yellow Line connecting to PTR */}
<div className="flex-1 h-0.75 bg-[#eab308]" />
{/* 5. PTR NODE */}
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className={`text-xs font-medium whitespace-nowrap ${isPtrActive ? 'text-[#ea512c] font-semibold' : 'text-foreground'}`}>
PTR
</span>
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-[#eab308] bg-white z-10 shadow-xs" />
{ptrDateFormatted && (
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono text-muted-foreground whitespace-nowrap">
{ptrDateFormatted}
</span>
</div>
)}
</div>
{insertTodayAfter === 'ptr' && (
<>
<div className="flex-1 h-0.75 bg-[#eab308]" />
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-10 flex flex-col items-center pointer-events-none z-20">
<div className="rounded-full bg-[#ea512c] px-2.5 py-0.5 text-[10px] font-bold text-white shadow-xs">
Today
</div>
<div className="w-0.5 h-3 bg-[#ea512c]" />
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-white bg-[#ea512c] z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono font-semibold text-foreground whitespace-nowrap">
{todayFormatted}
</span>
</div>
</div>
</>
)}
{/* Continuous Cyan Line connecting to Deployment */}
<div className="flex-1 h-0.75 bg-[#06b6d4]" />
{/* 6. DEPLOYMENT NODE */}
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className={`text-xs font-medium whitespace-nowrap ${isDeployActive ? 'text-[#ea512c] font-semibold' : 'text-foreground'}`}>
Deployment
</span>
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-[#06b6d4] bg-white z-10 shadow-xs" />
{deployDateFormatted && (
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono text-muted-foreground whitespace-nowrap">
{deployDateFormatted}
</span>
</div>
)}
</div>
{insertTodayAfter === 'deploy' && (
<>
<div className="flex-1 h-0.75 bg-[#06b6d4]" />
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-10 flex flex-col items-center pointer-events-none z-20">
<div className="rounded-full bg-[#ea512c] px-2.5 py-0.5 text-[10px] font-bold text-white shadow-xs">
Today
</div>
<div className="w-0.5 h-3 bg-[#ea512c]" />
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-white bg-[#ea512c] z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono font-semibold text-foreground whitespace-nowrap">
{todayFormatted}
</span>
</div>
</div>
</>
)}
{/* Continuous Pink Line connecting to Go Live */}
<div className="flex-1 h-0.75 bg-[#ec4899]" />
{/* 7. GO LIVE NODE */}
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className={`text-xs font-medium whitespace-nowrap ${isGoLiveActive ? 'text-[#ea512c] font-semibold' : 'text-foreground'}`}>
Go Live
</span>
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-[#ec4899] bg-white z-10 shadow-xs" />
{goLiveDateFormatted && (
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono text-muted-foreground whitespace-nowrap">
{goLiveDateFormatted}
</span>
</div>
)}
</div>
{insertTodayAfter === 'golive' && (
<>
<div className="flex-1 h-0.75 bg-[#ec4899]" />
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-10 flex flex-col items-center pointer-events-none z-20">
<div className="rounded-full bg-[#ea512c] px-2.5 py-0.5 text-[10px] font-bold text-white shadow-xs">
Today
</div>
<div className="w-0.5 h-3 bg-[#ea512c]" />
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-white bg-[#ea512c] z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono font-semibold text-foreground whitespace-nowrap">
{todayFormatted}
</span>
</div>
</div>
</>
)}
{/* Continuous Rose Line connecting to BAST */}
<div className="flex-1 h-0.75 bg-[#f43f5e]" />
{/* 8. BAST NODE */}
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className={`text-xs font-medium whitespace-nowrap ${isBastActive ? 'text-[#ea512c] font-semibold' : 'text-foreground'}`}>
BAST
</span>
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-[#f43f5e] bg-white z-10 shadow-xs" />
{bastDateFormatted && (
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono text-muted-foreground whitespace-nowrap">
{bastDateFormatted}
</span>
</div>
)}
</div>
{insertTodayAfter === 'bast' && (
<>
<div className="flex-1 h-0.75 bg-[#f43f5e]" />
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-10 flex flex-col items-center pointer-events-none z-20">
<div className="rounded-full bg-[#ea512c] px-2.5 py-0.5 text-[10px] font-bold text-white shadow-xs">
Today
</div>
<div className="w-0.5 h-3 bg-[#ea512c]" />
</div>
<div className="h-3.5 w-3.5 rounded-full border-2 border-white bg-[#ea512c] z-10 shadow-xs" />
<div className="absolute top-6 flex flex-col items-center pointer-events-none">
<span className="text-[10px] font-mono font-semibold text-foreground whitespace-nowrap">
{todayFormatted}
</span>
</div>
</div>
</>
)}
{/* Vertical Dashed Separator */}
<div className="h-10 border-r border-dashed border-zinc-700 mx-5 shrink-0" />
{/* 9. WARRANTY CAPSULE TRACK */}
<div className="relative shrink-0 flex flex-col items-center">
<div className="absolute -top-7 flex flex-col items-center pointer-events-none">
<span className="text-xs font-medium text-foreground whitespace-nowrap">
Warranty
</span>
</div>
{/* Capsule with < ---- > indicator */}
<div className="flex items-center justify-between rounded-full border border-zinc-700 bg-zinc-800/80 px-2.5 py-0.5 text-zinc-400 w-36 sm:w-44 z-10">
<ChevronLeft className="h-3 w-3 text-zinc-300" />
<div className="h-0.5 flex-1 bg-zinc-500/70 mx-1" />
<ChevronRight className="h-3 w-3 text-zinc-300" />
</div>
{/* Dates below warranty: strictly empty if not set */}
{(warrantyStart || warrantyEnd) && (
<div className="absolute top-6 flex items-center justify-between w-full text-[10px] font-mono text-muted-foreground px-1 pointer-events-none">
<span>{warrantyStart}</span>
<span>{warrantyEnd}</span>
</div>
)}
</div>
</div>
</div>
</section>
);
}
@@ -15,8 +15,6 @@ export default async function AssignmentDetailPage({ params }: Props) {
const [client, assignment] = await Promise.all([getClientById, getAssignmentById]);
// console.log(assignment)
// 3. Handle 404 Securely on the server
if (!assignment) {
return (
+16
View File
@@ -34,10 +34,26 @@ export interface IProjectAssignment {
wo_warranty: any
project_assignment_status_detail: ProjectAssignmentStatusDetail[]
project_assignment_work_order_detail: ProjectAssignmentWorkOrderDetail[]
project_assignment_history?: IProjectAssignmentHistory[]
status: Status
created_at: string
}
export interface IProjectAssignmentHistory {
id: number
project_assignment_id: number
description: string
old_data: any
new_data: any
created_at: string
user?: {
id: number
fullname?: string
nickname?: string
avatar?: string | null
} | null
}
export interface Client {
id: number
code: string
@@ -364,9 +364,50 @@ export function resolveProgressColor(
return COLOR_SPECTRUM.orange;
}
/**
* Extracts the latest assigned end date for the PTR (Production Trial Run) phase if present.
*/
export function getPtrEndDate(assignment: IProjectAssignment): number | null {
const details = assignment.project_assignment_status_detail || [];
const ptrDetail = details.find(d => {
const name = d.project_assignment_status?.name?.toLowerCase() || '';
return name.includes('ptr') || name.includes('trial');
});
if (!ptrDetail) return null;
let latestTime: number | null = null;
const parseTime = (dateStr: any): number | null => {
if (!dateStr || typeof dateStr !== 'string') return null;
const d = new Date(dateStr);
return isNaN(d.getTime()) ? null : d.getTime();
};
if (ptrDetail.end_date) {
latestTime = parseTime(ptrDetail.end_date);
}
if (Array.isArray(ptrDetail.date) && ptrDetail.date.length > 0) {
ptrDetail.date.forEach((item: any) => {
const t = parseTime(item?.end_date || item?.start_date);
if (t && (!latestTime || t > latestTime)) {
latestTime = t;
}
});
}
if (!latestTime && ptrDetail.start_date) {
latestTime = parseTime(ptrDetail.start_date);
}
return latestTime;
}
/**
* 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)
* - Near Go-live (Warna Teal) => technical status sudah lewat PTR dan tanggal hari ini sudah lewat dari tanggal PTR tapi masih dalam rentang end of date dan status belum sampai ke Go-Live
* - 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)
@@ -375,7 +416,8 @@ export function resolveDeliveryHealth(
technicalRank: number,
hasTechnicalStatus: boolean,
progressPercent: number,
endDate?: string
endDate?: string,
ptrEndDate?: number | null
): {
healthStatus: 'On Track' | 'At Risk' | 'Near Go-live' | 'Completed' | 'Critical' | 'Off Track';
healthBadgeClass: string;
@@ -412,7 +454,7 @@ export function resolveDeliveryHealth(
// KONDISI 2: Belum lewat deadline (atau tidak ada endDate)
// Sudah sampai ke Go-Live sebelum deadline -> Complete (Sky Blue)
// 1. Sudah sampai ke Go-Live sebelum deadline -> Complete (Sky Blue)
if (technicalRank >= 5) {
return {
healthStatus: 'Completed',
@@ -422,7 +464,18 @@ export function resolveDeliveryHealth(
};
}
// At Risk (Warna Kuning) => progress lewat dari 75% dan belum sampai ke PTR (rank < 4)
// 2. Near Go-live (Warna Teal) => Technical status sudah lewat PTR (rank >= 4), tanggal hari ini sudah lewat dari tanggal PTR tapi masih dalam rentang end of date, dan technical status belum sampai ke Go-Live (rank < 5)
const isPastPtrDate = typeof ptrEndDate === 'number' ? now >= ptrEndDate : (technicalRank >= 4 && progressPercent >= 75);
if (technicalRank >= 4 && isPastPtrDate) {
return {
healthStatus: 'Near Go-live',
healthBadgeClass: 'bg-teal-500/10 text-teal-600 dark:text-teal-400 border-teal-500/30',
healthDotClass: 'bg-teal-500',
isCritical: false,
};
}
// 3. At Risk (Warna Kuning) => progress lewat dari 75% dan belum sampai ke PTR (rank < 4)
if (progressPercent > 75 && technicalRank < 4) {
return {
healthStatus: 'At Risk',
@@ -432,9 +485,7 @@ export function resolveDeliveryHealth(
};
}
// 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)
// 4. On Track (Warna Hijau) => Belum lewat deadline dan progres sejalan dengan target
return {
healthStatus: 'On Track',
healthBadgeClass: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/30',
@@ -446,7 +497,7 @@ export function resolveDeliveryHealth(
/**
* Calculates complete visual representation for an assignment row
*/
export function getAssignmentOverview(assignment: IProjectAssignment, index: number): AssignmentOverview {
export function getAssignmentOverview(assignment: IProjectAssignment, index: number = 0): 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';
@@ -493,11 +544,13 @@ export function getAssignmentOverview(assignment: IProjectAssignment, index: num
// 2. Resolve Technical Status & Delivery Health
const { hasTechnicalStatus, technicalRank } = resolveTechnicalStatus(assignment);
const ptrEndDate = getPtrEndDate(assignment);
const { healthStatus, healthBadgeClass, healthDotClass, isCritical } = resolveDeliveryHealth(
technicalRank,
hasTechnicalStatus,
progressPercent,
endDate
endDate,
ptrEndDate
);
// 3. Resolve Progress Color (Orange -> Kuning -> Hijau -> Biru -> Ungu)
@@ -528,6 +581,10 @@ export function getAssignmentOverview(assignment: IProjectAssignment, index: num
} else if (healthStatus === 'Completed') {
remainingText = endDate ? `Completed on ${formatAssignmentDate(endDate)}` : 'Completed';
nextMilestoneText = 'Next: -';
} else if (healthStatus === 'Near Go-live') {
const remDays = Math.max(1, totalDays - elapsedDays);
remainingText = `${remDays} days remaining`;
nextMilestoneText = 'Next: Production Go-Live';
} else if (healthStatus === 'At Risk') {
const remDays = Math.max(1, totalDays - elapsedDays);
remainingText = `${remDays} days remaining`;
@@ -570,6 +627,8 @@ export function getAssignmentOverview(assignment: IProjectAssignment, index: num
};
}
export const buildAssignmentOverview = getAssignmentOverview;
/**
* Calculates top executive summary metrics for "Project Assignment Dashboard"
*/
@@ -600,7 +659,7 @@ export function calculateDashboardStats(assignments: IProjectAssignment[]) {
: 0;
// On-Time projects vs Total
const onTimeCount = overviews.filter(o => o.healthStatus === 'On Track' || o.healthStatus === 'Completed').length;
const onTimeCount = overviews.filter(o => o.healthStatus === 'On Track' || o.healthStatus === 'Completed' || o.healthStatus === 'Near Go-live').length;
const atRiskCount = overviews.filter(o => o.healthStatus === 'At Risk' || o.healthStatus === 'Critical' || o.healthStatus === 'Off Track').length;
return {