Compare commits
2 Commits
68644842fc
...
0f744f861b
Author | SHA1 | Date | |
---|---|---|---|
0f744f861b | |||
52320227d2 |
6227
pnpm-lock.yaml
generated
6227
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -95,29 +95,17 @@ export default function Table({ employees }: { employees: Employee[] }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (selectedIds.length === 0) {
|
|
||||||
if (!session) {
|
if (!session) {
|
||||||
alert("You must be signed in to update status.");
|
alert("You must be signed in to update status.");
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
const cur_user = employees.find(employee => employee.name === session?.user?.name);
|
// If no employee is selected and status is not empty
|
||||||
|
if (selectedIds.length === 0 && employeeStatus.trim() !== '') {
|
||||||
|
const cur_user = employees.find(employee => employee.name === session.user?.name);
|
||||||
if (cur_user) {
|
if (cur_user) {
|
||||||
await fetch('/api/v2/update_status', {
|
setSelectedIds([cur_user.id]);
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'Authorization': `Bearer ${process.env.API_KEY}`
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ employeeIds: [cur_user.id], newStatus: employeeStatus }),
|
|
||||||
});
|
|
||||||
// Optionally refresh data on the client-side after update
|
|
||||||
const updatedEmployees = await fetchEmployees();
|
|
||||||
setEmployeeData(updatedEmployees);
|
|
||||||
setSelectedIds([]);
|
|
||||||
setStatus('');
|
|
||||||
}
|
}
|
||||||
}
|
} else if (employeeStatus.trim() !== '') {
|
||||||
} else if (employeeStatus.trim() === '') {
|
|
||||||
await fetch('/api/v2/update_status', {
|
await fetch('/api/v2/update_status', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@ -126,6 +114,7 @@ export default function Table({ employees }: { employees: Employee[] }) {
|
|||||||
},
|
},
|
||||||
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);
|
||||||
|
Loading…
Reference in New Issue
Block a user