mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
93a9b489d0
This commit updates the task dashboard and assignment views for smaller screens by tightening spacing, improving text wrapping, and making filter/search controls responsive. It also refreshes the assignment detail layout with clearer date spans, team summaries, and switchable grid/list member views, while polishing client and assignment cards for better readability on mobile.
743 lines
40 KiB
TypeScript
743 lines
40 KiB
TypeScript
"use client"
|
|
|
|
/**
|
|
* 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 dayjs from 'dayjs';
|
|
import { motion, useReducedMotion } from 'motion/react';
|
|
import {
|
|
ArrowLeft, Briefcase, Calendar, CalendarDays, ChevronDown, Clock, ExternalLink, FileText,
|
|
FolderGit2, History, LayoutGrid, List, 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';
|
|
|
|
interface Props {
|
|
client: IClient | undefined;
|
|
initialAssignment: IProjectAssignment;
|
|
}
|
|
|
|
const TEAM_PREVIEW_LIMIT = 5;
|
|
|
|
function formatAssignmentDate(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. */
|
|
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 }: Props) {
|
|
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>();
|
|
const [showAllTeam, setShowAllTeam] = useState(false);
|
|
const [teamView, setTeamView] = useState<'grid' | 'list'>('grid');
|
|
|
|
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;
|
|
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 team = assignment.project_assignment_work_order_detail ?? [];
|
|
const visibleTeam = showAllTeam ? team : team.slice(0, TEAM_PREVIEW_LIMIT);
|
|
const hiddenTeamCount = team.length - visibleTeam.length;
|
|
|
|
const statusHistory = assignment.project_assignment_status_detail?.filter(s => s.start_date) ?? [];
|
|
const currentEntry = statusHistory.find(s => !s.end_date) ?? statusHistory[0];
|
|
|
|
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;
|
|
|
|
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">
|
|
<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>
|
|
|
|
{/* 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="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>
|
|
|
|
<h1 id="assignment-title" className="text-balance text-2xl font-semibold tracking-tight text-foreground md:text-3xl wrap-break-word">
|
|
{assignmentName}
|
|
</h1>
|
|
|
|
{assignmentDesc ? (
|
|
<p className="max-w-[65ch] text-sm leading-relaxed text-muted-foreground wrap-break-word">
|
|
{assignmentDesc}
|
|
</p>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
|
|
<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>
|
|
|
|
<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 ?? 'N/A'} />
|
|
<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>
|
|
</Surface>
|
|
</Reveal>
|
|
|
|
{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>
|
|
<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 ? (
|
|
<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">
|
|
<span className="mr-0.5 text-muted-foreground">#</span>
|
|
{assignment.project.code}
|
|
</span>
|
|
) : null}
|
|
{assignment.project.year ? (
|
|
<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">
|
|
<Calendar className="h-3 w-3 text-muted-foreground/70" />
|
|
<span>Year {assignment.project.year}</span>
|
|
</span>
|
|
) : 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>
|
|
</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={
|
|
<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>
|
|
<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">
|
|
{/* 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">
|
|
<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>
|
|
|
|
{/* 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>
|
|
)}
|
|
|
|
{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>
|
|
|
|
{/* 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-1.75 before:top-2 before:w-px before:bg-border">
|
|
{statusHistory.map(entry => {
|
|
const isCurrent = entry.id === currentEntry?.id;
|
|
const span = formatSpan(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-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.5 font-mono text-xs text-muted-foreground">
|
|
{formatAssignmentDate(entry.start_date)} - {entry.end_date ? formatAssignmentDate(entry.end_date) : 'Present'}
|
|
</p>
|
|
{span ? (
|
|
<p className="mt-0.5 text-xs text-muted-foreground/80">{span}</p>
|
|
) : null}
|
|
</li>
|
|
);
|
|
})}
|
|
</ol>
|
|
)}
|
|
</Surface>
|
|
</Reveal>
|
|
</div>
|
|
</div>
|
|
|
|
{action === 'UPDATE_STATUS' ? (
|
|
<UpdateTimelineStatus 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}
|
|
</>
|
|
);
|
|
}
|
|
|
|
/** 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 }) {
|
|
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 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>
|
|
</>
|
|
);
|
|
|
|
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';
|
|
}
|
|
|
|
/** Overlapping avatars used in the team summary. */
|
|
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>
|
|
);
|
|
}
|
|
|
|
/** 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-4 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)}
|
|
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>
|
|
|
|
{/* Middle row: Assignment Period & Duration pill */}
|
|
<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>
|
|
|
|
{/* Bottom row: Direct Actions & Contact */}
|
|
<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>
|
|
);
|
|
}
|
|
|
|
/** 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-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>
|
|
);
|
|
}
|