mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
279b642a7a
Enforce page access and action-level permissions across admin and task views, including exports and record actions. Move user creation to a client component behind server-side permission checks, standardize data fetching, and remove the deprecated user-role route.
949 lines
53 KiB
TypeScript
949 lines
53 KiB
TypeScript
"use client";
|
|
|
|
import { useState, type ReactNode } from 'react';
|
|
import Link from 'next/link';
|
|
import { useRouter } from 'next/navigation';
|
|
import dayjs from 'dayjs';
|
|
import {
|
|
ArrowLeft, ArrowUpRight, Briefcase, Calendar, ChevronDown, ClipboardCheck, Clock, ExternalLink, FileText,
|
|
FolderGit2, Gauge, LayoutGrid, List, Mail, Pencil, Phone, UserPlus, Users,
|
|
} from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Card900 } from '@/components/ui/card';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { LazyImage } from '@/components/ui/lazy-image';
|
|
import BadgeStatus from '@/components/ui/badge-status';
|
|
import {
|
|
Tooltip, TooltipContent, TooltipTrigger,
|
|
} from '@/components/ui/tooltip';
|
|
import dynamic from 'next/dynamic';
|
|
import { cn } from '@/lib/utils';
|
|
import { IClient, CLIENT_FALLBACK_IMAGE, END_USER_FALLBACK_IMAGE } from '../../../types';
|
|
import { IProjectAssignment, ProjectAssignmentWorkOrderDetail } from '../../../type.assignment';
|
|
import ConvertedAssignmentBadge from '../../../component/project-assignment/ConvertedAssignmentBadge';
|
|
import Reveal from '@/components/ui/reveal';
|
|
import { buildAssignmentOverview, formatAssignmentDate } from '../../../utils/assignment-overview-helpers';
|
|
|
|
// Dynamically imported heavy child components
|
|
const ProjectMilestoneTimeline = dynamic(
|
|
() => import('./ProjectMilestoneTimeline').then((mod) => mod.ProjectMilestoneTimeline),
|
|
{ ssr: false, loading: () => <div className="h-44 w-full animate-pulse rounded-2xl border border-border/80 bg-card p-6" /> }
|
|
);
|
|
|
|
const ActivityLogMilestoneTimeline = dynamic(
|
|
() => import('./ActivityLogMilestoneTimeline').then((mod) => mod.ActivityLogMilestoneTimeline),
|
|
{ ssr: false, loading: () => <div className="h-44 w-full animate-pulse rounded-2xl border border-border/80 bg-card p-6" /> }
|
|
);
|
|
|
|
const DevelopmentActivityLog = dynamic(
|
|
() => import('./DevelopmentActivityLog').then((mod) => mod.DevelopmentActivityLog),
|
|
{ ssr: false, loading: () => <div className="h-64 w-full animate-pulse rounded-2xl border border-border/80 bg-card p-6" /> }
|
|
);
|
|
|
|
const ModalActionLoader = () => (
|
|
<div className="fixed inset-0 z-50 bg-black/50 backdrop-blur-xs flex items-center justify-center animate-in fade-in duration-150">
|
|
<div className="bg-popover border border-border/80 rounded-2xl p-5 shadow-2xl flex items-center gap-3">
|
|
<span className="w-4 h-4 border-2 border-his border-t-transparent rounded-full animate-spin shrink-0" />
|
|
<span className="text-xs font-medium text-foreground">Loading action...</span>
|
|
</div>
|
|
</div>
|
|
);
|
|
|
|
const ManageTeam = dynamic(
|
|
() => import('../../../component/ManageTeam').then((mod) => mod.ManageTeam),
|
|
{ ssr: false, loading: () => <ModalActionLoader /> }
|
|
);
|
|
|
|
const UpdateAdministrationStatus = dynamic(
|
|
() => import('../../../component/UpdateAdministrationStatus'),
|
|
{ ssr: false, loading: () => <ModalActionLoader /> }
|
|
);
|
|
|
|
const UpdateTechnicalStatus = dynamic(
|
|
() => import('../../../component/UpdateTechnicalStatus'),
|
|
{ ssr: false, loading: () => <ModalActionLoader /> }
|
|
);
|
|
|
|
const UpdateRealProgressModal = dynamic(
|
|
() => import('./UpdateRealProgressModal'),
|
|
{ ssr: false, loading: () => <ModalActionLoader /> }
|
|
);
|
|
|
|
interface Props {
|
|
client: IClient | undefined;
|
|
initialAssignment: IProjectAssignment;
|
|
actions?: string[]
|
|
}
|
|
|
|
const TEAM_PREVIEW_LIMIT = 5;
|
|
|
|
/** Human span between two dates, e.g. "5 months" or "2 months 15 days". */
|
|
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 default function AssignmentDetail({ client, initialAssignment: assignment, actions }: Props) {
|
|
const router = useRouter();
|
|
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | 'UPDATE_ADMIN_STATUS' | 'UPDATE_REAL_PROGRESS' | undefined>();
|
|
const [showAllTeam, setShowAllTeam] = useState(false);
|
|
const [teamView, setTeamView] = useState<'grid' | 'list'>('list');
|
|
|
|
const isWorkOrder = !!assignment.wo_name;
|
|
const assignmentType = isWorkOrder ? 'Work Order' : 'Internal Memo';
|
|
const illustrationSrc = isWorkOrder ? '/assets/illustrations/work_order.jpg' : '/assets/illustrations/internal_memo.jpg';
|
|
|
|
const assignmentName = assignment.wo_name || assignment.im_name || 'Untitled Assignment';
|
|
const assignmentCode = assignment.wo_code || assignment.im_code;
|
|
const assignmentStartDate = assignment.wo_start_date || assignment.im_start_date;
|
|
const assignmentEndDate = assignment.wo_end_date || assignment.im_end_date || assignment.project?.end_date;
|
|
const assignmentDesc = assignment.wo_description || assignment.im_description;
|
|
|
|
const assignmentStatus = assignment.project_assignment_status.name
|
|
|
|
const owner = client ?? assignment.client;
|
|
const clientHref = owner?.id ? `/task/client-detail/${owner.id}` : '/task';
|
|
|
|
const team = assignment.project_assignment_work_order_detail ?? [];
|
|
const visibleTeam = showAllTeam ? team : team.slice(0, TEAM_PREVIEW_LIMIT);
|
|
const hiddenTeamCount = team.length - visibleTeam.length;
|
|
|
|
const duration = formatSpan(assignmentStartDate, assignmentEndDate);
|
|
const positionCount = new Set(team.map(m => m.user?.position?.name).filter(Boolean)).size;
|
|
const activeTeamCount = team.filter(m => !m.end_date || !dayjs(m.end_date).endOf('day').isBefore(dayjs())).length;
|
|
|
|
// Build assignment overview for progress metrics & dynamic 5-spectrum color
|
|
const overview = buildAssignmentOverview(assignment);
|
|
|
|
// Days metrics
|
|
const daysRemaining = assignmentEndDate ? dayjs(assignmentEndDate).diff(dayjs(), 'day') : 0;
|
|
const remainingText = daysRemaining >= 0 ? `${daysRemaining} hari sisa` : '0 hari sisa (Overdue)';
|
|
const totalDaysText = `${overview.totalDays} hari total / ${remainingText}`;
|
|
const dateRangeText = `${formatAssignmentDate(assignmentStartDate)} - ${formatAssignmentDate(assignmentEndDate)}`;
|
|
|
|
const handleClose = () => setAction(undefined);
|
|
|
|
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">
|
|
{/* Back to Client navigation */}
|
|
<Reveal>
|
|
<Link
|
|
href={clientHref}
|
|
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: {owner?.name ?? '---'}</span>
|
|
</Link>
|
|
</Reveal>
|
|
|
|
{/* 1. Header / Hero Card using Card900 */}
|
|
<Reveal delay={0.04}>
|
|
<Card900 aria-labelledby="assignment-title" className="p-5 sm:p-7 gap-6">
|
|
{/* Top Area */}
|
|
<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">
|
|
{/* Emblem */}
|
|
<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 sm:h-24 sm:w-24 dark:bg-zinc-100">
|
|
<LazyImage
|
|
src={illustrationSrc}
|
|
alt={`${assignmentType} emblem`}
|
|
className="h-full w-full bg-transparent"
|
|
imgClassName="object-contain rounded-lg"
|
|
/>
|
|
</div>
|
|
|
|
<div className="min-w-0 space-y-2">
|
|
{/* Top Pills */}
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<Badge variant="outline" className="gap-1.5 rounded-lg px-2 py-0.5 text-xs font-medium">
|
|
{isWorkOrder ? <Briefcase className="h-3 w-3 text-his" /> : <FileText className="h-3 w-3 text-his" />}
|
|
{assignmentType}
|
|
</Badge>
|
|
<ConvertedAssignmentBadge assignment={assignment} clientId={owner?.id} />
|
|
{assignmentStatus ? <BadgeStatus status={assignmentStatus} /> : null}
|
|
{assignmentCode ? (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="rounded-lg border border-border bg-muted/50 px-2 py-0.5 font-mono text-xs text-muted-foreground cursor-help hover:border-border transition-colors">
|
|
# {assignmentCode}
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="text-xs">
|
|
<p className="font-semibold text-popover-foreground">Assignment Code</p>
|
|
<p className="font-mono text-[11px] text-muted-foreground mt-0.5">{assignmentCode}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
) : null}
|
|
</div>
|
|
|
|
{/* Assignment Title */}
|
|
<h1 id="assignment-title" className="text-balance text-2xl font-bold tracking-tight text-foreground md:text-3xl wrap-break-word">
|
|
{assignmentName}
|
|
</h1>
|
|
|
|
{/* Assignment Description */}
|
|
{assignmentDesc ? (
|
|
<p className="w-full text-sm leading-relaxed text-muted-foreground wrap-break-word">
|
|
{assignmentDesc}
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Action Buttons: Keep Promote to Project (if IM), Update Technical Status, Update Admin Status */}
|
|
{/* Action Buttons: Administration & Technical status (+ Promote if IM) */}
|
|
<div className="flex flex-wrap sm:flex-nowrap items-center gap-2.5 w-full md:w-auto shrink-0">
|
|
{!isWorkOrder && actions?.includes('PROMOTE_ASSIGNMENT') && (
|
|
<Button
|
|
variant="outline"
|
|
asChild
|
|
className="w-full sm:w-auto shrink-0 gap-2 border-his/40 text-his hover:bg-his/10 transition-transform active:scale-[0.98]"
|
|
>
|
|
<Link href={owner?.id ? `/task/client-detail/${owner.id}/project-assignments?is_edit=true&assignment_id=${assignment.id}&promote=true` : `/task/project-assignment?is_edit=true&assignment_id=${assignment.id}&promote=true`}>
|
|
<ArrowUpRight className="h-4 w-4 text-his" />
|
|
Promote to Project
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
{actions?.includes('UPDATE_ADMINISTRATION_STATUS') &&
|
|
<Button
|
|
variant="outline"
|
|
onClick={() => setAction('UPDATE_ADMIN_STATUS')}
|
|
className="w-full sm:w-auto shrink-0 gap-2 transition-transform active:scale-[0.98]"
|
|
>
|
|
<ClipboardCheck className="h-4 w-4 text-his" />
|
|
Update Administration Status
|
|
</Button>
|
|
}
|
|
{actions?.includes("UPDATE_TECHNICAL_STATUS") &&
|
|
<Button
|
|
onClick={() => setAction('UPDATE_STATUS')}
|
|
className="w-full sm:w-auto shrink-0 gap-2 bg-[#ea512c] hover:bg-[#ea512c]/90 text-white font-medium shadow-md shadow-[#ea512c]/20 transition-transform active:scale-[0.98]"
|
|
>
|
|
<Clock className="h-4 w-4" />
|
|
Update Technical Status
|
|
</Button>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Progress Section: Side-by-Side Real Progress & Days Elapsed */}
|
|
<div className="space-y-3 pt-2">
|
|
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
{/* 1. Real Progress Card */}
|
|
<div className="rounded-xl border border-border/70 bg-muted/20 p-3.5 space-y-2.5">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<div className="flex items-center gap-2">
|
|
<span className="flex h-6 w-6 items-center justify-center rounded-lg bg-his/10 text-his">
|
|
<Gauge className="h-3.5 w-3.5" />
|
|
</span>
|
|
<span className="text-xs font-semibold text-foreground tracking-wide">
|
|
Real Progress
|
|
</span>
|
|
<span className="text-[10px] font-mono font-medium text-his bg-his/10 px-1.5 py-0.5 rounded">
|
|
Actual Work
|
|
</span>
|
|
</div>
|
|
|
|
{/* Percentage & Trigger Button next to Real Progress */}
|
|
<div className="flex items-center gap-2">
|
|
<span className="font-mono text-sm font-extrabold text-foreground">
|
|
{assignment.progress ?? 0}%
|
|
</span>
|
|
{actions?.includes("UPDATE_ASSIGNMENT_PROGRESS") &&
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => setAction('UPDATE_REAL_PROGRESS')}
|
|
className="h-6.5 px-2 text-[11px] font-medium hover:border-his/40 hover:bg-his hover:text-white transition-all shadow-2xs gap-1"
|
|
title="Update real progress and notes"
|
|
>
|
|
<Pencil className="size-3" />
|
|
<span>Update</span>
|
|
</Button>
|
|
}
|
|
</div>
|
|
</div>
|
|
<div className="relative h-2.5 w-full overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700/50">
|
|
<div
|
|
className="h-full rounded-full transition-all duration-700 ease-out bg-his"
|
|
style={{
|
|
width: `${Math.min(100, Math.max(0, assignment.progress ?? 0))}%`,
|
|
boxShadow: `0 0 10px rgba(234, 81, 44, 0.45)`,
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{/* 2. Days Elapsed Card */}
|
|
<div className="rounded-xl border border-border/70 bg-muted/20 p-3.5 space-y-2.5">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<div className="flex items-center gap-2">
|
|
<span className="flex h-6 w-6 items-center justify-center rounded-lg bg-emerald-500/10 text-emerald-600 dark:text-emerald-400">
|
|
<Clock className="h-3.5 w-3.5" />
|
|
</span>
|
|
<span className="text-xs font-semibold text-muted-foreground tracking-wide">
|
|
Days Elapsed
|
|
</span>
|
|
<span className="text-[10px] font-mono text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 px-1.5 py-0.5 rounded">
|
|
Timeline
|
|
</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<span className="font-mono text-sm font-bold text-foreground">
|
|
{overview.progressPercent}%
|
|
</span>
|
|
<span className="font-mono text-[11px] text-muted-foreground">
|
|
({remainingText})
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div className="relative h-2.5 w-full overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700/50">
|
|
<div
|
|
className="h-full rounded-full transition-all duration-700 ease-out"
|
|
style={{
|
|
width: `${overview.progressPercent}%`,
|
|
backgroundColor: overview.progressColor.hex,
|
|
boxShadow: `0 0 8px ${overview.progressColor.hex}66`,
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Timeline Date Range & Total Days */}
|
|
<div className="flex flex-wrap items-center justify-between gap-2 text-xs text-muted-foreground pt-0.5 px-0.5">
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<div className="flex items-center gap-1.5 shrink-0 cursor-help hover:text-foreground transition-colors">
|
|
<Calendar className="h-3.5 w-3.5 text-muted-foreground/70 shrink-0" />
|
|
<span>{dateRangeText}</span>
|
|
</div>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="text-xs">
|
|
<p className="font-semibold text-popover-foreground">Assignment Timeline</p>
|
|
<p className="text-[11px] text-muted-foreground mt-1">
|
|
Start: <span className="text-primary">{assignmentStartDate ? formatAssignmentDate(assignmentStartDate) : 'Start date not set'}</span>
|
|
</p>
|
|
<p className="text-[11px] text-muted-foreground">
|
|
End: <span className="text-primary">{assignmentEndDate ? formatAssignmentDate(assignmentEndDate) : 'End date not set'}</span>
|
|
</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
<div className="flex items-center gap-1.5 font-mono text-[11px]">
|
|
<Clock className="h-3.5 w-3.5 text-muted-foreground/70" />
|
|
<span>{totalDaysText}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Quick Stats */}
|
|
<dl className="grid grid-cols-2 gap-x-6 gap-y-4 border-t border-border/70 pt-5 sm:grid-cols-4">
|
|
<Fact label="Start" value={formatAssignmentDate(assignmentStartDate)} />
|
|
<Fact label="End" value={formatAssignmentDate(assignmentEndDate)} />
|
|
<Fact label="Duration" value={duration ?? 'N/A'} />
|
|
<Fact label="Team" value={team.length === 1 ? '1 person' : `${team.length} people`} />
|
|
</dl>
|
|
</Card900>
|
|
</Reveal>
|
|
|
|
{/* 2. Project Milestone Timeline */}
|
|
<Reveal delay={0.08}>
|
|
<ProjectMilestoneTimeline
|
|
statusDetails={assignment.project_assignment_status_detail}
|
|
technicalStatus={assignment.project_assignment_technical_status}
|
|
startDate={assignmentStartDate}
|
|
endDate={assignmentEndDate}
|
|
warrantyDate={assignment.wo_warranty}
|
|
/>
|
|
</Reveal>
|
|
|
|
{/* 3. Milestone Activity Log Timeline */}
|
|
<Reveal delay={0.10}>
|
|
<ActivityLogMilestoneTimeline
|
|
history={assignment.project_assignment_history}
|
|
startDate={assignmentStartDate}
|
|
endDate={assignmentEndDate}
|
|
/>
|
|
</Reveal>
|
|
|
|
{/* 4. Development Activity Log (with pagination & clean modal) */}
|
|
<Reveal delay={0.12}>
|
|
<DevelopmentActivityLog
|
|
history={assignment.project_assignment_history}
|
|
assignmentId={assignment.id}
|
|
actions={actions}
|
|
assignmentName={assignmentName}
|
|
assignmentCode={assignmentCode}
|
|
onLogAdded={() => router.refresh()}
|
|
/>
|
|
</Reveal>
|
|
|
|
{/* 4. Client and End User + Project in 2-Column Grid (Preserving exact original card style) */}
|
|
<Reveal delay={0.16}>
|
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6 items-stretch">
|
|
{/* Client and End User Card */}
|
|
<Surface title="Client and end user">
|
|
<div className="divide-y divide-border/70">
|
|
<PartyRow
|
|
role="Client"
|
|
party={owner}
|
|
href={owner?.id ? clientHref : undefined}
|
|
/>
|
|
<PartyRow role="End user" party={assignment.end_user} />
|
|
</div>
|
|
</Surface>
|
|
|
|
{/* Project Card */}
|
|
{assignment.project?.id ? (
|
|
<Surface title="Project">
|
|
<Link
|
|
href={`/task/client-detail/${owner?.id}/project-detail/${assignment.project.id}`}
|
|
className="group flex items-start gap-4 rounded-xl p-2 -m-2 transition-colors hover:bg-muted/40"
|
|
>
|
|
<div className="flex h-11 w-11 shrink-0 items-center justify-center rounded-xl border border-border bg-muted/40 text-muted-foreground transition-colors group-hover:text-his">
|
|
<FolderGit2 className="h-5 w-5" />
|
|
</div>
|
|
<div className="min-w-0 flex-1 space-y-2">
|
|
<div className="flex items-center justify-between gap-2">
|
|
<p className="font-semibold text-foreground transition-colors group-hover:text-his">
|
|
{assignment.project.name}
|
|
</p>
|
|
<ExternalLink className="h-4 w-4 shrink-0 text-muted-foreground/60 transition-colors group-hover:text-his" />
|
|
</div>
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
{assignment.project.code ? (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="inline-flex items-center rounded-md border border-border/80 bg-muted/60 px-2 py-0.5 font-mono text-xs font-medium text-foreground/90 cursor-help hover:border-border transition-colors">
|
|
<span className="mr-0.5 text-muted-foreground">#</span>
|
|
{assignment.project.code}
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="text-xs">
|
|
<p className="font-semibold text-popover-foreground">Project Code</p>
|
|
<p className="font-mono text-[11px] text-muted-foreground mt-0.5">{assignment.project.code}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
) : null}
|
|
{assignment.project.year ? (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<span className="inline-flex items-center gap-1 rounded-md border border-border/60 bg-muted/20 px-2 py-0.5 text-xs text-muted-foreground cursor-help hover:text-foreground transition-colors">
|
|
<Calendar className="h-3 w-3 text-muted-foreground/70" />
|
|
<span>Year {assignment.project.year}</span>
|
|
</span>
|
|
</TooltipTrigger>
|
|
<TooltipContent className="text-xs">
|
|
<p className="font-semibold text-popover-foreground">Project Year</p>
|
|
<p className="text-[11px] text-muted-foreground mt-0.5">Fiscal Year {assignment.project.year}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
) : null}
|
|
{assignment.project.start_date || assignment.project.end_date ? (
|
|
<span className="inline-flex items-center gap-1.5 text-xs text-muted-foreground">
|
|
<span className="text-muted-foreground/40" aria-hidden>·</span>
|
|
<Clock className="h-3 w-3 text-muted-foreground/70" />
|
|
<span>
|
|
{formatAssignmentDate(assignment.project.start_date)} to {formatAssignmentDate(assignment.project.end_date)}
|
|
</span>
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
<p className="line-clamp-3 max-w-[65ch] text-sm leading-relaxed text-muted-foreground">
|
|
{assignment.project.description || 'No description available.'}
|
|
</p>
|
|
</div>
|
|
</Link>
|
|
</Surface>
|
|
) : (
|
|
<Surface title="Project">
|
|
<div className="flex flex-col items-center justify-center py-8 text-center text-muted-foreground text-xs">
|
|
<FolderGit2 className="h-6 w-6 mb-1 text-muted-foreground/40" />
|
|
No project associated
|
|
</div>
|
|
</Surface>
|
|
)}
|
|
</div>
|
|
</Reveal>
|
|
|
|
{/* Optional assignment note */}
|
|
{assignment.note ? (
|
|
<Reveal delay={0.18}>
|
|
<Surface title="Notes">
|
|
<p className="max-w-[70ch] whitespace-pre-line text-sm leading-relaxed text-foreground/90">
|
|
{assignment.note}
|
|
</p>
|
|
</Surface>
|
|
</Reveal>
|
|
) : null}
|
|
|
|
{/* 5. Team / Scope Section */}
|
|
<Reveal delay={0.20}>
|
|
<Surface
|
|
title="Team"
|
|
meta={team.length > 0 ? `${team.length}` : undefined}
|
|
action={
|
|
<div className="flex items-center gap-2">
|
|
{team.length > 0 ? (
|
|
<div className="flex items-center rounded-lg border border-border bg-muted/30 p-0.5 shadow-xs">
|
|
<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 text-white shadow-xs'
|
|
: 'text-muted-foreground hover:text-foreground'
|
|
)}
|
|
title="Grid cards"
|
|
aria-label="Grid cards"
|
|
>
|
|
<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 text-white shadow-xs'
|
|
: 'text-muted-foreground hover:text-foreground'
|
|
)}
|
|
title="Compact list"
|
|
aria-label="Compact list"
|
|
>
|
|
<List className="h-3.5 w-3.5" />
|
|
</button>
|
|
</div>
|
|
) : null}
|
|
<Button
|
|
onClick={() => setAction('MANAGE_EMPLOYEE')}
|
|
variant="outline"
|
|
size="sm"
|
|
className="gap-1.5 transition-transform active:scale-[0.98]"
|
|
>
|
|
<UserPlus className="h-4 w-4" />
|
|
Manage team
|
|
</Button>
|
|
</div>
|
|
}
|
|
>
|
|
{team.length === 0 ? (
|
|
<div className="flex flex-col items-center gap-3 rounded-xl border border-dashed border-border bg-muted/20 px-6 py-10 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>
|
|
<div className="space-y-1">
|
|
<p className="text-sm font-medium text-foreground">Nobody is assigned yet</p>
|
|
<p className="max-w-xs text-sm text-muted-foreground">
|
|
Add people from the team directory to start tracking who works on this assignment.
|
|
</p>
|
|
</div>
|
|
{actions?.includes("MANAGE_TEAM") &&
|
|
<Button onClick={() => setAction('MANAGE_EMPLOYEE')} size="sm" className="mt-2 gap-1.5 transition-transform active:scale-[0.98]" >
|
|
<UserPlus className="h-4 w-4" />
|
|
Assign member
|
|
</Button>
|
|
}
|
|
</div>
|
|
) : (
|
|
<div className="space-y-4">
|
|
<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">
|
|
<AvatarStack members={team} />
|
|
<div className="min-w-0">
|
|
<p className="text-xs font-medium text-foreground">
|
|
{team.length} {team.length === 1 ? 'member assigned' : 'members assigned'}
|
|
</p>
|
|
<p className="text-[11px] text-muted-foreground">
|
|
{activeTeamCount} active · {positionCount} {positionCount === 1 ? 'role' : 'roles'}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<span className="font-mono text-[11px] text-muted-foreground/80">
|
|
Viewing {visibleTeam.length} of {team.length}
|
|
</span>
|
|
</div>
|
|
|
|
{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>
|
|
)}
|
|
|
|
{team.length > TEAM_PREVIEW_LIMIT ? (
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
onClick={() => setShowAllTeam(v => !v)}
|
|
className="gap-1.5 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>
|
|
)}
|
|
</Surface>
|
|
</Reveal>
|
|
</div >
|
|
|
|
{/* Modals */}
|
|
{
|
|
action === 'UPDATE_ADMIN_STATUS' ? (
|
|
<UpdateAdministrationStatus
|
|
assignmentId={assignment.id}
|
|
assignment={assignment}
|
|
onClose={handleClose}
|
|
onSuccess={() => {
|
|
router.refresh();
|
|
handleClose();
|
|
}}
|
|
/>
|
|
) : null
|
|
}
|
|
|
|
{
|
|
action === 'UPDATE_STATUS' ? (
|
|
<UpdateTechnicalStatus assignmentId={assignment.id} onClose={handleClose} />
|
|
) : null
|
|
}
|
|
|
|
{
|
|
action === 'MANAGE_EMPLOYEE' ? (
|
|
<ManageTeam
|
|
assignmentId={assignment.id}
|
|
onClose={handleClose}
|
|
startDate={assignment.wo_start_date || assignment.im_start_date}
|
|
endDate={assignment.wo_end_date || assignment.im_end_date}
|
|
/>
|
|
) : null
|
|
}
|
|
|
|
{
|
|
action === 'UPDATE_REAL_PROGRESS' ? (
|
|
<UpdateRealProgressModal
|
|
assignmentId={assignment.id}
|
|
assignmentName={assignmentName}
|
|
assignmentCode={assignmentCode}
|
|
currentProgress={assignment.progress}
|
|
open={action === 'UPDATE_REAL_PROGRESS'}
|
|
onClose={handleClose}
|
|
onSuccess={() => {
|
|
router.refresh();
|
|
handleClose();
|
|
}}
|
|
/>
|
|
) : null
|
|
}
|
|
</>
|
|
);
|
|
}
|
|
|
|
function Surface({ title, meta, action, children }: { title: string; meta?: string; action?: ReactNode; children: ReactNode }) {
|
|
return (
|
|
<Card900 className="p-5 sm:p-6 gap-0">
|
|
<div className="mb-4 flex items-center justify-between gap-3">
|
|
<h2 className="flex items-center gap-2 text-base font-semibold tracking-tight text-foreground">
|
|
{title}
|
|
{meta ? (
|
|
<span className="rounded-lg bg-muted px-1.5 py-0.5 font-mono text-xs font-medium text-muted-foreground">{meta}</span>
|
|
) : null}
|
|
</h2>
|
|
{action}
|
|
</div>
|
|
{children}
|
|
</Card900>
|
|
);
|
|
}
|
|
|
|
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-semibold text-foreground">{value}</dd>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function PartyRow({ role, party, href }: { role: string; party?: { name?: string; photo?: string; description?: string | null; code?: string } | null; href?: string }) {
|
|
const fallback = role.toLowerCase().includes('end user') ? END_USER_FALLBACK_IMAGE : CLIENT_FALLBACK_IMAGE;
|
|
|
|
const body = (
|
|
<>
|
|
<div className="relative h-12 w-12 shrink-0 overflow-hidden rounded-xl border border-border bg-muted/20 p-1">
|
|
<LazyImage
|
|
src={party?.photo || fallback}
|
|
fallbackSrc={fallback}
|
|
alt={party?.name ?? role}
|
|
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">{role}</p>
|
|
<p className={cn('truncate font-medium text-foreground', href && 'transition-colors group-hover:text-his')}>
|
|
{party?.name ?? 'Not set'}
|
|
</p>
|
|
{party?.description ? (
|
|
<p className="mt-0.5 line-clamp-1 text-xs text-muted-foreground">{party.description}</p>
|
|
) : null}
|
|
</div>
|
|
</>
|
|
);
|
|
|
|
const className = 'group flex items-center gap-4 py-4 first:pt-0 last:pb-0';
|
|
|
|
return href ? (
|
|
<Link href={href} className={cn(className, 'rounded-xl')}>
|
|
{body}
|
|
<ExternalLink className="h-4 w-4 shrink-0 text-muted-foreground/60 transition-colors group-hover:text-his" />
|
|
</Link>
|
|
) : (
|
|
<div className={className}>{body}</div>
|
|
);
|
|
}
|
|
|
|
function avatarSrc(user?: { avatar?: string | null }) {
|
|
return user?.avatar ? `${process.env.BASE_URL_IMG}/${user.avatar}` : '/assets/no-avatar.jpg';
|
|
}
|
|
|
|
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)}
|
|
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>
|
|
);
|
|
}
|
|
|
|
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-4 transition-all duration-200 hover:border-border hover:shadow-xs',
|
|
ended && 'bg-muted/10 opacity-75'
|
|
)}
|
|
>
|
|
<div className="flex items-start gap-3">
|
|
<div className="relative shrink-0">
|
|
<LazyImage
|
|
src={avatarSrc(user)}
|
|
alt={name}
|
|
className={cn(
|
|
'h-11 w-11 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>
|
|
|
|
<div className="mt-3.5 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 ? formatAssignmentDate(member.start_date) : 'N/A'} - {member.end_date ? formatAssignmentDate(member.end_date) : 'Present'}
|
|
</span>
|
|
</span>
|
|
{span ? (
|
|
<span className="shrink-0 font-medium text-[11px] text-foreground/80">
|
|
{span}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="mt-3.5 flex items-center justify-between border-t border-border/60 pt-2.5 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>
|
|
);
|
|
}
|
|
|
|
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-3 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)}
|
|
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 sm:pl-0">
|
|
<div className="text-left sm:text-right">
|
|
<p className="font-mono text-[11px] text-muted-foreground">
|
|
{member.start_date ? formatAssignmentDate(member.start_date) : 'N/A'} - {member.end_date ? formatAssignmentDate(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>
|
|
);
|
|
}
|