Add VPS deployment automation

This change adds staging and production deployment configuration for the VPS setup, including `.env.deploy.example`, `.env.staging`, and updated production environment values. It also introduces a PowerShell deployment script that builds the app, packages the Next.js artifact, uploads it to the server, and reloads PM2. Package scripts were added for staging and production deploys, and the TypeScript config now excludes legacy `.old` files.
This commit is contained in:
Ichsan Kurniawan
2026-10-05 19:52:11 +07:00
parent ffcf3c6e58
commit d0db9ee429
9 changed files with 919 additions and 235 deletions
@@ -1,272 +1,471 @@
"use client"
import { motion } from 'motion/react';
import { ArrowLeft, Briefcase, Calendar, History, UserPlus, ExternalLink, Building2, Hash, Users, Icon, FileText, CalendarRange } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardHeader, CardTitle, CardDescription, Card900 } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
import { cn } from '@/lib/utils';
import { useRouter } from 'next/navigation';
import { IClient } from '../../../types';
import { IProjectAssignment } from '../../../type.assignment';
import { useState } from 'react';
import BadgeStatus from '@/components/ui/badge-status';
/**
* Design read: internal ops detail page for staff, calm Linear-style language,
* existing shadcn + Tailwind stack, brand orange (`his`) as the single accent.
* Dials: VARIANCE 5, MOTION 4, DENSITY 5.
*
* Shape lock: surfaces rounded-2xl, inner tiles rounded-xl, small chips rounded-lg.
* Elevation comes from borders, not shadows. Accent is used only for the current
* timeline node, link hovers and the primary action.
*/
import { useState, type ReactNode } from 'react';
import Link from 'next/link';
import AssignedPeople from '../project-detail/[project_id]/AssignedPeople';
import { motion, useReducedMotion } from 'motion/react';
import {
ArrowLeft, Briefcase, CalendarDays, ChevronDown, ExternalLink, FileText, FolderGit2,
History, Mail, Phone, UserPlus, Users,
} from 'lucide-react';
import { Button } from '@/components/ui/button';
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 '../../../types';
import { IProjectAssignment, ProjectAssignmentWorkOrderDetail } from '../../../type.assignment';
import { ManageTeam } from '../../../component/ManageTeam';
import UpdateTimelineStatus from '../../../component/UpdateTimelineStatus';
import { LazyImage } from '@/components/ui/lazy-image';
interface Props {
client: IClient | undefined;
initialAssignment: IProjectAssignment;
}
const TEAM_PREVIEW_LIMIT = 6;
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
/** Deterministic dd Mon yyyy, avoids locale differences between server and browser. */
function formatAssignmentDate(dateStr?: string | null) {
if (!dateStr) return 'N/A';
const d = new Date(dateStr);
if (isNaN(d.getTime())) return 'N/A';
return `${String(d.getDate()).padStart(2, '0')} ${MONTHS[d.getMonth()]} ${d.getFullYear()}`;
}
function diffInDays(start?: string | null, end?: string | null) {
if (!start || !end) return null;
const s = new Date(start);
const e = new Date(end);
if (isNaN(s.getTime()) || isNaN(e.getTime())) return null;
return Math.max(0, Math.round((e.getTime() - s.getTime()) / 86_400_000));
}
function pluralDays(n: number) {
return `${n} ${n === 1 ? 'day' : 'days'}`;
}
export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) {
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>()
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>();
const [showAllTeam, setShowAllTeam] = useState(false);
const router = useRouter();
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 isProject = assignment.project?.code
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;
const assignmentDesc = assignment.wo_description || assignment.im_description;
const assignmentStatus = assignment.project?.status || assignment.project_assignment_status?.name;
const assignmentType = isProject ? 'Project' : 'IM'
const assignmentName = assignment.wo_name || assignment.im_name
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
const assignmentDesc = assignment.wo_description || assignment.im_description
const assignmentStatus = assignment.project?.status || assignment.project_assignment_status?.name
const owner = client ?? assignment.client;
const clientHref = owner?.id ? `/task/client-detail/${owner.id}` : '/task';
const statuslist = assignment.project_assignment_status_detail?.filter(status => status.start_date) || []
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 handleClose = () => {
setAction(undefined)
}
const statusHistory = assignment.project_assignment_status_detail?.filter(s => s.start_date) ?? [];
const currentEntry = statusHistory.find(s => !s.end_date) ?? statusHistory[0];
const formatDate = (date: string) =>
new Date(date).toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' });
const duration = diffInDays(assignmentStartDate, assignmentEndDate);
const handleClose = () => setAction(undefined);
return (
<>
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
className="flex-1 space-y-8 p-6 sm:p-8 pt-6"
>
{/* Header */}
<div className="flex flex-col md:flex-row md:items-center justify-between gap-6">
<div className="space-y-2">
<Button variant="ghost" size="sm" onClick={() => router.back()} className="p-0 h-auto hover:bg-transparent text-muted-foreground mb-2">
<ArrowLeft className="w-4 h-4 mr-1" />
Back to {client?.name}
</Button>
<div className="flex items-center gap-3">
<h1 className="text-4xl font-bold tracking-tight">Assignment Detail</h1>
{!isProject && <Badge variant={'info'} className="text-lg px-3 py-0">{assignmentType}</Badge>}
</div>
</div>
<div className="flex gap-3">
<Button onClick={() => setAction('UPDATE_STATUS')} className="gap-2">
<History className="w-4 h-4" />
Update Assignment Status
</Button>
</div>
</div>
<div className="mx-auto w-full max-w-7xl flex-1 space-y-6 p-6 pt-6 sm:p-8">
<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 ?? 'tasks'}</span>
</Link>
</Reveal>
<div className="grid gap-8 lg:grid-cols-3">
<div className="lg:col-span-2 space-y-8">
<Card900 className={`relative overflow-hidden border-border bg-card p-6 md:p-8`}>
{/* <div className={`pointer-events-none absolute inset-0 bg-linear-to-br from-his/25 via-his/5 to-transparent`} /> */}
<div className="relative">
<div className="flex flex-wrap items-center gap-2 text-[11px] font-bold uppercase tracking-[0.2em]">
<Badge variant={isProject ? 'default' : 'info'}>
{isProject ? 'Project' : 'Internal Memo'}
</Badge>
<BadgeStatus status={assignmentStatus} />
{/* Header: identity, status, primary action, key facts */}
<Reveal delay={0.04}>
<section aria-labelledby="assignment-title" 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 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"
/>
</div>
<div className="mt-4 flex flex-col gap-5 md:flex-row md:items-start md:justify-between">
<div className="flex items-start gap-4">
<div className={`flex h-12 sm:h-16 w-12 sm:w-16 shrink-0 items-center justify-center rounded-2xl border border-border bg-background/60 ${isProject ? 'text-his' : 'text-type-memo'}`}>
{isProject ? <Briefcase className="h-5 w-5 sm:h-8 sm:w-8" /> : <FileText className="h-5 w-5 sm:h-8 sm:w-8" />}
</div>
<div className="min-w-0">
<p className={`text-xs font-bold uppercase tracking-[0.2em] ${isProject ? 'text-his' : 'text-type-memo'}`}>{isProject ? 'Work Order' : 'Internal Memo'}</p>
<h1 className="mt-1 text-3xl font-bold tracking-tight text-foreground md:text-4xl">
{assignmentName}
</h1>
<p className="mt-2 max-w-2xl text-sm text-muted-foreground">{assignmentDesc}</p>
</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">
{isWorkOrder ? <Briefcase className="h-3 w-3" /> : <FileText className="h-3 w-3" />}
{assignmentType}
</Badge>
{assignmentStatus ? <BadgeStatus status={assignmentStatus} /> : null}
{assignmentCode ? (
<span className="rounded-lg border border-border bg-muted/50 px-2 py-0.5 font-mono text-xs text-muted-foreground">
{assignmentCode}
</span>
) : null}
</div>
</div>
{/* Quick meta row */}
<div className="mt-6 grid grid-cols-2 gap-3 sm:grid-cols-4">
<MetaTile icon={Hash} label={`${isProject ? 'WO' : 'IM'} Code`} value={assignmentCode} />
<MetaTile icon={Calendar} label="Start" value={new Date(assignmentStartDate).toLocaleDateString()} />
<MetaTile icon={Calendar} label="End" value={assignmentEndDate ? new Date(assignmentEndDate).toLocaleDateString() : 'N/A'} />
<MetaTile icon={Users} label="Team" value={`${assignment.project_assignment_work_order_detail?.length} People`} />
<h1 id="assignment-title" className="text-balance text-2xl font-semibold tracking-tight text-foreground md:text-3xl">
{assignmentName}
</h1>
{assignmentDesc ? (
<p className="max-w-[65ch] text-sm leading-relaxed text-muted-foreground">
{assignmentDesc}
</p>
) : null}
</div>
</div>
</Card900>
<div className="grid gap-5 md:grid-cols-2">
<PartyCard label="Client" party={client} accent="ring-primary/30" />
<PartyCard label="End User" party={assignment.end_user} accent="ring-primary/30" />
<Button
onClick={() => setAction('UPDATE_STATUS')}
className="w-full shrink-0 gap-2 transition-transform active:scale-[0.98] md:w-auto"
>
<History className="h-4 w-4" />
Update status
</Button>
</div>
{isProject && (
<Card900 className="p-6 gap-5">
<div className="flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground">
<FileText className="h-3 w-3" /> Project context
<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="Start" value={formatAssignmentDate(assignmentStartDate)} />
<Fact label="End" value={formatAssignmentDate(assignmentEndDate)} />
<Fact label="Duration" value={duration === null ? 'N/A' : pluralDays(duration)} />
<Fact label="Team" value={team.length === 1 ? '1 person' : `${team.length} people`} />
</dl>
</section>
</Reveal>
<div className="grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]">
{/* Main column */}
<div className="min-w-0 space-y-6">
<Reveal delay={0.08}>
<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>
<div className='transition duration-300'>
<Link href={`/task/client-detail/${client?.id}/project-detail/${assignment.project?.id}`} className='flex group hover:space-x-3'>
<h2 className="font-semibold text-foreground group-hover:underline duration-300 hover:text-his">{assignment.project?.name}</h2>
<Button size="icon" variant="secondary" className="h-5 w-5 rounded-full opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer duration-300">
<ExternalLink className="w-4 h-4" />
</Button>
<span className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-muted text-muted-foreground">
Year {assignment.project?.year}
</span>
</Link>
</div>
<div className="flex items-center gap-4 text-sm">
<span className="text-muted-foreground"># Code: <span className="text-foreground/80">{assignment.project?.code}</span></span>
<span className="inline-flex items-center gap-1.5 text-muted-foreground">
<CalendarRange size={16} />
{formatDate(assignment.project?.start_date!)} → {`${assignment.project?.end_date ? formatDate(assignment.project.end_date) : 'N/A'}`}
</span>
</div>
<p className='text-muted-foreground text-xs sm:text-sm'>{assignment.project?.description ?? 'No description available.'}</p>
</Card900>
)}
</Surface>
</Reveal>
{!assignment.wo_name ?
<Card className="border-dashed bg-accent/10">
<CardContent className="py-10 text-center text-muted-foreground">
No work orders defined for this assignment.
</CardContent>
</Card>
: null
}
<Card900 className="overflow-hidden border-l-4 border-l-primary">
<CardContent className="p-6 pt-2">
<div className='flex items-center justify-between mb-6 sm:mb-8'>
<div className="flex items-center gap-1.5 text-xs font-bold uppercase tracking-[0.18em] text-muted-foreground">
<Users className="h-4 w-4" /> Team
</div>
<Button onClick={() => setAction('MANAGE_EMPLOYEE')} className="gap-2" size='sm'>
<UserPlus className="w-4 h-4" />
Manage Team
</Button>
</div>
<AssignedPeople people={assignment.project_assignment_work_order_detail} defaultOpen={false} />
</CardContent>
</Card900>
</div>
{/* Right Column: Status History */}
<div className="space-y-8">
<Card900>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<History className="w-5 h-5 text-primary" /> Assignment Timeline
</CardTitle>
<CardDescription>Timeline of status changes</CardDescription>
</CardHeader>
<CardContent>
<div className="relative space-y-8 before:absolute before:inset-0 before:ml-2.5 before:h-full before:w-0.5 before:-translate-x-px before:bg-accent">
{statuslist?.map((history, idx) =>
<div key={history.id} className="relative flex items-start gap-4 pl-8">
<div className={cn(
"absolute left-0 mt-1 w-5 h-5 rounded-full border-4 border-background z-10",
idx === 0 ? "bg-primary" : "bg-muted-foreground/30"
)} />
<div className="flex-1 space-y-1">
<div className="flex items-center justify-between">
<Badge variant={idx === 0 ? "default" : "outline"} className="text-[10px] h-5">
{history.project_assignment_status.name}
</Badge>
<span className="text-xs text-muted-foreground font-mono">
{history.start_date ? new Date(history.start_date).toLocaleDateString() : 'N/A'} - {history.end_date ? new Date(history.end_date).toLocaleDateString() : 'Present'}
</span>
</div>
<p className="text-xs text-muted-foreground">
Recorded: {new Date(history.end_date!).toLocaleString()}
</p>
</div>
{assignment.project?.id ? (
<Reveal delay={0.12}>
<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>
)}
{(!statuslist || statuslist.length === 0) &&
<p className="text-sm text-muted-foreground italic pl-8">No history recorded yet.</p>
}
</div>
</CardContent>
</Card900>
<div className="min-w-0 flex-1 space-y-1.5">
<div className="flex flex-wrap items-center gap-x-2.5 gap-y-1">
<p className="font-medium text-foreground transition-colors group-hover:text-his">
{assignment.project.name}
</p>
{assignment.project.code ? (
<span className="font-mono text-xs text-muted-foreground">{assignment.project.code}</span>
) : null}
{assignment.project.year ? (
<span className="text-xs text-muted-foreground">Year {assignment.project.year}</span>
) : null}
</div>
<p className="flex items-center gap-1.5 text-xs text-muted-foreground">
<CalendarDays className="h-3.5 w-3.5" />
{formatAssignmentDate(assignment.project.start_date)} - {formatAssignmentDate(assignment.project.end_date)}
</p>
<p className="line-clamp-3 max-w-[65ch] text-sm leading-relaxed text-muted-foreground">
{assignment.project.description || 'No description available.'}
</p>
</div>
<ExternalLink className="mt-1 h-4 w-4 shrink-0 text-muted-foreground/60 transition-colors group-hover:text-his" />
</Link>
</Surface>
</Reveal>
) : null}
{assignment.note ? (
<Reveal delay={0.14}>
<Surface title="Notes">
<p className="max-w-[65ch] whitespace-pre-line text-sm leading-relaxed text-foreground/90">
{assignment.note}
</p>
</Surface>
</Reveal>
) : null}
<Reveal delay={0.16}>
<Surface
title="Team"
meta={team.length > 0 ? `${team.length}` : undefined}
action={
<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>
}
>
{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>
</div>
) : (
<>
<ul className="grid gap-3 sm:grid-cols-2">
{visibleTeam.map(member => (
<TeamMember key={member.id} member={member} />
))}
</ul>
{team.length > TEAM_PREVIEW_LIMIT ? (
<Button
variant="ghost"
size="sm"
onClick={() => setShowAllTeam(v => !v)}
className="mt-3 gap-1.5 text-muted-foreground"
aria-expanded={showAllTeam}
>
<ChevronDown className={cn('h-4 w-4 transition-transform duration-300', showAllTeam && 'rotate-180')} />
{showAllTeam ? 'Show fewer' : `Show ${hiddenTeamCount} more`}
</Button>
) : null}
</>
)}
</Surface>
</Reveal>
</div>
{/* Side rail: status history */}
<Reveal delay={0.12} className="lg:sticky lg:top-6">
<Surface title="Status history">
{statusHistory.length === 0 ? (
<p className="text-sm leading-relaxed text-muted-foreground">
No status changes recorded yet. Use Update status to log the first one.
</p>
) : (
<ol className="relative space-y-6 before:absolute before:bottom-2 before:left-[7px] before:top-2 before:w-px before:bg-border">
{statusHistory.map(entry => {
const isCurrent = entry.id === currentEntry?.id;
const days = diffInDays(entry.start_date, entry.end_date);
return (
<li key={entry.id} className="relative pl-7">
<span
aria-hidden
className={cn(
'absolute left-0 top-1 h-[15px] w-[15px] 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.5 font-mono text-xs text-muted-foreground">
{formatAssignmentDate(entry.start_date)} - {entry.end_date ? formatAssignmentDate(entry.end_date) : 'Present'}
</p>
{days !== null ? (
<p className="mt-0.5 text-xs text-muted-foreground/80">{pluralDays(days)}</p>
) : null}
</li>
);
})}
</ol>
)}
</Surface>
</Reveal>
</div>
</motion.div>
</div>
{action === 'UPDATE_STATUS' ?
{action === 'UPDATE_STATUS' ? (
<UpdateTimelineStatus assignmentId={assignment.id} onClose={handleClose} />
: null
}
) : null}
{action === 'MANAGE_EMPLOYEE' ?
{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}
assignmentId={assignment.id}
onClose={handleClose}
startDate={assignment.wo_start_date || assignment.im_start_date}
endDate={assignment.wo_end_date || assignment.im_end_date}
/>
: null
}
) : null}
</>
);
}
function MetaTile({ icon: Icon, label, value }: { icon: typeof Briefcase; label: string; value: string }) {
/** 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 (
<div className="p-3">
<p className="flex items-center gap-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground">
<Icon className="h-3 w-3" /> {label}
</p>
<p className="mt-1 truncate text-sm md:text-base font-semibold text-foreground">{value}</p>
<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 }) {
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">
<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}
</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>
);
}
function initials(name?: string) {
return (name ?? '')
.split(' ')
.map(n => n[0])
.filter(Boolean)
.slice(0, 2)
.join('')
.toUpperCase();
}
function PartyCard({ label, party, accent }: { label: string; party: any; accent: string }) {
function initials(name: string) {
return name?.split(" ").map((n) => n[0]).filter(Boolean).slice(0, 2).join("").toUpperCase();
}
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">
{party?.photo ? (
<LazyImage src={party.photo} alt={party.name ?? role} className="h-full w-full bg-transparent" imgClassName="object-contain p-1" />
) : (
<div className="flex h-full w-full items-center justify-center text-sm font-semibold text-muted-foreground">
{initials(party?.name) || '-'}
</div>
)}
</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>
</>
);
return (
<Card900 className="p-5 -space-y-2">
<div className="flex items-center gap-1.5 text-[10px] font-bold uppercase tracking-[0.18em] text-muted-foreground">
<Building2 className="h-3 w-3" /> {label}
</div>
<div className="flex items-center gap-4">
<div className={`relative h-14 w-14 shrink-0 overflow-hidden rounded-xl border border-border bg-background ring-1 ${accent}`}>
{party?.photo ?
<LazyImage src={party.photo} alt={party?.name} className="h-full w-full object-contain" />
:
<div className="flex h-full w-full items-center justify-center text-base font-bold text-foreground/80">
{initials(party?.name)}
</div>
}
</div>
<div className="min-w-0 flex-1">
<p className="truncate text-base font-semibold text-foreground">{party?.name}</p>
<p className="mt-0.5 flex items-center truncate text-xs text-muted-foreground">{party?.description ?? 'No description available.'}</p>
</div>
</div>
</Card900>
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 TeamMember({ member }: { member: ProjectAssignmentWorkOrderDetail }) {
const user = member.user;
const name = user?.fullname || user?.name || 'Unnamed member';
return (
<li className="flex min-w-0 items-start gap-3 rounded-xl border border-border/70 bg-muted/20 p-3 transition-colors hover:border-border hover:bg-muted/40">
<LazyImage
src={user?.avatar ? `${process.env.BASE_URL_IMG}/${user.avatar}` : '/assets/no-avatar.jpg'}
alt={name}
className="h-10 w-10 shrink-0 rounded-full border border-border"
/>
<div className="min-w-0 flex-1 space-y-1">
<p className="truncate text-sm font-medium text-foreground">{name}</p>
{user?.position?.name ? (
<p className="truncate text-xs text-muted-foreground">{user.position.name}</p>
) : null}
<div className="flex flex-col gap-0.5 pt-0.5 text-xs text-muted-foreground">
{user?.email ? (
<a
href={`mailto:${user.email}`}
referrerPolicy="no-referrer"
className="inline-flex min-w-0 items-center gap-1.5 transition-colors hover:text-his"
>
<Mail className="h-3 w-3 shrink-0" />
<span className="truncate">{user.email}</span>
</a>
) : null}
{user?.phone_number ? (
<span className="inline-flex items-center gap-1.5">
<Phone className="h-3 w-3 shrink-0" />
<span className="font-mono">{user.phone_number}</span>
</span>
) : null}
</div>
{member.start_date ? (
<p className="pt-1 font-mono text-[11px] text-muted-foreground/80">
{formatAssignmentDate(member.start_date)} - {member.end_date ? formatAssignmentDate(member.end_date) : 'Open'}
</p>
) : null}
</div>
</li>
);
}
@@ -0,0 +1,38 @@
export default function Loading() {
return (
<div
className="mx-auto w-full max-w-7xl flex-1 space-y-6 p-6 pt-6 sm:p-8"
role="status"
aria-label="Loading assignment"
>
<div className="h-5 w-40 animate-pulse rounded-lg bg-muted" />
<div className="rounded-2xl border border-border bg-card p-5 sm:p-7">
<div className="flex items-start gap-5">
<div className="h-24 w-24 shrink-0 animate-pulse rounded-2xl bg-muted" />
<div className="w-full space-y-3">
<div className="h-5 w-48 animate-pulse rounded-lg bg-muted" />
<div className="h-8 w-3/4 animate-pulse rounded-lg bg-muted" />
<div className="h-4 w-full max-w-md animate-pulse rounded-lg bg-muted" />
</div>
</div>
<div className="mt-7 grid grid-cols-2 gap-6 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>
<div className="grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]">
<div className="space-y-6">
<div className="h-44 animate-pulse rounded-2xl border border-border bg-card" />
<div className="h-64 animate-pulse rounded-2xl border border-border bg-card" />
</div>
<div className="h-80 animate-pulse rounded-2xl border border-border bg-card" />
</div>
</div>
);
}