feat: agency attachment

This commit is contained in:
puriphatt 2024-04-19 13:54:57 +07:00
parent 28ff4d8a45
commit e923825f24
2 changed files with 130 additions and 14 deletions

View file

@ -5,7 +5,12 @@ import useUserStore from 'stores/user';
import useBranchStore from 'src/stores/branch';
import { dialog } from 'src/stores/utils';
import { User, UserCreate, UserTypeStats } from 'src/stores/user/types';
import {
User,
UserAttachmentCreate,
UserCreate,
UserTypeStats,
} from 'src/stores/user/types';
import { BranchUserStats } from 'src/stores/branch/types';
import useAddressStore from 'src/stores/address';
@ -20,7 +25,7 @@ import FormInformation from 'src/components/02_personnel-management/FormInformat
import FormPerson from 'src/components/02_personnel-management/FormPerson.vue';
import FormByType from 'src/components/02_personnel-management/FormByType.vue';
import DrawerInfo from 'src/components/DrawerInfo.vue';
import infoForm from 'src/components/02_personnel-management/infoForm.vue';
import InfoForm from 'src/components/02_personnel-management/InfoForm.vue';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
@ -61,6 +66,8 @@ const defaultFormData = {
responsibleArea: null,
username: '',
status: 'CREATED',
checkpoint: null,
checkpointEN: null,
};
const currentUser = ref<User>();
@ -83,6 +90,8 @@ const code = ref<string>();
const formDialogRef = ref();
const userStats = ref<BranchUserStats[]>();
const typeStats = ref<UserTypeStats>();
const agencyFile = ref<File[]>([]);
const agencyFileList = ref<{ name: string; url: string }[]>([]);
const formData = ref<UserCreate>({
provinceId: null,
districtId: null,
@ -190,6 +199,14 @@ async function openDialog(action?: 'FORM' | 'INFO', idEdit?: string) {
if (idEdit && userData.value) {
assignFormData(idEdit);
if (formData.value.userType === 'AGENCY') {
const result = await userStore.fetchAttachment(idEdit);
if (result) {
agencyFileList.value = result;
}
}
}
}
@ -205,6 +222,7 @@ function onClose() {
brId.value = '';
userId.value = '';
urlProfile.value = '';
agencyFile.value = [];
profileSubmit.value = false;
modal.value = false;
infoDrawer.value = false;
@ -215,8 +233,6 @@ function onClose() {
}
async function onSubmit() {
console.log('hello');
formData.value.profileImage = profileFile.value as File;
if (isEdit.value === true && userId.value) {
dialog({
@ -234,7 +250,6 @@ async function onSubmit() {
status: !statusToggle.value ? 'INACTIVE' : 'ACTIVE',
} as const;
await userStore.editById(userId.value, formDataEdit);
onClose();
if (
hqId.value &&
@ -249,12 +264,25 @@ async function onSubmit() {
);
}
if (userId.value && formDataEdit.userType === 'AGENCY') {
if (!agencyFile.value) return;
const payload: UserAttachmentCreate = {
file: agencyFile.value,
};
if (payload?.file) {
await userStore.addAttachment(userId.value, payload);
}
}
userStore.fetchList({
includeBranch: true,
query: !!inputSearch.value ? inputSearch.value : undefined,
userType: selectorLabel.value ?? undefined,
});
typeStats.value = await userStore.typeStats();
onClose();
},
});
} else {
@ -279,6 +307,19 @@ async function onSubmit() {
result.id,
);
}
if (result && formData.value.userType === 'AGENCY') {
if (!agencyFile.value) return;
const payload: UserAttachmentCreate = {
file: agencyFile.value,
};
if (payload?.file) {
await userStore.addAttachment(result.id, payload);
}
}
selectorLabel.value = formData.value.userType;
userStore.fetchList({
includeBranch: true,
@ -286,6 +327,7 @@ async function onSubmit() {
userType: selectorLabel.value ?? undefined,
});
typeStats.value = await userStore.typeStats();
onClose();
},
});
@ -364,6 +406,8 @@ async function assignFormData(idEdit: string) {
userRole: foundUser.userRole,
userType: foundUser.userType,
username: foundUser.username,
checkpoint: foundUser.checkpoint,
checkpointEN: foundUser.checkpointEN,
responsibleArea: foundUser.responsibleArea,
status: foundUser.status,
licenseExpireDate:
@ -630,7 +674,7 @@ watch(inputSearch, async () => {
:editData="() => (infoPersonCardEdit = true)"
>
<template #info>
<infoForm
<InfoForm
:readonly="!infoPersonCardEdit"
v-model:address="formData.address"
v-model:addressEN="formData.addressEN"
@ -699,9 +743,14 @@ watch(inputSearch, async () => {
v-model:sourceNationality="formData.sourceNationality"
v-model:importNationality="formData.importNationality"
v-model:trainingPlace="formData.trainingPlace"
v-model:checkpoint="formData.checkpoint"
v-model:checkpointEN="formData.checkpointEN"
v-model:agencyFile="agencyFile"
v-model:agencyFileList="agencyFileList"
v-model:userId="userId"
/>
</template>
</infoForm>
</InfoForm>
</template>
</DrawerInfo>
@ -845,6 +894,9 @@ watch(inputSearch, async () => {
v-model:sourceNationality="formData.sourceNationality"
v-model:importNationality="formData.importNationality"
v-model:trainingPlace="formData.trainingPlace"
v-model:checkpoint="formData.checkpoint"
v-model:checkpointEN="formData.checkpointEN"
v-model:agencyFile="agencyFile"
/>
</template>
</FormDialog>