mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
49f766ad27
Pass assignment start/end dates into ManageTeam and enforce them in the UI. Updated components (ClientDetailComponent, AssignmentDetailComponent(.old), WorkOrderCard) to provide startDate/endDate props. Modified ManageTeam signature to accept startDate/endDate, added dayjs import to format displayed dates, and implemented disabledDate logic on the DatePicker controls to prevent selecting dates outside the assignment boundaries (normalizing dates to midnight and checking against assignment and user-selected dates). Also removed a stray console.log in AssignmentDetailComponent.old and adjusted ProjectDetailPage to fetch project assignments via the filtered query string (added a console.log(project) for debugging). Files changed: ClientDetailComponent.tsx, AssignmentDetailComponent.old.tsx, AssignmentDetailComponent.tsx, WorkOrderCard.tsx, page.tsx, ManageTeam.tsx.
246 lines
15 KiB
TypeScript
246 lines
15 KiB
TypeScript
// 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)
|
|
}
|
|
|
|
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}
|
|
startDate={assignment.wo_start_date || assignment.im_start_date} endDate={assignment.wo_end_date || assignment.im_end_date}
|
|
/>
|
|
: null
|
|
}
|
|
</>
|
|
);
|
|
} |