From 9b8f0b11390f1c4cbe9b604ed3940c3144b7fb0c Mon Sep 17 00:00:00 2001 From: puriphatt Date: Tue, 23 Jul 2024 11:04:44 +0000 Subject: [PATCH] feat: 01 dialog confirm change status --- src/i18n/en-US/alert-dialog.ts | 4 ++ src/i18n/th-th/alert-dialog.ts | 4 ++ src/pages/01_branch-management/MainPage.vue | 71 ++++++++++++--------- 3 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/i18n/en-US/alert-dialog.ts b/src/i18n/en-US/alert-dialog.ts index 7544ec49..6a9dc35f 100644 --- a/src/i18n/en-US/alert-dialog.ts +++ b/src/i18n/en-US/alert-dialog.ts @@ -9,6 +9,10 @@ export default { confirmLogoutTitle: 'Confirm Logout', confirmLogoutMessage: 'Do you want to log out?', + confirmChangeStatusTitle: 'Confirm Status Change', + confirmChangeStatusOnMessage: 'Do you want to open?', + confirmChangeStatusOffMessage: 'Do you want to close?', + // Backend productGroupNotFound: 'Product group cannot be found.', productGroupInUsed: 'Product group is in used.', diff --git a/src/i18n/th-th/alert-dialog.ts b/src/i18n/th-th/alert-dialog.ts index f01e8ee2..5f363d50 100644 --- a/src/i18n/th-th/alert-dialog.ts +++ b/src/i18n/th-th/alert-dialog.ts @@ -8,6 +8,10 @@ export default { confirmLogoutTitle: 'ยืนยันการออกจากระบบ', confirmLogoutMessage: 'คุณต้องการออกจากระบบ ใช่หรือไม่', + confirmChangeStatusTitle: 'ยืนยันการเปลี่ยนสถานะ', + confirmChangeStatusOnMessage: 'คุณต้องการเปิดใช่หรือไม่', + confirmChangeStatusOffMessage: 'คุณต้องการปิดใช่หรือไม่', + // Backend productGroupNotFound: 'ไม่พบกลุ่มสินค้า', productGroupInUsed: 'กลุ่มสินค้าที่ใช้งานอยู่', diff --git a/src/pages/01_branch-management/MainPage.vue b/src/pages/01_branch-management/MainPage.vue index ca309e98..f6657265 100644 --- a/src/pages/01_branch-management/MainPage.vue +++ b/src/pages/01_branch-management/MainPage.vue @@ -9,7 +9,7 @@ import type { QTableProps } from 'quasar'; import useBranchStore from 'stores/branch'; import useFlowStore from 'src/stores/flow'; -import { BranchWithChildren, BranchCreate } from 'stores/branch/types'; +import { BranchWithChildren, BranchCreate, Branch } from 'stores/branch/types'; import { Status } from 'src/stores/types'; import useUtilsStore, { dialog } from 'src/stores/utils'; @@ -411,6 +411,32 @@ function triggerDelete(id: string) { } } +async function triggerChangeStatus( + id: string, + status: string, +): Promise { + return await new Promise((resolve) => { + dialog({ + color: 'warning', + icon: 'mdi-alert', + title: t('confirmChangeStatusTitle'), + actionText: + status !== 'INACTIVE' ? t('switchOffLabel') : t('switchOnLabel'), + message: + status !== 'INACTIVE' + ? t('confirmChangeStatusOffMessage') + : t('confirmChangeStatusOnMessage'), + action: async () => { + const res = await branchStore.editById(id, { + status: status !== 'INACTIVE' ? 'INACTIVE' : 'ACTIVE', + }); + if (res) resolve(res); + }, + cancel: () => {}, + }); + }); +} + async function onSubmit() { if (formType.value === 'edit') { delete formData.value['codeHeadOffice']; @@ -622,7 +648,7 @@ watch( -
+
{ const res = - await branchStore.editById( + await triggerChangeStatus( props.row.id, - { - status: - props.row.status !== - 'INACTIVE' - ? 'INACTIVE' - : 'ACTIVE', - }, + props.row.status, ); + if (res) props.row.status = res.status; } @@ -1815,10 +1826,10 @@ watch( @click=" async () => { if (!currentNode) return; - const res = await branchStore.editById(currentNode.id, { - status: - currentNode.status !== 'INACTIVE' ? 'INACTIVE' : 'ACTIVE', - }); + const res = await triggerChangeStatus( + currentNode.id, + currentNode.status, + ); if (res) currentNode.status = res.status; } "