From 017c07a1cf764e756ab92d333abd713f3c6cdfb4 Mon Sep 17 00:00:00 2001 From: gibbyb Date: Sun, 21 Jul 2024 19:48:47 -0500 Subject: [PATCH] All good now --- src/components/ui/Table.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/ui/Table.tsx b/src/components/ui/Table.tsx index 269a429..773613c 100644 --- a/src/components/ui/Table.tsx +++ b/src/components/ui/Table.tsx @@ -103,7 +103,14 @@ const handleSubmit = async () => { if (selectedIds.length === 0 && employeeStatus.trim() !== '') { const cur_user = employees.find(employee => employee.name === session.user?.name); if (cur_user) { - setSelectedIds([cur_user.id]); + await fetch('/api/v2/update_status', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${process.env.API_KEY}` + }, + body: JSON.stringify({ employeeIds: [cur_user.id], newStatus: employeeStatus }), + }); } } else if (employeeStatus.trim() !== '') { await fetch('/api/v2/update_status', { @@ -114,13 +121,12 @@ const handleSubmit = async () => { }, body: JSON.stringify({ employeeIds: selectedIds, newStatus: employeeStatus }), }); - - // Optionally refresh data on the client-side after update - const updatedEmployees = await fetchEmployees(); - setEmployeeData(updatedEmployees); - setSelectedIds([]); - setStatus(''); } + // Optionally refresh data on the client-side after update + const updatedEmployees = await fetchEmployees(); + setEmployeeData(updatedEmployees); + setSelectedIds([]); + setStatus(''); }; const handleKeyPress = async (e: React.KeyboardEvent) => {