From 3529f81352cb09b4550ebf00aa4e8165e22023d2 Mon Sep 17 00:00:00 2001 From: Net Date: Wed, 28 Aug 2024 17:36:30 +0700 Subject: [PATCH] refactor: edit map data --- src/pages/03_customer-management/form.ts | 39 ++++++++---------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/pages/03_customer-management/form.ts b/src/pages/03_customer-management/form.ts index 54eceb2a..441e892b 100644 --- a/src/pages/03_customer-management/form.ts +++ b/src/pages/03_customer-management/form.ts @@ -181,33 +181,17 @@ export const useCustomerForm = defineStore('form-customer', () => { contactName: v.contactName || '', file: await customerStore.listAttachment(v.id).then(async (r) => { if (r) { - const fileGroups: Record< - string, - { label: string; files: { label: string }[] } - > = {}; - - r.forEach((file) => { - const temp = file.split('-')[0]; - - if (!fileGroups[temp]) { - fileGroups[temp] = { - label: t(`customer.typeFile.${temp}`), - files: [], - }; - } - - fileGroups[temp].files.push({ label: file }); - }); - - state.value.treeFile = Object.values(fileGroups).map((group) => ({ - label: group.label, - file: group.files, - })); - return await Promise.all( - r.map(async (item) => ({ - url: await customerStore.getAttachment(v.id, item), - })), + r.map(async (item) => { + const fragment = item.split('-'); + const group = fragment.length === 1 ? 'other' : fragment.at(0); + + return { + url: await customerStore.getAttachment(v.id, item), + name: item, + group: group, + }; + }), ); } return []; @@ -321,6 +305,7 @@ export const useCustomerForm = defineStore('form-customer', () => { assignFormData, submitFormCustomer, addCurrentCustomerBranch, + deleteAttachment, }; }); @@ -475,8 +460,8 @@ export const useCustomerBranchForm = defineStore('form-customer-branch', () => { return { state, - initForm, currentFormData, + initForm, isFormDataDifferent, submitForm, };