diff --git a/app/(dashboard)/components/Overview.tsx b/app/(dashboard)/components/Overview.tsx index 616e166..a99fbbf 100644 --- a/app/(dashboard)/components/Overview.tsx +++ b/app/(dashboard)/components/Overview.tsx @@ -109,7 +109,7 @@ export default function Overview() { }; return ( -
+
= ({ data }) => { } }, mounted: (chart) => { - chart?.windowResizeHandler(); + (chart as any)?.windowResizeHandler(); } }, }, @@ -99,7 +99,7 @@ const PieChart: FC = ({ data }) => { enabled: true, formatter: function (val: any, 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] }, }, @@ -135,7 +135,7 @@ const PieChart: FC = ({ data }) => { return ( <> -
+
-}; - -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(null); - const [selectedEmployeeIds, setSelectedEmployeeIds] = useState([]); - - const [updatingStatusAssignment, setUpdatingStatusAssignment] = useState(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 ( -
-

Client not found

- -
- ); - } - - return ( - -
-
- - {client.name} - -
- -

{client.name}

-

End User: {client.endUser}

-
-
-
- - - -
-
- -
-
-
-

Project Assignments

-
- setViewMode(v as 'grid' | 'table')}> - - - - - - - - - - - {clientAssignments.length} Total - -
-
- - {clientAssignments.length === 0 ? ( - - -
- -
-
-

No Project Assignments

-

- This client doesn't have any projects or internal memos yet. Create one to get started. -

-
- - - -
-
- ) : viewMode === 'grid' ? ( -
- {clientAssignments?.map((assignment) => ( - - -
-
-
- {assignment.type === 'Project' ? : } -
-
-
-

{assignment.name}

- - {assignment.type} - - - {assignment.status} - -
- - {assignment.workOrder && ( -

- WO: {assignment.workOrder.name} -

- )} - -

- {assignment.description} -

- -
-
- - - {assignment.startDate ? new Date(assignment.startDate).toLocaleDateString() : 'N/A'} - - {assignment.endDate ? new Date(assignment.endDate).toLocaleDateString() : 'N/A'} - -
-
- -
- {assignment.assignedEmployees.slice(0, 3).map(empId => { - const emp = DUMMY_EMPLOYEES.find(e => e.id === empId); - return ( -
- - - {emp?.name} - - -
-

{emp?.name}

-

{emp?.role}

-
-
-
-
- ); - })} - {assignment.assignedEmployees.length > 3 && ( -
- +{assignment.assignedEmployees.length - 3} -
- )} - {assignment.assignedEmployees.length === 0 && No employees assigned} -
-
-
-
-
- - - - - - - View Details - - Edit Assignment - handleOpenEmployeeDialog(assignment)}> - Manage Team - - Archive - - -
-
-
- ))} -
- ) : ( - -
- - - - Project Name - Project Code - Description - Year - Proj Start - Proj End - Work Order - WO Code - WO Start - WO End - Status - - - - - {clientAssignments.map((assignment) => { - const wo = assignment.workOrder; - return ( - - {assignment.name} - {assignment.code || '-'} - - {assignment.description} - - {assignment.year || '-'} - - {assignment.startDate ? new Date(assignment.startDate).toLocaleDateString() : '-'} - - - {assignment.endDate ? new Date(assignment.endDate).toLocaleDateString() : '-'} - - {wo?.name || '-'} - {wo?.code || '-'} - - {wo?.startDate ? new Date(wo.startDate).toLocaleDateString() : '-'} - - - {wo?.endDate ? new Date(wo.endDate).toLocaleDateString() : '-'} - - - - {assignment.status} - - - - - - - - - - View Details - - Edit Assignment - handleOpenEmployeeDialog(assignment)}> - Manage Team - - Archive - - - - - ); - })} - -
-
-
- )} -
- -
- - - Client Info - - -
- -

{client.name}

-
-
- -

{client.endUser}

-
- -
- -

{new Date(client?.createdAt)?.toLocaleDateString()}

-
-
-
- - - - Quick Stats - - -
- Total Projects - {clientAssignments.filter(a => a.type === 'Project').length} -
-
- Total IMs - {clientAssignments.filter(a => a.type === 'IM').length} -
-
- Total WOs - - {clientAssignments.reduce((acc, curr) => acc + curr.workOrders?.length, 0)} - -
-
-
-
-
- - {/* Employee Management Dialog */} - !open && setEditingEmployeesAssignment(null)}> - - - Manage Team - - Assign or remove employees for {editingEmployeesAssignment?.name} - - -
- {DUMMY_EMPLOYEES.map((emp) => ( -
toggleEmployee(emp.id)} - > -
- {emp.name} - {selectedEmployeeIds.includes(emp.id) && ( -
- -
- )} -
-
-

{emp.name}

-

{emp.role}

-
-
- ))} -
- - - - -
-
- - {/* Status Update Dialog */} - !open && setUpdatingStatusAssignment(null)}> - - - Update Status - - Update the current status for {updatingStatusAssignment?.name} - - -
-
- - -
-
- -
- setStatusForm({ ...statusForm, date: e.target.value })} - /> -
-
-
- -