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.
This commit is contained in:
Ichsan Kurniawan
2026-10-17 21:26:05 +07:00
parent 390d03204a
commit a991f114ef
4 changed files with 124 additions and 18 deletions
@@ -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 (
@@ -11,7 +11,7 @@ import {
Tooltip, TooltipContent, TooltipTrigger,
} from '@/components/ui/tooltip';
import { LazyImage } from '@/components/ui/lazy-image';
import { Calendar, MoreVertical, ArrowUpRight } from 'lucide-react';
import { Calendar, MoreVertical, ArrowUpRight, Clock } from 'lucide-react';
import Link from 'next/link';
import { cn } from '@/lib/utils';
import ConvertedAssignmentBadge from './ConvertedAssignmentBadge';
@@ -287,21 +287,39 @@ export default function AssignmentGrid({
{/* Progress & Stepper Section */}
<div className="space-y-2 pt-2 border-t 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-muted-foreground">{item.daysRatioText}</span>
<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-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>
<span className="text-muted-foreground font-semibold shrink-0">{item.progressPercent}%</span>
</div>
<CompactPhaseStepper phaseIndex={item.phaseIndex} progressColor={item.progressColor} />
</div>
{/* Footer: Delivery Health Badge & Team Avatars */}
{/* Footer: Delivery Health Badge, Schedule, Latest Activity & 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(
@@ -312,6 +330,13 @@ export default function AssignmentGrid({
<span>{item.healthStatus}</span>
</span>
<p className="text-[11px] text-muted-foreground truncate">{item.remainingText}</p>
<p
className="text-[10px] text-muted-foreground/75 truncate flex items-center gap-1 font-sans"
title={item.latestActivityText}
>
<Clock className="w-2.5 h-2.5 text-muted-foreground/60 shrink-0" />
<span className="truncate">{item.latestActivityText}</span>
</p>
</div>
<div className="flex items-center gap-1.5 shrink-0">
@@ -11,7 +11,7 @@ import {
Tooltip, TooltipContent, TooltipTrigger,
} from '@/components/ui/tooltip';
import { LazyImage } from '@/components/ui/lazy-image';
import { Calendar, MoreVertical, ArrowUpRight } from 'lucide-react';
import { Calendar, MoreVertical, ArrowUpRight, Clock, FolderGit2 } from 'lucide-react';
import Link from 'next/link';
import { cn } from '@/lib/utils';
import ConvertedAssignmentBadge from './ConvertedAssignmentBadge';
@@ -187,6 +187,23 @@ export default function AssignmentList({
</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 && (
@@ -225,18 +242,35 @@ export default function AssignmentList({
</div>
</div>
{/* 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">
{/* 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 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">
<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-foreground font-bold shrink-0">{item.progressPercent}%</span>
<span className="text-muted-foreground font-semibold shrink-0">{item.progressPercent}%</span>
</div>
{/* 5-Node Milestone Stepper Rail */}
@@ -282,7 +316,7 @@ export default function AssignmentList({
{/* 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">
<div className="space-y-1.5 min-w-0 xl:w-48 2xl:w-56 text-left">
{/* Health Badge */}
<div>
<span className={cn(
@@ -300,11 +334,14 @@ export default function AssignmentList({
<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>
{/* 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 */}
@@ -137,6 +137,7 @@ export interface AssignmentOverview {
totalDays: number;
daysRatioText: string;
progressPercent: number;
actualProgress: number;
progressColor: ProgressColorConfig;
// Team
@@ -155,6 +156,7 @@ export interface AssignmentOverview {
remainingText: string;
nextMilestoneText: string;
updatedAgoText: string;
latestActivityText: string;
}
export function formatAssignmentDate(dateStr?: string) {
@@ -168,6 +170,42 @@ export function formatAssignmentDate(dateStr?: string) {
return `${day} ${month} ${year}`;
}
export function formatHistoryRelativeTime(dateStr?: string | null): string {
if (!dateStr) return '';
const d = dayjs(dateStr);
if (!d.isValid()) return '';
const now = dayjs();
const diffSec = Math.max(0, now.diff(d, 'second'));
if (diffSec < 60) return 'just now';
const diffMin = Math.floor(diffSec / 60);
if (diffMin < 60) return `${diffMin} ${diffMin === 1 ? 'minute' : 'minutes'} ago`;
const diffHours = Math.floor(diffMin / 60);
if (diffHours < 24) return `${diffHours} ${diffHours === 1 ? 'hour' : 'hours'} ago`;
const diffDays = Math.floor(diffHours / 24);
if (diffDays < 7) return `${diffDays} ${diffDays === 1 ? 'day' : 'days'} ago`;
const diffWeeks = Math.floor(diffDays / 7);
if (diffWeeks < 4) return diffWeeks === 1 ? 'a week ago' : `${diffWeeks} weeks ago`;
const diffMonths = Math.floor(diffDays / 30);
if (diffMonths < 12) return diffMonths === 1 ? 'a month ago' : `${diffMonths} months ago`;
const diffYears = Math.floor(diffDays / 365);
return diffYears === 1 ? 'a year ago' : `${diffYears} years ago`;
}
export function formatLatestActivityWording(historyList?: any[] | null): string {
if (!historyList || !Array.isArray(historyList) || historyList.length === 0) {
return 'No updated activity';
}
const latest = historyList[0];
if (!latest || !latest.created_at) return 'No updated activity';
const rel = formatHistoryRelativeTime(latest.created_at);
if (!rel) return 'No updated activity';
const user = latest.user?.nickname || latest.user?.fullname || 'system';
return `Updated ${rel} by ${user}`;
}
export function formatRelativeTime(dateStr?: string): string {
if (!dateStr) return 'Updated 1 day ago';
const d = new Date(dateStr);
@@ -723,6 +761,12 @@ export function getAssignmentOverview(assignment: IProjectAssignment, index: num
const updatedAgoText = formatRelativeTime(assignment.created_at || startDate);
const actualProgress = typeof assignment.progress === 'number' && !isNaN(assignment.progress)
? Math.min(100, Math.max(0, assignment.progress))
: 0;
const latestActivityText = formatLatestActivityWording(assignment.project_assignment_history);
return {
assignmentType,
isProject,
@@ -741,6 +785,7 @@ export function getAssignmentOverview(assignment: IProjectAssignment, index: num
totalDays,
daysRatioText,
progressPercent,
actualProgress,
progressColor,
teamCount,
teamMembers,
@@ -750,6 +795,7 @@ export function getAssignmentOverview(assignment: IProjectAssignment, index: num
remainingText,
nextMilestoneText,
updatedAgoText,
latestActivityText,
};
}