From d7e606fb16348431b89802cba806f7d2a3791149 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:32:18 +0700 Subject: [PATCH 1/2] feat: show image on upload --- src/pages/02_personnel-management/MainPage.vue | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/pages/02_personnel-management/MainPage.vue b/src/pages/02_personnel-management/MainPage.vue index ac4a37e1..1183a110 100644 --- a/src/pages/02_personnel-management/MainPage.vue +++ b/src/pages/02_personnel-management/MainPage.vue @@ -108,6 +108,18 @@ const inputFile = document.createElement('input'); inputFile.type = 'file'; inputFile.accept = 'image/*'; +const reader = new FileReader(); + +reader.addEventListener('load', () => { + if (typeof reader.result === 'string') { + urlProfile.value = reader.result; + } +}); + +watch(profileFile, () => { + if (profileFile.value) reader.readAsDataURL(profileFile.value); +}); + inputFile.addEventListener('change', (e) => { profileFile.value = (e.currentTarget as HTMLInputElement).files?.[0]; }); From fe34f018ac5cdadd4210c67330191c6795f44ccb Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Wed, 17 Apr 2024 11:34:14 +0700 Subject: [PATCH 2/2] refactor: remove keycloak id from type --- .../02_personnel-management/MainPage.vue | 23 +++---------------- src/stores/user/types.ts | 4 +--- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/pages/02_personnel-management/MainPage.vue b/src/pages/02_personnel-management/MainPage.vue index 1183a110..bcc0bd9a 100644 --- a/src/pages/02_personnel-management/MainPage.vue +++ b/src/pages/02_personnel-management/MainPage.vue @@ -52,7 +52,6 @@ const defaultFormData = { firstName: '', userRole: '', userType: '', - keycloakId: '', profileImage: null, birthDate: null, responsibleArea: '', @@ -97,7 +96,6 @@ const formData = ref({ firstName: '', userRole: '', userType: '', - keycloakId: '', profileImage: null, birthDate: null, responsibleArea: '', @@ -131,16 +129,6 @@ const selectorList = [ { label: 'AGENCY', count: 0 }, ]; -async function createKeycloak() { - const res = await api.post('/keycloak/user', { - lastName: formData.value.lastNameEN, - firstName: formData.value.firstNameEN, - password: username.value, - username: username.value, - }); - return res.data; -} - async function openDialog(idEdit?: string) { modal.value = true; userStore.userOption.brOpts = []; @@ -178,7 +166,6 @@ async function openDialog(idEdit?: string) { firstName: foundUser.firstName, userRole: foundUser.userRole, userType: foundUser.userType, - keycloakId: foundUser.keycloakId, responsibleArea: foundUser.responsibleArea, licenseExpireDate: (foundUser.licenseExpireDate && @@ -238,7 +225,6 @@ async function onSubmit() { message: 'คุณต้องการแก้ไขข้อมูล ใช่หรือไม่', action: async () => { const formDataEdit = { ...formData.value }; - delete formDataEdit.keycloakId; await userStore.editById(userId.value, formDataEdit); onClose(); userStore.fetchList({ includeBranch: true }); @@ -253,12 +239,9 @@ async function onSubmit() { persistent: true, message: 'คุณต้องการเพิ่มบุคลากร ใช่หรือไม่', action: async () => { - formData.value.keycloakId = await createKeycloak(); - if (formData.value.keycloakId) { - const result = await userStore.create(formData.value); - if (result) { - await branchStore.addUser(brId.value, result.id); - } + const result = await userStore.create(formData.value); + if (result) { + await branchStore.addUser(brId.value, result.id); } onClose(); userStore.fetchList({ includeBranch: true }); diff --git a/src/stores/user/types.ts b/src/stores/user/types.ts index 19f3381a..ec036312 100644 --- a/src/stores/user/types.ts +++ b/src/stores/user/types.ts @@ -36,7 +36,6 @@ export type User = { lastName: string; firstNameEN: string; firstName: string; - keycloakId: string; id: string; profileImageUrl: string; code: string; @@ -71,7 +70,6 @@ export type UserCreate = { firstName: string; userRole: string; userType: string; - keycloakId?: string; profileImage?: File | null; // required but not strict birthDate?: Date | null; responsibleArea: string; @@ -116,4 +114,4 @@ export type Option = { export type RoleData = { id: string; name: string; -} +};