From e284a7bd4c5ca24c036ceb2fcd1b416a491b4003 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Thu, 13 Jun 2024 03:50:14 +0000 Subject: [PATCH] feat: incomplete form warning (employee) --- src/pages/03_customer-management/MainPage.vue | 86 +++++++++++++++---- 1 file changed, 69 insertions(+), 17 deletions(-) diff --git a/src/pages/03_customer-management/MainPage.vue b/src/pages/03_customer-management/MainPage.vue index 4c511575..ceabce68 100644 --- a/src/pages/03_customer-management/MainPage.vue +++ b/src/pages/03_customer-management/MainPage.vue @@ -390,6 +390,19 @@ async function openDialogInputForm( if (selectorLabel.value === 'EMPLOYEE') { if (!id) return; await assignFormDataEmployee(id); + const code = currentEmployee.value?.code.split('-')[0]; + + const result = await fetchListBranch({ + includeCustomer: true, + query: code, + pageSize: 30, + }); + if (result) { + employeeStore.ownerOption = result.result.map((i) => ({ + label: i.code, + value: i.id, + })); + } dialogEmployee.value = true; } } @@ -587,17 +600,20 @@ async function onSubmit() { } if (selectorLabel.value === 'EMPLOYEE') { - await employeeStore.create({ - ...formDataEmployee.value, - image: profileSubmit.value ? profileFile.value ?? null : null, - }); - const resultList = await employeeStore.fetchList(); - if (resultList) listEmployee.value = resultList.result; + const isOk = await checkEmployeeForm(); + if (isOk) { + await employeeStore.create({ + ...formDataEmployee.value, + image: profileSubmit.value ? profileFile.value ?? null : null, + }); + const resultList = await employeeStore.fetchList(); + if (resultList) listEmployee.value = resultList.result; - const resultStatsEmployee = await employeeStore.getStatsEmployee(); - if (resultStatsEmployee) statsEmployee.value = resultStatsEmployee; + const resultStatsEmployee = await employeeStore.getStatsEmployee(); + if (resultStatsEmployee) statsEmployee.value = resultStatsEmployee; - clearFormEmployee(); + clearFormEmployee(); + } } } @@ -670,17 +686,20 @@ async function onSubmitEdit(id: string) { } if (selectorLabel.value === 'EMPLOYEE') { - if (!formDataEmployee.value) return; + const isOk = await checkEmployeeForm(); + if (isOk) { + if (!formDataEmployee.value) return; - await employeeStore.editById(id, { - ...formDataEmployee.value, - image: profileSubmit.value ? profileFile.value ?? null : null, - }); + await employeeStore.editById(id, { + ...formDataEmployee.value, + image: profileSubmit.value ? profileFile.value ?? null : null, + }); - const resultList = await employeeStore.fetchList(); - if (resultList) listEmployee.value = resultList.result; + const resultList = await employeeStore.fetchList(); + if (resultList) listEmployee.value = resultList.result; - clearFormEmployee(); + clearFormEmployee(); + } } } @@ -893,6 +912,39 @@ async function assignFormDataEmployee(id: string) { } } +async function checkEmployeeForm() { + const formData = formDataEmployee.value; + let forget = false; + + for (const [key, val] of Object.entries(formData)) { + if (key === 'workerStatus') continue; + if (key === 'image') continue; + + if (val === '' || val === null) { + forget = true; + } + } + + if (forget) { + return await new Promise((resolve) => { + dialog({ + color: 'warning', + icon: 'mdi-alert', + title: t('warning'), + actionText: t('ok'), + persistent: true, + message: t('warningForgetInput'), + action: () => { + resolve(true); + }, + cancel: () => { + resolve(false); + }, + }); + }); + } else return true; +} + onMounted(async () => { const resultStats = await getStatsCustomer();