From 46041c3f37f0c96e9c01308330dfe608857ef64a Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Mon, 16 Sep 2024 14:47:29 +0700 Subject: [PATCH] refactor: wait for upload --- src/pages/03_customer-management/MainPage.vue | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/pages/03_customer-management/MainPage.vue b/src/pages/03_customer-management/MainPage.vue index 23f92526..04149025 100644 --- a/src/pages/03_customer-management/MainPage.vue +++ b/src/pages/03_customer-management/MainPage.vue @@ -1970,7 +1970,7 @@ const emptyCreateDialog = ref(false); ); if (tapIsUndefined.length > 0) { - dialog({ + return dialog({ color: 'warning', icon: 'mdi-alert', title: t('dialog.title.incompleteDataEntry'), @@ -1983,30 +1983,30 @@ const emptyCreateDialog = ref(false); return; }, }); + } + if (!customerFormData.customerBranch[idx].id) { + await customerFormStore.submitFormCustomer( + onCreateImageList, + ); + customerFormState.readonly = true; + notify('create', $t('general.success')); + // await customerStore.createBranch({ + // ...customerFormData.customerBranch[idx], + // customerId: customerFormState.editCustomerId, + // id: undefined, + // }); } else { - if (!customerFormData.customerBranch[idx].id) { - await customerFormStore.submitFormCustomer( - onCreateImageList, - ); - customerFormState.readonly = true; - notify('create', $t('general.success')); - await fetchListCustomer(); - // await customerStore.createBranch({ - // ...customerFormData.customerBranch[idx], - // customerId: customerFormState.editCustomerId, - // id: undefined, - // }); - } else { - await customerStore.editBranchById( - customerFormData.customerBranch[idx].id || '', - { - ...customerFormData.customerBranch[idx], - id: undefined, - }, - ); - } + await customerStore.editBranchById( + customerFormData.customerBranch[idx].id || '', + { + ...customerFormData.customerBranch[idx], + id: undefined, + }, + ); + } - customerFormData.customerBranch[idx].file?.forEach( + const uploadResult = + customerFormData.customerBranch[idx].file?.map( async (v) => { if (!v.file) return; @@ -2027,13 +2027,16 @@ const emptyCreateDialog = ref(false); ); } }, - ); + ) || []; - await customerFormStore.assignFormData( - customerFormState.editCustomerId, - ); - customerFormStore.resetForm(); - } + for (const r of uploadResult) await r; + + await customerFormStore.assignFormData( + customerFormState.editCustomerId, + ); + + await fetchListCustomer(); + customerFormStore.resetForm(); } " >