refactor: waning young worker

This commit is contained in:
Thanaphon Frappet 2025-02-25 10:50:03 +07:00
parent 60966e0f1c
commit 33a3a929e1
2 changed files with 45 additions and 2 deletions

View file

@ -177,7 +177,7 @@ function setDefaultFormEmployee() {
namePrefix: '',
nationality: '',
gender: '',
dateOfBirth: new Date(),
dateOfBirth: null,
attachment: [],
};
@ -261,6 +261,49 @@ async function getWorkerFromCriteria(
}
watch(() => state.search, getWorkerList);
watch(
() => formDataEmployee.value.dateOfBirth,
() => {
const age = calculateAge(formDataEmployee.value.dateOfBirth, 'year');
if (formDataEmployee.value.dateOfBirth && Number(age) < 15) {
dialog({
color: 'warning',
icon: 'mdi-alert',
title: t('dialog.title.youngWorker15'),
cancelText: t('general.edit'),
persistent: true,
message: t('dialog.message.youngWorker15'),
cancel: async () => {
formDataEmployee.value.dateOfBirth = null;
return;
},
});
}
if (
formDataEmployee.value.dateOfBirth &&
Number(age) > 15 &&
Number(age) <= 18
) {
dialog({
color: 'warning',
icon: 'mdi-alert',
title: t('dialog.title.youngWorker18'),
cancelText: t('general.cancel'),
actionText: t('general.confirm'),
persistent: true,
message: t('dialog.message.youngWorker18'),
action: () => {},
cancel: async () => {
formDataEmployee.value.dateOfBirth = null;
return;
},
});
}
},
);
</script>
<template>