From f0cc469d24e1a4def289ab9d46f6eecb22a51fcf Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan <43689091+ichsankurnia@users.noreply.github.com> Date: Wed, 4 Nov 2026 14:34:58 +0700 Subject: [PATCH 1/4] Update client actions and dashboard labels Show client edit and delete actions directly in grid and list views, simplify work-order and dashboard metric labels, and adjust spacing for milestone timelines without upcoming milestones. --- app/(dashboard)/task/component/HomeTask.tsx | 10 +-- .../task/component/client/ClientGrid.tsx | 64 +++++++--------- .../task/component/client/ClientList.tsx | 74 ++++++++----------- .../client/ClientMilestoneTimeline.tsx | 4 +- 4 files changed, 66 insertions(+), 86 deletions(-) diff --git a/app/(dashboard)/task/component/HomeTask.tsx b/app/(dashboard)/task/component/HomeTask.tsx index ea7be72..f77d796 100644 --- a/app/(dashboard)/task/component/HomeTask.tsx +++ b/app/(dashboard)/task/component/HomeTask.tsx @@ -31,19 +31,19 @@ export default function HomeTask({ clients = [] }: HomeTaskProps) { trend: null, }, { - title: 'Active Projects', + title: 'Projects', value: stats.activeProjects, icon: FolderGit2, trend: stats.projectsTrend, }, { - title: 'Active Internal Memos', + title: 'Internal Memos', value: stats.activeInternalMemos, icon: ClipboardClock, trend: stats.personnelTrend, }, { - title: 'Active Work Orders', + title: 'Work Orders', value: stats.activeWorkOrders, icon: FileText, trend: stats.workOrdersTrend, @@ -91,7 +91,7 @@ export default function HomeTask({ clients = [] }: HomeTaskProps) { {card.value} - {card.trend && ( + {/* {card.trend && (
↑ {card.trend} @@ -100,7 +100,7 @@ export default function HomeTask({ clients = [] }: HomeTaskProps) { vs last month
- )} + )} */} diff --git a/app/(dashboard)/task/component/client/ClientGrid.tsx b/app/(dashboard)/task/component/client/ClientGrid.tsx index 9fd7f9d..54279a8 100644 --- a/app/(dashboard)/task/component/client/ClientGrid.tsx +++ b/app/(dashboard)/task/component/client/ClientGrid.tsx @@ -2,7 +2,7 @@ import { motion } from 'motion/react'; import Link from 'next/link'; -import { ExternalLink, MoreHorizontal, FileText, Users, ClipboardList } from 'lucide-react'; +import { ExternalLink, MoreHorizontal, FileText, Users, ClipboardList, PencilLine, Trash } from 'lucide-react'; import { Card900 } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { LazyImage } from '@/components/ui/lazy-image'; @@ -122,33 +122,6 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp - {/* Dropdown Action Menu */} - - - - - - - View Client Detail - - onEdit(client)}> - Edit Client - - onDelete(client)} - className="text-destructive focus:text-destructive" - > - Delete Client - - - {/* Client Brand Logo & Corporate Name */} @@ -271,16 +244,35 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp )} - - + + - + + + diff --git a/app/(dashboard)/task/component/client/ClientList.tsx b/app/(dashboard)/task/component/client/ClientList.tsx index 1993a34..6b8ea54 100644 --- a/app/(dashboard)/task/component/client/ClientList.tsx +++ b/app/(dashboard)/task/component/client/ClientList.tsx @@ -2,7 +2,7 @@ import { motion } from 'motion/react'; import Link from 'next/link'; -import { FileText, Users, ClipboardList, MoreHorizontal, ExternalLink } from 'lucide-react'; +import { FileText, Users, ClipboardList, MoreHorizontal, ExternalLink, Trash, PencilLine } from 'lucide-react'; import { Card900 } from '@/components/ui/card'; import { LazyImage } from '@/components/ui/lazy-image'; import { Button } from '@/components/ui/button'; @@ -21,19 +21,16 @@ import { IClient, CLIENT_FALLBACK_IMAGE } from '../../types'; import { getProjectStatusBreakdown } from '../../utils/client-overview-helpers'; import dynamic from 'next/dynamic'; -const ClientMilestoneTimeline = dynamic( - () => import('./ClientMilestoneTimeline'), - { - ssr: false, - loading: () => ( -
-
-
-
-
- ), - } -); +const ClientMilestoneTimeline = dynamic(() => import('./ClientMilestoneTimeline'), { + ssr: false, + loading: () => ( +
+
+
+
+
+ ), +}); interface ClientListProps { clients: IClient[]; @@ -240,7 +237,7 @@ export default function ClientList({ clients, onEdit, onDelete }: ClientListProp
- Active Work Orders + Work Orders
{activeWorkOrders}
@@ -250,41 +247,32 @@ export default function ClientList({ clients, onEdit, onDelete }: ClientListProp
- - - - - - - View Client Detail - - onEdit(client)}> - Edit Client - - onDelete(client)} - className="text-destructive focus:text-destructive" - > - Delete Client - - - + + +
diff --git a/app/(dashboard)/task/component/client/ClientMilestoneTimeline.tsx b/app/(dashboard)/task/component/client/ClientMilestoneTimeline.tsx index ee1a020..563e0d0 100644 --- a/app/(dashboard)/task/component/client/ClientMilestoneTimeline.tsx +++ b/app/(dashboard)/task/component/client/ClientMilestoneTimeline.tsx @@ -150,7 +150,7 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl {/* Timeline Viewport Container with group/rail for sibling hover coordination */}
-
+
{/* Continuous 2-Month Horizontal Rail */}
{/* Gradient Segments connecting Hari Ini -> Agenda 1 -> Agenda 2 -> ... */} @@ -200,7 +200,7 @@ export default function ClientMilestoneTimeline({ client, variant = 'list' }: Cl {/* If no milestones in range, show gentle notice */} {!hasAgendas && (
- + No upcoming milestones in the next 2 months
From 47076b1d09c6fa632e48fdf9b47b2d6a77f3187d Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan <43689091+ichsankurnia@users.noreply.github.com> Date: Wed, 4 Nov 2026 16:03:26 +0700 Subject: [PATCH 2/4] Improve task search and filtering Search clients and assignments by employee, add end-user filters to client details, and refine filter options and sorting behavior. --- .../(main)/ClientDetailComponent.tsx | 30 +++++- .../task/component/FilterComponent.tsx | 15 ++- .../task/component/FilterModal.tsx | 49 +++++---- app/(dashboard)/task/component/HomeTask.tsx | 11 +-- app/(dashboard)/task/data.ts | 99 +++++++++++++------ app/(dashboard)/task/error.tsx | 2 +- 6 files changed, 141 insertions(+), 65 deletions(-) diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx index ba68b10..f81746a 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -1,11 +1,11 @@ "use client"; -import { useState } from 'react'; +import { useState, useMemo } from 'react'; import { Briefcase } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import Link from 'next/link'; -import { IProjectAssignment } from '../../../type.assignment'; +import { EndUser, IProjectAssignment } from '../../../type.assignment'; import { useRouter, useSearchParams } from 'next/navigation'; import dynamic from 'next/dynamic'; import FilterComponent from '../../../component/FilterComponent'; @@ -89,13 +89,35 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro setAction(undefined); }; + const uniqueEndUsers = useMemo(() => { + const seen = new Set(); + const result: EndUser[] = []; + + for (const item of assignmentLists) { + const endUser = item?.end_user; + if (!endUser) continue; + const key = String(endUser.id ?? endUser.code ?? endUser.name ?? ''); + if (key && !seen.has(key)) { + seen.add(key); + result.push(endUser); + } + } + + return result; + }, [assignmentLists]); + return (
{/* --- PROJECT ASSIGNMENT DASHBOARD STATS --- */} {/* --- FILTER & SEARCH TOOLBAR --- */} - + {/* --- EMPTY STATE --- */} {assignmentLists.length === 0 ? ( @@ -199,4 +221,4 @@ export default function ClientDetailComponent({ clientId, assignmentLists }: Pro ) : null}
); -} \ No newline at end of file +} diff --git a/app/(dashboard)/task/component/FilterComponent.tsx b/app/(dashboard)/task/component/FilterComponent.tsx index 714af28..b7c80a6 100644 --- a/app/(dashboard)/task/component/FilterComponent.tsx +++ b/app/(dashboard)/task/component/FilterComponent.tsx @@ -11,6 +11,8 @@ import { import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import useDebounce from '@/hooks/useDebounce'; +import { EndUser } from '../type.assignment'; +import { IEndUser } from '../types'; const FilterModal = dynamic( () => import('./FilterModal').then((mod) => mod.FilterModal), @@ -26,6 +28,7 @@ const FilterModal = dynamic( ); type Props = { + endUserList?: (EndUser | IEndUser)[] hideClient?: boolean hideEndUser?: boolean hideStatus?: boolean; @@ -41,6 +44,7 @@ type Props = { }; const FilterComponent: FC = ({ + endUserList, hideFilterModal, hideClient, hideEndUser, @@ -52,7 +56,7 @@ const FilterComponent: FC = ({ hideCategory, hideSort, showLayoutToggle, - placeholder = "Search client...", + placeholder = "Search client or employee...", }) => { const router = useRouter(); const pathname = usePathname(); @@ -60,6 +64,7 @@ const FilterComponent: FC = ({ const currentQuery = searchParams?.get('q') || ''; const currentSort = searchParams?.get('sort') || ''; + const sortValue = (currentSort === 'active_first' || !currentSort) ? 'default' : currentSort; const currentLayout = searchParams?.get('layout') === 'grid' ? 'grid' : 'list'; const [searchText, setSearchText] = useState(currentQuery); @@ -117,6 +122,7 @@ const FilterComponent: FC = ({ {!hideFilterModal ? @@ -159,12 +165,11 @@ const FilterComponent: FC = ({ ) : null} {!hideSort ? ( - - + - Active First Default Latest Oldest @@ -178,4 +183,4 @@ const FilterComponent: FC = ({ ); } -export default FilterComponent; \ No newline at end of file +export default FilterComponent; diff --git a/app/(dashboard)/task/component/FilterModal.tsx b/app/(dashboard)/task/component/FilterModal.tsx index 7b4a353..1d36037 100644 --- a/app/(dashboard)/task/component/FilterModal.tsx +++ b/app/(dashboard)/task/component/FilterModal.tsx @@ -1,6 +1,6 @@ "use client" -import { useState, useEffect, type FC } from 'react'; +import { useState, useEffect, useMemo, type FC } from 'react'; import { usePathname, useRouter, useSearchParams } from 'next/navigation'; import { format, parseISO } from 'date-fns'; import { ListFilter } from 'lucide-react'; @@ -23,11 +23,12 @@ import { DatePickerMultiMode } from '@/components/ui/datepicker-multi-mode'; import { MultiSelect } from '@/components/ui/multi-select'; import { useFetchWithAxios } from '@/lib/axios/useFetch'; -import { ProjectStatus } from '../type.assignment'; +import { EndUser, ProjectStatus } from '../type.assignment'; import { IUser } from '@/app/admin/administration/user/component/type'; import { IClient, IEndUser } from '../types'; interface Props { + endUserList?: (EndUser | IEndUser)[] hideClient?: boolean hideEndUser?: boolean hideStatus?: boolean; @@ -38,16 +39,15 @@ interface Props { hideCategory?: boolean; } -export const FilterModal: FC = ({ hideClient = true, hideEndUser = true, hideStatus, hideAssignedTo, hideProjectDateFilter, hideWoDateFilter, hideImDateFilter, hideCategory }) => { +export const FilterModal: FC = ({ hideClient = true, hideEndUser = true, endUserList, hideStatus, hideAssignedTo, hideProjectDateFilter, hideWoDateFilter, hideImDateFilter, hideCategory }) => { const [open, setOpen] = useState(false); const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); const { data: clientList } = useFetchWithAxios(!hideClient ? '/client' : null) - const { data: endUserList } = useFetchWithAxios(!hideEndUser ? '/end-user' : null) - const { data: statusList } = useFetchWithAxios(!hideStatus ? '/project-assignment-status' : null); - const { data: userList } = useFetchWithAxios(!hideAssignedTo ? '/user' : null); + const { data: statusList } = useFetchWithAxios(!hideStatus ? '/project-assignment-status?type=master' : null); + const { data: userList } = useFetchWithAxios(!hideAssignedTo ? '/user/active' : null); const [clientFilter, setClientFilter] = useState([]); const [enduserFilter, setEnduserFilter] = useState([]); @@ -58,6 +58,23 @@ export const FilterModal: FC = ({ hideClient = true, hideEndUser = true, const [woDate, setWoDate] = useState(); const [imDate, setImDate] = useState(); + // Deduplicate end users options + const endUserOptions = useMemo(() => { + if (!endUserList || endUserList.length === 0) return []; + const seen = new Set(); + const options: { label: string; value: string }[] = []; + + for (const item of endUserList) { + if (!item || item.id === undefined || item.id === null) continue; + const val = String(item.id); + if (!seen.has(val)) { + seen.add(val); + options.push({ label: item.name, value: val }); + } + } + return options; + }, [endUserList]); + // Set initial filter if values exist in URL useEffect(() => { if (open) { @@ -91,14 +108,13 @@ export const FilterModal: FC = ({ hideClient = true, hideEndUser = true, } }, [open, searchParams]); - const handleApplyFilters = () => { const params = new URLSearchParams(searchParams?.toString()); - if (clientFilter.length > 0) params.set('client', clientFilter.join(',')); + if (clientFilter?.length > 0) params.set('client', clientFilter.join(',')); else params.delete('client'); - if (endUserList.length > 0) params.set('end_user', endUserList.join(',')); + if (enduserFilter?.length > 0) params.set('end_user', enduserFilter.join(',')); else params.delete('end_user'); // Single string values @@ -111,7 +127,6 @@ export const FilterModal: FC = ({ hideClient = true, hideEndUser = true, if (assignedToFilter.length > 0) params.set('users', assignedToFilter.join(',')); else params.delete('users'); - // Helper to format DateRange into URL params const applyDateRangeToParams = (range: DateRange | undefined, prefix: string) => { if (range?.from) { @@ -152,7 +167,7 @@ export const FilterModal: FC = ({ hideClient = true, hideEndUser = true, // Calculate active filter count for the badge const activeFilterCount = Array.from(searchParams!.keys()).filter(key => - ['category', 'status', 'users', 'project_date_from', 'wo_date_from', 'im_date_from'].includes(key) + ['client', 'end_user', 'category', 'status', 'users', 'project_date_from', 'wo_date_from', 'im_date_from'].includes(key) ).length; return ( @@ -189,17 +204,17 @@ export const FilterModal: FC = ({ hideClient = true, hideEndUser = true, placeholder='Select end user to filter' value={enduserFilter} onChange={setEnduserFilter} - options={endUserList && endUserList.length > 0 ? endUserList.map((item: IEndUser) => ({ label: item.name, value: String(item.id) })) : []} + options={endUserOptions} maxCount={1} />
: null } {!hideCategory ?
- + + )} /> ( {assignmentType} Year - + + { + const cleaned = e.target.value.replace(/\D/g, '').slice(0, 4); + field.onChange(cleaned); + }} + /> + )} /> @@ -932,6 +1081,24 @@ export default function ProjectAssignmentForm( WO Code + {woCodeStatus === 'checking' && ( + + + Checking availability... + + )} + {woCodeStatus === 'available' && ( + + + {woCodeMessage || 'Available'} + + )} + {woCodeStatus === 'unavailable' && ( + + + {woCodeMessage || 'Already in use'} + + )}
@@ -950,15 +1117,30 @@ export default function ProjectAssignmentForm( field.onChange(val); }} /> + {woCodeStatus === 'checking' && ( + + + + )} + {woCodeStatus === 'available' && ( + + + + )} + {woCodeStatus === 'unavailable' && ( + + + + )} +

Full work order code will be submitted as: # {projectCode}-{field.value?.trim() || '...'}

- ); }} @@ -1185,9 +1367,9 @@ export default function ProjectAssignmentForm( {/* --- FOOTER NAVIGATION --- */} -
-
@@ -1208,6 +1390,29 @@ export default function ProjectAssignmentForm( {showEndUserForm ? setShowEndUserForm(false)} onSuccess={() => { mutateEndUserList(); setShowEndUserForm(false) }} /> : null} {showClientForm ? setShowClientForm(false)} onSuccess={() => { mutateClientList(); setShowClientForm(false) }} /> : null} {isFullLoading ? : null} + + + + + Discard unsaved changes? + + You have unsaved changes in this form. If you leave now, your progress will be lost. + + + + Keep Editing + { + setShowLeaveConfirmModal(false); + router.back(); + }} + > + Discard & Leave + + + + ); } \ No newline at end of file diff --git a/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx b/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx index 1f2e4b0..0920200 100644 --- a/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx +++ b/app/(dashboard)/task/component/project-assignment/AssignmentGrid.tsx @@ -11,7 +11,7 @@ import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; import { LazyImage } from '@/components/ui/lazy-image'; -import { Calendar, MoreVertical, ArrowUpRight, Clock } from 'lucide-react'; +import { Calendar, MoreVertical, ArrowUpRight, Clock, AlertTriangle } from 'lucide-react'; import Link from 'next/link'; import { cn } from '@/lib/utils'; import ConvertedAssignmentBadge from './ConvertedAssignmentBadge'; @@ -289,9 +289,54 @@ export default function AssignmentGrid({
{/* Actual Progress (Real Work) matching detail page styling */}
- - Actual - +
+ + Actual + + {item.hasWarning && ( + + + + + + + +
+ + {item.warningTitle} +
+

+ {item.warningReason} +

+ {item.warningDetails.length > 0 && ( +
+ {item.warningDetails.map((detail, idx) => ( +
+ • + {detail} +
+ ))} +
+ )} +
+
+ )} +
- - - {item.healthStatus} -

{item.remainingText}

{item.assignmentType} - {/* Project Status Badge matching technical status badge colors */} - {/* Code Pill with Tooltip */} {item.code ? ( @@ -245,10 +243,58 @@ export default function AssignmentList({ {/* 2. CENTER: Progress Bars (Actual Progress & Timeline) & 5-Node Stepper Track */}

{/* Actual Progress (Real Work) matching detail page styling */} -
- - Actual - +
+
+ + Actual + + {item.hasWarning && ( + + +
+
+ +
+ +
+
+ +
+ + {item.warningTitle} +
+

+ {item.warningReason} +

+ {item.warningDetails.length > 0 && ( +
+ {item.warningDetails.map((detail, idx) => ( +
+ • + {detail} +
+ ))} +
+ )} +
+
+ )} +
- {/* Health Badge */} -
- - - {item.healthStatus} - -
+ {/* Project Status Badge matching technical status badge colors */} + {/* Remaining days or completion date */}

diff --git a/app/(dashboard)/task/component/project-assignment/ProjectAssignmentDashboardStats.tsx b/app/(dashboard)/task/component/project-assignment/ProjectAssignmentDashboardStats.tsx index 086dbdc..cad2fc7 100644 --- a/app/(dashboard)/task/component/project-assignment/ProjectAssignmentDashboardStats.tsx +++ b/app/(dashboard)/task/component/project-assignment/ProjectAssignmentDashboardStats.tsx @@ -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 -

+
{/* 1. Total Projects */} @@ -45,7 +45,7 @@ export default function ProjectAssignmentDashboardStats({
-

Active Work Orders

+

Work Orders

{stats.activeWorkOrders}

@@ -64,41 +64,17 @@ export default function ProjectAssignmentDashboardStats({ - {/* 4. Average Progress */} + {/* 4. Needs Attention / Behind Schedule (Replaces Average Progress) */} - -
- + +
+
-

Average Progress

-

{stats.averageProgress}%

-
-
- - - {/* 5. On-Time Projects */} - - -
- -
-
-

On-Time Projects

-

{stats.onTimeRatio}

-
-
-
- - {/* 6. At Risk / Delayed */} - - -
- -
-
-

At Risk / Delayed

-

{stats.atRiskDelayed}

+

+ Needs Attention +

+

{stats.needsAttention}

diff --git a/app/(dashboard)/task/utils/assignment-overview-helpers.ts b/app/(dashboard)/task/utils/assignment-overview-helpers.ts index eb5551a..f354d7d 100644 --- a/app/(dashboard)/task/utils/assignment-overview-helpers.ts +++ b/app/(dashboard)/task/utils/assignment-overview-helpers.ts @@ -157,6 +157,14 @@ export interface AssignmentOverview { nextMilestoneText: string; updatedAgoText: string; latestActivityText: string; + + // Warning status & reasons (Health Critical/Off Track or Actual Progress < Days Elapsed) + hasWarning: boolean; + warningTitle: string; + warningReason: string; + warningDetails: string[]; + isCriticalOrOffTrack: boolean; + isBehindSchedule: boolean; } export function formatAssignmentDate(dateStr?: string) { @@ -705,7 +713,7 @@ 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( + const { healthStatus, healthBadgeClass, healthDotClass } = resolveDeliveryHealth( technicalRank, hasTechnicalStatus, progressPercent, @@ -761,12 +769,41 @@ 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 actualProgress = typeof assignment.progress === 'number' && !isNaN(assignment.progress) ? Math.min(100, Math.max(0, assignment.progress)) : 0; const latestActivityText = formatLatestActivityWording(assignment.project_assignment_history); + // 5. Warning condition: healthStatus is 'Critical' or 'Off Track' OR actualProgress < progressPercent (days elapsed) + const isCriticalOrOffTrack = healthStatus === 'Critical' || healthStatus === 'Off Track'; + const isBehindSchedule = healthStatus !== 'Completed' && actualProgress < progressPercent; + const hasWarning = isCriticalOrOffTrack || isBehindSchedule; + + let warningTitle = ''; + let warningReason = ''; + const warningDetails: string[] = []; + + if (isCriticalOrOffTrack && isBehindSchedule) { + warningTitle = `Attention Needed: ${healthStatus} & Behind Schedule`; + warningReason = `Project deadline has passed and actual progress (${actualProgress}%) is lagging behind timeline elapsed (${progressPercent}%).`; + warningDetails.push(`Status: ${healthStatus} (${remainingText || 'Passed deadline'})`); + warningDetails.push(`Actual: ${actualProgress}% vs Elapsed: ${progressPercent}% (${daysRatioText})`); + } else if (isCriticalOrOffTrack) { + warningTitle = `Attention Needed: ${healthStatus}`; + warningReason = `Project deadline has passed without reaching completion status (${remainingText || 'Passed deadline'}).`; + warningDetails.push(`Status: ${healthStatus}`); + if (endDate) { + warningDetails.push(`Deadline: ${formatAssignmentDate(endDate)}`); + } + } else if (isBehindSchedule) { + warningTitle = 'Attention Needed: Behind Schedule'; + warningReason = `Actual progress (${actualProgress}%) is lagging behind the timeline elapsed (${progressPercent}%).`; + warningDetails.push(`Actual Progress: ${actualProgress}%`); + warningDetails.push(`Timeline Elapsed: ${progressPercent}% (${daysRatioText})`); + if (totalDays > elapsedDays) { + warningDetails.push(`${totalDays - elapsedDays} days remaining`); + } + } + return { assignmentType, isProject, @@ -796,6 +833,12 @@ export function getAssignmentOverview(assignment: IProjectAssignment, index: num nextMilestoneText, updatedAgoText, latestActivityText, + hasWarning, + warningTitle, + warningReason, + warningDetails, + isCriticalOrOffTrack, + isBehindSchedule, }; } @@ -825,10 +868,11 @@ export function calculateDashboardStats(assignments: IProjectAssignment[]) { }); const assignedPeopleCount = uniqueUsers.size; - // Average progress - const avgProgress = overviews.length > 0 - ? Math.round(overviews.reduce((acc, o) => acc + o.progressPercent, 0) / overviews.length) - : 0; + // Warning / Needs Attention count: healthStatus is 'Critical' or 'Off Track' OR actualProgress < progressPercent (days elapsed) + const needsAttentionCount = overviews.filter(o => o.hasWarning).length; + + // Average progress (kept for backwards compatibility) + const avgProgress = overviews.length > 0 ? Math.round(overviews.reduce((acc, o) => acc + o.progressPercent, 0) / overviews.length) : 0; // On-Time projects vs Total const onTimeCount = overviews.filter(o => o.healthStatus === 'On Track' || o.healthStatus === 'Completed' || o.healthStatus === 'Near Go-live').length; @@ -838,6 +882,7 @@ export function calculateDashboardStats(assignments: IProjectAssignment[]) { totalProjects: totalProjects || totalAssignments, activeWorkOrders: activeWorkOrders || totalAssignments, assignedPeople: assignedPeopleCount, + needsAttention: needsAttentionCount, averageProgress: avgProgress, onTimeRatio: `${onTimeCount} / ${totalAssignments}`, atRiskDelayed: atRiskCount, diff --git a/package.json b/package.json index 58bd47b..b401e1b 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "framer-motion": "^12.23.25", "get-orientation": "^1.1.2", "heic2any": "^0.0.4", - "lucide-react": "^1.49.0", + "lucide-react": "^1.68.0", "motion": "^12.38.0", "next": "^16.0.10", "next-auth": "^4.24.13", @@ -93,4 +93,4 @@ "tw-animate-css": "^1.4.0", "typescript": "^5" } -} \ No newline at end of file +}