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.
This commit is contained in:
Ichsan Kurniawan
2026-10-06 15:58:43 +07:00
parent 26f2c16608
commit bd42c2defa
16 changed files with 1394 additions and 527 deletions
@@ -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 (
<section aria-labelledby="client-name" className="rounded-2xl border border-border bg-card p-5 sm:p-7">
<div className="flex flex-col gap-6 md:flex-row md:items-start md:justify-between">
<div className="flex min-w-0 items-start gap-4 sm:gap-5">
<div className="flex h-20 w-20 shrink-0 items-center justify-center overflow-hidden rounded-2xl border border-border bg-zinc-50 p-1.5 sm:h-24 sm:w-24 dark:bg-zinc-100">
<LazyImage
src={client.photo}
alt={client.name}
className="h-full w-full bg-transparent"
imgClassName="object-contain"
/>
</div>
<div className="min-w-0 space-y-2.5">
<div className="flex flex-wrap items-center gap-2">
{client.code ? (
<span className="rounded-lg border border-border bg-muted/50 px-2 py-0.5 font-mono text-xs text-muted-foreground">
{client.code}
</span>
) : null}
<span className="inline-flex items-center gap-1.5 rounded-lg border border-border px-2 py-0.5 text-xs font-medium text-foreground">
<span className={cn('h-1.5 w-1.5 rounded-full', isActive ? 'bg-emerald-500' : 'bg-amber-500')} />
{client.status_name}
</span>
</div>
<h1 id="client-name" className="text-balance text-2xl font-semibold tracking-tight text-foreground wrap-break-word md:text-3xl">
{client.name}
</h1>
<p className="max-w-[65ch] text-sm leading-relaxed text-muted-foreground wrap-break-word line-clamp-3">
{client.description || 'No description available for this client.'}
</p>
</div>
</div>
<Link href={`/task/client-detail/${clientId}/project-assignments`} className="w-full shrink-0 md:w-auto">
<Button className="w-full gap-2 transition-transform active:scale-[0.98] md:w-auto">
<Plus className="h-4 w-4" />
New assignment
</Button>
</Link>
</div>
<dl className="mt-7 grid grid-cols-2 gap-x-6 gap-y-5 border-t border-border/70 pt-6 sm:grid-cols-4">
<Fact label="Projects" value={String(client.total_project ?? 0)} />
<Fact label="Work orders" value={String(client.total_work_order ?? 0)} />
<Fact label="Team" value={teamCount === 1 ? '1 person' : `${teamCount} people`} />
<Fact label="Client since" value={since} />
</dl>
{users.length > 0 || statusSummary.length > 0 ? (
<div className="mt-6 flex flex-col gap-4 rounded-xl border border-border/60 bg-muted/20 p-3 sm:flex-row sm:items-center sm:justify-between">
{users.length > 0 ? (
<div className="flex min-w-0 items-center gap-3">
<div className="flex shrink-0 items-center" aria-hidden>
{shown.map((u, i) => (
<LazyImage
key={u.id ?? i}
src={avatarSrc(u.avatar)}
alt=""
className={cn('h-8 w-8 shrink-0 rounded-full border-2 border-card bg-muted', i > 0 && '-ml-2')}
/>
))}
{extra > 0 ? (
<span className="-ml-2 flex h-8 min-w-8 shrink-0 items-center justify-center rounded-full border-2 border-card bg-muted px-1.5 font-mono text-[11px] font-medium text-muted-foreground">
+{extra}
</span>
) : null}
</div>
<p className="min-w-0 truncate text-xs text-muted-foreground">Assigned across this client's work orders</p>
</div>
) : null}
{statusSummary.length > 0 ? (
<ul className="flex flex-wrap items-center gap-x-3 gap-y-2">
{statusSummary.map(item => (
<li key={item.project_status} className="flex items-center gap-1.5">
<BadgeStatus status={item.project_status} />
<span className="font-mono text-xs font-medium text-foreground">{item.total}</span>
</li>
))}
</ul>
) : null}
</div>
) : null}
</section>
);
}
function Fact({ label, value }: { label: string; value: string }) {
return (
<div className="min-w-0 sm:border-l sm:border-border/70 sm:pl-5 sm:first:border-l-0 sm:first:pl-0">
<dt className="text-xs text-muted-foreground">{label}</dt>
<dd className="mt-1 truncate font-mono text-sm font-medium text-foreground">{value}</dd>
</div>
);
}
@@ -0,0 +1,73 @@
export default function Loading() {
return (
<div
className="flex-1 space-y-6 p-4 sm:p-8 pt-4 sm:pt-6"
role="status"
aria-label="Loading client details"
>
{/* Back Link Skeleton */}
<div className="h-5 w-32 animate-pulse rounded-md bg-muted" />
{/* Client Profile Card Skeleton */}
<div className="rounded-2xl border border-border bg-card p-5 sm:p-7">
<div className="flex flex-col gap-6 md:flex-row md:items-start md:justify-between">
<div className="flex min-w-0 items-start gap-4 sm:gap-5 flex-1">
<div className="h-20 w-20 sm:h-24 sm:w-24 shrink-0 animate-pulse rounded-2xl bg-muted" />
<div className="min-w-0 flex-1 space-y-3">
<div className="flex flex-wrap items-center gap-2">
<div className="h-5 w-16 animate-pulse rounded-lg bg-muted" />
<div className="h-5 w-20 animate-pulse rounded-lg bg-muted" />
</div>
<div className="h-8 w-3/4 max-w-sm animate-pulse rounded-lg bg-muted" />
<div className="h-4 w-48 animate-pulse rounded bg-muted" />
</div>
</div>
<div className="h-9 w-36 shrink-0 animate-pulse rounded-lg bg-muted" />
</div>
<div className="mt-7 grid grid-cols-2 gap-x-6 gap-y-5 border-t border-border/70 pt-6 sm:grid-cols-4">
{Array.from({ length: 4 }).map((_, i) => (
<div key={i} className="space-y-2">
<div className="h-3 w-14 animate-pulse rounded bg-muted" />
<div className="h-4 w-24 animate-pulse rounded bg-muted" />
</div>
))}
</div>
</div>
{/* Project Assignments Section Skeleton */}
<div className="space-y-4 pt-2">
<div className="flex items-center justify-between gap-4">
<div className="h-7 w-48 animate-pulse rounded-lg bg-muted" />
<div className="h-6 w-20 animate-pulse rounded-md bg-muted" />
</div>
{/* Filter & Layout Bar Skeleton */}
<div className="h-10 w-full animate-pulse rounded-xl border border-border bg-card" />
{/* Assignment Cards Grid Skeleton */}
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{Array.from({ length: 3 }).map((_, i) => (
<div key={i} className="rounded-xl border border-border/80 bg-card p-5 space-y-4">
<div className="flex items-center justify-between">
<div className="h-5 w-24 animate-pulse rounded bg-muted" />
<div className="h-4 w-16 animate-pulse rounded bg-muted" />
</div>
<div className="space-y-2">
<div className="h-5 w-3/4 animate-pulse rounded bg-muted" />
<div className="h-3.5 w-full animate-pulse rounded bg-muted" />
</div>
<div className="flex items-center justify-between border-t border-border/60 pt-3">
<div className="h-4 w-28 animate-pulse rounded bg-muted" />
<div className="h-6 w-16 animate-pulse rounded-full bg-muted" />
</div>
</div>
))}
</div>
</div>
</div>
);
}
@@ -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 (
<div className="flex-1 space-y-8 p-4 sm:p-8 pt-4 sm:pt-6">
<div className="flex flex-col md:flex-row md:items-end justify-between gap-6">
<div className="flex flex-col sm:flex-row items-start gap-4 sm:gap-6 min-w-0 flex-1">
<div className="w-16 h-16 sm:w-24 sm:h-24 rounded-2xl overflow-hidden shadow-lg border-2 sm:border-4 border-background shrink-0">
<LazyImage src={client.photo!} alt={client.name} className="w-full h-full object-cover" />
</div>
<div className="space-y-1 min-w-0 flex-1">
<Link href="/task">
<Button variant="ghost" size="sm" className="p-0 h-auto hover:bg-transparent text-muted-foreground mb-2">
<ArrowLeft className="w-4 h-4 mr-1" /> Back to Clients
</Button>
</Link>
<h1 className="text-xl sm:text-3xl md:text-4xl font-bold tracking-tight wrap-break-word">{client.name}</h1>
<p className="text-sm sm:text-base text-muted-foreground wrap-break-word">{client?.description || 'No description available for this client.'}</p>
</div>
</div>
<div className="flex gap-3 w-full sm:w-auto">
<Link href={`/task/client-detail/${client_id}/project-assignments`} className='w-full sm:w-max'>
<Button className="gap-2 w-full">
<Plus className="w-4 h-4" /> Create Project Assignment
</Button>
</Link>
</div>
</div>
<div className="flex-1 space-y-6 p-4 sm:p-8 pt-4 sm:pt-6">
<Reveal>
<Link
href="/task"
className="group inline-flex items-center gap-1.5 text-sm text-muted-foreground transition-colors hover:text-foreground"
>
<ArrowLeft className="h-4 w-4 transition-transform duration-300 group-hover:-translate-x-0.5" />
<span>Back to clients</span>
</Link>
</Reveal>
<Reveal delay={0.04}>
<ClientProfileCard client={client} clientId={client_id} />
</Reveal>
<ClientDetailComponent
clientId={client_id}
@@ -13,9 +13,8 @@
import { useState, type ReactNode } from 'react';
import Link from 'next/link';
import dayjs from 'dayjs';
import { motion, useReducedMotion } from 'motion/react';
import {
ArrowLeft, Briefcase, Calendar, CalendarDays, ChevronDown, Clock, ExternalLink, FileText,
ArrowLeft, Briefcase, Calendar, ChevronDown, Clock, ExternalLink, FileText,
FolderGit2, History, LayoutGrid, List, Mail, Phone, UserPlus, Users,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
@@ -27,6 +26,7 @@ import { IClient } from '../../../types';
import { IProjectAssignment, ProjectAssignmentWorkOrderDetail } from '../../../type.assignment';
import { ManageTeam } from '../../../component/ManageTeam';
import UpdateTimelineStatus from '../../../component/UpdateTimelineStatus';
import Reveal from '@/components/ui/reveal';
interface Props {
client: IClient | undefined;
@@ -58,7 +58,7 @@ function formatSpan(start?: string | null, end?: string | null) {
export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) {
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>();
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
</div>
{/* Side rail: status history */}
<Reveal delay={0.12} className="lg:sticky lg:top-6">
<Reveal delay={0.12} className="lg:sticky lg:top-14">
<Surface title="Status history">
{statusHistory.length === 0 ? (
<p className="text-sm leading-relaxed text-muted-foreground">
@@ -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 (
<motion.div
className={className}
initial={reduce ? false : { opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.45, delay, ease: [0.16, 1, 0.3, 1] }}
>
{children}
</motion.div>
);
}
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 (
<section className="rounded-2xl border border-border bg-card p-5 sm:p-6">
<div className="mb-4 flex items-center justify-between gap-3">
@@ -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 = (
<>
<div className="relative h-12 w-12 shrink-0 overflow-hidden rounded-xl border border-border bg-background">
@@ -0,0 +1 @@
export { default } from './(main)/loading';
@@ -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 (
<div className="flex items-center" aria-hidden>
{shown.map((m, i) => (
<LazyImage
key={m.id}
src={avatarSrc(m.user?.avatar)}
alt=""
className={cn('h-8 w-8 shrink-0 rounded-full border-2 border-card bg-muted', i > 0 && '-ml-2')}
/>
))}
{extra > 0 ? (
<span className="-ml-2 flex h-8 min-w-8 shrink-0 items-center justify-center rounded-full border-2 border-card bg-muted px-1.5 font-mono text-[11px] font-medium text-muted-foreground">
+{extra}
</span>
) : null}
</div>
);
}
function ContactButton({ href, label, children }: { href: string; label: string; children: ReactNode }) {
return (
<a
href={href}
title={label}
aria-label={label}
referrerPolicy="no-referrer"
className="flex h-7 w-7 items-center justify-center rounded-lg text-muted-foreground transition-all hover:bg-muted hover:text-his active:scale-[0.96]"
>
{children}
</a>
);
}
/** 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 (
<li
className={cn(
'group relative flex flex-col justify-between rounded-xl border border-border/80 bg-card p-3.5 transition-all duration-200 hover:border-border hover:shadow-xs',
ended && 'bg-muted/10 opacity-75'
)}
>
{/* Top row: Avatar + Identity + Status */}
<div className="flex items-start gap-3">
<div className="relative shrink-0">
<LazyImage
src={avatarSrc(user?.avatar)}
alt={name}
className={cn(
'h-10 w-10 rounded-full border border-border bg-muted',
ended && 'grayscale'
)}
/>
<span
aria-label={ended ? 'Ended' : 'Active'}
className={cn(
'absolute bottom-0 right-0 h-2.5 w-2.5 rounded-full border-2 border-card',
ended ? 'bg-muted-foreground/50' : 'bg-emerald-500'
)}
/>
</div>
<div className="min-w-0 flex-1">
<div className="flex items-center justify-between gap-1.5">
<p className="truncate text-sm font-semibold text-foreground transition-colors group-hover:text-his">
{name}
</p>
<span
className={cn(
'shrink-0 rounded-md px-1.5 py-0.5 text-[10px] font-medium tracking-wide uppercase',
ended
? 'bg-muted text-muted-foreground'
: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400'
)}
>
{ended ? 'Ended' : 'Active'}
</span>
</div>
<p className="mt-0.5 truncate text-xs font-medium text-muted-foreground">
{position || 'Team Member'}
</p>
</div>
</div>
{/* Middle row: Assignment Period & Duration pill */}
<div className="mt-3 rounded-lg border border-border/50 bg-muted/20 px-2.5 py-1.5 text-xs">
<div className="flex flex-wrap items-center justify-between gap-1.5">
<span className="inline-flex min-w-0 items-center gap-1.5 font-mono text-[11px] text-muted-foreground">
<Calendar className="h-3 w-3 shrink-0 text-muted-foreground/70" />
<span className="truncate">
{member.start_date ? formatDate(member.start_date) : 'N/A'} - {member.end_date ? formatDate(member.end_date) : 'Present'}
</span>
</span>
{span ? (
<span className="shrink-0 font-medium text-[11px] text-foreground/80">
{span}
</span>
) : null}
</div>
</div>
{/* Bottom row: Direct Actions & Contact */}
<div className="mt-3 flex items-center justify-between border-t border-border/60 pt-2 text-xs">
{user?.email ? (
<a
href={`mailto:${user.email}`}
referrerPolicy="no-referrer"
title={`Email ${user.email}`}
className="group/mail inline-flex min-w-0 flex-1 items-center gap-1.5 truncate text-muted-foreground transition-colors hover:text-his"
>
<Mail className="h-3.5 w-3.5 shrink-0 text-muted-foreground/70 group-hover/mail:text-his" />
<span className="truncate text-[11px]">{user.email}</span>
</a>
) : (
<span className="text-[11px] text-muted-foreground/50">No email</span>
)}
{user?.phone_number ? (
<a
href={`tel:${user.phone_number}`}
referrerPolicy="no-referrer"
title={`Call ${user.phone_number}`}
className="group/phone inline-flex shrink-0 items-center gap-1 font-mono text-[11px] text-muted-foreground transition-colors hover:text-his"
>
<Phone className="h-3.5 w-3.5 shrink-0 text-muted-foreground/70 group-hover/phone:text-his" />
<span>{user.phone_number}</span>
</a>
) : null}
</div>
</li>
);
}
/** 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 (
<li
className={cn(
'group flex flex-col gap-2.5 p-3.5 transition-colors hover:bg-muted/30 sm:flex-row sm:items-center sm:justify-between',
ended && 'opacity-75'
)}
>
<div className="flex min-w-0 items-center gap-3">
<div className="relative shrink-0">
<LazyImage
src={avatarSrc(user?.avatar)}
alt={name}
className={cn('h-10 w-10 rounded-full border border-border bg-muted', ended && 'grayscale')}
/>
<span
aria-label={ended ? 'Ended' : 'Active'}
className={cn(
'absolute bottom-0 right-0 h-2.5 w-2.5 rounded-full border-2 border-card',
ended ? 'bg-muted-foreground/50' : 'bg-emerald-500'
)}
/>
</div>
<div className="min-w-0">
<div className="flex items-center gap-2">
<p className="truncate text-sm font-semibold text-foreground transition-colors group-hover:text-his">
{name}
</p>
<span
className={cn(
'rounded-md px-1.5 py-0.5 text-[10px] font-medium tracking-wide uppercase',
ended
? 'bg-muted text-muted-foreground'
: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400'
)}
>
{ended ? 'Ended' : 'Active'}
</span>
</div>
<p className="truncate text-xs text-muted-foreground">{position || 'Team Member'}</p>
</div>
</div>
<div className="flex flex-wrap items-center justify-between gap-3 sm:justify-end">
<div className="text-left sm:text-right">
<p className="font-mono text-[11px] text-muted-foreground">
{member.start_date ? formatDate(member.start_date) : 'N/A'} - {member.end_date ? formatDate(member.end_date) : 'Present'}
</p>
{span ? (
<p className="text-[11px] font-medium text-foreground/80">{span}</p>
) : null}
</div>
<div className="flex items-center gap-1">
{user?.email ? (
<ContactButton href={`mailto:${user.email}`} label={`Email ${user.email}`}>
<Mail className="h-3.5 w-3.5" />
</ContactButton>
) : null}
{user?.phone_number ? (
<ContactButton href={`tel:${user.phone_number}`} label={`Call ${user.phone_number}`}>
<Phone className="h-3.5 w-3.5" />
</ContactButton>
) : null}
</div>
</div>
</li>
);
}
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 (
<div className="text-center py-8 text-sm text-muted-foreground bg-muted/40 rounded-lg border border-dashed border-border mt-5">
No team assigned yet
<div className="flex flex-col items-center justify-center rounded-xl border border-dashed border-border/80 bg-muted/20 p-8 text-center">
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-muted text-muted-foreground">
<Users className="h-5 w-5" />
</div>
<p className="mt-2 text-sm font-medium text-foreground">No team members assigned</p>
<p className="mt-0.5 text-xs text-muted-foreground">
Assign members to start tracking who is working on this work order.
</p>
{onManageTeam ? (
<Button
onClick={onManageTeam}
size="sm"
variant="outline"
className="mt-3 gap-1.5 text-xs"
>
<UserPlus className="h-3.5 w-3.5" />
Assign member
</Button>
) : null}
</div>
);
}
const visibleTeam = showAllTeam ? people : people.slice(0, TEAM_PREVIEW_LIMIT);
const hiddenTeamCount = people.length - visibleTeam.length;
return (
<div className="space-y-6">
{/* Stacked avatars */}
<div className='flex items-center'>
<div className="space-y-4">
{/* Team Overview Bar */}
<div className="flex flex-col gap-2 rounded-xl border border-border/60 bg-muted/20 p-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex items-center gap-3">
<div className="flex -space-x-3">
{people?.slice(0, 5).map((user, i) =>
<LazyImage key={i} src={user?.user.avatar ? `${process.env.BASE_URL_IMG}/${user?.user.avatar}` : '/assets/no-avatar.jpg'} alt={user?.user.fullname!} className="w-10 h-10 rounded-full ring-2 ring-background hover:scale-110 hover:z-10 transition-transform" />
)}
{people?.length > 5 &&
<div className="w-10 h-10 rounded-full bg-muted ring-2 ring-background flex items-center justify-center text-xs font-bold text-muted-foreground shadow-md">
+{people?.length - 5}
</div>
}
</div>
<div className="text-sm">
<p className="font-semibold text-foreground">{people?.length} People</p>
<p className="text-muted-foreground">assigned to this work order</p>
<AvatarStack members={people} />
<div className="min-w-0">
<p className="text-xs font-medium text-foreground">
{people.length} {people.length === 1 ? 'member assigned' : 'members assigned'}
</p>
<p className="text-[11px] text-muted-foreground">
{activeCount} active · {positionCount} {positionCount === 1 ? 'role' : 'roles'}
</p>
</div>
</div>
<div className="flex items-center justify-between gap-3 sm:justify-end">
<span className="font-mono text-[11px] text-muted-foreground/80">
Viewing {visibleTeam.length} of {people.length}
</span>
<div className="flex items-center rounded-lg border border-border bg-muted/30 p-0.5 shadow-2xs">
<button
type="button"
onClick={() => setTeamView('grid')}
className={cn(
'flex h-7 w-7 items-center justify-center rounded-md text-xs transition-colors',
teamView === 'grid'
? 'bg-his font-medium text-white shadow-2xs'
: 'text-muted-foreground hover:text-foreground'
)}
aria-label="Grid view"
title="Grid view"
>
<LayoutGrid className="h-3.5 w-3.5" />
</button>
<button
type="button"
onClick={() => setTeamView('list')}
className={cn(
'flex h-7 w-7 items-center justify-center rounded-md text-xs transition-colors',
teamView === 'list'
? 'bg-his font-medium text-white shadow-2xs'
: 'text-muted-foreground hover:text-foreground'
)}
aria-label="List view"
title="List view"
>
<List className="h-3.5 w-3.5" />
</button>
</div>
</div>
<Button onClick={() => setIsOpen(!isOpen)} variant='ghost' size='sm' className="ml-auto text-xs text-muted-foreground">
<ChevronDown className={`w-4 h-4 mr-1 transition-transform ${isOpen ? 'rotate-180' : ''}`} /> {isOpen ? 'Hide' : 'View'} details
</Button>
</div>
<AnimatePresence initial={false}>
{isOpen && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.3, ease: "easeInOut" }}
className="overflow-hidden"
>
<div className="space-y-2 pt-2">
{people.map((user) => (
<div key={user.id} className="group flex items-center gap-3 p-3 rounded-xl bg-card/40 border border-border/60 hover:border-primary/40 hover:bg-card/80 transition-all">
<LazyImage src={user?.user.avatar ? `${process.env.BASE_URL_IMG}/${user?.user.avatar}` : '/assets/no-avatar.jpg'} alt={user?.user.fullname!} className="w-11 h-11 rounded-full border border-border" />
<div className="flex-1 min-w-0">
<div className="flex items-start gap-2 flex-wrap">
<p className="text-sm font-semibold text-foreground truncate min-w-0">{user.user.fullname}</p>
<Badge variant='violet'>{user.user.position?.name}</Badge>
</div>
<div className="flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-3 mt-1 text-xs text-muted-foreground sm:flex-wrap min-w-0">
<span className="inline-flex items-center gap-1 min-w-0">
<Mail className="w-3 h-3 shrink-0" />
<a href={`mailto:${user.user.email}`} referrerPolicy="no-referrer" className='hover:text-his duration-300'>
<span className="truncate">{user.user.email}</span>
</a>
</span>
<span className="inline-flex items-center gap-1">
<Phone className="w-3 h-3 shrink-0" />
<span className="font-mono">{user.user.phone_number}</span>
</span>
</div>
</div>
{/* Member Roster Display: Grid or List */}
{teamView === 'grid' ? (
<ul className="grid gap-3 sm:grid-cols-2">
{visibleTeam.map(member => (
<TeamCard key={member.id} member={member} />
))}
</ul>
) : (
<ul className="divide-y divide-border/60 overflow-hidden rounded-xl border border-border/80 bg-card">
{visibleTeam.map(member => (
<TeamRow key={member.id} member={member} />
))}
</ul>
)}
<div className="hidden sm:flex flex-col items-end shrink-0">
<span className="text-[10px] uppercase tracking-wider text-muted-foreground">
Assigned
</span>
<span className="text-xs font-medium text-foreground inline-flex items-center gap-1">
<Calendar className="w-3 h-3" />
{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'}
</span>
</div>
</div>
))}
</div>
</motion.div>
)}
</AnimatePresence>
{/* Show More / Show Less Disclosure */}
{people.length > TEAM_PREVIEW_LIMIT ? (
<Button
variant="ghost"
size="sm"
onClick={() => setShowAllTeam(v => !v)}
className="gap-1.5 text-xs text-muted-foreground transition-colors hover:text-foreground"
aria-expanded={showAllTeam}
>
<ChevronDown className={cn('h-4 w-4 transition-transform duration-300', showAllTeam && 'rotate-180')} />
{showAllTeam ? 'Show fewer' : `Show ${hiddenTeamCount} more members`}
</Button>
) : null}
</div>
);
};
export default AssignedPeople;
}
@@ -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 (
<section aria-labelledby="delivery-title" className="rounded-2xl border border-border bg-card p-5 sm:p-6">
<div className="mb-4 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1">
<h2 id="delivery-title" className="text-base font-semibold tracking-tight text-foreground">Delivery</h2>
<p className="font-mono text-xs text-muted-foreground">
<span className="font-semibold text-emerald-600 dark:text-emerald-400">{donePct}%</span> complete, {completed} of {total} work orders
</p>
</div>
<div
role="img"
aria-label={`${completed} completed, ${inProgress} in progress, ${other} other out of ${total} work orders`}
className="flex h-2.5 w-full gap-0.5 overflow-hidden rounded-full bg-muted"
>
<span className="h-full rounded-full bg-emerald-500 transition-[width] duration-700" style={{ width: `${pct(completed)}%` }} />
<span className="h-full rounded-full bg-his transition-[width] duration-700" style={{ width: `${pct(inProgress)}%` }} />
</div>
<dl className="mt-5 grid grid-cols-2 gap-3 lg:grid-cols-4">
<Stat label="Work orders" value={total} icon={ClipboardList} tone="neutral" />
<Stat label="In progress" value={inProgress} icon={Clock3} tone="active" />
<Stat label="Completed" value={completed} icon={CheckCircle2} tone="done" />
<Stat label="Team members" value={team} icon={Users} tone="neutral" />
</dl>
</section>
);
}
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 (
<div className={cn('flex min-w-0 items-center gap-3 rounded-xl border p-3.5 transition-colors', t.tile)}>
<span className={cn('flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border', t.icon)}>
<Icon className="h-4 w-4" />
</span>
<div className="min-w-0">
<dt className="truncate text-xs text-muted-foreground">{label}</dt>
<dd className="font-mono text-xl font-semibold leading-tight text-foreground">{value}</dd>
</div>
</div>
);
}
@@ -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 (
<section aria-labelledby="project-title" className="relative isolate overflow-hidden rounded-2xl border border-border bg-card p-5 sm:p-7">
<div aria-hidden className="pointer-events-none absolute inset-x-0 top-0 -z-10 h-32" />
<div className="flex min-w-0 items-start gap-4 sm:gap-5">
<div className="flex h-14 w-14 shrink-0 items-center justify-center rounded-2xl border border-cyan-500/25 bg-cyan-500/12 text-cyan-500 sm:h-20 sm:w-20">
<FolderGit2 className="h-6 w-6 sm:h-8 sm:w-8" strokeWidth={1.5} />
</div>
<div className="min-w-0 space-y-2.5">
<div className="flex flex-wrap items-center gap-2">
<Badge variant="outline" className="gap-1 rounded-lg px-2 py-0.5 text-xs font-medium">
<Briefcase className="h-3 w-3" />
Project
</Badge>
{status ? <BadgeStatus status={status} /> : null}
{project.code ? (
<span className="rounded-lg border border-border bg-muted/50 px-2 py-0.5 font-mono text-xs text-muted-foreground">
# {project.code}
</span>
) : null}
{left ? (
<span
className={cn(
'rounded-lg px-2 py-0.5 text-xs font-medium',
left.tone === 'live' ? 'bg-his/10 text-his' : 'bg-muted text-muted-foreground'
)}
>
{left.label}
</span>
) : null}
</div>
<h1 id="project-title" className="text-balance text-2xl font-semibold tracking-tight text-foreground wrap-break-word md:text-3xl">
{project.name}
</h1>
<p className="max-w-[65ch] text-sm leading-relaxed text-muted-foreground wrap-break-word">
{project.description || 'No description available for this project.'}
</p>
</div>
</div>
<dl className="mt-7 grid grid-cols-2 gap-x-6 gap-y-5 border-t border-border/70 pt-6 sm:grid-cols-4">
<Fact label="Year" value={project.year ? String(project.year) : 'N/A'} />
<Fact label="Start" value={formatDate(project.start_date)} />
<Fact label="End" value={formatDate(project.end_date)} />
<Fact label="Duration" value={duration ?? 'N/A'} />
</dl>
{client ? (
<Link
href={`/task/client-detail/${clientId}`}
className="group mt-6 flex items-center gap-3 rounded-xl border border-border/60 bg-muted/20 p-3 transition-colors hover:bg-muted/40"
>
<div className="flex h-10 w-10 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-border bg-zinc-50 p-1 dark:bg-zinc-100">
<LazyImage src={client.photo} alt={client.name} className="h-full w-full bg-transparent" imgClassName="object-contain" />
</div>
<div className="min-w-0 flex-1">
<p className="text-xs text-muted-foreground">Client</p>
<p className="truncate text-sm font-medium text-foreground transition-colors group-hover:text-his">{client.name}</p>
</div>
<ExternalLink className="h-4 w-4 shrink-0 text-muted-foreground/60 transition-colors group-hover:text-his" />
</Link>
) : null}
</section>
);
}
function Fact({ label, value }: { label: string; value: string }) {
return (
<div className="min-w-0 sm:border-l sm:border-border/70 sm:pl-5 sm:first:border-l-0 sm:first:pl-0">
<dt className="text-xs text-muted-foreground">{label}</dt>
<dd className="mt-1 truncate font-mono text-sm font-medium text-foreground">{value}</dd>
</div>
);
}
@@ -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 (
<div className="flex flex-col items-center justify-center rounded-xl border border-dashed border-border/80 bg-muted/20 p-8 text-center">
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-muted text-muted-foreground">
<History className="h-5 w-5" />
</div>
<p className="mt-2 text-sm font-medium text-foreground">No status changes recorded</p>
<p className="mt-0.5 text-xs text-muted-foreground">
Use the Update Status action to record the current stage of this work order.
</p>
</div>
);
}
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 (
<div className="relative">
{/* Vertical connector line */}
<div className="absolute left-3.75 top-2 bottom-2 w-px bg-linear-to-b from-primary/40 via-border to-transparent" />
<div className="space-y-4">
<ol className="relative space-y-5 before:absolute before:bottom-2 before:left-1.75 before:top-2 before:w-px before:bg-border">
{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;
<div className='flex justify-between items-start mb-5'>
<div className="relative flex items-start gap-4 group">
{/* Dot */}
<div className="relative z-10 shrink-0">
<div className={`w-8 h-8 rounded-full flex items-center justify-center bg-linear-to-br from-zinc-700 to-zinc-500 dark:from-zinc-400 dark:to-zinc-600 ring-4 ring-background shadow-lg animate-pulse-slow `}>
<div className="w-2 h-2 rounded-full bg-white" />
</div>
<div className={`absolute inset-0 rounded-full bg-linear-to-br from-his to-yellow-700 blur-md opacity-60 -z-10`} />
</div>
return (
<li key={entry.id} className="relative pl-7">
<span
aria-hidden
className={cn(
'absolute left-0 top-1 h-3.75 w-3.75 rounded-full border-[3px] border-card',
isCurrent ? 'bg-his' : 'bg-muted-foreground/40'
)}
/>
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
{isCurrent ? (
<BadgeStatus status={entry.project_assignment_status?.name} />
) : (
<span className="text-sm font-medium text-foreground/80">
{entry.project_assignment_status?.name}
</span>
)}
{isCurrent ? (
<span className="text-xs text-muted-foreground">Current</span>
) : null}
</div>
<p className="mt-1 font-mono text-xs text-muted-foreground">
{formatDate(entry.start_date)} - {entry.end_date ? formatDate(entry.end_date) : 'Present'}
</p>
{span ? (
<p className="mt-0.5 text-xs text-muted-foreground/80">{span}</p>
) : null}
{remarks ? (
<p className="mt-1.5 rounded-lg border border-border/50 bg-muted/30 p-2 text-xs leading-relaxed text-foreground/90 italic">
{remarks}
</p>
) : null}
</li>
);
})}
</ol>
{/* Content */}
<div className="flex-1 min-w-0 pb-1">
<div className="flex flex-wrap items-center gap-2 mb-1">
<BadgeStatus status={history[0]?.project_assignment_status.name} />
<span className="text-xs font-bold uppercase tracking-wider text-primary">Current</span>
</div>
<div className="flex items-center gap-1.5 text-xs text-muted-foreground mb-1.5">
<Clock className="w-3 h-3" />
<span>{history[0]?.start_date ? dayjs(history[0]?.start_date).format('MMM D, YYYY') : ''}</span>
<span className="opacity-70">-</span>
<span className="font-mono">{history[0]?.end_date ? dayjs(history[0]?.end_date).format('MMM D, YYYY') : ''}</span>
</div>
</div>
</div>
<Button onClick={() => setIsOpen(!isOpen)} variant='ghost' size='sm' className="text-xs ml-auto text-muted-foreground">
<ChevronDown className={`w-4 h-4 mr-1 transition-transform ${isOpen ? 'rotate-180' : ''}`} /> {isOpen ? 'Hide' : 'View'} details
{history.length > TIMELINE_PREVIEW_LIMIT ? (
<Button
variant="ghost"
size="sm"
onClick={() => setShowAll(v => !v)}
className="gap-1.5 text-xs text-muted-foreground transition-colors hover:text-foreground"
aria-expanded={showAll}
>
<ChevronDown className={cn('h-4 w-4 transition-transform duration-300', showAll && 'rotate-180')} />
{showAll ? 'Show fewer' : `Show ${hiddenCount} more ${hiddenCount === 1 ? 'stage' : 'stages'}`}
</Button>
</div>
<AnimatePresence initial={false}>
{isOpen && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.3, ease: "easeInOut" }}
className="overflow-hidden"
>
<div className="space-y-5">
{history.slice(1, history.length).map((item, i) => {
// const isLatest = i === 0;
return (
<div className="relative flex items-start gap-4 group">
{/* Dot */}
<div className="relative z-10 shrink-0">
<div className={`w-8 h-8 rounded-full flex items-center justify-center bg-linear-to-br from-zinc-700 to-zinc-500 dark:from-zinc-400 dark:to-zinc-600 ring-4 ring-background shadow-lg`}>
<div className="w-2 h-2 rounded-full bg-white" />
</div>
{/* {isLatest && <div className={`absolute inset-0 rounded-full bg-linear-to-br from-his to-yellow-700 blur-md opacity-60 -z-10`} />} */}
</div>
{/* Content */}
<div className="flex-1 min-w-0 pb-1">
<div className="flex flex-wrap items-center gap-2 mb-1">
<BadgeStatus status={item.project_assignment_status.name} />
{/* {isLatest && <span className="text-xs font-bold uppercase tracking-wider text-primary">Current</span>} */}
</div>
<div className="flex items-center gap-1.5 text-xs text-muted-foreground mb-1.5">
<Clock className="w-3 h-3" />
<span>{item.start_date ? dayjs(item.start_date).format('MMM D, YYYY') : ''}</span>
<span className="opacity-70">-</span>
<span className="font-mono">{item.end_date ? dayjs(item.end_date).format('MMM D, YYYY') : ''}</span>
</div>
{/* {item.status_remarks &&
<p className="text-sm text-foreground/80 bg-muted/30 rounded-md px-3 py-2 border border-border/50">
{item.status_remarks}
</p>
} */}
</div>
</div>
);
})}
</div>
</motion.div>
)}
</AnimatePresence>
) : null}
</div>
);
};
export default StatusTimeline;
}
@@ -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<IProjectAssignment>()
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<IProjectAssignment>();
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 (
<>
<Card900 className="overflow-hidden border-border/60 bg-card/80 backdrop-blur-sm hover:shadow-xl transition-all text-sm border-l-4 border-l-primary py-3">
{/* Header (always visible) */}
<li>
<article
className={cn(
'relative overflow-hidden rounded-2xl border bg-card transition-all duration-300 shadow-2xs',
isOpen
? 'border-border ring-1 ring-border/50 shadow-sm'
: 'border-border/80 hover:border-border hover:shadow-xs'
)}
>
{/* Accent Highlight Bar on Top */}
<div
className={cn('absolute inset-x-0 top-0 h-1 bg-linear-to-r', cardAccentBar)}
aria-hidden
/>
{/* Summary View (Always visible) */}
<div className="p-4 sm:p-6">
<div className="flex items-start gap-3 sm:gap-4">
{/* Index badge */}
<div className={`w-10 h-10 sm:w-12 sm:h-12 shrink-0 rounded-xl bg-zinc-500 text-primary flex items-center justify-center shadow-lg`}>
<span className="text-sm sm:text-lg font-bold text-white">
<div className="flex flex-col gap-3.5 sm:flex-row sm:items-start sm:justify-between">
{/* Identity & Badges */}
<div className="flex min-w-0 items-start gap-3.5 sm:gap-4 flex-1">
<span
aria-hidden
className={cn(
'flex h-11 w-11 shrink-0 items-center justify-center rounded-xl border font-mono text-sm font-bold shadow-2xs',
indexTone
)}
>
{String(index + 1).padStart(2, '0')}
</span>
<div className="min-w-0 flex-1 space-y-1.5">
<div className="flex flex-wrap items-center gap-2">
<BadgeStatus status={workOrder.project_assignment_status?.name} />
{workOrder.wo_code ? (
<span className="rounded-md border border-border/70 bg-muted/50 px-2 py-0.5 font-mono text-xs text-muted-foreground">
#{workOrder.wo_code}
</span>
) : null}
{span ? (
<span className="hidden sm:inline-flex items-center rounded-md border border-border/50 bg-muted/30 px-2 py-0.5 text-xs font-medium text-foreground/80">
{span}
</span>
) : null}
</div>
<h3 className="text-base font-bold tracking-tight text-foreground transition-colors hover:text-his wrap-break-word sm:text-lg">
{workOrder.wo_name}
</h3>
{workOrder.wo_description ? (
<p className="max-w-[75ch] text-xs leading-relaxed text-muted-foreground wrap-break-word line-clamp-2 sm:text-sm">
{workOrder.wo_description}
</p>
) : null}
</div>
</div>
{/* Toggle Button */}
<Button
variant="outline"
size="sm"
onClick={() => setIsOpen(v => !v)}
aria-expanded={isOpen}
className="w-full shrink-0 gap-1.5 font-medium border-border/80 hover:bg-muted/60 sm:w-auto"
>
<ChevronDown
className={cn(
'h-4 w-4 transition-transform duration-300',
isOpen && 'rotate-180 text-his'
)}
/>
{isOpen ? 'Collapse details' : 'View details'}
</Button>
</div>
{/* Quick Glance Metrics Strip */}
<div className="mt-4 flex flex-col gap-2.5 border-t border-border/60 pt-3.5 sm:flex-row sm:items-center sm:justify-between text-xs text-muted-foreground">
<div className="flex flex-wrap items-center gap-x-4 gap-y-1.5 min-w-0">
{/* Schedule */}
<span className="inline-flex min-w-0 items-center gap-1.5 font-mono">
<Calendar className="h-3.5 w-3.5 shrink-0 text-muted-foreground/70" />
<span className="truncate">
{formatDate(workOrder.wo_start_date)} to {workOrder.wo_end_date ? formatDate(workOrder.wo_end_date) : 'Present'}
</span>
</span>
{/* Timeline Stage summary */}
<span className="inline-flex items-center gap-1.5">
<History className="h-3.5 w-3.5 shrink-0 text-his" />
<span>{statusList.length} status {statusList.length === 1 ? 'stage' : 'stages'}</span>
</span>
</div>
<div className="flex-1 min-w-0">
<div className="flex items-start gap-2 flex-wrap mb-1.5">
<h3 className="text-base sm:text-xl font-bold text-foreground wrap-break-word flex-1 min-w-0">
{workOrder.wo_name}
</h3>
<BadgeStatus status={workOrder.project_assignment_status?.name} />
</div>
<div className="flex flex-col sm:flex-row sm:items-center gap-1.5 sm:gap-3 text-muted-foreground sm:flex-wrap">
<span className="inline-flex items-center gap-1.5 font-mono">
<FileText className="w-3 h-3 shrink-0" />
{workOrder.wo_code}
</span>
<span className="inline-flex items-center gap-1.5 min-w-0">
<Calendar className="w-3 h-3 shrink-0" />
<span className="truncate">
{formatDate(workOrder.wo_start_date)} → {workOrder.wo_end_date ? formatDate(workOrder.wo_end_date!) : 'N/A'}
{/* Team Avatar Stack */}
<div className="flex items-center gap-2">
{team.length > 0 ? (
<div className="flex items-center gap-2">
<div className="flex items-center -space-x-2" aria-hidden>
{shownAvatars.map((m, i) => (
<LazyImage
key={m.id}
src={avatarSrc(m.user?.avatar)}
alt=""
className={cn(
'h-6 w-6 shrink-0 rounded-full border-2 border-card bg-muted',
i > 0 && '-ml-1.5'
)}
/>
))}
{extraAvatars > 0 ? (
<span className="-ml-1.5 flex h-6 min-w-6 shrink-0 items-center justify-center rounded-full border-2 border-card bg-muted px-1 font-mono text-[10px] font-medium text-muted-foreground">
+{extraAvatars}
</span>
) : null}
</div>
<span className="text-xs font-medium text-foreground">
{team.length} {team.length === 1 ? 'member' : 'members'}
</span>
</div>
) : (
<span className="inline-flex items-center gap-1.5 text-xs text-muted-foreground/80 italic">
<Users className="h-3.5 w-3.5" />
No team assigned
</span>
<span className="inline-flex items-center gap-1.5">
<Users className="w-3 h-3 shrink-0" />
{workOrder.project_assignment_work_order_detail.length} assigned
</span>
</div>
)}
</div>
</div>
{/* Description */}
{workOrder.wo_description &&
<p className="text-sm text-muted-foreground mt-3 sm:mt-4 sm:ml-16 wrap-break-word">
{workOrder.wo_description}
</p>
}
{/* Toggle button - full width on mobile */}
<Button variant='secondary' size="sm" onClick={() => setIsOpen((v) => !v)} className="w-full sm:w-auto mt-4 sm:ml-16">
<ChevronDown className={`w-4 h-4 mr-1 transition-transform ${isOpen ? 'rotate-180' : ''}`} />
{isOpen ? 'Hide details' : 'View details'}
</Button>
</div>
{/* Expandable content */}
{isOpen &&
<div className="border-t border-border/60 bg-muted/10 p-4 sm:p-6 animate-fade-in">
{workOrder.note &&
<div className="mb-6 flex items-start gap-3 p-3 rounded-lg bg-amber-500/5 border border-amber-500/20">
<StickyNote className="w-4 h-4 text-amber-400 shrink-0 mt-0.5" />
<div>
<p className="font-semibold uppercase tracking-wider text-amber-400 mb-0.5">Note</p>
<p className="text-sm text-foreground/90">{workOrder.note}</p>
</div>
</div>
}
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* Status history */}
<div>
<div className='flex items-center justify-between mb-6'>
<div className="flex items-center gap-3 sm:gap-4">
<History className="w-5 h-5" />
<div>
<h4 className="text-base font-bold text-foreground">Assignment Timeline</h4>
<p className="text-muted-foreground">
{statusList.length} status changes
{/* Expandable Section: Timeline & Team Details */}
<AnimatePresence initial={false}>
{isOpen ? (
<motion.div
initial={reduce ? false : { height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={reduce ? { opacity: 0 } : { height: 0, opacity: 0 }}
transition={{ duration: 0.35, ease: [0.16, 1, 0.3, 1] }}
className="overflow-hidden"
>
<div className="space-y-6 border-t border-border/80 bg-muted/15 p-4 sm:p-6">
{/* Note Section if available */}
{workOrder.note ? (
<div className="flex items-start gap-3 rounded-xl border border-amber-500/20 bg-amber-500/5 p-3.5 shadow-2xs">
<StickyNote className="mt-0.5 h-4 w-4 shrink-0 text-amber-500" />
<div className="min-w-0 flex-1">
<p className="text-xs font-semibold uppercase tracking-wider text-amber-600 dark:text-amber-400">
Work Order Note
</p>
<p className="mt-1 whitespace-pre-line text-xs sm:text-sm leading-relaxed text-foreground/90 wrap-break-word">
{workOrder.note}
</p>
</div>
</div>
<Button size='sm' onClick={() => { setAction('UPDATE_STATUS'); setSelectedData(workOrder) }}><IterationCcw /> Update Status</Button>
</div>
) : null}
<StatusTimeline history={statusList} />
</div>
{/* Dual Panel Layout: Timeline & Team */}
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2 lg:gap-8">
{/* Left: Assignment Timeline */}
<section
aria-label="Assignment Timeline"
className="flex flex-col rounded-xl border border-border/70 bg-card p-4 sm:p-5 shadow-2xs"
>
<div className="space-y-4">
<PanelHeader
icon={<History className="h-4 w-4 text-his" />}
title="Assignment Timeline"
badgeText={`${statusList.length} stages`}
action={
<Button
size="sm"
variant="outline"
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
onClick={() => {
setSelectedData(workOrder);
setAction('UPDATE_STATUS');
}}
>
<IterationCcw className="h-3.5 w-3.5 text-his" />
Update Status
</Button>
}
/>
{/* Assigned people */}
<div>
<div className='flex items-center justify-between mb-6'>
<div className="flex items-center gap-3 sm:gap-4">
<Users className="w-5 h-5" />
<div>
<h4 className="text-base font-bold text-foreground">Assigned People</h4>
<p className="text-muted-foreground">Team members on this work order</p>
<StatusTimeline history={statusList} />
</div>
</div>
<Button size='sm' onClick={() => { setAction('MANAGE_EMPLOYEE'); setSelectedData(workOrder) }}><UserPlus /> Manage Team</Button>
</section>
{/* Right: Assigned Team */}
<section
aria-label="Assigned Team"
className="flex flex-col rounded-xl border border-border/70 bg-card p-4 sm:p-5 shadow-2xs"
>
<div className="space-y-4">
<PanelHeader
icon={<Users className="h-4 w-4 text-his" />}
title="Assigned Team"
badgeText={`${team.length} people`}
action={
<Button
size="sm"
variant="outline"
className="gap-1.5 text-xs h-8 border-border hover:bg-muted"
onClick={() => {
setSelectedData(workOrder);
setAction('MANAGE_EMPLOYEE');
}}
>
<UserPlus className="h-3.5 w-3.5 text-his" />
Manage Team
</Button>
}
/>
<AssignedPeople
people={team}
onManageTeam={() => {
setSelectedData(workOrder);
setAction('MANAGE_EMPLOYEE');
}}
/>
</div>
</section>
</div>
<AssignedPeople people={workOrder.project_assignment_work_order_detail} />
</div>
</div>
</div>
}
</Card900>
</motion.div>
) : null}
</AnimatePresence>
</article>
{action === 'UPDATE_STATUS' ?
<UpdateTimelineStatus assignmentId={selectedData?.id!} onClose={handleClose} />
: null
}
{/* Modals */}
{action === 'UPDATE_STATUS' && selectedData ? (
<UpdateTimelineStatus assignmentId={selectedData.id} onClose={handleClose} />
) : null}
{action === 'MANAGE_EMPLOYEE' ?
<ManageTeam assignmentId={selectedData?.id!} onClose={handleClose}
startDate={selectedData?.wo_start_date || selectedData?.im_start_date} endDate={selectedData?.wo_end_date || selectedData?.im_end_date}
{action === 'MANAGE_EMPLOYEE' && selectedData ? (
<ManageTeam
assignmentId={selectedData.id}
onClose={handleClose}
startDate={selectedData.wo_start_date || selectedData.im_start_date}
endDate={selectedData.wo_end_date || selectedData.im_end_date}
/>
: null
}
</>
) : null}
</li>
);
};
}
export default WorkOrderCard;
function PanelHeader({ icon, title, badgeText, action }: { icon: React.ReactNode; title: string; badgeText?: string; action?: React.ReactNode }) {
return (
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-border/60 pb-3.5">
<div className="flex items-center gap-2.5">
<span className="flex h-8 w-8 shrink-0 items-center justify-center rounded-lg border border-border bg-muted/30">
{icon}
</span>
<div className="flex items-center gap-2">
<h4 className="text-sm font-bold text-foreground">{title}</h4>
{badgeText ? (
<span className="rounded-md bg-muted px-1.5 py-0.5 font-mono text-[11px] font-medium text-muted-foreground">
{badgeText}
</span>
) : null}
</div>
</div>
{action}
</div>
);
}
@@ -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';
}
@@ -0,0 +1,103 @@
export default function Loading() {
return (
<div
className="mx-auto w-full max-w-7xl flex-1 space-y-6 p-4 pt-4 sm:p-8 sm:pt-6"
role="status"
aria-label="Loading project detail"
>
{/* Back Link Skeleton */}
<div className="h-5 w-32 animate-pulse rounded-md bg-muted" />
{/* Project Header Skeleton */}
<div className="rounded-2xl border border-border bg-card p-5 sm:p-7">
<div className="flex flex-col gap-6 md:flex-row md:items-start md:justify-between">
<div className="flex min-w-0 items-start gap-4 sm:gap-5 flex-1">
<div className="h-14 w-14 sm:h-20 sm:w-20 shrink-0 animate-pulse rounded-2xl bg-muted" />
<div className="min-w-0 flex-1 space-y-3">
<div className="flex flex-wrap items-center gap-2">
<div className="h-5 w-20 animate-pulse rounded-lg bg-muted" />
<div className="h-5 w-16 animate-pulse rounded-lg bg-muted" />
<div className="h-5 w-24 animate-pulse rounded-lg bg-muted" />
</div>
<div className="h-8 w-3/4 max-w-md animate-pulse rounded-lg bg-muted" />
<div className="h-4 w-full max-w-xl animate-pulse rounded bg-muted" />
</div>
</div>
<div className="h-9 w-28 shrink-0 animate-pulse rounded-lg bg-muted" />
</div>
<div className="mt-7 grid grid-cols-2 gap-4 border-t border-border/70 pt-6 sm:grid-cols-4">
{Array.from({ length: 4 }).map((_, i) => (
<div key={i} className="space-y-2">
<div className="h-3 w-12 animate-pulse rounded bg-muted" />
<div className="h-4 w-24 animate-pulse rounded bg-muted" />
</div>
))}
</div>
</div>
{/* Delivery Overview Skeleton */}
<div className="rounded-2xl border border-border bg-card p-5 sm:p-6 space-y-5">
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
<div className="space-y-1">
<div className="h-4 w-36 animate-pulse rounded bg-muted" />
<div className="h-3 w-48 animate-pulse rounded bg-muted" />
</div>
<div className="h-6 w-24 animate-pulse rounded-md bg-muted" />
</div>
<div className="h-2.5 w-full animate-pulse rounded-full bg-muted" />
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4">
{Array.from({ length: 4 }).map((_, i) => (
<div key={i} className="rounded-xl border border-border/70 bg-muted/20 p-3.5 space-y-2">
<div className="h-3 w-16 animate-pulse rounded bg-muted" />
<div className="h-6 w-12 animate-pulse rounded bg-muted" />
</div>
))}
</div>
</div>
{/* Work Orders List Skeleton */}
<div className="space-y-4 pt-2">
<div className="flex items-center gap-2">
<div className="h-6 w-28 animate-pulse rounded-md bg-muted" />
<div className="h-5 w-8 animate-pulse rounded-md bg-muted" />
</div>
{/* Filter Bar Skeleton */}
<div className="h-10 w-full animate-pulse rounded-xl border border-border bg-card" />
{/* Work Order Cards */}
<div className="space-y-4">
{Array.from({ length: 2 }).map((_, i) => (
<div key={i} className="rounded-2xl border border-border/80 bg-card p-4 sm:p-6 space-y-4">
<div className="flex items-start justify-between gap-4">
<div className="flex items-start gap-4 flex-1">
<div className="h-11 w-11 shrink-0 animate-pulse rounded-xl bg-muted" />
<div className="space-y-2 flex-1">
<div className="flex items-center gap-2">
<div className="h-5 w-20 animate-pulse rounded-md bg-muted" />
<div className="h-5 w-16 animate-pulse rounded-md bg-muted" />
</div>
<div className="h-5 w-2/3 max-w-sm animate-pulse rounded bg-muted" />
<div className="h-3.5 w-full max-w-md animate-pulse rounded bg-muted" />
</div>
</div>
<div className="h-8 w-28 shrink-0 animate-pulse rounded-md bg-muted" />
</div>
<div className="flex items-center justify-between border-t border-border/60 pt-3.5">
<div className="h-4 w-48 animate-pulse rounded bg-muted" />
<div className="h-6 w-24 animate-pulse rounded-full bg-muted" />
</div>
</div>
))}
</div>
</div>
</div>
);
}
@@ -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 (
<div className="flex flex-col items-center justify-center h-[60vh] space-y-4">
@@ -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 (
<>
<MotionDiv
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
className="flex-1 p-6 sm:p-8 pt-6 space-y-12"
>
{/* Back link */}
<Link href="..">
<Button variant="ghost" size="sm" className="mb-4 -ml-2 text-muted-foreground hover:text-foreground">
<ArrowLeft className="w-4 h-4 mr-1" />
Back to {client?.name}
</Button>
<div className="mx-auto w-full max-w-7xl flex-1 space-y-6 p-4 pt-4 sm:p-8 sm:pt-6">
<Reveal>
<Link
href={`/task/client-detail/${client_id}`}
className="group inline-flex items-center gap-1.5 text-sm text-muted-foreground transition-colors hover:text-foreground"
>
<ArrowLeft className="h-4 w-4 transition-transform duration-300 group-hover:-translate-x-0.5" />
<span>Back to {client?.name ?? 'client'}</span>
</Link>
</Reveal>
<Card900 className="relative overflow-hidden border-border/60 bg-card/80 backdrop-blur-sm py-3">
{/* <div className="absolute inset-0 bg-linear-to-br from-primary/5 via-transparent to-violet-500/5" /> */}
{/* <div className="absolute top-0 left-0 h-1 w-full bg-linear-to-r from-primary via-violet-500 to-emerald-500" /> */}
<Reveal delay={0.04}>
<ProjectHeader client={client} clientId={client_id} project={project} />
</Reveal>
<div className="relative p-6 sm:p-8">
<div className="flex items-start justify-between gap-6 flex-wrap">
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 mb-3 flex-wrap">
<Badge>Project</Badge>
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-muted text-muted-foreground">
Year {project.year}
</span>
</div>
<Reveal delay={0.08}>
<DeliveryOverview
total={totalWorkOrders}
completed={completedWO}
inProgress={inProgressWO}
team={totalAssigned}
/>
</Reveal>
<h1 className="text-3xl sm:text-4xl lg:text-5xl font-bold tracking-tight mb-2 bg-linear-to-r from-foreground via-foreground to-foreground/70 bg-clip-text">
{project.name}
</h1>
<Reveal delay={0.12} className="space-y-4 pt-2">
<div className="flex items-center gap-2">
<h2 className="text-lg font-semibold tracking-tight text-foreground">Work orders</h2>
<span className="rounded-lg bg-muted px-1.5 py-0.5 font-mono text-xs font-medium text-muted-foreground">
{totalWorkOrders}
</span>
</div>
<div className="flex items-center gap-4 text-muted-foreground flex-wrap mb-5">
<span className="inline-flex items-center gap-1.5 font-mono">
<Hash className="w-3.5 h-3.5" />
Code: {project.code}
</span>
<span className="inline-flex items-center gap-1.5">
<Calendar className="w-3.5 h-3.5" />
{formatDate(project.start_date)} → {formatDate(project.end_date)}
</span>
{daysRemaining > 0 && (
<span className="inline-flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-primary/10 text-primary ring-1 ring-primary/20 text-xs font-semibold">
{daysRemaining} days remaining
</span>
)}
</div>
<FilterComponent hideCategory hideProjectDateFilter hideImDateFilter />
{/* Client card */}
<div className="inline-flex flex-col sm:flex-row items-center gap-5 p-5 rounded-xl bg-muted/40 border border-border/60 backdrop-blur-sm">
<div className="w-full h-20 sm:w-14 sm:h-14 rounded-lg bg-linear-to-br from-primary to-his shadow-lg shrink-0">
<LazyImage alt={client.name} src={client.photo} className='w-full h-full object-cover rounded-lg' />
</div>
<div>
<p className="text-[10px] uppercase tracking-wider text-muted-foreground font-semibold">
Client
</p>
<p className="text-base font-bold text-foreground">{client?.name}</p>
<p className="text-sm text-muted-foreground">
{client?.description ?? "No description available for this client."}
</p>
</div>
</div>
</div>
{filterAssignments && filterAssignments.length > 0 ? (
<ul className="space-y-4">
{filterAssignments.map((wo: any, i: number) => (
<WorkOrderCard key={wo.id} workOrder={wo} index={i} defaultOpen={i === 0} />
))}
</ul>
) : (
<div className="flex flex-col items-center gap-3 rounded-2xl border border-dashed border-border bg-muted/20 px-6 py-14 text-center">
<div className="flex h-10 w-10 items-center justify-center rounded-xl bg-muted text-muted-foreground">
<Briefcase className="h-5 w-5" />
</div>
{/* Description */}
<div className="mt-6 pt-6 border-t border-border/60">
<p className="text-xs uppercase tracking-wider font-semibold text-muted-foreground mb-2">
Description
</p>
<p className="text-sm text-foreground/80 leading-relaxed max-w-3xl">
{project.description ?? "No description available for this project."}
<div className="space-y-1">
<p className="text-sm font-medium text-foreground">No work orders found</p>
<p className="max-w-xs text-sm text-muted-foreground">
Try changing the filter, or add a work order from the client page.
</p>
</div>
</div>
</Card900>
{/* Stats grid */}
<div className="grid grid-cols-2 lg:grid-cols-4 gap-3 sm:gap-8">
{stats.map((stat) => {
const Icon = stat.icon;
return (
<Card900
key={stat.label}
className={`relative overflow-hidden border-border/60 bg-card/80 backdrop-blur-sm p-4 sm:p-5 hover:scale-[1.02] transition-transform ${stat.glow} ring-1 ${stat.ring}`}
>
<div className={`absolute -top-8 -right-8 w-24 h-24 rounded-full bg-linear-to-br ${stat.gradient} opacity-10 blur-2xl`} />
<div className="relative flex items-center gap-3">
<div
className={`w-10 h-10 sm:w-12 sm:h-12 rounded-xl bg-linear-to-br ${stat.gradient} flex items-center justify-center shadow-lg shrink-0`}
>
<Icon className="w-5 h-5 sm:w-6 sm:h-6 text-white" />
</div>
<div className="min-w-0">
<p className="text-[10px] uppercase tracking-wider text-muted-foreground font-semibold truncate">
{stat.label}
</p>
<p className="text-2xl sm:text-3xl font-bold font-mono text-foreground">
{stat.value}
</p>
</div>
</div>
</Card900>
);
})}
</div>
{/* Work Orders section */}
<div className="mb-4 flex items-center justify-between flex-wrap gap-3">
<div className="flex items-center gap-3">
<ClipboardList className="w-6 h-6 text-primary" />
<div>
<h2 className="text-xl sm:text-2xl font-bold text-foreground">Work Orders</h2>
<p className="text-muted-foreground">
{totalWorkOrders} work order{totalWorkOrders !== 1 ? 's' : ''} in this project
</p>
</div>
</div>
</div>
<div className='mb-5'>
<FilterComponent hideCategory hideProjectDateFilter hideImDateFilter />
</div>
<div className="space-y-4">
{filterAssignments && filterAssignments.length > 0 ? project.project_assignment.map((wo: any, i: number) =>
<WorkOrderCard key={wo.id} workOrder={wo} index={i} defaultOpen={i === 0} />
)
:
<Card className="border-dashed bg-accent/20">
<CardContent className="flex flex-col items-center justify-center py-16 space-y-4">
<div className="w-16 h-16 rounded-full bg-accent flex items-center justify-center">
<Briefcase className="w-8 h-8 text-muted-foreground" />
</div>
<div className="text-center">
<h3 className="text-xl font-semibold">No Project Assignments Found</h3>
<p className="text-muted-foreground max-w-xs mx-auto mt-2">
Try to change the filter or create one to get started.
</p>
</div>
</CardContent>
</Card>
}
</div>
</MotionDiv>
{/* <ProjectDetailComponent client={client} project={project} /> */}
</>
)}
</Reveal>
</div>
);
}
@@ -110,7 +110,7 @@ export default function ClientGrid({ clients, onEdit, onDelete }: ClientGridProp
</Link>
</div>
<p className="text-xs sm:text-sm leading-relaxed text-muted-foreground line-clamp-3 min-h-[3.75rem] wrap-break-word">
<p className="text-xs sm:text-sm leading-relaxed text-muted-foreground line-clamp-3 min-h-15 wrap-break-word">
{projectCount === 0 && imCount === 0 && woCount === 0 ? (
"No active projects, internal memos, or work orders recorded for this client yet."
) : (
+54
View File
@@ -0,0 +1,54 @@
export default function Loading() {
return (
<div
className="flex-1 space-y-8 p-4 sm:p-8 pt-4 sm:pt-6"
role="status"
aria-label="Loading tasks and clients"
>
{/* Top Page Header Skeleton */}
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
<div>
<div className="h-8 w-56 animate-pulse rounded-lg bg-muted" />
<div className="mt-2 h-4 w-72 max-w-full animate-pulse rounded bg-muted" />
</div>
<div className="flex flex-col sm:flex-row items-stretch sm:items-center gap-2.5 sm:gap-3 w-full md:w-auto">
<div className="h-10 w-full sm:w-44 animate-pulse rounded-md bg-muted" />
<div className="h-10 w-full sm:w-32 animate-pulse rounded-md bg-muted" />
</div>
</div>
{/* Filter and Layout Toolbar Skeleton */}
<div className="h-11 w-full animate-pulse rounded-xl border border-border bg-card" />
{/* Client Cards Grid Skeleton */}
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{Array.from({ length: 6 }).map((_, i) => (
<div
key={i}
className="overflow-hidden rounded-xl border border-border/80 bg-card shadow-2xs"
>
{/* Image Banner Skeleton */}
<div className="h-40 border-b border-border/50 bg-muted/20 animate-pulse" />
{/* Card Content Skeleton */}
<div className="p-5 space-y-3">
<div className="flex items-center justify-between">
<div className="h-4 w-16 animate-pulse rounded bg-muted" />
<div className="h-4 w-14 animate-pulse rounded-full bg-muted" />
</div>
<div className="h-5 w-44 animate-pulse rounded bg-muted" />
<div className="h-3.5 w-32 animate-pulse rounded bg-muted" />
<div className="grid grid-cols-3 gap-2 border-t border-border/50 pt-3">
<div className="h-8 animate-pulse rounded bg-muted/20" />
<div className="h-8 animate-pulse rounded bg-muted/20" />
<div className="h-8 animate-pulse rounded bg-muted/20" />
</div>
</div>
</div>
))}
</div>
</div>
);
}
+19
View File
@@ -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 (
<motion.div
className={className}
initial={reduce ? false : { opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.45, delay, ease: [0.16, 1, 0.3, 1] }}
>
{children}
</motion.div>
);
}