mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:46:29 +00:00
fixing typescript error during production build
Adjust chart components (Overview, PieChart) for sizing and safer typings/casting; add v1.2.0 release note. Remove several obsolete dummy/old task pages and the useDummyTaskData hook. Also include minor fixes to FormClient and DonutChart/performance pages.
This commit is contained in:
@@ -109,7 +109,7 @@ export default function Overview() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full h-[275px] sm:h-[420px] 2xl:h-[450px]">
|
<div className="w-full h-68.75 sm:h-105 2xl:h-112.5">
|
||||||
<Chart
|
<Chart
|
||||||
options={barChartOptionsDailyTraffic}
|
options={barChartOptionsDailyTraffic}
|
||||||
series={barChartDataDailyTraffic}
|
series={barChartDataDailyTraffic}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const PieChart: FC<Props> = ({ data }) => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted: (chart) => {
|
mounted: (chart) => {
|
||||||
chart?.windowResizeHandler();
|
(chart as any)?.windowResizeHandler();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -99,7 +99,7 @@ const PieChart: FC<Props> = ({ data }) => {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
formatter: function (val: any, opts) {
|
formatter: function (val: any, opts) {
|
||||||
// console.log(opts)
|
// console.log(opts)
|
||||||
return opts.w.globals.labels[opts.seriesIndex] + ': ' + opts.w.globals.series[opts.seriesIndex]
|
return opts?.w.globals.labels[opts?.seriesIndex!] + ': ' + opts?.w.globals.series[opts.seriesIndex]
|
||||||
// return opts.w.globals.series[opts.seriesIndex]
|
// return opts.w.globals.series[opts.seriesIndex]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -135,7 +135,7 @@ const PieChart: FC<Props> = ({ data }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className='h-[300px] sm:h-[350px] flex items-center justify-center'>
|
<div className='h-75 sm:h-87.5 flex items-center justify-center'>
|
||||||
<ReactApexChart
|
<ReactApexChart
|
||||||
type='donut'
|
type='donut'
|
||||||
options={options}
|
options={options}
|
||||||
|
|||||||
@@ -15,6 +15,15 @@ interface ReleaseNote {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const releaseNotes: ReleaseNote[] = [
|
const releaseNotes: ReleaseNote[] = [
|
||||||
|
{
|
||||||
|
version: "v1.2.0",
|
||||||
|
date: "23 April 2026",
|
||||||
|
type: "minor",
|
||||||
|
changes: [
|
||||||
|
{ category: "feature", description: "Project Assignment" },
|
||||||
|
{ category: "bugfix", description: "Fixed typescript error during compilation and production builds" },
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
version: "v1.1.2",
|
version: "v1.1.2",
|
||||||
date: "20 February 2026",
|
date: "20 February 2026",
|
||||||
|
|||||||
@@ -1,514 +0,0 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import { motion } from 'motion/react';
|
|
||||||
import { ArrowLeft, Plus, Briefcase, Clock, Users, MoreVertical, Check, Calendar as CalendarIcon, LayoutGrid, Table as TableIcon } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } 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 {
|
|
||||||
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
|
||||||
} from '@/components/ui/dropdown-menu';
|
|
||||||
import {
|
|
||||||
Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import {
|
|
||||||
Select, SelectContent, SelectItem, SelectTrigger, SelectValue,
|
|
||||||
} from '@/components/ui/select';
|
|
||||||
import {
|
|
||||||
Tooltip, TooltipContent, TooltipTrigger,
|
|
||||||
} from '@/components/ui/tooltip';
|
|
||||||
import {
|
|
||||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
|
||||||
} from "@/components/ui/table";
|
|
||||||
import {
|
|
||||||
Tabs, TabsList, TabsTrigger,
|
|
||||||
} from "@/components/ui/tabs";
|
|
||||||
import { use, useState } from 'react';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { DUMMY_EMPLOYEES, IProjectAssignment } from '../../../types';
|
|
||||||
import { useAppState } from '@/hooks/useDummyTaskData';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import Link from 'next/link';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
params: Promise<{ client_id: string | undefined }>
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function ClientDetailPage({ params }: Props) {
|
|
||||||
|
|
||||||
const [viewMode, setViewMode] = useState<'grid' | 'table'>('grid');
|
|
||||||
const [statusForm, setStatusForm] = useState({
|
|
||||||
status: 'Active' as IProjectAssignment['status'],
|
|
||||||
note: '',
|
|
||||||
date: new Date().toISOString().split('T')[0]
|
|
||||||
});
|
|
||||||
|
|
||||||
// const { id } = await params;
|
|
||||||
const { client_id } = use(params);
|
|
||||||
const router = useRouter()
|
|
||||||
const { clients, assignments, updateAssignment } = useAppState();
|
|
||||||
|
|
||||||
|
|
||||||
const [editingEmployeesAssignment, setEditingEmployeesAssignment] = useState<IProjectAssignment | null>(null);
|
|
||||||
const [selectedEmployeeIds, setSelectedEmployeeIds] = useState<string[]>([]);
|
|
||||||
|
|
||||||
const [updatingStatusAssignment, setUpdatingStatusAssignment] = useState<IProjectAssignment | null>(null);
|
|
||||||
|
|
||||||
const client = clients.find((c) => c.id === client_id);
|
|
||||||
const clientAssignments = assignments.filter((a) => a.clientId === client_id);
|
|
||||||
|
|
||||||
const handleOpenEmployeeDialog = (assignment: IProjectAssignment) => {
|
|
||||||
setEditingEmployeesAssignment(assignment);
|
|
||||||
setSelectedEmployeeIds(assignment.assignedEmployees);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleOpenStatusDialog = (assignment: IProjectAssignment) => {
|
|
||||||
setUpdatingStatusAssignment(assignment);
|
|
||||||
setStatusForm({
|
|
||||||
status: assignment.status,
|
|
||||||
note: '',
|
|
||||||
date: new Date().toISOString().split('T')[0]
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const toggleEmployee = (empId: string) => {
|
|
||||||
setSelectedEmployeeIds(prev =>
|
|
||||||
prev.includes(empId) ? prev.filter(i => i !== empId) : [...prev, empId]
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSaveEmployees = () => {
|
|
||||||
if (editingEmployeesAssignment) {
|
|
||||||
updateAssignment(editingEmployeesAssignment.id, {
|
|
||||||
assignedEmployees: selectedEmployeeIds
|
|
||||||
});
|
|
||||||
toast.success('Team updated successfully');
|
|
||||||
setEditingEmployeesAssignment(null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSaveStatus = () => {
|
|
||||||
if (updatingStatusAssignment) {
|
|
||||||
updateAssignment(updatingStatusAssignment.id, {
|
|
||||||
status: statusForm.status
|
|
||||||
});
|
|
||||||
// In a real app we would save the note and date to a history log
|
|
||||||
toast.success(`Status updated to ${statusForm.status}`);
|
|
||||||
setUpdatingStatusAssignment(null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!client) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col items-center justify-center h-[60vh] space-y-4">
|
|
||||||
<h2 className="text-2xl font-bold">Client not found</h2>
|
|
||||||
<Button onClick={() => router.replace('/task')} variant='outline'>Back to Clients</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0 }}
|
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
exit={{ opacity: 0 }}
|
|
||||||
className="flex-1 space-y-8 p-6 sm:p-8 pt-6"
|
|
||||||
>
|
|
||||||
<div className="flex flex-col md:flex-row md:items-end justify-between gap-6">
|
|
||||||
<div className="flex items-start gap-6">
|
|
||||||
<motion.div
|
|
||||||
initial={{ scale: 0.8, opacity: 0 }}
|
|
||||||
animate={{ scale: 1, opacity: 1 }}
|
|
||||||
className="w-24 h-24 rounded-2xl overflow-hidden shadow-xl border-4 border-background"
|
|
||||||
>
|
|
||||||
<img src={client.imageUrl} alt={client.name} className="w-full h-full object-cover" />
|
|
||||||
</motion.div>
|
|
||||||
<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.replace('/task')}>
|
|
||||||
<ArrowLeft className="w-4 h-4 mr-1" />
|
|
||||||
Back to Clients
|
|
||||||
</Button>
|
|
||||||
<h1 className="text-4xl font-bold tracking-tight">{client.name}</h1>
|
|
||||||
<p className="text-lg text-muted-foreground">End User: {client.endUser}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex gap-3">
|
|
||||||
<Link href={`/task/client-detail/${client_id}/project-assignments`} className='w-full sm:w-max'>
|
|
||||||
<Button className="gap-2 w-full">
|
|
||||||
<Plus className="w-4 h-4" />
|
|
||||||
Create Project Assignment
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-8 lg:grid-cols-3">
|
|
||||||
<div className="lg:col-span-2 space-y-6">
|
|
||||||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
|
|
||||||
<h2 className="text-2xl font-bold">Project Assignments</h2>
|
|
||||||
<div className="flex items-center gap-4">
|
|
||||||
<Tabs value={viewMode} onValueChange={(v) => setViewMode(v as 'grid' | 'table')}>
|
|
||||||
<TabsList className="grid w-24 grid-cols-2">
|
|
||||||
<TabsTrigger value="grid" className="p-1">
|
|
||||||
<LayoutGrid className="w-4 h-4" />
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger value="table" className="p-1">
|
|
||||||
<TableIcon className="w-4 h-4" />
|
|
||||||
</TabsTrigger>
|
|
||||||
</TabsList>
|
|
||||||
</Tabs>
|
|
||||||
<Badge variant="outline" className="px-3 py-1">
|
|
||||||
{clientAssignments.length} Total
|
|
||||||
</Badge>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{clientAssignments.length === 0 ? (
|
|
||||||
<Card className="border-dashed bg-accent/20">
|
|
||||||
<CardContent className="flex flex-col items-center justify-center py-16 space-y-4">
|
|
||||||
<div className="w-16 h-16 rounded-full bg-accent flex items-center justify-center">
|
|
||||||
<Briefcase className="w-8 h-8 text-muted-foreground" />
|
|
||||||
</div>
|
|
||||||
<div className="text-center">
|
|
||||||
<h3 className="text-xl font-semibold">No Project Assignments</h3>
|
|
||||||
<p className="text-muted-foreground max-w-xs mx-auto mt-2">
|
|
||||||
This client doesn't have any projects or internal memos yet. Create one to get started.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<Link href={`/task/client-detail/${client_id}/project-assignments`}>
|
|
||||||
<Button variant="outline" className="mt-4">Create Assignment</Button>
|
|
||||||
</Link>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
) : viewMode === 'grid' ? (
|
|
||||||
<div className="grid gap-4">
|
|
||||||
{clientAssignments?.map((assignment) => (
|
|
||||||
<Card key={assignment.id} className="group hover:border-primary/30 transition-all duration-300">
|
|
||||||
<CardContent className="p-6">
|
|
||||||
<div className="flex items-start justify-between gap-4">
|
|
||||||
<div className="flex items-start gap-4">
|
|
||||||
<div className={`w-12 h-12 rounded-xl flex items-center justify-center shrink-0 ${assignment.type === 'Project' ? 'bg-orange-500/10 text-orange-500' : 'bg-purple-500/10 text-purple-500'
|
|
||||||
}`}>
|
|
||||||
{assignment.type === 'Project' ? <Briefcase className="w-6 h-6" /> : <Clock className="w-6 h-6" />}
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div className="flex items-center gap-3 mb-1">
|
|
||||||
<h3 className="font-bold text-xl">{assignment.name}</h3>
|
|
||||||
<Badge variant={assignment.type === 'Project' ? 'default' : 'secondary'}>
|
|
||||||
{assignment.type}
|
|
||||||
</Badge>
|
|
||||||
<Badge variant="outline" className={
|
|
||||||
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>
|
|
||||||
|
|
||||||
{assignment.workOrder && (
|
|
||||||
<p className="text-sm font-medium text-primary mb-1">
|
|
||||||
WO: {assignment.workOrder.name}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<p className="text-muted-foreground line-clamp-2 text-sm mb-4">
|
|
||||||
{assignment.description}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div className="flex flex-wrap items-center gap-6 text-sm text-muted-foreground">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<CalendarIcon className="w-4 h-4" />
|
|
||||||
<span>
|
|
||||||
{assignment.startDate ? new Date(assignment.startDate).toLocaleDateString() : 'N/A'} -
|
|
||||||
{assignment.endDate ? new Date(assignment.endDate).toLocaleDateString() : 'N/A'}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Users className="w-4 h-4" />
|
|
||||||
<div className="flex -space-x-2">
|
|
||||||
{assignment.assignedEmployees.slice(0, 3).map(empId => {
|
|
||||||
const emp = DUMMY_EMPLOYEES.find(e => e.id === empId);
|
|
||||||
return (
|
|
||||||
<div key={empId}>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<img
|
|
||||||
src={emp?.avatar}
|
|
||||||
alt={emp?.name}
|
|
||||||
className="w-6 h-6 rounded-full border-2 border-background cursor-help"
|
|
||||||
/>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>
|
|
||||||
<div className="text-xs">
|
|
||||||
<p className="font-bold">{emp?.name}</p>
|
|
||||||
<p className="opacity-80">{emp?.role}</p>
|
|
||||||
</div>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
{assignment.assignedEmployees.length > 3 && (
|
|
||||||
<div className="w-6 h-6 rounded-full bg-accent border-2 border-background flex items-center justify-center text-[10px] font-bold">
|
|
||||||
+{assignment.assignedEmployees.length - 3}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{assignment.assignedEmployees.length === 0 && <span>No employees assigned</span>}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button variant="ghost" size="icon">
|
|
||||||
<MoreVertical className="w-5 h-5" />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end">
|
|
||||||
<DropdownMenuItem asChild>
|
|
||||||
<Link href={`/task/client-detail/${client_id}/${assignment.id}`}>View Details</Link>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem>Edit Assignment</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem onClick={() => handleOpenEmployeeDialog(assignment)}>
|
|
||||||
Manage Team
|
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem className="text-destructive">Archive</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Card className="overflow-hidden">
|
|
||||||
<div className="overflow-x-auto">
|
|
||||||
<Table>
|
|
||||||
<TableHeader className="bg-accent/50">
|
|
||||||
<TableRow>
|
|
||||||
<TableHead className="min-w-[200px]">Project Name</TableHead>
|
|
||||||
<TableHead>Project Code</TableHead>
|
|
||||||
<TableHead className="min-w-[200px]">Description</TableHead>
|
|
||||||
<TableHead>Year</TableHead>
|
|
||||||
<TableHead>Proj Start</TableHead>
|
|
||||||
<TableHead>Proj End</TableHead>
|
|
||||||
<TableHead className="min-w-[150px]">Work Order</TableHead>
|
|
||||||
<TableHead>WO Code</TableHead>
|
|
||||||
<TableHead>WO Start</TableHead>
|
|
||||||
<TableHead>WO End</TableHead>
|
|
||||||
<TableHead>Status</TableHead>
|
|
||||||
<TableHead className="w-[50px]"></TableHead>
|
|
||||||
</TableRow>
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{clientAssignments.map((assignment) => {
|
|
||||||
const wo = assignment.workOrder;
|
|
||||||
return (
|
|
||||||
<TableRow key={assignment.id}>
|
|
||||||
<TableCell className="font-medium">{assignment.name}</TableCell>
|
|
||||||
<TableCell>{assignment.code || '-'}</TableCell>
|
|
||||||
<TableCell className="max-w-[300px] truncate" title={assignment.description}>
|
|
||||||
{assignment.description}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>{assignment.year || '-'}</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap">
|
|
||||||
{assignment.startDate ? new Date(assignment.startDate).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap">
|
|
||||||
{assignment.endDate ? new Date(assignment.endDate).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>{wo?.name || '-'}</TableCell>
|
|
||||||
<TableCell>{wo?.code || '-'}</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap">
|
|
||||||
{wo?.startDate ? new Date(wo.startDate).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap">
|
|
||||||
{wo?.endDate ? new Date(wo.endDate).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<Badge variant="outline" className={
|
|
||||||
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>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
|
||||||
<MoreVertical className="w-4 h-4" />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end">
|
|
||||||
<DropdownMenuItem asChild>
|
|
||||||
<Link href={`/task/client-detail/${client_id}/${assignment.id}`}>View Details</Link>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem>Edit Assignment</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem onClick={() => handleOpenEmployeeDialog(assignment)}>
|
|
||||||
Manage Team
|
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem className="text-destructive">Archive</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-6">
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>Client Info</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="space-y-4">
|
|
||||||
<div>
|
|
||||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Client Name</Label>
|
|
||||||
<p className="font-medium">{client.name}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">End User</Label>
|
|
||||||
<p className="font-medium">{client.endUser}</p>
|
|
||||||
</div>
|
|
||||||
<Separator />
|
|
||||||
<div>
|
|
||||||
<Label className="text-xs text-muted-foreground uppercase tracking-wider">Created At</Label>
|
|
||||||
<p className="font-medium">{new Date(client?.createdAt)?.toLocaleDateString()}</p>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>Quick Stats</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="space-y-4">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<span className="text-sm text-muted-foreground">Total Projects</span>
|
|
||||||
<span className="font-bold">{clientAssignments.filter(a => a.type === 'Project').length}</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<span className="text-sm text-muted-foreground">Total IMs</span>
|
|
||||||
<span className="font-bold">{clientAssignments.filter(a => a.type === 'IM').length}</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<span className="text-sm text-muted-foreground">Total WOs</span>
|
|
||||||
<span className="font-bold">
|
|
||||||
{clientAssignments.reduce((acc, curr) => acc + curr.workOrders?.length, 0)}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Employee Management Dialog */}
|
|
||||||
<Dialog open={!!editingEmployeesAssignment} onOpenChange={(open) => !open && setEditingEmployeesAssignment(null)}>
|
|
||||||
<DialogContent className="max-w-md">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>Manage Team</DialogTitle>
|
|
||||||
<DialogDescription>
|
|
||||||
Assign or remove employees for <strong>{editingEmployeesAssignment?.name}</strong>
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
<div className="grid gap-4 py-4 max-h-[400px] overflow-y-auto pr-2">
|
|
||||||
{DUMMY_EMPLOYEES.map((emp) => (
|
|
||||||
<div
|
|
||||||
key={emp.id}
|
|
||||||
className={cn(
|
|
||||||
"flex items-center gap-4 p-3 rounded-xl border-2 transition-all cursor-pointer",
|
|
||||||
selectedEmployeeIds.includes(emp.id) ? "border-primary bg-primary/5" : "border-transparent hover:bg-accent"
|
|
||||||
)}
|
|
||||||
onClick={() => toggleEmployee(emp.id)}
|
|
||||||
>
|
|
||||||
<div className="relative">
|
|
||||||
<img src={emp.avatar} alt={emp.name} className="w-10 h-10 rounded-full object-cover" />
|
|
||||||
{selectedEmployeeIds.includes(emp.id) && (
|
|
||||||
<div className="absolute -top-1 -right-1 w-4 h-4 bg-primary rounded-full flex items-center justify-center text-white border-2 border-background">
|
|
||||||
<Check className="w-2 h-2" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div className="flex-1 min-w-0">
|
|
||||||
<p className="font-bold text-sm truncate">{emp.name}</p>
|
|
||||||
<p className="text-xs text-muted-foreground truncate">{emp.role}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
<DialogFooter>
|
|
||||||
<Button variant="ghost" onClick={() => setEditingEmployeesAssignment(null)}>Cancel</Button>
|
|
||||||
<Button onClick={handleSaveEmployees}>Save Changes</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
|
|
||||||
{/* Status Update Dialog */}
|
|
||||||
<Dialog open={!!updatingStatusAssignment} onOpenChange={(open) => !open && setUpdatingStatusAssignment(null)}>
|
|
||||||
<DialogContent className="max-w-md">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>Update Status</DialogTitle>
|
|
||||||
<DialogDescription>
|
|
||||||
Update the current status for <strong>{updatingStatusAssignment?.name}</strong>
|
|
||||||
</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</Label>
|
|
||||||
<div className="relative">
|
|
||||||
<Input
|
|
||||||
type="date"
|
|
||||||
value={statusForm.date}
|
|
||||||
onChange={(e) => setStatusForm({ ...statusForm, date: e.target.value })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>Note / Remarks</Label>
|
|
||||||
<Textarea
|
|
||||||
placeholder="Add a note about 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={() => setUpdatingStatusAssignment(null)}>Cancel</Button>
|
|
||||||
<Button onClick={handleSaveStatus}>Update Status</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</motion.div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,420 +0,0 @@
|
|||||||
"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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,503 +0,0 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import { motion, AnimatePresence } from 'motion/react';
|
|
||||||
import {
|
|
||||||
ArrowLeft, ArrowRight, Save, Briefcase, Clock, Search, Check
|
|
||||||
} from 'lucide-react';
|
|
||||||
import { useState, useMemo, use } from 'react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { Separator } from '@/components/ui/separator';
|
|
||||||
import {
|
|
||||||
Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList,
|
|
||||||
} from '@/components/ui/command';
|
|
||||||
import {
|
|
||||||
Popover, PopoverContent, PopoverTrigger,
|
|
||||||
} from '@/components/ui/popover';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { useAppState } from '@/hooks/useDummyTaskData';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import { IProjectType } from '../../../types';
|
|
||||||
import { DatePicker } from '@/components/ui/datepicker';
|
|
||||||
|
|
||||||
type IStep = 'type' | 'details' | 'work-orders' | 'review';
|
|
||||||
|
|
||||||
type Props = {
|
|
||||||
params: Promise<{ client_id: string | undefined }>
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function CreateAssignment({ params }: Props) {
|
|
||||||
const { clients, assignments, addAssignment } = useAppState();
|
|
||||||
const router = useRouter()
|
|
||||||
// const { id } = await params;
|
|
||||||
const { client_id: clientId } = use(params);
|
|
||||||
|
|
||||||
// Form State
|
|
||||||
const [type, setType] = useState<IProjectType>('Project');
|
|
||||||
const [name, setName] = useState('');
|
|
||||||
const [description, setDescription] = useState('');
|
|
||||||
const [code, setCode] = useState('');
|
|
||||||
const [year, setYear] = useState(new Date().getFullYear().toString());
|
|
||||||
const [startDate, setStartDate] = useState<Date | undefined>();
|
|
||||||
const [endDate, setEndDate] = useState<Date | undefined>();
|
|
||||||
const [workOrder, setWorkOrder] = useState({
|
|
||||||
name: '',
|
|
||||||
description: '',
|
|
||||||
code: '',
|
|
||||||
startDate: new Date(),
|
|
||||||
endDate: new Date()
|
|
||||||
});
|
|
||||||
|
|
||||||
// Autocomplete state for existing projects
|
|
||||||
const [openProjectSearch, setOpenProjectSearch] = useState(false);
|
|
||||||
|
|
||||||
|
|
||||||
const [step, setStep] = useState<IStep>('type');
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
|
|
||||||
|
|
||||||
const existingProjects = useMemo(() => {
|
|
||||||
const projects = assignments.filter(a => a.type === 'Project');
|
|
||||||
// Unique projects by name
|
|
||||||
const unique: Record<string, typeof projects[0]> = {};
|
|
||||||
projects.forEach(p => {
|
|
||||||
if (!unique[p.name]) unique[p.name] = p;
|
|
||||||
});
|
|
||||||
return Object.values(unique);
|
|
||||||
}, [assignments]);
|
|
||||||
|
|
||||||
const currentClient = clients.find(c => c.id === clientId);
|
|
||||||
|
|
||||||
const handleNext = () => {
|
|
||||||
if (step === 'type') setStep('details');
|
|
||||||
else if (step === 'details') {
|
|
||||||
if (type === 'Project') setStep('work-orders');
|
|
||||||
else setStep('review');
|
|
||||||
}
|
|
||||||
else if (step === 'work-orders') setStep('review');
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBack = () => {
|
|
||||||
if (step === 'details') setStep('type');
|
|
||||||
else if (step === 'work-orders') setStep('details');
|
|
||||||
else if (step === 'review') {
|
|
||||||
if (type === 'Project') setStep('work-orders');
|
|
||||||
else setStep('details');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSave = async () => {
|
|
||||||
setLoading(true);
|
|
||||||
const assignmentId = Math.random().toString(36).substr(2, 9);
|
|
||||||
|
|
||||||
const newAssignment = {
|
|
||||||
id: assignmentId,
|
|
||||||
clientId,
|
|
||||||
type,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
code,
|
|
||||||
year,
|
|
||||||
startDate,
|
|
||||||
endDate,
|
|
||||||
status: 'Active' as const,
|
|
||||||
statusHistory: [{
|
|
||||||
id: Math.random().toString(36).substr(2, 9),
|
|
||||||
status: 'Active',
|
|
||||||
date: new Date().toISOString().split('T')[0],
|
|
||||||
note: 'Initial assignment creation',
|
|
||||||
createdAt: new Date().toISOString()
|
|
||||||
}],
|
|
||||||
createdAt: new Date().toISOString(),
|
|
||||||
workOrders: type === 'Project' ? [{
|
|
||||||
id: Math.random().toString(36).substr(2, 9),
|
|
||||||
projectId: assignmentId,
|
|
||||||
name: workOrder.name,
|
|
||||||
description: workOrder.description,
|
|
||||||
code: workOrder.code,
|
|
||||||
startDate: workOrder.startDate,
|
|
||||||
endDate: workOrder.endDate,
|
|
||||||
status: 'Active' as const,
|
|
||||||
statusHistory: [{
|
|
||||||
id: Math.random().toString(36).substr(2, 9),
|
|
||||||
status: 'Active',
|
|
||||||
date: new Date().toISOString().split('T')[0],
|
|
||||||
note: 'Initial work order creation',
|
|
||||||
createdAt: new Date().toISOString()
|
|
||||||
}],
|
|
||||||
createdAt: new Date().toISOString(),
|
|
||||||
}] : [],
|
|
||||||
assignedEmployees: [], // Initialized as empty
|
|
||||||
};
|
|
||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
||||||
addAssignment(newAssignment);
|
|
||||||
|
|
||||||
setLoading(false);
|
|
||||||
toast.success(`${type} created successfully`);
|
|
||||||
router.replace(`/task/client-detail/${clientId}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
const steps: { id: IStep; label: string }[] = [
|
|
||||||
{ id: 'type', label: 'Type' },
|
|
||||||
{ id: 'details', label: 'Details' },
|
|
||||||
...(type === 'Project' ? [{ id: 'work-orders' as IStep, label: 'Work Orders' }] : []),
|
|
||||||
{ id: 'review', label: 'Review' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const currentStepIndex = steps.findIndex(s => s.id === step);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div className="max-w-4xl mx-auto space-y-8 p-6 sm:p-8 pt-6 pb-20">
|
|
||||||
<div className="flex items-center justify-between">
|
|
||||||
<div className="flex items-center gap-4">
|
|
||||||
<Button variant="ghost" size="icon" onClick={() => router.back()}>
|
|
||||||
<ArrowLeft className="w-5 h-5" />
|
|
||||||
</Button>
|
|
||||||
<div>
|
|
||||||
<h1 className="text-3xl font-bold">Create Project Assignment</h1>
|
|
||||||
<p className="text-muted-foreground">
|
|
||||||
{currentClient ? `For ${currentClient.name}` : 'Assign a new project or IM to a client'}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Stepper */}
|
|
||||||
<div className="flex items-center justify-between px-2">
|
|
||||||
{steps.map((s, i) => (
|
|
||||||
<div key={s.id} className="flex items-center flex-1 last:flex-none">
|
|
||||||
<div className="flex flex-col items-center gap-2">
|
|
||||||
<div className={cn(
|
|
||||||
"w-10 h-10 rounded-full flex items-center justify-center border-2 transition-all duration-300",
|
|
||||||
i <= currentStepIndex ? "bg-zinc-900 dark:bg-zinc-100 border-primary text-secondary" : "border-border text-muted-foreground"
|
|
||||||
)}>
|
|
||||||
{i < currentStepIndex ? <Check className="w-5 h-5" /> : <span>{i + 1}</span>}
|
|
||||||
</div>
|
|
||||||
<span className={cn(
|
|
||||||
"text-xs font-medium hidden md:block",
|
|
||||||
i <= currentStepIndex ? "text-primary" : "text-muted-foreground"
|
|
||||||
)}>{s.label}</span>
|
|
||||||
</div>
|
|
||||||
{i < steps.length - 1 && (
|
|
||||||
<div className={cn(
|
|
||||||
"h-0.5 flex-1 mx-4 transition-all duration-500",
|
|
||||||
i < currentStepIndex ? "bg-primary" : "bg-border"
|
|
||||||
)} />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<AnimatePresence mode="wait">
|
|
||||||
<motion.div
|
|
||||||
key={step}
|
|
||||||
initial={{ opacity: 0, x: 20 }}
|
|
||||||
animate={{ opacity: 1, x: 0 }}
|
|
||||||
exit={{ opacity: 0, x: -20 }}
|
|
||||||
transition={{ duration: 0.3 }}
|
|
||||||
>
|
|
||||||
{step === 'type' && (
|
|
||||||
<div className="grid md:grid-cols-2 gap-6">
|
|
||||||
<Card
|
|
||||||
className={cn(
|
|
||||||
"cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400",
|
|
||||||
type === 'Project' ? "border-his ring-2 ring-his/10 dark:ring-his" : ""
|
|
||||||
)}
|
|
||||||
onClick={() => setType('Project')}
|
|
||||||
>
|
|
||||||
<CardContent className="p-8 flex flex-col items-center text-center space-y-4">
|
|
||||||
<div className="w-16 h-16 rounded-2xl bg-orange-500/10 text-orange-500 flex items-center justify-center">
|
|
||||||
<Briefcase className="w-8 h-8" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 className="text-xl font-bold">Project</h3>
|
|
||||||
<p className="text-muted-foreground text-sm mt-2">
|
|
||||||
Standard project assignment. Requires Work Orders and detailed planning.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card
|
|
||||||
className={cn(
|
|
||||||
"cursor-pointer transition-all hover:border-his dark:hover:border-his duration-400",
|
|
||||||
type === 'IM' ? "border-his ring-2 ring-his/10 dark:ring-his" : ""
|
|
||||||
)}
|
|
||||||
onClick={() => setType('IM')}
|
|
||||||
>
|
|
||||||
<CardContent className="p-8 flex flex-col items-center text-center space-y-4">
|
|
||||||
<div className="w-16 h-16 rounded-2xl bg-purple-500/10 text-purple-500 flex items-center justify-center">
|
|
||||||
<Clock className="w-8 h-8" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 className="text-xl font-bold">Internal Memo (IM)</h3>
|
|
||||||
<p className="text-muted-foreground text-sm mt-2">
|
|
||||||
Used for Proof of Concept (PoC) stages. Can be converted to a Project later.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{step === 'details' && (
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>{type} Details</CardTitle>
|
|
||||||
<CardDescription>Provide the basic information for this assignment.</CardDescription>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="space-y-6">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>Assignment Name</Label>
|
|
||||||
<div className="flex gap-2">
|
|
||||||
<div className="flex-1 relative">
|
|
||||||
<Input
|
|
||||||
placeholder={type === 'Project' ? "Project Name" : "IM Name"}
|
|
||||||
value={name}
|
|
||||||
onChange={(e) => setName(e.target.value)}
|
|
||||||
/>
|
|
||||||
{type === 'Project' && (
|
|
||||||
<div className="absolute right-2 top-1/2 -translate-y-1/2">
|
|
||||||
<Popover open={openProjectSearch} onOpenChange={setOpenProjectSearch}>
|
|
||||||
<PopoverTrigger asChild>
|
|
||||||
<Button variant="ghost" size="sm" className="h-7 px-2 text-xs">
|
|
||||||
<Search className="w-3 h-3 mr-1" />
|
|
||||||
Existing
|
|
||||||
</Button>
|
|
||||||
</PopoverTrigger>
|
|
||||||
<PopoverContent className="p-0 w-[300px]" align="end">
|
|
||||||
<Command>
|
|
||||||
<CommandInput placeholder="Search existing projects..." />
|
|
||||||
<CommandList>
|
|
||||||
<CommandEmpty>No projects found.</CommandEmpty>
|
|
||||||
<CommandGroup heading="Recent Projects">
|
|
||||||
{existingProjects.map(p => (
|
|
||||||
<CommandItem
|
|
||||||
key={p.id}
|
|
||||||
onSelect={() => {
|
|
||||||
setName(p.name);
|
|
||||||
setDescription(p.description);
|
|
||||||
setOpenProjectSearch(false);
|
|
||||||
toast.info(`Autofilled details from ${p.name}`);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Check className={cn("mr-2 h-4 w-4", name === p.name ? "opacity-100" : "opacity-0")} />
|
|
||||||
{p.name}
|
|
||||||
</CommandItem>
|
|
||||||
))}
|
|
||||||
</CommandGroup>
|
|
||||||
</CommandList>
|
|
||||||
</Command>
|
|
||||||
</PopoverContent>
|
|
||||||
</Popover>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid md:grid-cols-2 gap-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>Project Code</Label>
|
|
||||||
<Input
|
|
||||||
placeholder="e.g. 24016"
|
|
||||||
value={code}
|
|
||||||
onChange={(e) => setCode(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>Project Year</Label>
|
|
||||||
<Input
|
|
||||||
placeholder="e.g. 2024"
|
|
||||||
value={year}
|
|
||||||
onChange={(e) => setYear(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid md:grid-cols-2 gap-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>Start Date</Label>
|
|
||||||
<DatePicker date={startDate} setDate={setStartDate} />
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>End Date</Label>
|
|
||||||
<DatePicker date={endDate} setDate={setEndDate} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>Description</Label>
|
|
||||||
<Textarea
|
|
||||||
placeholder="Describe the scope of this assignment..."
|
|
||||||
className="min-h-[120px]"
|
|
||||||
value={description}
|
|
||||||
onChange={(e) => setDescription(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{step === 'work-orders' && (
|
|
||||||
<div className="space-y-6">
|
|
||||||
<div>
|
|
||||||
<h2 className="text-2xl font-bold">Work Order</h2>
|
|
||||||
<p className="text-muted-foreground">Define the initial task for this project.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Card>
|
|
||||||
<CardContent className="p-6 space-y-4">
|
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>WO Name</Label>
|
|
||||||
<Input
|
|
||||||
placeholder="e.g. Initial Site Survey"
|
|
||||||
value={workOrder.name}
|
|
||||||
onChange={(e) => setWorkOrder({ ...workOrder, name: e.target.value })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>WO Code</Label>
|
|
||||||
<Input
|
|
||||||
placeholder="e.g. WO-24016"
|
|
||||||
value={workOrder.code}
|
|
||||||
onChange={(e) => setWorkOrder({ ...workOrder, code: e.target.value })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>WO Start Date</Label>
|
|
||||||
<DatePicker date={workOrder.startDate} setDate={(val) => setWorkOrder({ ...workOrder, startDate: val! })} />
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>WO End Date</Label>
|
|
||||||
<DatePicker date={workOrder.endDate} setDate={(val) => setWorkOrder({ ...workOrder, endDate: val! })} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>WO Description</Label>
|
|
||||||
<Input
|
|
||||||
placeholder="Briefly describe the task..."
|
|
||||||
value={workOrder.description}
|
|
||||||
onChange={(e) => setWorkOrder({ ...workOrder, description: e.target.value })}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{step === 'review' && (
|
|
||||||
<div className="space-y-6">
|
|
||||||
<div>
|
|
||||||
<h2 className="text-2xl font-bold">Review Assignment</h2>
|
|
||||||
<p className="text-muted-foreground">Double check everything before saving.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid gap-6">
|
|
||||||
<Card>
|
|
||||||
<CardHeader>
|
|
||||||
<CardTitle>Overview</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent className="space-y-6">
|
|
||||||
<div className="grid grid-cols-2 gap-4">
|
|
||||||
<div>
|
|
||||||
<Label className="text-xs text-muted-foreground uppercase">Type</Label>
|
|
||||||
<div className="mt-1">
|
|
||||||
<Badge variant={type === 'Project' ? 'default' : 'secondary'}>{type}</Badge>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label className="text-xs text-muted-foreground uppercase">Client</Label>
|
|
||||||
<p className="font-medium mt-1">{currentClient?.name}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label className="text-xs text-muted-foreground uppercase">Name</Label>
|
|
||||||
<p className="text-xl font-bold mt-1">{name || 'Untitled Assignment'}</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Label className="text-xs text-muted-foreground uppercase">Description</Label>
|
|
||||||
<p className="text-muted-foreground mt-1">{description || 'No description provided.'}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{type === 'Project' && workOrder.name && (
|
|
||||||
<>
|
|
||||||
<Separator />
|
|
||||||
<div>
|
|
||||||
<Label className="text-xs text-muted-foreground uppercase mb-3 block">Work Order</Label>
|
|
||||||
<div className="flex items-center gap-3 p-2 bg-accent/30 rounded-md">
|
|
||||||
<div className="w-6 h-6 rounded-full bg-primary/10 text-primary flex items-center justify-center text-[10px] font-bold">
|
|
||||||
1
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="text-sm font-medium">{workOrder.name}</p>
|
|
||||||
<p className="text-xs text-muted-foreground">{workOrder.description}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
<p className="text-sm text-muted-foreground italic text-center">
|
|
||||||
Note: Employees can be assigned after the assignment is created.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</motion.div>
|
|
||||||
</AnimatePresence>
|
|
||||||
|
|
||||||
{/* Navigation Buttons */}
|
|
||||||
<div className="fixed bottom-0 left-0 right-0 p-6 bg-background/80 backdrop-blur-md border-t border-border flex justify-between items-center z-50">
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
onClick={handleBack}
|
|
||||||
disabled={step === 'type'}
|
|
||||||
>
|
|
||||||
Back
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<div className="flex gap-4">
|
|
||||||
{step !== 'review' ?
|
|
||||||
<Button
|
|
||||||
className="gap-2"
|
|
||||||
onClick={handleNext}
|
|
||||||
disabled={
|
|
||||||
(step === 'details' && (!name || !clientId)) ||
|
|
||||||
(step === 'type' && !type)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Next Step
|
|
||||||
<ArrowRight className="w-4 h-4" />
|
|
||||||
</Button>
|
|
||||||
:
|
|
||||||
<Button
|
|
||||||
className="gap-2"
|
|
||||||
onClick={handleSave}
|
|
||||||
disabled={loading}
|
|
||||||
>
|
|
||||||
{loading ? 'Saving...' : (
|
|
||||||
<>
|
|
||||||
<Save className="w-4 h-4" />
|
|
||||||
Save Assignment
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -23,7 +23,6 @@ import FormEndUser from './FormEndUser';
|
|||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
name: Yup.string().required(),
|
name: Yup.string().required(),
|
||||||
end_user_id: Yup.number().required(),
|
end_user_id: Yup.number().required(),
|
||||||
imageUrl: Yup.string().optional().default('')
|
|
||||||
});
|
});
|
||||||
|
|
||||||
type FormDataType = Yup.InferType<typeof validationSchema>;
|
type FormDataType = Yup.InferType<typeof validationSchema>;
|
||||||
@@ -75,7 +74,6 @@ const FormClient: FC<Props> = ({ data, onSuccess, onCancel }) => {
|
|||||||
defaultValues: {
|
defaultValues: {
|
||||||
"name": data?.name || '',
|
"name": data?.name || '',
|
||||||
"end_user_id": data?.end_user_id || undefined,
|
"end_user_id": data?.end_user_id || undefined,
|
||||||
'imageUrl': data?.imageUrl || ''
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,339 +0,0 @@
|
|||||||
"use client"
|
|
||||||
|
|
||||||
import { motion } from 'motion/react';
|
|
||||||
import { Plus, Search, MoreHorizontal, ExternalLink, Users, LayoutGrid, List } from 'lucide-react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import { Card, CardContent } from '@/components/ui/card';
|
|
||||||
import {
|
|
||||||
DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,
|
|
||||||
} from '@/components/ui/dropdown-menu';
|
|
||||||
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|
||||||
import {
|
|
||||||
Table, TableBody, TableCell, TableHead, TableHeader, TableRow,
|
|
||||||
} from '@/components/ui/table';
|
|
||||||
import {
|
|
||||||
Tooltip, TooltipContent, TooltipTrigger,
|
|
||||||
} from '@/components/ui/tooltip';
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import { useAppState } from '@/hooks/useDummyTaskData';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import { LazyImage } from '@/components/ui/lazy-image';
|
|
||||||
import { DUMMY_EMPLOYEES, IClient } from './types';
|
|
||||||
import ClientForm from './component/FormClient';
|
|
||||||
|
|
||||||
export default function Clients() {
|
|
||||||
const [search, setSearch] = useState('');
|
|
||||||
const [view, setView] = useState<'grid' | 'table'>('grid');
|
|
||||||
const [selectedData, setSelectedData] = useState<IClient | undefined>()
|
|
||||||
const [showForm, setShowForm] = useState(false)
|
|
||||||
|
|
||||||
const { clients, assignments } = useAppState();
|
|
||||||
|
|
||||||
const filteredClients = clients.filter((c) =>
|
|
||||||
c.name.toLowerCase().includes(search.toLowerCase()) ||
|
|
||||||
c.endUser.toLowerCase().includes(search.toLowerCase())
|
|
||||||
);
|
|
||||||
|
|
||||||
// Flatten data for table view
|
|
||||||
const masterData = assignments.flatMap((assignment: any) => {
|
|
||||||
const client = clients.find(c => c.id === assignment.clientId);
|
|
||||||
if (!client) return [];
|
|
||||||
|
|
||||||
// If no work orders, still show the assignment?
|
|
||||||
// The user image shows WO details, so usually it's WO based.
|
|
||||||
if (assignment.workOrder) {
|
|
||||||
return [{
|
|
||||||
client,
|
|
||||||
assignment,
|
|
||||||
wo: null
|
|
||||||
}];
|
|
||||||
}
|
|
||||||
|
|
||||||
return assignment.workOrder.map((wo: any) => ({
|
|
||||||
client,
|
|
||||||
assignment,
|
|
||||||
wo
|
|
||||||
}));
|
|
||||||
}).filter((item: any) =>
|
|
||||||
item.client.name.toLowerCase().includes(search.toLowerCase()) ||
|
|
||||||
item.assignment.name.toLowerCase().includes(search.toLowerCase()) ||
|
|
||||||
(item.wo?.name.toLowerCase().includes(search.toLowerCase()) ?? false)
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleClose = () => {
|
|
||||||
setSelectedData(undefined)
|
|
||||||
setShowForm(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<motion.div
|
|
||||||
initial={{ opacity: 0, x: 20 }}
|
|
||||||
animate={{ opacity: 1, x: 0 }}
|
|
||||||
exit={{ opacity: 0, x: -20 }}
|
|
||||||
className="flex-1 space-y-8 p-6 sm:p-8 pt-6"
|
|
||||||
>
|
|
||||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
|
||||||
<div>
|
|
||||||
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">My Task & Projects</h1>
|
|
||||||
<p className="text-xs md:text-base text-muted-foreground w-full lg:w-1/2 xl:w-3/4 mt-2">Something that can be done at any time is often done at no time. Do it now, or decide when you'll do it.</p>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<Tabs value={view} onValueChange={(v) => setView(v as 'grid' | 'table')} className="w-auto">
|
|
||||||
<TabsList>
|
|
||||||
<TabsTrigger value="grid" className="gap-2">
|
|
||||||
<LayoutGrid className="w-4 h-4" />
|
|
||||||
Grid
|
|
||||||
</TabsTrigger>
|
|
||||||
<TabsTrigger value="table" className="gap-2">
|
|
||||||
<List className="w-4 h-4" />
|
|
||||||
Table
|
|
||||||
</TabsTrigger>
|
|
||||||
</TabsList>
|
|
||||||
</Tabs>
|
|
||||||
<Button className="gap-2" onClick={() => setShowForm(true)}><Plus className="w-4 h-4" />Add Client</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="relative">
|
|
||||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
|
||||||
<Input
|
|
||||||
placeholder="Search clients, projects, or work orders..."
|
|
||||||
className="pl-10"
|
|
||||||
value={search}
|
|
||||||
onChange={(e) => setSearch(e.target.value)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{view === 'grid' ? (
|
|
||||||
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
|
||||||
{filteredClients.map((client, i) => {
|
|
||||||
const clientAssignments = assignments.filter(a => a.clientId === client.id);
|
|
||||||
const imCount = clientAssignments.filter(a => a.type === 'IM').length;
|
|
||||||
const projectCount = clientAssignments.filter(a => a.type === 'Project').length;
|
|
||||||
// const woCount = clientAssignments.reduce((acc, a) => acc + a.workOrders.length, 0);
|
|
||||||
const woCount = 1
|
|
||||||
const assignedEmployeeIds = Array.from(new Set(clientAssignments.flatMap(a => a.assignedEmployees)));
|
|
||||||
|
|
||||||
return (
|
|
||||||
<motion.div
|
|
||||||
key={client.id}
|
|
||||||
initial={{ opacity: 0, scale: 0.95 }}
|
|
||||||
animate={{ opacity: 1, scale: 1 }}
|
|
||||||
transition={{ delay: i * 0.05 }}
|
|
||||||
className="h-full"
|
|
||||||
>
|
|
||||||
<Card className="h-full group overflow-hidden hover:shadow-lg transition-all duration-300 border-primary/5 hover:border-primary/20 flex flex-col py-0">
|
|
||||||
<CardContent className="p-0 flex flex-col h-full">
|
|
||||||
<div className="relative h-32 bg-accent/50 overflow-hidden">
|
|
||||||
<LazyImage
|
|
||||||
src={client.imageUrl}
|
|
||||||
alt={client.name}
|
|
||||||
className="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500"
|
|
||||||
/>
|
|
||||||
<div className="absolute inset-0 bg-linear-to-t from-black/80 via-black/40 to-transparent" />
|
|
||||||
<div className="absolute bottom-4 left-4 right-4 flex items-end justify-between">
|
|
||||||
<div className="text-white">
|
|
||||||
<h3 className="font-bold text-lg leading-tight">{client.name}</h3>
|
|
||||||
<p className="text-xs opacity-80">{client.endUser}</p>
|
|
||||||
</div>
|
|
||||||
<Link href={`/task/client-detail/${client.id}`}>
|
|
||||||
<Button size="icon" variant="secondary" className="h-8 w-8 rounded-full opacity-0 group-hover:opacity-100 transition-opacity">
|
|
||||||
<ExternalLink className="w-4 h-4" />
|
|
||||||
</Button>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="p-5 flex flex-col flex-1 justify-between gap-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
{/* <p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
|
||||||
Currently managing a portfolio of <span className="font-bold text-foreground">{projectCount} projects</span> and <span className="font-bold text-foreground">{imCount} internal memos</span>.
|
|
||||||
A dedicated team of <span className="font-bold text-foreground">{assignedEmployeeIds.length} experts</span> is handling <span className="font-bold text-foreground">{woCount} work orders</span> to ensure successful delivery for <span className="italic">{client.endUser}</span>.
|
|
||||||
</p> */}
|
|
||||||
<p className="text-sm leading-relaxed text-muted-foreground line-clamp-3 h-16">
|
|
||||||
{projectCount === 0 && imCount === 0 && woCount === 0 ?
|
|
||||||
"No active projects, internal memos, or work orders recorded for this client yet."
|
|
||||||
:
|
|
||||||
<>
|
|
||||||
{(projectCount > 0 || imCount > 0) && (
|
|
||||||
<>
|
|
||||||
Currently managing a portfolio of{" "}
|
|
||||||
{projectCount > 0 &&
|
|
||||||
<span className="font-bold text-foreground">{projectCount} project{projectCount > 1 ? 's' : ''}</span>
|
|
||||||
}
|
|
||||||
{projectCount > 0 && imCount > 0 && " and "}
|
|
||||||
{imCount > 0 &&
|
|
||||||
<span className="font-bold text-foreground">{imCount} internal memo{imCount > 1 ? 's' : ''}</span>
|
|
||||||
}
|
|
||||||
.{" "}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{woCount > 0 && (
|
|
||||||
<>
|
|
||||||
A dedicated team of{" "}
|
|
||||||
<span className="font-bold text-foreground">{assignedEmployeeIds.length} experts</span> is handling{" "}
|
|
||||||
<span className="font-bold text-foreground">{woCount} work order{woCount > 1 ? 's' : ''}</span>{" "}to ensure successful delivery for <span className="italic">{client.endUser}</span>.
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center justify-between pt-4 pb-2 border-t border-border">
|
|
||||||
<div className="flex flex-col gap-1">
|
|
||||||
<span className="text-[10px] uppercase tracking-wider font-semibold text-muted-foreground">Assigned Team</span>
|
|
||||||
<div className="flex -space-x-2 overflow-hidden">
|
|
||||||
{assignedEmployeeIds.slice(0, 5).map((empId) => {
|
|
||||||
const emp = DUMMY_EMPLOYEES.find(e => e.id === empId);
|
|
||||||
return (
|
|
||||||
<div key={empId}>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<LazyImage
|
|
||||||
className="inline-block h-8 w-8 rounded-full ring-2 ring-background object-cover"
|
|
||||||
src={emp?.avatar!}
|
|
||||||
alt={emp?.name!}
|
|
||||||
/>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent>
|
|
||||||
<p className="text-xs font-bold">{emp?.name}</p>
|
|
||||||
<p className="text-[10px] opacity-80">{emp?.role}</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
{assignedEmployeeIds.length > 5 && (
|
|
||||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-accent ring-2 ring-background text-[10px] font-bold">
|
|
||||||
+{assignedEmployeeIds.length - 5}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{assignedEmployeeIds.length === 0 && (
|
|
||||||
<span className="text-[10px] text-muted-foreground italic">No team assigned</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-2 self-end">
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button variant="ghost" size="icon" className="h-8 w-8">
|
|
||||||
<MoreHorizontal className="w-4 h-4" />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end">
|
|
||||||
<DropdownMenuItem asChild>
|
|
||||||
<Link href={`/task/client-detail/${client.id}`}>View Client Detail</Link>
|
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem onSelect={() => { setShowForm(true); setSelectedData(client) }}>Edit Client</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem className="text-destructive">Delete Client</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</motion.div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Card className="overflow-hidden">
|
|
||||||
<div className="overflow-x-auto">
|
|
||||||
<Table>
|
|
||||||
<TableHeader className="bg-accent/50">
|
|
||||||
<TableRow>
|
|
||||||
<TableHead className="min-w-[150px]">Client</TableHead>
|
|
||||||
<TableHead className="min-w-[120px]">End User</TableHead>
|
|
||||||
<TableHead className="min-w-[200px]">Project Name</TableHead>
|
|
||||||
<TableHead>Project Code</TableHead>
|
|
||||||
<TableHead className="min-w-[200px]">Description</TableHead>
|
|
||||||
<TableHead>Year</TableHead>
|
|
||||||
<TableHead>Proj Start</TableHead>
|
|
||||||
<TableHead>Proj End</TableHead>
|
|
||||||
<TableHead className="min-w-[180px]">Work Order</TableHead>
|
|
||||||
<TableHead>WO Code</TableHead>
|
|
||||||
<TableHead>WO Start</TableHead>
|
|
||||||
<TableHead>WO End</TableHead>
|
|
||||||
<TableHead>Last Status</TableHead>
|
|
||||||
<TableHead>Date Status Changed</TableHead>
|
|
||||||
<TableHead className="min-w-[200px]">Status Remarks</TableHead>
|
|
||||||
</TableRow>
|
|
||||||
</TableHeader>
|
|
||||||
<TableBody>
|
|
||||||
{masterData.map((item, idx) => {
|
|
||||||
const { client, assignment, wo } = item;
|
|
||||||
const latestStatus = wo?.statusHistory?.[0] || assignment.statusHistory?.[0];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TableRow key={`${assignment.id}-${wo?.id || idx}`} className="hover:bg-accent/30">
|
|
||||||
<TableCell className="font-bold text-primary">{client.name}</TableCell>
|
|
||||||
<TableCell>{client.endUser}</TableCell>
|
|
||||||
<TableCell className="font-medium">
|
|
||||||
<Link href={`/assignments/${assignment.id}`} className="hover:underline text-blue-600 dark:text-blue-400">
|
|
||||||
{assignment.name}
|
|
||||||
</Link>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="font-mono text-xs">{assignment.code || '-'}</TableCell>
|
|
||||||
<TableCell className="max-w-[250px] truncate text-xs" title={assignment.description}>
|
|
||||||
{assignment.description}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>{assignment.year || '-'}</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap text-xs">
|
|
||||||
{assignment.startDate ? new Date(assignment.startDate).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap text-xs">
|
|
||||||
{assignment.endDate ? new Date(assignment.endDate).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="font-medium">{wo?.name || '-'}</TableCell>
|
|
||||||
<TableCell className="font-mono text-xs">{wo?.code || '-'}</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap text-xs">
|
|
||||||
{wo?.startDate ? new Date(wo.startDate).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap text-xs">
|
|
||||||
{wo?.endDate ? new Date(wo.endDate).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell>
|
|
||||||
<Badge variant="outline" className={cn(
|
|
||||||
"text-[10px] px-2 py-0 h-5",
|
|
||||||
(wo?.status || assignment.status) === 'Active' ? 'text-green-600 border-green-200 bg-green-50' :
|
|
||||||
(wo?.status || assignment.status) === 'Completed' ? 'text-blue-600 border-blue-200 bg-blue-50' :
|
|
||||||
'text-orange-600 border-orange-200 bg-orange-50'
|
|
||||||
)}>
|
|
||||||
{wo?.status || assignment.status}
|
|
||||||
</Badge>
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="whitespace-nowrap text-xs">
|
|
||||||
{latestStatus ? new Date(latestStatus.date).toLocaleDateString() : '-'}
|
|
||||||
</TableCell>
|
|
||||||
<TableCell className="text-xs italic text-muted-foreground">
|
|
||||||
{latestStatus?.note || '-'}
|
|
||||||
</TableCell>
|
|
||||||
</TableRow>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</TableBody>
|
|
||||||
</Table>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{(view === 'grid' ? filteredClients : masterData).length === 0 && (
|
|
||||||
<div className="py-12 text-center border-2 border-dashed rounded-xl">
|
|
||||||
<Users className="w-12 h-12 mx-auto text-muted-foreground mb-4 opacity-20" />
|
|
||||||
<h3 className="text-lg font-medium">No data found</h3>
|
|
||||||
<p className="text-muted-foreground">Try adjusting your search or add new entries.</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</motion.div>
|
|
||||||
|
|
||||||
{showForm ?
|
|
||||||
<ClientForm data={selectedData} onCancel={handleClose} onSuccess={handleClose} /> : null
|
|
||||||
}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -64,7 +64,7 @@ const DonutChart: FC<Props> = ({ data, labels, colors }) => {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
formatter: function (val: any, opts) {
|
formatter: function (val: any, opts) {
|
||||||
// console.log(opts)
|
// console.log(opts)
|
||||||
return opts.w.globals.labels[opts.seriesIndex] + ': ' + opts.w.globals.series[opts.seriesIndex]
|
return opts?.w.globals.labels[opts.seriesIndex] + ': ' + opts?.w.globals.series[opts.seriesIndex]
|
||||||
// return opts.w.globals.series[opts.seriesIndex]
|
// return opts.w.globals.series[opts.seriesIndex]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const DonutChart: FC<Props> = ({ data, labels, colors }) => {
|
|||||||
enabled: true,
|
enabled: true,
|
||||||
formatter: function (val: any, opts) {
|
formatter: function (val: any, opts) {
|
||||||
// console.log(opts)
|
// console.log(opts)
|
||||||
return opts.w.globals.labels[opts.seriesIndex] + ': ' + opts.w.globals.series[opts.seriesIndex]
|
return opts?.w.globals.labels[opts.seriesIndex] + ': ' + opts?.w.globals.series[opts.seriesIndex]
|
||||||
// return opts.w.globals.series[opts.seriesIndex]
|
// return opts.w.globals.series[opts.seriesIndex]
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ const PerformancePage: FC<Props> = async ({ params, searchParams }) => {
|
|||||||
<Suspense fallback={<LazyLoading />}>
|
<Suspense fallback={<LazyLoading />}>
|
||||||
<Header />
|
<Header />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
<div className='p-6 2xl:w-[1400px] mx-auto space-y-8'>
|
<div className='p-6 2xl:w-350 mx-auto space-y-8'>
|
||||||
<div className="flex flex-col sm:flex-row items-start justify-between space-y-2 sm:space-y-0">
|
<div className="flex flex-col sm:flex-row items-start justify-between space-y-2 sm:space-y-0">
|
||||||
<div>
|
<div>
|
||||||
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">Employee Perfomance</h1>
|
<h1 className="text-lg sm:text-3xl font-medium tracking-tight capitalize">Employee Perfomance</h1>
|
||||||
|
|||||||
@@ -1,44 +0,0 @@
|
|||||||
import { IClient, INITIAL_CLIENTS, IProjectAssignment } from '@/app/(dashboard)/task/types';
|
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
|
|
||||||
export function useAppState() {
|
|
||||||
const [clients, setClients] = useState<IClient[]>(() => {
|
|
||||||
const saved = localStorage.getItem('clients');
|
|
||||||
return saved ? JSON.parse(saved) : INITIAL_CLIENTS;
|
|
||||||
});
|
|
||||||
|
|
||||||
const [assignments, setAssignments] = useState<IProjectAssignment[]>(() => {
|
|
||||||
const saved = localStorage.getItem('assignments');
|
|
||||||
return saved ? JSON.parse(saved) : [];
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
localStorage.setItem('clients', JSON.stringify(clients));
|
|
||||||
}, [clients]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
localStorage.setItem('assignments', JSON.stringify(assignments));
|
|
||||||
}, [assignments]);
|
|
||||||
|
|
||||||
const addClient = (client: IClient) => {
|
|
||||||
setClients((prev) => [...prev, client]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const addAssignment = (assignment: IProjectAssignment) => {
|
|
||||||
setAssignments((prev) => [...prev, assignment]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const updateAssignment = (id: string, updates: Partial<IProjectAssignment>) => {
|
|
||||||
setAssignments((prev) =>
|
|
||||||
prev.map((a) => (a.id === id ? { ...a, ...updates } : a))
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
clients,
|
|
||||||
assignments,
|
|
||||||
addClient,
|
|
||||||
addAssignment,
|
|
||||||
updateAssignment,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user