mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
78f48d783f
Introduce client and assignment detail pages and client-side components for the Task dashboard. Adds interactive ClientDetailComponent, AssignmentDetailComponent, page entries (server + dummy variants), project-assignment form, various UI components (AssignmentTable, ClientGrid, ManageEmployee, FormUpdateStatus, ConfirmDelete, LazyImage helper), types and a dummy data hook. Update app/(dashboard)/task/page.tsx to use the new components. Update .env.development to point to dev API endpoints, bump NEXT_PUBLIC_APP_VERSION to v1.2.0 and add NEXT_PUBLIC_S3_IMAGE_URL.
421 lines
23 KiB
TypeScript
421 lines
23 KiB
TypeScript
"use client"
|
|
|
|
import { motion } from 'motion/react';
|
|
import {
|
|
ArrowLeft,
|
|
Briefcase,
|
|
Users,
|
|
Calendar,
|
|
CheckCircle2,
|
|
History,
|
|
AlertCircle
|
|
} from 'lucide-react';
|
|
import { use, useState } from 'react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import { Separator } from '@/components/ui/separator';
|
|
import { Label } from '@/components/ui/label';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Textarea } from '@/components/ui/textarea';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogFooter,
|
|
} from '@/components/ui/dialog';
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from '@/components/ui/select';
|
|
import { toast } from 'sonner';
|
|
import { cn } from '@/lib/utils';
|
|
import { useRouter } from 'next/navigation';
|
|
import { useAppState } from '@/hooks/useDummyTaskData';
|
|
import { DUMMY_EMPLOYEES, IProjectAssignment, IStatusUpdate } from '../../../types';
|
|
import Link from 'next/link';
|
|
|
|
type Props = {
|
|
params: Promise<{ client_id: string; assignment_id: string }>
|
|
};
|
|
export default function ProjectOrIMDetailPage({ params }: Props) {
|
|
// const { id } = await params;
|
|
const { client_id, assignment_id: id } = use(params);
|
|
|
|
const router = useRouter();
|
|
const { assignments, clients, updateAssignment } = useAppState();
|
|
|
|
const [updatingStatusType, setUpdatingStatusType] = useState<'assignment' | 'wo' | null>(null);
|
|
const [targetWoId, setTargetWoId] = useState<string | null>(null);
|
|
const [statusForm, setStatusForm] = useState({
|
|
status: 'Active' as IProjectAssignment['status'],
|
|
note: '',
|
|
date: new Date().toISOString().split('T')[0]
|
|
});
|
|
|
|
const assignment = assignments.find((a) => a.id === id);
|
|
const client = clients.find((c) => c.id === assignment?.clientId);
|
|
|
|
if (!assignment) {
|
|
return (
|
|
<div className="flex flex-col items-center justify-center h-[60vh] space-y-4">
|
|
<h2 className="text-2xl font-bold">Assignment not found</h2>
|
|
<Button onClick={() => router.replace('/task')} variant='outline'>Back to Clients</Button>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const title = assignment.type === 'Project' ? 'Project Detail' : 'Internal Memo Detail';
|
|
|
|
const handleOpenStatusDialog = (type: 'assignment' | 'wo', woId?: string) => {
|
|
setUpdatingStatusType(type);
|
|
setTargetWoId(woId || null);
|
|
|
|
const currentStatus = type === 'assignment' ? assignment.status : assignment.workOrder.status || 'Active';
|
|
|
|
setStatusForm({
|
|
status: currentStatus,
|
|
note: '',
|
|
date: new Date().toISOString().split('T')[0]
|
|
});
|
|
};
|
|
|
|
const handleSaveStatus = () => {
|
|
const newUpdate: IStatusUpdate = {
|
|
id: Math.random().toString(36).substr(2, 9),
|
|
status: statusForm.status,
|
|
date: statusForm.date,
|
|
note: statusForm.note,
|
|
createdAt: new Date().toISOString()
|
|
};
|
|
|
|
if (updatingStatusType === 'assignment') {
|
|
updateAssignment(assignment.id, {
|
|
status: statusForm.status,
|
|
statusHistory: [newUpdate, ...(assignment.statusHistory || [])]
|
|
});
|
|
toast.success(`Assignment status updated to ${statusForm.status}`);
|
|
} else if (updatingStatusType === 'wo' && targetWoId) {
|
|
const updatedWOs = assignment.workOrders.map(wo => {
|
|
if (wo.id === targetWoId) {
|
|
return {
|
|
...wo,
|
|
status: statusForm.status,
|
|
statusHistory: [newUpdate, ...(wo.statusHistory || [])]
|
|
};
|
|
}
|
|
return wo;
|
|
});
|
|
updateAssignment(assignment.id, { workOrders: updatedWOs });
|
|
toast.success(`Work Order status updated to ${statusForm.status}`);
|
|
}
|
|
|
|
setUpdatingStatusType(null);
|
|
setTargetWoId(null);
|
|
};
|
|
|
|
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-1">
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="p-0 h-auto hover:bg-transparent text-muted-foreground mb-2"
|
|
onClick={() => router.back()}
|
|
>
|
|
<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">{title}</h1>
|
|
<Badge variant={assignment.type === 'Project' ? 'default' : 'secondary'} className="text-lg px-3 py-1">
|
|
{assignment.type}
|
|
</Badge>
|
|
</div>
|
|
<div className="flex items-center gap-3 mt-2">
|
|
<h2 className="text-xl font-medium text-muted-foreground">{assignment.name}</h2>
|
|
</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: {assignment.code || 'N/A'}
|
|
</p>
|
|
<Separator orientation="vertical" className="h-4" />
|
|
<p className="flex items-center gap-1">
|
|
<Calendar className="w-4 h-4" />
|
|
Year: {assignment.year || 'N/A'}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="flex gap-3">
|
|
<Button variant="outline" onClick={() => handleOpenStatusDialog('assignment')} className="gap-2">
|
|
<History className="w-4 h-4" />
|
|
Update {assignment.type} 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 */}
|
|
<Card>
|
|
<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">Current Status</Label>
|
|
<div className="mt-1">
|
|
<Badge variant="outline" className={cn(
|
|
"px-3 py-1",
|
|
assignment.status === 'Active' ? 'text-green-600 border-green-200 bg-green-50' :
|
|
assignment.status === 'Completed' ? 'text-blue-600 border-blue-200 bg-blue-50' :
|
|
'text-orange-600 border-orange-200 bg-orange-50'
|
|
)}>
|
|
{assignment.status}
|
|
</Badge>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Start Date</Label>
|
|
<p className="font-medium mt-1">{assignment.startDate ? new Date(assignment.startDate).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">{assignment.endDate ? new Date(assignment.endDate).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">{assignment.description}</p>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
{/* 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.workOrder ? (
|
|
<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">
|
|
<Card key={assignment.workOrder?.id} 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.workOrder?.name}</h3>
|
|
<Badge variant="outline" className={cn(
|
|
assignment.workOrder?.status === 'Active' ? 'text-green-600 border-green-200 bg-green-50' :
|
|
assignment.workOrder?.status === 'Completed' ? 'text-blue-600 border-blue-200 bg-blue-50' :
|
|
'text-orange-600 border-orange-200 bg-orange-50'
|
|
)}>
|
|
{assignment.workOrder?.status || 'Active'}
|
|
</Badge>
|
|
</div>
|
|
<p className="text-muted-foreground text-sm">{assignment.workOrder?.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.workOrder?.code || 'N/A'}
|
|
</span>
|
|
<span className="flex items-center gap-1">
|
|
<Calendar className="w-3 h-3" />
|
|
{assignment.workOrder?.startDate ? new Date(assignment.workOrder?.startDate).toLocaleDateString() : 'N/A'} - {assignment.workOrder?.endDate ? new Date(assignment.workOrder?.endDate).toLocaleDateString() : 'N/A'}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-start">
|
|
<Button variant="outline" size="sm" onClick={() => handleOpenStatusDialog('wo', assignment.workOrder?.id)}>
|
|
Update WO Status
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* WO Status History Mini-Timeline */}
|
|
{assignment.workOrder?.statusHistory && assignment.workOrder?.statusHistory.length > 0 && (
|
|
<div className="mt-6 pt-6 border-t">
|
|
<p className="text-xs font-bold uppercase text-muted-foreground mb-4">WO Status History</p>
|
|
<div className="space-y-4">
|
|
{assignment.workOrder?.statusHistory.slice(0, 2).map((history, idx) => (
|
|
<div key={history.id} className="flex gap-3 text-sm">
|
|
<div className="w-2 h-2 rounded-full bg-primary mt-1.5 shrink-0" />
|
|
<div>
|
|
<div className="flex items-center gap-2">
|
|
<span className="font-bold">{history.status}</span>
|
|
<span className="text-muted-foreground text-xs">{new Date(history.date).toLocaleDateString()}</span>
|
|
</div>
|
|
<p className="text-muted-foreground text-xs mt-0.5">{history.note}</p>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
{/* Right Column: Status History & Team */}
|
|
<div className="space-y-8">
|
|
{/* Project Status History Timeline */}
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<History className="w-5 h-5 text-primary" />
|
|
{assignment.type} History
|
|
</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">
|
|
{assignment.statusHistory?.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.status}
|
|
</Badge>
|
|
<span className="text-[10px] text-muted-foreground font-mono">
|
|
{new Date(history.date).toLocaleDateString()}
|
|
</span>
|
|
</div>
|
|
<p className="text-sm font-medium">{history.note}</p>
|
|
<p className="text-[10px] text-muted-foreground">
|
|
Recorded: {new Date(history.createdAt).toLocaleString()}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
))}
|
|
{(!assignment.statusHistory || assignment.statusHistory.length === 0) && (
|
|
<p className="text-sm text-muted-foreground italic pl-8">No history recorded yet.</p>
|
|
)}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
|
|
{/* Team Card */}
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<Users className="w-5 h-5 text-primary" />
|
|
Assigned Team
|
|
</CardTitle>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<div className="space-y-4">
|
|
{assignment.assignedEmployees.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground italic">No employees assigned yet.</p>
|
|
) : (
|
|
assignment.assignedEmployees.map(empId => {
|
|
const emp = DUMMY_EMPLOYEES.find(e => e.id === empId);
|
|
return (
|
|
<div key={empId} className="flex items-center gap-3 p-2 rounded-lg hover:bg-accent/50 transition-colors">
|
|
<img src={emp?.avatar} alt={emp?.name} className="w-10 h-10 rounded-full object-cover" />
|
|
<div className="min-w-0">
|
|
<p className="text-sm font-bold truncate">{emp?.name}</p>
|
|
<p className="text-xs text-muted-foreground truncate">{emp?.role}</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
})
|
|
)}
|
|
<Separator />
|
|
<Button variant="ghost" size="sm" className="w-full text-primary hover:text-primary hover:bg-primary/5" asChild>
|
|
<Link href={`/clients/${client?.id}`}>Manage Team in Client Page</Link>
|
|
</Button>
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Status Update Dialog */}
|
|
<Dialog open={!!updatingStatusType} onOpenChange={(open) => !open && setUpdatingStatusType(null)}>
|
|
<DialogContent className="max-w-md">
|
|
<DialogHeader>
|
|
<DialogTitle>Update {updatingStatusType === 'assignment' ? assignment.type : 'Work Order'} Status</DialogTitle>
|
|
<DialogDescription>
|
|
Record a new status update for this {updatingStatusType === 'assignment' ? (assignment.type === 'Project' ? 'project' : 'memo') : 'work order'}.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<div className="grid gap-6 py-4">
|
|
<div className="space-y-2">
|
|
<Label>New Status</Label>
|
|
<Select
|
|
value={statusForm.status}
|
|
onValueChange={(v) => setStatusForm({ ...statusForm, status: v as IProjectAssignment['status'] })}
|
|
>
|
|
<SelectTrigger>
|
|
<SelectValue placeholder="Select status" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="Active">Active</SelectItem>
|
|
<SelectItem value="Completed">Completed</SelectItem>
|
|
<SelectItem value="On Hold">On Hold</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label>Date of Change</Label>
|
|
<Input
|
|
type="date"
|
|
value={statusForm.date}
|
|
onChange={(e) => setStatusForm({ ...statusForm, date: e.target.value })}
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label>Note / Remarks</Label>
|
|
<Textarea
|
|
placeholder="Explain the reason for this status change..."
|
|
value={statusForm.note}
|
|
onChange={(e) => setStatusForm({ ...statusForm, note: e.target.value })}
|
|
className="min-h-[100px]"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button variant="ghost" onClick={() => setUpdatingStatusType(null)}>Cancel</Button>
|
|
<Button onClick={handleSaveStatus}>Save Update</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</motion.div>
|
|
);
|
|
}
|