From bd42c2defac47e444b452ffec7bdcb7985862b0f Mon Sep 17 00:00:00 2001 From: Ichsan Kurniawan Date: Tue, 6 Oct 2026 15:58:43 +0700 Subject: [PATCH] Revamp task client and project detail pages This commit adds dedicated loading states and a reusable Reveal animation, and refactors the task client/project detail flows to present a cleaner summary UI. It introduces richer client and project headers, delivery overview cards, improved work-order timeline/team sections, and more consistent visual styling across the task dashboard. The update also improves mobile readability and team assignment presentation, while keeping the same underlying data flow. --- .../[client_id]/(main)/ClientProfileCard.tsx | 133 ++++++ .../[client_id]/(main)/loading.tsx | 73 +++ .../client-detail/[client_id]/(main)/page.tsx | 43 +- .../AssignmentDetailComponent.tsx | 31 +- .../client-detail/[client_id]/loading.tsx | 1 + .../[project_id]/AssignedPeople.tsx | 422 ++++++++++++++---- .../[project_id]/DeliveryOverview.tsx | 81 ++++ .../[project_id]/ProjectHeader.tsx | 114 +++++ .../[project_id]/StatusTimeline.tsx | 176 ++++---- .../[project_id]/WorkOrderCard.tsx | 393 +++++++++++----- .../project-detail/[project_id]/format.ts | 25 ++ .../project-detail/[project_id]/loading.tsx | 103 +++++ .../project-detail/[project_id]/page.tsx | 251 +++-------- .../task/component/client/ClientGrid.tsx | 2 +- app/(dashboard)/task/loading.tsx | 54 +++ components/ui/reveal.tsx | 19 + 16 files changed, 1394 insertions(+), 527 deletions(-) create mode 100644 app/(dashboard)/task/client-detail/[client_id]/(main)/ClientProfileCard.tsx create mode 100644 app/(dashboard)/task/client-detail/[client_id]/(main)/loading.tsx create mode 100644 app/(dashboard)/task/client-detail/[client_id]/loading.tsx create mode 100644 app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/DeliveryOverview.tsx create mode 100644 app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/ProjectHeader.tsx create mode 100644 app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/format.ts create mode 100644 app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/loading.tsx create mode 100644 app/(dashboard)/task/loading.tsx create mode 100644 components/ui/reveal.tsx diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientProfileCard.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientProfileCard.tsx new file mode 100644 index 0000000..3f4dcbe --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/ClientProfileCard.tsx @@ -0,0 +1,133 @@ +/** + * Client information section for /task/client-detail/[client_id]. + * Same visual language as the assignment detail page: rounded-2xl surface, + * border-based elevation, mono facts row, `his` as the only accent. + */ + +import Link from 'next/link'; +import dayjs from 'dayjs'; +import { Plus } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { LazyImage } from '@/components/ui/lazy-image'; +import BadgeStatus from '@/components/ui/badge-status'; +import { cn } from '@/lib/utils'; +import { IClient } from '../../../types'; + +interface Props { + client: IClient; + clientId: string; +} + +const AVATAR_LIMIT = 5; + +function avatarSrc(avatar?: string | null) { + return avatar ? `${process.env.BASE_URL_IMG}/${avatar}` : '/assets/no-avatar.jpg'; +} + +export default function ClientProfileCard({ client, clientId }: Props) { + const isActive = client.status_name?.toLowerCase() === 'active'; + const users = client.users ?? []; + const teamCount = client.total_user_assigned || users.length; + const shown = users.slice(0, AVATAR_LIMIT); + const extra = users.length - shown.length; + const statusSummary = client.project_status_summary ?? []; + const since = client.created_at && dayjs(client.created_at).isValid() ? dayjs(client.created_at).format('MMM YYYY') : 'N/A'; + + return ( +
+
+
+
+ +
+ +
+
+ {client.code ? ( + + {client.code} + + ) : null} + + + {client.status_name} + +
+ +

+ {client.name} +

+ +

+ {client.description || 'No description available for this client.'} +

+
+
+ + + + +
+ +
+ + + + +
+ + {users.length > 0 || statusSummary.length > 0 ? ( +
+ {users.length > 0 ? ( +
+
+ {shown.map((u, i) => ( + 0 && '-ml-2')} + /> + ))} + {extra > 0 ? ( + + +{extra} + + ) : null} +
+

Assigned across this client's work orders

+
+ ) : null} + + {statusSummary.length > 0 ? ( +
    + {statusSummary.map(item => ( +
  • + + {item.total} +
  • + ))} +
+ ) : null} +
+ ) : null} +
+ ); +} + +function Fact({ label, value }: { label: string; value: string }) { + return ( +
+
{label}
+
{value}
+
+ ); +} diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/loading.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/loading.tsx new file mode 100644 index 0000000..7a91a8e --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/loading.tsx @@ -0,0 +1,73 @@ +export default function Loading() { + return ( +
+ {/* Back Link Skeleton */} +
+ + {/* Client Profile Card Skeleton */} +
+
+
+
+ +
+
+
+
+
+ +
+
+
+
+ +
+
+ +
+ {Array.from({ length: 4 }).map((_, i) => ( +
+
+
+
+ ))} +
+
+ + {/* Project Assignments Section Skeleton */} +
+
+
+
+
+ + {/* Filter & Layout Bar Skeleton */} +
+ + {/* Assignment Cards Grid Skeleton */} +
+ {Array.from({ length: 3 }).map((_, i) => ( +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ))} +
+
+
+ ); +} diff --git a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx index fc9e36b..5e99a1f 100644 --- a/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx +++ b/app/(dashboard)/task/client-detail/[client_id]/(main)/page.tsx @@ -1,11 +1,12 @@ -import { ArrowLeft, Plus } from 'lucide-react'; +import { ArrowLeft } from 'lucide-react'; import { Button } from '@/components/ui/button'; import Link from 'next/link'; import ClientDetailComponent from './ClientDetailComponent'; +import ClientProfileCard from './ClientProfileCard'; import fetchData, { getQueryStringFilteredAssignments } from '@/lib/fetchData'; -import { LazyImage } from '@/components/ui/lazy-image'; import { getFilteredAssignments } from '../../../data'; +import Reveal from '@/components/ui/reveal'; type Props = { params: Promise<{ client_id: string }> @@ -43,30 +44,20 @@ export default async function ClientDetailPage({ params, searchParams }: Props) const filterAssignments = getFilteredAssignments(assignmentList, query, sortBy) return ( -
-
-
-
- -
-
- - - -

{client.name}

-

{client?.description || 'No description available for this client.'}

-
-
-
- - - -
-
+
+ + + + Back to clients + + + + + + (); const [showAllTeam, setShowAllTeam] = useState(false); - const [teamView, setTeamView] = useState<'grid' | 'list'>('grid'); + const [teamView, setTeamView] = useState<'grid' | 'list'>('list'); const isWorkOrder = !!assignment.wo_name; const assignmentType = isWorkOrder ? 'Work Order' : 'Internal Memo'; @@ -359,7 +359,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
{/* Side rail: status history */} - + {statusHistory.length === 0 ? (

@@ -421,24 +421,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment ); } -/** Entry reveal. Honors prefers-reduced-motion by rendering static. */ -function Reveal({ children, delay = 0, className }: { children: ReactNode; delay?: number; className?: string }) { - const reduce = useReducedMotion(); - return ( - - {children} - - ); -} - -function Surface({ - title, meta, action, children, -}: { title: string; meta?: string; action?: ReactNode; children: ReactNode }) { +function Surface({ title, meta, action, children }: { title: string; meta?: string; action?: ReactNode; children: ReactNode }) { return (

@@ -474,9 +457,7 @@ function initials(name?: string) { .toUpperCase(); } -function PartyRow({ - role, party, href, -}: { role: string; party?: { name?: string; photo?: string; description?: string | null; code?: string } | null; href?: string }) { +function PartyRow({ role, party, href }: { role: string; party?: { name?: string; photo?: string; description?: string | null; code?: string } | null; href?: string }) { const body = ( <>
diff --git a/app/(dashboard)/task/client-detail/[client_id]/loading.tsx b/app/(dashboard)/task/client-detail/[client_id]/loading.tsx new file mode 100644 index 0000000..7ad0393 --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/loading.tsx @@ -0,0 +1 @@ +export { default } from './(main)/loading'; 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 4b31389..03a3de6 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 @@ -1,102 +1,364 @@ -import { ProjectAssignmentWorkOrderDetail } from '@/app/(dashboard)/task/type.assignment'; -import { Badge } from '@/components/ui/badge'; +"use client"; + +import { useMemo, useState, ReactNode } from 'react'; +import dayjs from 'dayjs'; +import { Calendar, ChevronDown, LayoutGrid, List, Mail, Phone, UserPlus, Users } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { LazyImage } from '@/components/ui/lazy-image'; -import dayjs from 'dayjs'; -import { Mail, Phone, Calendar, ChevronDown } from 'lucide-react'; -import { useState } from 'react'; -import { motion, AnimatePresence } from 'motion/react'; +import { ProjectAssignmentWorkOrderDetail } from '@/app/(dashboard)/task/type.assignment'; +import { cn } from '@/lib/utils'; +import { avatarSrc, formatDate, formatSpan } from './format'; interface Props { people: ProjectAssignmentWorkOrderDetail[]; - defaultOpen?: boolean; + onManageTeam?: () => void; } -const AssignedPeople = ({ people, defaultOpen = true }: Props) => { - const [isOpen, setIsOpen] = useState(defaultOpen); +const TEAM_PREVIEW_LIMIT = 4; - if (people?.length === 0) { +function memberName(member: ProjectAssignmentWorkOrderDetail) { + return member.user?.fullname || member.user?.name || 'Unnamed member'; +} + +function AvatarStack({ members }: { members: ProjectAssignmentWorkOrderDetail[] }) { + const shown = members.slice(0, 5); + const extra = members.length - shown.length; + return ( +
+ {shown.map((m, i) => ( + 0 && '-ml-2')} + /> + ))} + {extra > 0 ? ( + + +{extra} + + ) : null} +
+ ); +} + +function ContactButton({ href, label, children }: { href: string; label: string; children: ReactNode }) { + return ( + + {children} + + ); +} + +/** Grid view card for a team member */ +function TeamCard({ member }: { member: ProjectAssignmentWorkOrderDetail }) { + const user = member.user; + const name = memberName(member); + const ended = !!member.end_date && dayjs(member.end_date).endOf('day').isBefore(dayjs()); + const span = formatSpan(member.start_date, member.end_date); + const position = user?.position?.name; + + return ( +
  • + {/* Top row: Avatar + Identity + Status */} +
    +
    + + +
    + +
    +
    +

    + {name} +

    + + {ended ? 'Ended' : 'Active'} + +
    + +

    + {position || 'Team Member'} +

    +
    +
    + + {/* Middle row: Assignment Period & Duration pill */} +
    +
    + + + + {member.start_date ? formatDate(member.start_date) : 'N/A'} - {member.end_date ? formatDate(member.end_date) : 'Present'} + + + {span ? ( + + {span} + + ) : null} +
    +
    + + {/* Bottom row: Direct Actions & Contact */} +
    + {user?.email ? ( + + + {user.email} + + ) : ( + No email + )} + + {user?.phone_number ? ( + + + {user.phone_number} + + ) : null} +
    +
  • + ); +} + +/** List view row for a team member */ +function TeamRow({ member }: { member: ProjectAssignmentWorkOrderDetail }) { + const user = member.user; + const name = memberName(member); + const ended = !!member.end_date && dayjs(member.end_date).endOf('day').isBefore(dayjs()); + const span = formatSpan(member.start_date, member.end_date); + const position = user?.position?.name; + + return ( +
  • +
    +
    + + +
    +
    +
    +

    + {name} +

    + + {ended ? 'Ended' : 'Active'} + +
    +

    {position || 'Team Member'}

    +
    +
    + +
    +
    +

    + {member.start_date ? formatDate(member.start_date) : 'N/A'} - {member.end_date ? formatDate(member.end_date) : 'Present'} +

    + {span ? ( +

    {span}

    + ) : null} +
    + +
    + {user?.email ? ( + + + + ) : null} + {user?.phone_number ? ( + + + + ) : null} +
    +
    +
  • + ); +} + +export default function AssignedPeople({ people, onManageTeam }: Props) { + const [teamView, setTeamView] = useState<'grid' | 'list'>('list'); + const [showAllTeam, setShowAllTeam] = useState(false); + + const { activeCount, positionCount } = useMemo(() => { + if (!people || people.length === 0) return { activeCount: 0, positionCount: 0 }; + const active = people.filter(m => !m.end_date || !dayjs(m.end_date).endOf('day').isBefore(dayjs())).length; + const positions = new Set(people.map(m => m.user?.position?.name).filter(Boolean)).size; + return { activeCount: active, positionCount: positions }; + }, [people]); + + if (!people || people.length === 0) { return ( -
    - No team assigned yet +
    +
    + +
    +

    No team members assigned

    +

    + Assign members to start tracking who is working on this work order. +

    + {onManageTeam ? ( + + ) : null}
    ); } + const visibleTeam = showAllTeam ? people : people.slice(0, TEAM_PREVIEW_LIMIT); + const hiddenTeamCount = people.length - visibleTeam.length; + return ( -
    - {/* Stacked avatars */} -
    +
    + {/* Team Overview Bar */} +
    -
    - {people?.slice(0, 5).map((user, i) => - - )} - {people?.length > 5 && -
    - +{people?.length - 5} -
    - } -
    -
    -

    {people?.length} People

    -

    assigned to this work order

    + +
    +

    + {people.length} {people.length === 1 ? 'member assigned' : 'members assigned'} +

    +

    + {activeCount} active · {positionCount} {positionCount === 1 ? 'role' : 'roles'} +

    +
    +
    +
    + + Viewing {visibleTeam.length} of {people.length} + +
    + +
    -
    - - {isOpen && ( - -
    - {people.map((user) => ( -
    - -
    -
    -

    {user.user.fullname}

    - {user.user.position?.name} -
    -
    - - - - {user.user.email} - - - - - {user.user.phone_number} - -
    -
    + {/* Member Roster Display: Grid or List */} + {teamView === 'grid' ? ( +
      + {visibleTeam.map(member => ( + + ))} +
    + ) : ( +
      + {visibleTeam.map(member => ( + + ))} +
    + )} -
    - - Assigned - - - - {user.start_date ? `${dayjs(user.start_date).format('MMMM DD, YYYY')} - ${user.end_date ? dayjs(user.end_date).format('MMMM DD, YYYY') : 'N/A'}` : 'N/A'} - -
    -
    - ))} -
    -
    - )} -
    + {/* Show More / Show Less Disclosure */} + {people.length > TEAM_PREVIEW_LIMIT ? ( + + ) : null}
    ); -}; - -export default AssignedPeople; +} diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/DeliveryOverview.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/DeliveryOverview.tsx new file mode 100644 index 0000000..823833f --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/DeliveryOverview.tsx @@ -0,0 +1,81 @@ +/** + * Delivery overview: one surface, semantic color. + * `his` = active work, emerald = done, neutral = everything else. + * Tiles are tinted, the segmented bar mirrors the same two hues. + */ + +import type { ComponentType, ReactNode } from 'react'; +import { CheckCircle2, ClipboardList, Clock3, Users } from 'lucide-react'; +import { cn } from '@/lib/utils'; + +interface Props { + total: number; + completed: number; + inProgress: number; + team: number; +} + +export default function DeliveryOverview({ total, completed, inProgress, team }: Props) { + const other = Math.max(total - completed - inProgress, 0); + const pct = (n: number) => (total > 0 ? (n / total) * 100 : 0); + const donePct = Math.round(pct(completed)); + + return ( +
    +
    +

    Delivery

    +

    + {donePct}% complete, {completed} of {total} work orders +

    +
    + +
    + + +
    + +
    + + + + +
    +
    + ); +} + +const TONES = { + neutral: { + tile: 'border-border/70 bg-muted/30', + icon: 'border-border bg-card text-muted-foreground', + }, + active: { + tile: 'border-yellow-600/25 bg-yellow-600/8', + icon: 'border-yellow-600/25 bg-yellow-600/15 text-yellow-600', + }, + done: { + tile: 'border-emerald-500/25 bg-emerald-500/8', + icon: 'border-emerald-500/25 bg-emerald-500/15 text-emerald-600 dark:text-emerald-400', + }, +} as const; + +function Stat({ + label, value, icon: Icon, tone, +}: { label: string; value: number; icon: ComponentType<{ className?: string }>; tone: keyof typeof TONES }): ReactNode { + const t = TONES[tone]; + return ( +
    + + + +
    +
    {label}
    +
    {value}
    +
    +
    + ); +} diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/ProjectHeader.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/ProjectHeader.tsx new file mode 100644 index 0000000..c532e9d --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/ProjectHeader.tsx @@ -0,0 +1,114 @@ +/** + * Header surface for the project detail page. + * Identity first, then a mono facts row, then the owning client as a quiet link row. + * Code and year are separate elements on purpose: the code is a chip, the year is a fact. + */ + +import Link from 'next/link'; +import dayjs from 'dayjs'; +import { Briefcase, ExternalLink, FolderGit2 } from 'lucide-react'; +import { Badge } from '@/components/ui/badge'; +import { LazyImage } from '@/components/ui/lazy-image'; +import BadgeStatus from '@/components/ui/badge-status'; +import { cn } from '@/lib/utils'; +import { IClient } from '@/app/(dashboard)/task/types'; +import { IProject } from '@/app/(dashboard)/task/type.project'; +import { formatDate, formatSpan } from './format'; + +interface Props { + client?: IClient; + clientId: string; + project: IProject; +} + +function timeLeft(endDate?: string | null) { + if (!endDate) return null; + const end = dayjs(endDate).startOf('day'); + if (!end.isValid()) return null; + const today = dayjs().startOf('day'); + if (end.isBefore(today)) return { label: 'Ended', tone: 'muted' as const }; + const span = formatSpan(today.toISOString(), end.toISOString()); + return { label: span === 'Same day' ? 'Ends today' : `${span} left`, tone: 'live' as const }; +} + +export default function ProjectHeader({ client, clientId, project }: Props) { + const status = typeof project.status === 'string' ? project.status : project.status?.name; + const left = timeLeft(project.end_date); + const duration = formatSpan(project.start_date, project.end_date); + + return ( +
    +
    +
    +
    + +
    + +
    +
    + + + Project + + {status ? : null} + {project.code ? ( + + # {project.code} + + ) : null} + {left ? ( + + {left.label} + + ) : null} +
    + +

    + {project.name} +

    + +

    + {project.description || 'No description available for this project.'} +

    +
    +
    + +
    + + + + +
    + + {client ? ( + +
    + +
    +
    +

    Client

    +

    {client.name}

    +
    + + + ) : null} +
    + ); +} + +function Fact({ label, value }: { label: string; value: string }) { + return ( +
    +
    {label}
    +
    {value}
    +
    + ); +} 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 3ba814a..444179e 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 @@ -1,105 +1,97 @@ -import { ProjectAssignmentStatusDetail } from '@/app/(dashboard)/task/type.assignment'; -import BadgeStatus from '@/components/ui/badge-status'; -import { Button } from '@/components/ui/button'; -import dayjs from 'dayjs'; -import { ChevronDown, Clock } from 'lucide-react'; +"use client"; + import { useState } from 'react'; -import { motion, AnimatePresence } from 'motion/react'; +import { ChevronDown, History } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import BadgeStatus from '@/components/ui/badge-status'; +import { ProjectAssignmentStatusDetail } from '@/app/(dashboard)/task/type.assignment'; +import { cn } from '@/lib/utils'; +import { formatDate, formatSpan } from './format'; interface StatusTimelineProps { history: ProjectAssignmentStatusDetail[]; - defaultOpen?: boolean; } -const StatusTimeline = ({ history, defaultOpen = true }: StatusTimelineProps) => { - const [isOpen, setIsOpen] = useState(defaultOpen); +const TIMELINE_PREVIEW_LIMIT = 3; + +export default function StatusTimeline({ history }: StatusTimelineProps) { + const [showAll, setShowAll] = useState(false); + + if (!history || history.length === 0) { + return ( +
    +
    + +
    +

    No status changes recorded

    +

    + Use the Update Status action to record the current stage of this work order. +

    +
    + ); + } + + const currentEntry = history.find(s => !s.end_date) ?? history[0]; + const visibleHistory = showAll ? history : history.slice(0, TIMELINE_PREVIEW_LIMIT); + const hiddenCount = history.length - visibleHistory.length; return ( -
    - {/* Vertical connector line */} -
    +
    +
      + {visibleHistory.map(entry => { + const isCurrent = entry.id === currentEntry?.id; + const span = formatSpan(entry.start_date, entry.end_date); + const remarks = (entry as any).status_remarks || (entry as any).remarks; -
      -
      - {/* Dot */} -
      -
      -
      -
      -
      -
      + return ( +
    1. + +
      + {isCurrent ? ( + + ) : ( + + {entry.project_assignment_status?.name} + + )} + {isCurrent ? ( + Current + ) : null} +
      +

      + {formatDate(entry.start_date)} - {entry.end_date ? formatDate(entry.end_date) : 'Present'} +

      + {span ? ( +

      {span}

      + ) : null} + {remarks ? ( +

      + {remarks} +

      + ) : null} +
    2. + ); + })} +
    - {/* Content */} -
    -
    - - Current -
    -
    - - {history[0]?.start_date ? dayjs(history[0]?.start_date).format('MMM D, YYYY') : ''} - - - {history[0]?.end_date ? dayjs(history[0]?.end_date).format('MMM D, YYYY') : ''} -
    -
    -
    - - -
    - - - {isOpen && ( - - -
    - {history.slice(1, history.length).map((item, i) => { - // const isLatest = i === 0; - - return ( -
    - {/* Dot */} -
    -
    -
    -
    - {/* {isLatest &&
    } */} -
    - - {/* Content */} -
    -
    - - {/* {isLatest && Current} */} -
    -
    - - {item.start_date ? dayjs(item.start_date).format('MMM D, YYYY') : ''} - - - {item.end_date ? dayjs(item.end_date).format('MMM D, YYYY') : ''} -
    - {/* {item.status_remarks && -

    - {item.status_remarks} -

    - } */} -
    -
    - ); - })} -
    - - )} - + ) : null}
    ); -}; - -export default StatusTimeline; +} 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 8c20bd8..4553ca3 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,15 +1,27 @@ -"use client" +"use client"; import { useState } from 'react'; -import { ChevronDown, Calendar, FileText, History, Users, StickyNote, UserPlus, IterationCcw } from 'lucide-react'; -import { Card900 } from '@/components/ui/card'; +import { motion, AnimatePresence, useReducedMotion } from 'motion/react'; +import { + Calendar, + ChevronDown, + History, + IterationCcw, + StickyNote, + UserPlus, + Users, +} from 'lucide-react'; import { Button } from '@/components/ui/button'; +import { LazyImage } from '@/components/ui/lazy-image'; import StatusTimeline from './StatusTimeline'; import AssignedPeople from './AssignedPeople'; import BadgeStatus from '@/components/ui/badge-status'; import { IProjectAssignment } from '@/app/(dashboard)/task/type.assignment'; import UpdateTimelineStatus from '@/app/(dashboard)/task/component/UpdateTimelineStatus'; import { ManageTeam } from '@/app/(dashboard)/task/component/ManageTeam'; +import { cn } from '@/lib/utils'; +import { COMPLETE_STATUS_LIST, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data'; +import { avatarSrc, formatDate, formatSpan } from './format'; interface WorkOrderCardProps { workOrder: IProjectAssignment; @@ -17,138 +29,303 @@ interface WorkOrderCardProps { defaultOpen?: boolean; } -const WorkOrderCard = ({ workOrder, index, defaultOpen = false }: WorkOrderCardProps) => { +export default function WorkOrderCard({ workOrder, index, defaultOpen = false }: WorkOrderCardProps) { const [isOpen, setIsOpen] = useState(defaultOpen); - const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>() - const [selectedData, setSelectedData] = useState() - - const formatDate = (date: string) => - new Date(date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); + const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>(); + const [selectedData, setSelectedData] = useState(); + const reduce = useReducedMotion(); const handleClose = () => { - setSelectedData(undefined) - setAction(undefined) - } + setSelectedData(undefined); + setAction(undefined); + }; - const statusList = workOrder.project_assignment_status_detail?.filter(status => status.start_date) || [] + const statusList = workOrder.project_assignment_status_detail?.filter(status => status.start_date) || []; + const team = workOrder.project_assignment_work_order_detail ?? []; + const span = formatSpan(workOrder.wo_start_date, workOrder.wo_end_date); + const shownAvatars = team.slice(0, 4); + const extraAvatars = team.length - shownAvatars.length; + + const statusName = workOrder.project_assignment_status?.name?.toUpperCase() ?? ''; + const isCompleted = COMPLETE_STATUS_LIST.includes(statusName); + const isInProgress = ONPROGRESS_STATUS_LIST.includes(statusName); + + const indexTone = isCompleted + ? 'border-emerald-500/25 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400' + : isInProgress + ? 'border-his/25 bg-his/10 text-his' + : 'border-border/80 bg-muted/40 text-muted-foreground'; + + const cardAccentBar = isCompleted + ? 'from-emerald-500/80 via-emerald-500/40 to-transparent' + : isInProgress + ? 'from-his/80 via-his/40 to-transparent' + : 'from-muted-foreground/30 to-transparent'; return ( - <> - - {/* Header (always visible) */} +
  • +
    + {/* Accent Highlight Bar on Top */} +
    + + {/* Summary View (Always visible) */}
    -
    - {/* Index badge */} -
    - +
    + {/* Identity & Badges */} +
    + {String(index + 1).padStart(2, '0')} + +
    +
    + + {workOrder.wo_code ? ( + + #{workOrder.wo_code} + + ) : null} + {span ? ( + + {span} + + ) : null} +
    + +

    + {workOrder.wo_name} +

    + + {workOrder.wo_description ? ( +

    + {workOrder.wo_description} +

    + ) : null} +
    +
    + + {/* Toggle Button */} + +
    + + {/* Quick Glance Metrics Strip */} +
    +
    + {/* Schedule */} + + + + {formatDate(workOrder.wo_start_date)} to {workOrder.wo_end_date ? formatDate(workOrder.wo_end_date) : 'Present'} + + + + {/* Timeline Stage summary */} + + + {statusList.length} status {statusList.length === 1 ? 'stage' : 'stages'} +
    -
    -
    -

    - {workOrder.wo_name} -

    - -
    -
    - - - {workOrder.wo_code} - - - - - {formatDate(workOrder.wo_start_date)} → {workOrder.wo_end_date ? formatDate(workOrder.wo_end_date!) : 'N/A'} + {/* Team Avatar Stack */} +
    + {team.length > 0 ? ( +
    +
    + {shownAvatars.map((m, i) => ( + 0 && '-ml-1.5' + )} + /> + ))} + {extraAvatars > 0 ? ( + + +{extraAvatars} + + ) : null} +
    + + {team.length} {team.length === 1 ? 'member' : 'members'} +
    + ) : ( + + + No team assigned - - - {workOrder.project_assignment_work_order_detail.length} assigned - -
    + )}
    - - {/* Description */} - {workOrder.wo_description && -

    - {workOrder.wo_description} -

    - } - - {/* Toggle button - full width on mobile */} -
    - {/* Expandable content */} - {isOpen && -
    - {workOrder.note && -
    - -
    -

    Note

    -

    {workOrder.note}

    -
    -
    - } - -
    - {/* Status history */} -
    -
    -
    - -
    -

    Assignment Timeline

    -

    - {statusList.length} status changes + {/* Expandable Section: Timeline & Team Details */} + + {isOpen ? ( + +

    + {/* Note Section if available */} + {workOrder.note ? ( +
    + +
    +

    + Work Order Note +

    +

    + {workOrder.note}

    - -
    + ) : null} - -
    + {/* Dual Panel Layout: Timeline & Team */} +
    + {/* Left: Assignment Timeline */} +
    +
    + } + title="Assignment Timeline" + badgeText={`${statusList.length} stages`} + action={ + + } + /> - {/* Assigned people */} -
    -
    -
    - -
    -

    Assigned People

    -

    Team members on this work order

    +
    -
    - +
    + + {/* Right: Assigned Team */} +
    +
    + } + title="Assigned Team" + badgeText={`${team.length} people`} + action={ + + } + /> + + { + setSelectedData(workOrder); + setAction('MANAGE_EMPLOYEE'); + }} + /> +
    +
    -
    -
    -
    - } - + + ) : null} + +
    - {action === 'UPDATE_STATUS' ? - - : null - } + {/* Modals */} + {action === 'UPDATE_STATUS' && selectedData ? ( + + ) : null} - {action === 'MANAGE_EMPLOYEE' ? - - : null - } - + ) : null} +
  • ); -}; +} -export default WorkOrderCard; +function PanelHeader({ icon, title, badgeText, action }: { icon: React.ReactNode; title: string; badgeText?: string; action?: React.ReactNode }) { + return ( +
    +
    + + {icon} + +
    +

    {title}

    + {badgeText ? ( + + {badgeText} + + ) : null} +
    +
    + {action} +
    + ); +} diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/format.ts b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/format.ts new file mode 100644 index 0000000..5dafe7f --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/format.ts @@ -0,0 +1,25 @@ +import dayjs from 'dayjs'; + +export function formatDate(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. */ +export function formatSpan(start?: string | null, end?: string | null) { + if (!start || !end) return null; + const s = dayjs(start).startOf('day'); + const e = dayjs(end).startOf('day'); + if (!s.isValid() || !e.isValid() || e.isBefore(s)) return null; + const months = e.diff(s, 'month'); + const days = e.diff(s.add(months, 'month'), 'day'); + const parts: string[] = []; + if (months > 0) parts.push(`${months} ${months === 1 ? 'month' : 'months'}`); + if (days > 0) parts.push(`${days} ${days === 1 ? 'day' : 'days'}`); + return parts.length ? parts.join(' ') : 'Same day'; +} + +export function avatarSrc(avatar?: string | null) { + return avatar ? `${process.env.BASE_URL_IMG}/${avatar}` : '/assets/no-avatar.jpg'; +} diff --git a/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/loading.tsx b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/loading.tsx new file mode 100644 index 0000000..eb90f63 --- /dev/null +++ b/app/(dashboard)/task/client-detail/[client_id]/project-detail/[project_id]/loading.tsx @@ -0,0 +1,103 @@ +export default function Loading() { + return ( +
    + {/* Back Link Skeleton */} +
    + + {/* Project Header Skeleton */} +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    + {Array.from({ length: 4 }).map((_, i) => ( +
    +
    +
    +
    + ))} +
    +
    + + {/* Delivery Overview Skeleton */} +
    +
    +
    +
    +
    +
    +
    +
    + +
    + +
    + {Array.from({ length: 4 }).map((_, i) => ( +
    +
    +
    +
    + ))} +
    +
    + + {/* Work Orders List Skeleton */} +
    +
    +
    +
    +
    + + {/* Filter Bar Skeleton */} +
    + + {/* Work Order Cards */} +
    + {Array.from({ length: 2 }).map((_, i) => ( +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    + ))} +
    +
    +
    + ); +} 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 b538b13..99becba 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 @@ -1,14 +1,13 @@ import { Button } from '@/components/ui/button'; import Link from 'next/link'; import fetchData, { getQueryStringFilteredAssignments } from '@/lib/fetchData'; -import { ArrowLeft, Briefcase, Calendar, CheckCircle2, ClipboardList, Clock3, Hash, Users } from 'lucide-react'; -import { Card, Card900, CardContent } from '@/components/ui/card'; +import { ArrowLeft, Briefcase } from 'lucide-react'; import WorkOrderCard from './WorkOrderCard'; -import { MotionDiv } from '@/components/ui/motion-wrapper'; -import { LazyImage } from '@/components/ui/lazy-image'; -import { Badge } from '@/components/ui/badge'; +import ProjectHeader from './ProjectHeader'; +import DeliveryOverview from './DeliveryOverview'; import FilterComponent from '@/app/(dashboard)/task/component/FilterComponent'; import { COMPLETE_STATUS_LIST, getFilteredAssignments, ONPROGRESS_STATUS_LIST } from '@/app/(dashboard)/task/data'; +import Reveal from '@/components/ui/reveal'; type Props = { params: Promise<{ client_id: string; project_id: string }> @@ -29,12 +28,9 @@ export default async function ProjectDetailPage({ params, searchParams }: Props) const getClientById = fetchData(`/client/${client_id}`) const getAssignmentByProjectId = fetchData(queryString ? `/project/project-assignment/${project_id}?${queryString}` : `/project/project-assignment/${project_id}`) - // const getAssignmentByProjectId = fetchData(`/project/${project_id}`) const [client, project] = await Promise.all([getClientById, getAssignmentByProjectId]); - console.log(project) - // 3. Handle 404 Securely on the server if (!project) { return (
    @@ -46,209 +42,74 @@ export default async function ProjectDetailPage({ params, searchParams }: Props) ); } - const filterAssignments = getFilteredAssignments(project.project_assignment, query, sortBy) - - const formatDate = (date: string) => - new Date(date).toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' }); + const assignments: any[] = project.project_assignment ?? []; + const filterAssignments = getFilteredAssignments(assignments, query, sortBy) // 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 totalWorkOrders = assignments.length; + const completedWO = assignments.filter((wo: any) => COMPLETE_STATUS_LIST.includes(wo.project_status?.name?.toUpperCase())).length; + const inProgressWO = assignments.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), + assignments.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', - }, - ]; - return ( - <> - - {/* Back link */} - - +
    + + + + Back to {client?.name ?? 'client'} + - - {/*
    */} - {/*
    */} + + + -
    -
    -
    -
    - Project - - Year {project.year} - -
    + + + -

    - {project.name} -

    + +
    +

    Work orders

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

    - Client -

    -

    {client?.name}

    -

    - {client?.description ?? "No description available for this client."} -

    -
    -
    -
    + {filterAssignments && filterAssignments.length > 0 ? ( +
      + {filterAssignments.map((wo: any, i: number) => ( + + ))} +
    + ) : ( +
    +
    +
    - - {/* Description */} -
    -

    - Description -

    -

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

    +

    No work orders found

    +

    + Try changing the filter, or add a work order from the client page.

    - - - {/* 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 -

    -
    -
    -
    - -
    - -
    -
    - {filterAssignments && filterAssignments.length > 0 ? project.project_assignment.map((wo: any, i: number) => - - ) - : - - -
    - -
    -
    -

    No Project Assignments Found

    -

    - Try to change the filter or create one to get started. -

    -
    -
    -
    - } -
    - - - {/* */} - + )} + +
    ); } \ No newline at end of file diff --git a/app/(dashboard)/task/component/client/ClientGrid.tsx b/app/(dashboard)/task/component/client/ClientGrid.tsx index e896198..b13c762 100644 --- a/app/(dashboard)/task/component/client/ClientGrid.tsx +++ b/app/(dashboard)/task/component/client/ClientGrid.tsx @@ -110,7 +110,7 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp
    -

    +

    {projectCount === 0 && imCount === 0 && woCount === 0 ? ( "No active projects, internal memos, or work orders recorded for this client yet." ) : ( diff --git a/app/(dashboard)/task/loading.tsx b/app/(dashboard)/task/loading.tsx new file mode 100644 index 0000000..617f8d2 --- /dev/null +++ b/app/(dashboard)/task/loading.tsx @@ -0,0 +1,54 @@ +export default function Loading() { + return ( +

    + {/* Top Page Header Skeleton */} +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + {/* Filter and Layout Toolbar Skeleton */} +
    + + {/* Client Cards Grid Skeleton */} +
    + {Array.from({ length: 6 }).map((_, i) => ( +
    + {/* Image Banner Skeleton */} +
    + + {/* Card Content Skeleton */} +
    +
    +
    +
    +
    + +
    +
    + +
    +
    +
    +
    +
    +
    +
    + ))} +
    +
    + ); +} diff --git a/components/ui/reveal.tsx b/components/ui/reveal.tsx new file mode 100644 index 0000000..3d0e060 --- /dev/null +++ b/components/ui/reveal.tsx @@ -0,0 +1,19 @@ +"use client" + +import type { ReactNode } from 'react'; +import { motion, useReducedMotion } from 'motion/react'; + +/** Entry reveal. Honors prefers-reduced-motion by rendering static. */ +export default function Reveal({ children, delay = 0, className }: { children: ReactNode; delay?: number; className?: string }) { + const reduce = useReducedMotion(); + return ( + + {children} + + ); +}