Add assignment validation and attention alerts

Validate project years and Work Order code availability, confirm before discarding unsaved changes, and surface critical or behind-schedule assignments in dashboard warnings and stats. Also update assignment form and dashboard labels.
This commit is contained in:
Ichsan Kurniawan
2026-11-05 11:27:05 +07:00
parent 20b77dc0b7
commit b71d84db06
7 changed files with 391 additions and 89 deletions
@@ -2,7 +2,7 @@
import { useMemo } from 'react';
import { motion } from 'motion/react';
import { Briefcase, FileText, Users, TrendingUp, CheckCircle2, AlertTriangle } from 'lucide-react';
import { Briefcase, FileText, Users, AlertCircle, CheckCircle2, AlertTriangle } from 'lucide-react';
import { Card900 } from '@/components/ui/card';
import { IProjectAssignment } from '../../type.assignment';
import { calculateDashboardStats } from '../../utils/assignment-overview-helpers';
@@ -24,7 +24,7 @@ export default function ProjectAssignmentDashboardStats({
Project Assignment Dashboard
</h2>
<div className="grid grid-cols-2 sm:grid-cols-3 xl:grid-cols-6 gap-3 sm:gap-4">
<div className="grid grid-cols-2 sm:grid-cols-4 xl:grid-cols-4 gap-3 sm:gap-4">
{/* 1. Total Projects */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-blue-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
@@ -45,7 +45,7 @@ export default function ProjectAssignmentDashboardStats({
<Briefcase className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">Active Work Orders</p>
<p className="text-xs text-muted-foreground truncate">Work Orders</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.activeWorkOrders}</p>
</div>
</Card900>
@@ -64,41 +64,17 @@ export default function ProjectAssignmentDashboardStats({
</Card900>
</motion.div>
{/* 4. Average Progress */}
{/* 4. Needs Attention / Behind Schedule (Replaces Average Progress) */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2, delay: 0.09 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-orange-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-orange-500/10 dark:bg-orange-500/15 border border-orange-500/20 flex items-center justify-center shrink-0 text-orange-500 dark:text-orange-400">
<TrendingUp className="w-5 h-5" />
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-amber-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-amber-500/10 dark:bg-amber-500/15 border border-amber-500/20 flex items-center justify-center shrink-0 text-amber-500 dark:text-amber-400">
<AlertCircle className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">Average Progress</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.averageProgress}%</p>
</div>
</Card900>
</motion.div>
{/* 5. On-Time Projects */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2, delay: 0.12 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-emerald-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-emerald-500/10 dark:bg-emerald-500/15 border border-emerald-500/20 flex items-center justify-center shrink-0 text-emerald-500 dark:text-emerald-400">
<CheckCircle2 className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">On-Time Projects</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.onTimeRatio}</p>
</div>
</Card900>
</motion.div>
{/* 6. At Risk / Delayed */}
<motion.div initial={{ opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.2, delay: 0.15 }}>
<Card900 className="p-3.5 sm:p-5 rounded-2xl border border-border/80 bg-card hover:border-rose-500/30 transition-all flex flex-row items-center gap-3 md:gap-3.5 min-w-0 shadow-2xs">
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-xl bg-rose-500/10 dark:bg-rose-500/15 border border-rose-500/20 flex items-center justify-center shrink-0 text-rose-500 dark:text-rose-400">
<AlertTriangle className="w-5 h-5" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground truncate">At Risk / Delayed</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.atRiskDelayed}</p>
<p className="text-xs text-muted-foreground truncate" title="Assignments with Critical/Off Track status or actual progress lagging behind timeline">
Needs Attention
</p>
<p className="text-lg sm:text-xl font-bold tracking-tight text-foreground">{stats.needsAttention}</p>
</div>
</Card900>
</motion.div>