fix: change status employee

This commit is contained in:
puriphatt 2025-07-07 11:19:57 +07:00
parent a5791a1b54
commit a59e0c5157

View file

@ -397,7 +397,11 @@ async function fetchListEmployee(opt?: {
employeeStats.value = await employeeStore.getStatsEmployee();
}
async function triggerChangeStatus(id: string, status: string) {
async function triggerChangeStatus(
id: string,
status: string,
employeeName?: string,
) {
return await new Promise((resolve, reject) => {
dialog({
color: status !== 'INACTIVE' ? 'warning' : 'info',
@ -412,7 +416,11 @@ async function triggerChangeStatus(id: string, status: string) {
: t('dialog.message.confirmChangeStatusOn'),
action: async () => {
if (currentTab.value === 'employee') {
await toggleStatusEmployee(id, status === 'INACTIVE' ? false : true)
await toggleStatusEmployee(
id,
status === 'INACTIVE' ? false : true,
employeeName,
)
.then(resolve)
.catch(reject);
} else {
@ -426,9 +434,14 @@ async function triggerChangeStatus(id: string, status: string) {
});
}
async function toggleStatusEmployee(id: string, status: boolean) {
async function toggleStatusEmployee(
id: string,
status: boolean,
employeeName: string,
) {
const res = await employeeStore.editById(id, {
status: !status ? 'ACTIVE' : 'INACTIVE',
firstNameEN: employeeName,
});
if (res && employeeFormState.value.drawerModal)
currentFromDataEmployee.value.status = res.status;
@ -1831,7 +1844,11 @@ const emptyCreateDialog = ref(false);
"
@toggle-status="
async (item: any) => {
triggerChangeStatus(item.id, item.status);
triggerChangeStatus(
item.id,
item.status,
item.firstNameEN,
);
}
"
/>
@ -4585,7 +4602,11 @@ const emptyCreateDialog = ref(false);
@update:toggle-status="
(v) => {
if (currentFromDataEmployee.id !== undefined)
triggerChangeStatus(currentFromDataEmployee.id, v);
triggerChangeStatus(
currentFromDataEmployee.id,
v,
currentFromDataEmployee.firstNameEN,
);
}
"
:active="currentFromDataEmployee.status !== 'INACTIVE'"