Refactor assignment detail UI and team components

Refactor Assignment detail view and related team components to improve layout, UX and behaviour. Key changes:

- Added a backup of the previous AssignmentDetailComponent as AssignmentDetailComponent.old.tsx.
- Reworked AssignmentDetailComponent.tsx: simplified assignment fields, added LazyImage, formatDate helper, visual redesign (MetaTile, PartyCard), improved project context card and conditional badges/UI for IM vs Project, and minor status-list rendering tweaks.
- AssignedPeople.tsx: made team list collapsible with motion animations, added toggle button, defaultOpen prop, and preserved stacked avatars UI.
- page.tsx: adjusted project assignment fetch to use /project/{id} (commented previous query-based call).
- AddTeam.tsx: updated existingTeam type and filter logic to exclude already-assigned users when mapping candidates.
- ManageTeam.tsx: removed an unused import.
- UpdateTimelineStatus.tsx: removed some form libs, updated success/error toast messages and sort timeline rows before rendering.
- globals.css: added --type-memo and --type-wo CSS variables and minor variable tweaks.

These changes aim to improve clarity, consistency and interactivity of the assignment and team management UI.
This commit is contained in:
Ichsan Kurniawan
2026-05-05 20:14:21 +07:00
parent dcb74c0f2b
commit 7892eda589
8 changed files with 460 additions and 161 deletions
@@ -0,0 +1,245 @@
// app/task/client-detail/[client_id]/[assignment_id]/project-detail-client.tsx
"use client"
import { motion } from 'motion/react';
import { ArrowLeft, Briefcase, Calendar, CheckCircle2, History, AlertCircle, UserPlus, ExternalLink } 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 { Separator } from '@/components/ui/separator';
import { Label } from '@/components/ui/label';
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';
import Link from 'next/link';
import AssignedPeople from '../project-detail/[project_id]/AssignedPeople';
import { ManageTeam } from '../../../component/ManageTeam';
import UpdateTimelineStatus from '../../../component/UpdateTimelineStatus';
interface Props {
client: IClient | undefined;
initialAssignment: IProjectAssignment;
}
export default function AssignmentDetail({ client, initialAssignment: assignment }: Props) {
const [action, setAction] = useState<'MANAGE_EMPLOYEE' | 'UPDATE_STATUS' | undefined>()
const router = useRouter();
const isProject = assignment.project?.code
const assignmentType = isProject ? 'Project' : 'IM'
const assignmentName = assignment.project?.name || assignment.im_name
const assignmentCode = assignment.project?.code || assignment.im_code
const assignmentYear = assignment.project?.year || assignment.im_year
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 statuslist = assignment.project_assignment_status_detail?.filter(status => status.start_date) || []
const handleClose = () => {
setAction(undefined)
}
console.log(assignment)
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>
<Badge variant={isProject ? 'default' : 'info'} className="text-lg px-3 py-0">{assignmentType}</Badge>
</div>
<div className="flex items-center gap-3 mt-2">
{!isProject ?
<h2 className="text-xl font-medium text-muted-foreground">{assignmentName}</h2>
:
<Link href={`/task/client-detail/${client?.id}/project-detail/${assignment.project?.id}`} className='flex group gap-3'>
<h2 className="text-xl font-medium text-muted-foreground group-hover:underline duration-300 hover:text-his">{assignmentName}</h2>
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer duration-300">
<ExternalLink className="w-4 h-4" />
</Button>
</Link>
}
</div>
<div className="flex items-center gap-4 text-muted-foreground">
<p className="flex items-center gap-1">
<Briefcase className="w-4 h-4" /> Code: {assignmentCode || 'N/A'}
</p>
<Separator orientation="vertical" className="h-4" />
<p className="flex items-center gap-1">
<Calendar className="w-4 h-4" /> Year: {assignmentYear || 'N/A'}
</p>
</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="grid gap-8 lg:grid-cols-3">
{/* Left Column: Details & Work Orders */}
<div className="lg:col-span-2 space-y-8">
{/* Overview Card */}
<Card900>
<CardHeader>
<CardTitle>Overview</CardTitle>
</CardHeader>
<CardContent className="space-y-6">
<div className="grid grid-cols-2 md:grid-cols-4 gap-6">
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Project Assignment Status</Label>
<div className="mt-1">
<BadgeStatus status={assignmentStatus} className='px-3 py-1' />
</div>
</div>
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Start Date</Label>
<p className="font-medium mt-1">{assignmentStartDate ? new Date(assignmentStartDate).toLocaleDateString() : 'N/A'}</p>
</div>
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">End Date</Label>
<p className="font-medium mt-1">{assignmentEndDate ? new Date(assignmentEndDate).toLocaleDateString() : 'N/A'}</p>
</div>
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Client</Label>
<p className="font-medium mt-1">{client?.name}</p>
</div>
</div>
<Separator />
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Description</Label>
<p className="mt-2 text-muted-foreground leading-relaxed">{assignmentDesc ?? 'No description available for this assignment!'}</p>
</div>
</CardContent>
</Card900>
{/* Work Orders Section */}
<div className="space-y-4">
<div className="flex items-center justify-between">
<h2 className="text-2xl font-bold flex items-center gap-2">
<CheckCircle2 className="w-6 h-6 text-primary" /> Work Orders
</h2>
</div>
{!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>
:
<div className="grid gap-4">
<Card900 className="overflow-hidden border-l-4 border-l-primary">
<CardContent className="p-6">
<div className="flex flex-col md:flex-row justify-between gap-6">
<div className="space-y-3 flex-1">
<div className="flex items-center gap-3">
<h3 className="text-xl font-bold">{assignment.wo_name}</h3>
</div>
<p className="text-muted-foreground text-sm">{assignment.wo_description}</p>
<div className="flex flex-wrap gap-4 text-xs text-muted-foreground">
<span className="flex items-center gap-1">
<AlertCircle className="w-3 h-3" /> Code: {assignment.wo_code || 'N/A'}
</span>
<span className="flex items-center gap-1">
<Calendar className="w-3 h-3" />
{assignment.wo_start_date ? new Date(assignment.wo_start_date).toLocaleDateString() : 'N/A'} - {assignment.wo_end_date ? new Date(assignment.wo_end_date).toLocaleDateString() : 'N/A'}
</span>
</div>
</div>
</div>
<div className="mt-6 pt-6 border-t">
<div className='flex items-center justify-between'>
<p className="text-xs font-bold uppercase text-muted-foreground mb-4">Team</p>
<Button onClick={() => setAction('MANAGE_EMPLOYEE')} className="gap-2" size='sm'>
<UserPlus className="w-4 h-4" />
Manage Team
</Button>
</div>
</div>
<AssignedPeople people={assignment.project_assignment_work_order_detail} />
</CardContent>
</Card900>
</div>
}
</div>
</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>
</div>
))}
{(!statuslist || statuslist.length === 0) && (
<p className="text-sm text-muted-foreground italic pl-8">No history recorded yet.</p>
)}
</div>
</CardContent>
</Card900>
</div>
</div>
</motion.div>
{action === 'UPDATE_STATUS' ?
<UpdateTimelineStatus assignmentId={assignment.id} onClose={handleClose} />
: null
}
{action === 'MANAGE_EMPLOYEE' ?
<ManageTeam assignmentId={assignment.id} onClose={handleClose} />
: null
}
</>
);
}
@@ -1,13 +1,10 @@
// app/task/client-detail/[client_id]/[assignment_id]/project-detail-client.tsx
"use client"
import { motion } from 'motion/react';
import { ArrowLeft, Briefcase, Calendar, CheckCircle2, History, AlertCircle, UserPlus, ExternalLink } from 'lucide-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 { Separator } from '@/components/ui/separator';
import { Label } from '@/components/ui/label';
import { cn } from '@/lib/utils';
import { useRouter } from 'next/navigation';
import { IClient } from '../../../types';
@@ -18,6 +15,7 @@ import Link from 'next/link';
import AssignedPeople from '../project-detail/[project_id]/AssignedPeople';
import { ManageTeam } from '../../../component/ManageTeam';
import UpdateTimelineStatus from '../../../component/UpdateTimelineStatus';
import { LazyImage } from '@/components/ui/lazy-image';
interface Props {
client: IClient | undefined;
@@ -32,9 +30,8 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
const isProject = assignment.project?.code
const assignmentType = isProject ? 'Project' : 'IM'
const assignmentName = assignment.project?.name || assignment.im_name
const assignmentCode = assignment.project?.code || assignment.im_code
const assignmentYear = assignment.project?.year || assignment.im_year
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
@@ -46,7 +43,8 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
setAction(undefined)
}
console.log(assignment)
const formatDate = (date: string) =>
new Date(date).toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric' });
return (
<>
@@ -64,28 +62,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
</Button>
<div className="flex items-center gap-3">
<h1 className="text-4xl font-bold tracking-tight">Assignment Detail</h1>
<Badge variant={isProject ? 'default' : 'info'} className="text-lg px-3 py-0">{assignmentType}</Badge>
</div>
<div className="flex items-center gap-3 mt-2">
{!isProject ?
<h2 className="text-xl font-medium text-muted-foreground">{assignmentName}</h2>
:
<Link href={`/task/client-detail/${client?.id}/project-detail/${assignment.project?.id}`} className='flex group gap-3'>
<h2 className="text-xl font-medium text-muted-foreground group-hover:underline duration-300 hover:text-his">{assignmentName}</h2>
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity cursor-pointer duration-300">
<ExternalLink className="w-4 h-4" />
</Button>
</Link>
}
</div>
<div className="flex items-center gap-4 text-muted-foreground">
<p className="flex items-center gap-1">
<Briefcase className="w-4 h-4" /> Code: {assignmentCode || 'N/A'}
</p>
<Separator orientation="vertical" className="h-4" />
<p className="flex items-center gap-1">
<Calendar className="w-4 h-4" /> Year: {assignmentYear || 'N/A'}
</p>
{!isProject && <Badge variant={'info'} className="text-lg px-3 py-0">{assignmentType}</Badge>}
</div>
</div>
<div className="flex gap-3">
@@ -97,50 +74,76 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
</div>
<div className="grid gap-8 lg:grid-cols-3">
{/* Left Column: Details & Work Orders */}
<div className="lg:col-span-2 space-y-8">
{/* Overview Card */}
<Card900>
<CardHeader>
<CardTitle>Overview</CardTitle>
</CardHeader>
<CardContent className="space-y-6">
<div className="grid grid-cols-2 md:grid-cols-4 gap-6">
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Project Assignment Status</Label>
<div className="mt-1">
<BadgeStatus status={assignmentStatus} className='px-3 py-1' />
<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} />
</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>
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Start Date</Label>
<p className="font-medium mt-1">{assignmentStartDate ? new Date(assignmentStartDate).toLocaleDateString() : 'N/A'}</p>
</div>
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">End Date</Label>
<p className="font-medium mt-1">{assignmentEndDate ? new Date(assignmentEndDate).toLocaleDateString() : 'N/A'}</p>
</div>
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Client</Label>
<p className="font-medium mt-1">{client?.name}</p>
</div>
</div>
<Separator />
<div>
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Description</Label>
<p className="mt-2 text-muted-foreground leading-relaxed">{assignmentDesc ?? 'No description available for this assignment!'}</p>
{/* 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`} />
</div>
</CardContent>
</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" />
</div>
{isProject && (
<Card900 className="p-5 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
</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>
</Link>
</div>
<div className="grid grid-cols-3 text-sm">
{/* <span className="font-semibold text-foreground">{assignment.project?.name}</span> */}
<span className="text-muted-foreground"># Code: <span className="text-foreground/80">{assignment.project?.code}</span></span>
<span className="text-muted-foreground flex items-center"><Calendar size={16} className='mr-1' /> Year: <span className="text-foreground/80"> {assignment.project?.year}</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>
)}
{/* Work Orders Section */}
<div className="space-y-4">
<div className="flex items-center justify-between">
<h2 className="text-2xl font-bold flex items-center gap-2">
<CheckCircle2 className="w-6 h-6 text-primary" /> Work Orders
</h2>
</div>
{!assignment.wo_name ?
<Card className="border-dashed bg-accent/10">
<CardContent className="py-10 text-center text-muted-foreground">
@@ -150,36 +153,18 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
:
<div className="grid gap-4">
<Card900 className="overflow-hidden border-l-4 border-l-primary">
<CardContent className="p-6">
<div className="flex flex-col md:flex-row justify-between gap-6">
<div className="space-y-3 flex-1">
<div className="flex items-center gap-3">
<h3 className="text-xl font-bold">{assignment.wo_name}</h3>
</div>
<p className="text-muted-foreground text-sm">{assignment.wo_description}</p>
<div className="flex flex-wrap gap-4 text-xs text-muted-foreground">
<span className="flex items-center gap-1">
<AlertCircle className="w-3 h-3" /> Code: {assignment.wo_code || 'N/A'}
</span>
<span className="flex items-center gap-1">
<Calendar className="w-3 h-3" />
{assignment.wo_start_date ? new Date(assignment.wo_start_date).toLocaleDateString() : 'N/A'} - {assignment.wo_end_date ? new Date(assignment.wo_end_date).toLocaleDateString() : 'N/A'}
</span>
</div>
<CardContent className="p-6 pt-4">
<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>
<div className="mt-6 pt-6 border-t">
<div className='flex items-center justify-between'>
<p className="text-xs font-bold uppercase text-muted-foreground mb-4">Team</p>
<Button onClick={() => setAction('MANAGE_EMPLOYEE')} className="gap-2" size='sm'>
<UserPlus className="w-4 h-4" />
Manage Team
</Button>
</div>
</div>
<AssignedPeople people={assignment.project_assignment_work_order_detail} />
<AssignedPeople people={assignment.project_assignment_work_order_detail} defaultOpen={false} />
</CardContent>
</Card900>
@@ -199,7 +184,7 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
</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) => (
{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",
@@ -219,10 +204,10 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
</p>
</div>
</div>
))}
{(!statuslist || statuslist.length === 0) && (
<p className="text-sm text-muted-foreground italic pl-8">No history recorded yet.</p>
)}
{(!statuslist || statuslist.length === 0) &&
<p className="text-sm text-muted-foreground italic pl-8">No history recorded yet.</p>
}
</div>
</CardContent>
</Card900>
@@ -241,4 +226,46 @@ export default function AssignmentDetail({ client, initialAssignment: assignment
}
</>
);
}
}
function MetaTile({ icon: Icon, label, value }: { icon: typeof Briefcase; label: string; value: string }) {
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>
</div>
);
}
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();
}
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>
);
}
@@ -1,14 +1,20 @@
import { ProjectAssignmentWorkOrderDetail } from '@/app/(dashboard)/task/type.assignment';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { LazyImage } from '@/components/ui/lazy-image';
import dayjs from 'dayjs';
import { Mail, Phone, Calendar } from 'lucide-react';
import { Mail, Phone, Calendar, ChevronDown } from 'lucide-react';
import { useState } from 'react';
import { motion, AnimatePresence } from 'motion/react';
interface Props {
people: ProjectAssignmentWorkOrderDetail[];
defaultOpen?: boolean;
}
const AssignedPeople = ({ people }: Props) => {
const AssignedPeople = ({ people, defaultOpen = true }: Props) => {
const [isOpen, setIsOpen] = useState(defaultOpen);
if (people.length === 0) {
return (
<div className="text-center py-8 text-sm text-muted-foreground bg-muted/40 rounded-lg border border-dashed border-border mt-5">
@@ -20,59 +26,75 @@ const AssignedPeople = ({ people }: Props) => {
return (
<div className="space-y-6">
{/* Stacked avatars */}
<div className="flex items-center gap-3">
<div className="flex -space-x-3">
{people.slice(0, 5).map((user, i) =>
<LazyImage key={i} src={user?.user.avatar ? `${process.env.BASE_URL_IMG}/${user?.user.avatar}` : '/assets/no-avatar.jpg'} alt={user?.user.fullname!} className="w-10 h-10 rounded-full ring-2 ring-background hover:scale-110 hover:z-10 transition-transform" />
)}
{people.length > 5 &&
<div className="w-10 h-10 rounded-full bg-muted ring-2 ring-background flex items-center justify-center text-xs font-bold text-muted-foreground shadow-md">
+{people.length - 5}
</div>
}
</div>
<div className="text-sm">
<p className="font-semibold text-foreground">{people.length} People</p>
<p className="text-muted-foreground">assigned to this work order</p>
</div>
</div>
{/* Detailed list */}
<div className="space-y-2">
{people.map((user, i) => (
<div key={user.id} className="group flex items-center gap-3 p-3 rounded-xl bg-card/40 border border-border/60 hover:border-primary/40 hover:bg-card/80 transition-all">
<LazyImage src={user?.user.avatar ? `${process.env.BASE_URL_IMG}/${user?.user.avatar}` : '/assets/no-avatar.jpg'} alt={user?.user.fullname!} className="w-11 h-11 rounded-full border border-border" />
<div className="flex-1 min-w-0">
<div className="flex items-start gap-2 flex-wrap">
<p className="text-sm font-semibold text-foreground truncate min-w-0">{user.user.fullname}</p>
<Badge variant='violet'>{user.user.position?.name}</Badge>
<div className='flex items-center'>
<div className="flex items-center gap-3">
<div className="flex -space-x-3">
{people.slice(0, 5).map((user, i) =>
<LazyImage key={i} src={user?.user.avatar ? `${process.env.BASE_URL_IMG}/${user?.user.avatar}` : '/assets/no-avatar.jpg'} alt={user?.user.fullname!} className="w-10 h-10 rounded-full ring-2 ring-background hover:scale-110 hover:z-10 transition-transform" />
)}
{people.length > 5 &&
<div className="w-10 h-10 rounded-full bg-muted ring-2 ring-background flex items-center justify-center text-xs font-bold text-muted-foreground shadow-md">
+{people.length - 5}
</div>
<div className="flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-3 mt-1 text-xs text-muted-foreground sm:flex-wrap min-w-0">
<span className="inline-flex items-center gap-1 min-w-0">
<Mail className="w-3 h-3 shrink-0" />
<a href={`mailto:${user.user.email}`} referrerPolicy="no-referrer" className='hover:text-his duration-300'>
<span className="truncate">{user.user.email}</span>
</a>
</span>
<span className="inline-flex items-center gap-1">
<Phone className="w-3 h-3 shrink-0" />
<span className="font-mono">{user.user.phone_number}</span>
</span>
</div>
</div>
<div className="hidden sm:flex flex-col items-end shrink-0">
<span className="text-[10px] uppercase tracking-wider text-muted-foreground">
Assigned
</span>
<span className="text-xs font-medium text-foreground inline-flex items-center gap-1">
<Calendar className="w-3 h-3" />
{user.start_date ? `${dayjs(user.start_date).format('MMMM DD, YYYY')} - ${user.end_date ? dayjs(user.end_date).format('MMMM DD, YYYY') : 'N/A'}` : 'N/A'}
</span>
</div>
}
</div>
))}
<div className="text-sm">
<p className="font-semibold text-foreground">{people.length} People</p>
<p className="text-muted-foreground">assigned to this work order</p>
</div>
</div>
<Button onClick={() => setIsOpen(!isOpen)} variant='ghost' size='sm' className="ml-auto">
<ChevronDown className={`w-4 h-4 mr-1 transition-transform ${isOpen ? 'rotate-180' : ''}`} /> {isOpen ? 'Hide' : 'View'} Team
</Button>
</div>
<AnimatePresence initial={false}>
{isOpen && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: "auto", opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.3, ease: "easeInOut" }}
className="overflow-hidden"
>
<div className="space-y-2 pt-2">
{people.map((user) => (
<div key={user.id} className="group flex items-center gap-3 p-3 rounded-xl bg-card/40 border border-border/60 hover:border-primary/40 hover:bg-card/80 transition-all">
<LazyImage src={user?.user.avatar ? `${process.env.BASE_URL_IMG}/${user?.user.avatar}` : '/assets/no-avatar.jpg'} alt={user?.user.fullname!} className="w-11 h-11 rounded-full border border-border" />
<div className="flex-1 min-w-0">
<div className="flex items-start gap-2 flex-wrap">
<p className="text-sm font-semibold text-foreground truncate min-w-0">{user.user.fullname}</p>
<Badge variant='violet'>{user.user.position?.name}</Badge>
</div>
<div className="flex flex-col sm:flex-row sm:items-center gap-1 sm:gap-3 mt-1 text-xs text-muted-foreground sm:flex-wrap min-w-0">
<span className="inline-flex items-center gap-1 min-w-0">
<Mail className="w-3 h-3 shrink-0" />
<a href={`mailto:${user.user.email}`} referrerPolicy="no-referrer" className='hover:text-his duration-300'>
<span className="truncate">{user.user.email}</span>
</a>
</span>
<span className="inline-flex items-center gap-1">
<Phone className="w-3 h-3 shrink-0" />
<span className="font-mono">{user.user.phone_number}</span>
</span>
</div>
</div>
<div className="hidden sm:flex flex-col items-end shrink-0">
<span className="text-[10px] uppercase tracking-wider text-muted-foreground">
Assigned
</span>
<span className="text-xs font-medium text-foreground inline-flex items-center gap-1">
<Calendar className="w-3 h-3" />
{user.start_date ? `${dayjs(user.start_date).format('MMMM DD, YYYY')} - ${user.end_date ? dayjs(user.end_date).format('MMMM DD, YYYY') : 'N/A'}` : 'N/A'}
</span>
</div>
</div>
))}
</div>
</motion.div>
)}
</AnimatePresence>
</div>
);
};
@@ -28,8 +28,8 @@ export default async function ProjectDetailPage({ params, searchParams }: Props)
const queryString = getQueryStringFilteredAssignments(searchParams_)
const getClientById = fetchData(`/client/${client_id}`)
const getAssignmentByProjectId = fetchData(queryString ? `/project/project-assignment/${project_id}?${queryString}` : `/project/project-assignment/${project_id}`)
// const getAssignmentByProjectId = fetchData(`/project/${project_id}`)
// const getAssignmentByProjectId = fetchData(queryString ? `/project/project-assignment/${project_id}?${queryString}` : `/project/project-assignment/${project_id}`)
const getAssignmentByProjectId = fetchData(`/project/${project_id}`)
const [client, project] = await Promise.all([getClientById, getAssignmentByProjectId]);
+6 -2
View File
@@ -17,10 +17,11 @@ import { useForm } from 'react-hook-form';
import { serverApiCall } from '@/lib/server-api';
import { toast } from 'sonner';
import { ComboboxCustomUI } from '@/components/ui/combobox-custom-ui';
import type { ProjectAssignmentWorkOrderDetail } from '../type.assignment';
type Props = {
assignmentId: number;
existingTeam?: number[];
existingTeam?: ProjectAssignmentWorkOrderDetail[];
onCancel?: VoidFunction
onSuccess?: VoidFunction;
};
@@ -67,7 +68,10 @@ const AddTeam: FC<Props> = ({ assignmentId, existingTeam, onCancel, onSuccess })
};
const mappedUsers = useMemo(() => {
return userList?.user?.map((item: IUser) => ({
if (!userList?.user) return []
const filterUser = userList?.user.filter((item: IUser) => existingTeam?.every(team => team.user.id !== item.id)) || []
return filterUser?.map((item: IUser) => ({
label: item.fullname,
value: item.id,
originalData: item
@@ -14,7 +14,6 @@ import {
Select, SelectContent, SelectItem, SelectTrigger, SelectValue
} from "@/components/ui/select";
import { DatePicker } from "@/components/ui/datepicker";
import BadgeStatus from "@/components/ui/badge-status";
import {
AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle
} from "@/components/ui/alert-dialog"
@@ -3,10 +3,6 @@ import {
AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle
} from "@/components/ui/alert-dialog"
import { Button } from '@/components/ui/button';
import { Textarea } from '@/components/ui/textarea';
import * as Yup from 'yup'
import { yupResolver } from '@hookform/resolvers/yup';
import { useForm } from 'react-hook-form';
import { DatePicker } from '@/components/ui/datepicker';
import { Edit2, Loader2, Save, X } from 'lucide-react';
import { useFetchWithAxios } from '@/lib/axios/useFetch';
@@ -76,10 +72,10 @@ const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
setIsSaving(false);
if (res.success) {
toast.success('Team updated successfully')
toast.success('Status updated successfully')
handleSuccess!()
} else {
toast.error(`Fail to save team`, { description: `(${res.code || '-'}) ${res.message}` })
toast.error(`Fail to save status`, { description: `(${res.code || '-'}) ${res.message}` })
}
};
@@ -138,7 +134,7 @@ const UpdateTimelineStatus: FC<Props> = ({ assignmentId, onClose }) => {
</TableCell>
</TableRow>
:
existTimeline.map((row: IProjectAssignmentTimeline) => {
existTimeline.sort((a: any, b: any) => a.id - b.id).map((row: IProjectAssignmentTimeline) => {
const isEditing = editingId === row.id;
const isOtherRowEditing = editingId !== null && editingId !== row.id;
+6
View File
@@ -8,6 +8,9 @@
--color-his: #EA512C;
--color-soft: #f6f6f6;
/* --type-memo: #925cf0;
--type-wo: #fa832e; */
--color-background: var(--background);
--color-foreground: var(--foreground);
--font-sans: var(--font-geist-sans);
@@ -48,6 +51,9 @@
}
:root {
--type-memo: hsl(262 83% 65%);
--type-wo: hsl(25 95% 58%);
--radius: 0.625rem;
--background: oklch(1 0 0);
--foreground: oklch(0.141 0.005 285.823);