From ad4925bd55c5480d5450ba02fd99167cfd4fdc03 Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan Date: Sun, 19 Apr 2026 18:54:47 +0700 Subject: [PATCH] update UI --- .../(main)/ClientDetailComponent.tsx | 194 +++++++++--------- .../AssignmentDetailComponent.tsx | 45 ++-- .../ProjectAssignmentForm.tsx | 6 +- .../[project_id]/AssignedPeople.tsx | 4 +- .../[project_id]/StatusTimeline.tsx | 2 +- .../[project_id]/WorkOrderCard.tsx | 22 +- .../project-detail/[project_id]/page.tsx | 194 +++++++++++++++++- app/(dashboard)/task/type.assignment.ts | 2 + components/ui/motion-wrapper.tsx | 17 ++ 9 files changed, 359 insertions(+), 127 deletions(-) create mode 100644 components/ui/motion-wrapper.tsx 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 4ec8d35..825163e 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientDetailComponent.tsx @@ -94,106 +94,111 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: return ( - - -
-
-
- {isProject ? : } -
-
- {isProject ? - -
-
-

{assignmentName}

- + + + +
+
+
+ {isProject ? : } +
+
+ {isProject ? + e.stopPropagation()}> +
+
+

{assignmentName}

+ +
+ {assignmentType} +
- {assignmentType} + + : +
+

{assignmentName}

+ {assignmentType}
- - : -
-

{assignmentName}

- {assignmentType} - -
- } + } - {assignment.wo_code && ( -

- WO: {assignment.wo_name} + {assignment.wo_code && ( +

+ WO: {assignment.wo_name} +

+ )} + +

+ {assignmentDesc}

- )} -

- {assignmentDesc} -

