All good now

This commit is contained in:
Gabriel Brown 2024-07-21 19:48:47 -05:00
parent 0f744f861b
commit 017c07a1cf

View File

@ -103,7 +103,14 @@ const handleSubmit = async () => {
if (selectedIds.length === 0 && employeeStatus.trim() !== '') { if (selectedIds.length === 0 && employeeStatus.trim() !== '') {
const cur_user = employees.find(employee => employee.name === session.user?.name); const cur_user = employees.find(employee => employee.name === session.user?.name);
if (cur_user) { 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() !== '') { } else if (employeeStatus.trim() !== '') {
await fetch('/api/v2/update_status', { await fetch('/api/v2/update_status', {
@ -114,13 +121,12 @@ const handleSubmit = async () => {
}, },
body: JSON.stringify({ employeeIds: selectedIds, newStatus: employeeStatus }), body: JSON.stringify({ employeeIds: selectedIds, newStatus: employeeStatus }),
}); });
}
// Optionally refresh data on the client-side after update // Optionally refresh data on the client-side after update
const updatedEmployees = await fetchEmployees(); const updatedEmployees = await fetchEmployees();
setEmployeeData(updatedEmployees); setEmployeeData(updatedEmployees);
setSelectedIds([]); setSelectedIds([]);
setStatus(''); setStatus('');
}
}; };
const handleKeyPress = async (e: React.KeyboardEvent<HTMLInputElement>) => { const handleKeyPress = async (e: React.KeyboardEvent<HTMLInputElement>) => {