From 4bd2a08cb5777f748b99d336a285132d713205d3 Mon Sep 17 00:00:00 2001 From: puriphatt Date: Mon, 22 Apr 2024 10:54:32 +0700 Subject: [PATCH] feat: i18n, edit branch --- .../02_personnel-management/MainPage.vue | 67 +++++++++++++------ 1 file changed, 46 insertions(+), 21 deletions(-) diff --git a/src/pages/02_personnel-management/MainPage.vue b/src/pages/02_personnel-management/MainPage.vue index b1349157..30830668 100644 --- a/src/pages/02_personnel-management/MainPage.vue +++ b/src/pages/02_personnel-management/MainPage.vue @@ -198,6 +198,7 @@ async function openDialog(action?: 'FORM' | 'INFO', idEdit?: string) { } if (idEdit && userData.value) { + isEdit.value = true; assignFormData(idEdit); if (formData.value.userType === 'AGENCY') { @@ -239,7 +240,7 @@ async function onSubmit() { formData.value.profileImage = null; } - if (isEdit.value === true && userId.value) { + if (isEdit.value && userId.value) { dialog({ color: 'primary', icon: 'mdi-pencil-outline', @@ -262,7 +263,10 @@ async function onSubmit() { hqId.value !== currentUser.value.branch[0].id && brId.value !== currentUser.value.branch[0].id ) { - userStore.removeBranch(userId.value, currentUser.value.branch[0].id); + await branchStore.removeUser( + currentUser.value.branch[0].id, + userId.value, + ); await branchStore.addUser( !!brId.value ? brId.value : hqId.value, @@ -270,6 +274,15 @@ async function onSubmit() { ); } + if (!currentUser.value?.branch[0]) { + if (brId.value || hqId.value) { + await branchStore.addUser( + (!!brId.value ? brId.value : hqId.value)!, + userId.value, + ); + } + } + if (userId.value && formDataEdit.userType === 'AGENCY') { if (!agencyFile.value) return; const payload: UserAttachmentCreate = { @@ -433,17 +446,21 @@ async function assignFormData(idEdit: string) { ? (statusToggle.value = true) : (statusToggle.value = false); userId.value = foundUser.id; - if (foundUser.branch[0].isHeadOffice) { - hqId.value = foundUser.branch[0].id as string; - } else { - hqId.value = foundUser.branch[0].headOfficeId as string; - brId.value = foundUser.branch[0].id; + + if (foundUser.branch[0]) { + if (foundUser.branch[0].isHeadOffice) { + hqId.value = foundUser.branch[0].id as string; + } else { + hqId.value = foundUser.branch[0].headOfficeId as string; + brId.value = foundUser.branch[0].id; + } } + code.value = foundUser.code; urlProfile.value = foundUser.profileImageUrl; isEdit.value = true; profileSubmit.value = true; - await userStore.fetchBrOption(hqId.value); + hqId.value && (await userStore.fetchBrOption(hqId.value)); if (formData.value.districtId) { await adrressStore.fetchSubDistrictByProvinceId( formData.value.districtId, @@ -538,9 +555,10 @@ watch( {{ selectorLabel === '' ? '' : $t(selectorLabel) }}
@@ -639,10 +658,10 @@ watch( male: v.gender === 'male', female: v.gender === 'female', detail: [ - { label: 'ประเภท', value: $t(v.userType) }, - { label: 'โทรศัพท์', value: v.telephoneNo }, + { label: $t('personnelCardUserType'), value: $t(v.userType) }, + { label: $t('personnelCardTelephone'), value: v.telephoneNo }, { - label: 'อายุ', + label: $t('personnelCardAge'), value: userStore.calculateAge(v.birthDate as Date), }, ], @@ -697,6 +716,8 @@ watch( >