- -
-
- - - {assignmentStartDate ? new Date(assignmentStartDate).toLocaleDateString() : 'N/A'} - - {assignmentEndDate ? new Date(assignmentEndDate).toLocaleDateString() : 'N/A'} - -
-
- -
- {assignment?.users?.slice(0, 3).map(empId => { - const emp = DUMMY_EMPLOYEES.find(e => e.id === empId); - return ( -
- - - - - -
-

{emp?.name}

-

{emp?.role}

-
-
-
+
+
+ + + {assignmentStartDate ? new Date(assignmentStartDate).toLocaleDateString() : 'N/A'} - + {assignmentEndDate ? new Date(assignmentEndDate).toLocaleDateString() : 'N/A'} + +
+
+ +
+ {assignment?.users?.slice(0, 3).map(empId => { + const emp = DUMMY_EMPLOYEES.find(e => e.id === empId); + return ( +
+ + + + + +
+

{emp?.name}

+

{emp?.role}

+
+
+
+
+ ); + })} + {assignment.project_assignment_work_order_detail?.length > 3 && ( +
+ +{assignment.project_assignment_work_order_detail?.length - 3}
- ); - })} - {assignment.project_assignment_work_order_detail?.length > 3 && ( -
- +{assignment.project_assignment_work_order_detail?.length - 3} -
- )} - {assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length === 0 && No employees assigned} + )} + {assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length === 0 && No employees assigned} +
+ + + + + + + View Assignment Details + + + View Project Details + + + Edit Assignment + + { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Manage Employees + { setSelectedData(assignment); setAction('UPDATE_STATUS') }}>Update Assignment Status + Delete + +
- - - - - - - View Details Assignment - - - Edit Assignment - - { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Manage Employees - { setSelectedData(assignment); setAction('UPDATE_STATUS') }}>Update Assignment Status - Delete - - -
- - + + + ) })} @@ -263,7 +268,7 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: {assignment.wo_end_date ? new Date(assignment.wo_end_date).toLocaleDateString() : '-'} - + @@ -274,13 +279,16 @@ export default function ClientDetailComponent({ clientId, initialAssignments }: - View Details + View Assignment Details - Edit Assignment + View Project Details - { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Manage Employees - { setSelectedData(assignment); setAction('UPDATE_STATUS') }}>Update Assignment Status + + Edit Assignment + + { setSelectedData(assignment); setAction('MANAGE_EMPLOYEE') }}>Add Team + { setSelectedData(assignment); setAction('UPDATE_STATUS') }}>Update Status Delete diff --git a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx index d03ae06..a28ca98 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/[assignment_id]/AssignmentDetailComponent.tsx @@ -2,7 +2,7 @@ "use client" import { motion } from 'motion/react'; -import { ArrowLeft, Briefcase, Calendar, CheckCircle2, History, AlertCircle } from 'lucide-react'; +import { ArrowLeft, Briefcase, Calendar, CheckCircle2, History, AlertCircle, UserPlus, ExternalLink } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle, CardDescription, Card900 } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; @@ -15,6 +15,8 @@ import { IProjectAssignment } from '../../../type.assignment'; import { useState } from 'react'; import FormUpdateStatus from '../../../component/FormUpdateStatus'; import BadgeStatus from '@/components/ui/badge-status'; +import Link from 'next/link'; +import ManageEmployee from '../../../component/ManageEmployee'; interface Props { client: IClient | undefined; @@ -22,7 +24,7 @@ interface Props { } export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) { - const [action, setAction] = useState<'ASSIGNMENT' | 'WO' | undefined>() + const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>() const [selectedData, setSelectedData] = useState() const router = useRouter(); @@ -57,7 +59,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment > {/* Header */}
-
+
-

{assignmentName}

+ {!isProject ? +

{assignmentName}

+ : + +

{assignmentName}

+ + + }

@@ -84,9 +95,9 @@ export default function AssignmentDetail({ client, initialAssignment: assignment

-
@@ -150,7 +161,6 @@ export default function AssignmentDetail({ client, initialAssignment: assignment

{assignment.wo_name}

-

{assignment.wo_description}

@@ -163,17 +173,18 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
-
- -
{/* WO Status History Mini-Timeline */} {assignment.project_assignment_status_detail && assignment.project_assignment_status_detail.length > 0 && (
-

Team

+
+

Team

+ +
{assignment.project_assignment_work_order_detail && assignment.project_assignment_work_order_detail.length === 0 && No employees assigned} {assignment.project_assignment_work_order_detail.map((history) => ( @@ -241,13 +252,13 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
- {action === 'ASSIGNMENT' ? - + {action === 'UPDATE_STATUS' ? + : null } - {action === 'WO' ? - + {action === 'MANAGE_EMPLOYEE' ? + : null } diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx index 2ab2fcc..2d8f2b3 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-assignments/ProjectAssignmentForm.tsx @@ -175,21 +175,21 @@ export default function CreateAssignmentForm({ client, clientId, projectList, is "im_name": assignmentType === 'IM' ? payload.name : isEdit ? existAssignment?.im_name : "", "im_year": assignmentType === 'IM' ? Number(payload.year) : isEdit ? existAssignment?.im_year : 2026, "im_start_date": assignmentType === 'IM' ? dayjs(payload.startDate).format('YYYY-MM-DD') : isEdit ? existAssignment?.im_start_date : "", - "im_end_date": assignmentType === 'IM' ? dayjs(payload.endDate).format('YYYY-MM-DD') : isEdit ? existAssignment?.im_end_date : "", + "im_end_date": assignmentType === 'IM' ? payload.endDate ? dayjs(payload.endDate).format('YYYY-MM-DD') : "" : isEdit ? existAssignment?.im_end_date : "", "im_description": assignmentType === 'IM' ? payload.description : isEdit ? existAssignment?.im_description : "", "project_code": assignmentType === 'Project' ? payload.code : '', "project_name": assignmentType === 'Project' ? payload.name : '', "project_year": assignmentType === 'Project' ? Number(payload.year) : 2026, "project_start_date": assignmentType === 'Project' ? dayjs(payload.startDate).format('YYYY-MM-DD') : '', - "project_end_date": assignmentType === 'Project' ? dayjs(payload.endDate).format('YYYY-MM-DD') : '', + "project_end_date": assignmentType === 'Project' ? payload.endDate ? dayjs(payload.endDate).format('YYYY-MM-DD') : '' : '', "project_description": assignmentType === 'Project' ? payload.description : '', "project_status_id": isEdit ? existAssignment?.project_status.id : 1, "wo_code": (payload.workOrder as any).code, "wo_name": (payload.workOrder as any).name, "wo_start_date": (payload.workOrder as any).startDate ? dayjs((payload.workOrder as any).startDate).format('YYYY-MM-DD') : '', - "wo_end_date": (payload.workOrder as any).endDate ? dayjs((payload.workOrder as any).endDate).format('YYYY-MM-DD') : '', + "wo_end_date": (payload.workOrder as any).endDate ? (payload.workOrder as any).endDate ? dayjs((payload.workOrder as any).endDate).format('YYYY-MM-DD') : '' : '', "wo_description": (payload.workOrder as any).description, "wo_warranty": isEdit ? existAssignment?.wo_warranty : '', diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx index cb8cb9a..c3b90e9 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/AssignedPeople.tsx @@ -19,7 +19,7 @@ const getInitials = (name: string) => const AssignedPeople = ({ people }: AssignedPeopleProps) => { if (people.length === 0) { return ( -
+
No people assigned yet
); @@ -50,7 +50,7 @@ const AssignedPeople = ({ people }: AssignedPeopleProps) => {

{people.length} People

-

assigned to this work order

+

assigned to this work order

diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/StatusTimeline.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/StatusTimeline.tsx index 3a97567..ba9bff0 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/StatusTimeline.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/StatusTimeline.tsx @@ -39,7 +39,7 @@ const StatusTimeline = ({ history }: StatusTimelineProps) => {
- {isLatest && Current} + {isLatest && Current}
diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx index b6d3144..2fd89df 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/WorkOrderCard.tsx @@ -1,3 +1,5 @@ +"use client" + import { useState } from 'react'; import { ChevronDown, Calendar, FileText, History, Users, StickyNote } from 'lucide-react'; import { Card900 } from '@/components/ui/card'; @@ -20,12 +22,12 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); return ( - + {/* Header (always visible) */}
{/* Index badge */} -
+
{String(index + 1).padStart(2, '0')} @@ -38,7 +40,7 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP
-
+
{workOrder.wo_code} @@ -80,7 +82,7 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP
-

Note

+

Note

{workOrder.note}

@@ -89,13 +91,13 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP
{/* Status history */}
-
+
-

Status History

-

+

Status History

+

{workOrder.project_assignment_status_detail.length} status changes

@@ -105,13 +107,13 @@ const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardP {/* Assigned people */}
-
+
-

Assigned People

-

Team members on this work order

+

Assigned People

+

Team members on this work order

diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx index 5b654bd..bbe48fa 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/page.tsx @@ -2,6 +2,14 @@ import { Button } from '@/components/ui/button'; import Link from 'next/link'; import fetchData from '@/lib/fetchData'; import ProjectDetailComponent from './ProjectDetailComponent'; +import { ArrowLeft, Briefcase, Building2, Calendar, CheckCircle2, ClipboardList, Clock3, Hash, Users } from 'lucide-react'; +import { COMPLETE_STATUS_LIST, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/type.assignment'; +import { motion } from 'motion/react'; +import { Card900 } from '@/components/ui/card'; +import WorkOrderCard from './WorkOrderCard'; +import { MotionDiv } from '@/components/ui/motion-wrapper'; +import { LazyImage } from '@/components/ui/lazy-image'; +import { Badge } from '@/components/ui/badge'; type Props = { params: Promise<{ client_id: string; project_id: string }> @@ -27,9 +35,193 @@ export default async function ProjectDetailPage({ params }: Props) { ); } + const formatDate = (date: string) => + new Date(date).toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' }); + + // Aggregate stats + const totalWorkOrders = project.project_assignment.length; + const completedWO = project.project_assignment.filter((wo: any) => COMPLETE_STATUS_LIST.includes(wo.project_status.name.toUpperCase())).length; + const inProgressWO = project.project_assignment.filter((wo: any) => ONPROGRESS_STATUS_LIST.includes(wo.project_status.name.toUpperCase())).length; + const totalAssigned = new Set( + project.project_assignment.flatMap((wo: any) => + wo.project_assignment_work_order_detail.map((p: any) => p.id), + ), + ).size; + + // Days remaining + const today = new Date(); + const endDate = new Date(project.end_date); + const daysRemaining = Math.ceil((endDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24)); + + const stats = [ + { + label: 'Total Work Orders', + value: totalWorkOrders, + icon: ClipboardList, + gradient: 'from-rose-500 to-red-600', + glow: 'shadow-[0_0_30px_-5px_hsl(270_70%_60%/0.4)]', + ring: 'ring-rose-500/20', + }, + { + label: 'In Progress', + value: inProgressWO, + icon: Clock3, + gradient: 'from-sky-500 to-blue-600', + glow: 'shadow-[0_0_30px_-5px_hsl(210_90%_55%/0.4)]', + ring: 'ring-sky-500/20', + }, + { + label: 'Completed', + value: completedWO, + icon: CheckCircle2, + gradient: 'from-emerald-500 to-green-600', + glow: 'shadow-[0_0_30px_-5px_hsl(160_84%_45%/0.4)]', + ring: 'ring-emerald-500/20', + }, + { + label: 'Team Members', + value: totalAssigned, + icon: Users, + gradient: 'from-amber-500 to-orange-600', + glow: 'shadow-[0_0_30px_-5px_hsl(38_95%_55%/0.4)]', + ring: 'ring-amber-500/20', + }, + ]; + // 4. Pass the fetched data to the interactive Client Component return ( - + <> + + {/* Back link */} + + + + + + {/*
*/} + {/*
*/} + +
+
+
+
+ Project + + Year {project.year} + +
+ +

+ {project.name} +

+ +
+ + + Code: {project.code} + + + + {formatDate(project.start_date)} → {formatDate(project.end_date)} + + {daysRemaining > 0 && ( + + {daysRemaining} days remaining + + )} +
+ + {/* Client card */} +
+
+ +
+
+

+ Client +

+

{client?.name}

+

+ End user: {client?.end_user_name} +

+
+
+
+
+ + {/* Description */} +
+

+ Description +

+

+ {project.description ?? "No description available for this project."} +

+
+
+ + + {/* Stats grid */} +
+ {stats.map((stat) => { + const Icon = stat.icon; + return ( + +
+
+
+ +
+
+

+ {stat.label} +

+

+ {stat.value} +

+
+
+ + ); + })} +
+ + {/* Work Orders section */} +
+
+
+ +
+
+

Work Orders

+

+ {totalWorkOrders} work order{totalWorkOrders !== 1 ? 's' : ''} in this project +

+
+
+
+ +
+ {project.project_assignment.map((wo: any, i: number) => + + )} +
+ + + {/* */} + ); } \ No newline at end of file diff --git a/app/(dashboard)/task/type.assignment.ts b/app/(dashboard)/task/type.assignment.ts index 1dc57f7..1111175 100644 --- a/app/(dashboard)/task/type.assignment.ts +++ b/app/(dashboard)/task/type.assignment.ts @@ -1,4 +1,6 @@ export const STATUS_LIST = ["Not Started", "On Progress", "On Going", "Halted", "Issue", "SIT", "UAT", "PTR", "BAST", "Warranty", "End Of Support", "Canceled"] +export const COMPLETE_STATUS_LIST = ['BAST', 'WARRANTY', 'END OF SUPPORT'] +export const ONPROGRESS_STATUS_LIST = ['ON PROGRESS', 'ON GOING', 'HALTED', 'ISSUE', 'SIT', 'UAT', 'PTR'] export interface IProjectAssignment { id: number diff --git a/components/ui/motion-wrapper.tsx b/components/ui/motion-wrapper.tsx new file mode 100644 index 0000000..1f0d2e0 --- /dev/null +++ b/components/ui/motion-wrapper.tsx @@ -0,0 +1,17 @@ +// components/motion-wrapper.tsx +"use client"; + +import { motion } from 'motion/react'; +import { ComponentProps } from 'react'; + +// This automatically extracts every possible prop that motion.div accepts, +// including standard HTML div props (className, onClick, etc.) +type MotionWrapperProps = ComponentProps; + +export function MotionDiv({ children, ...props }: MotionWrapperProps) { + return ( + + {children} + + ); +} \ No newline at end of file