From 4f085e068ae80215ec91379af45d0608f44d2c2e Mon Sep 17 00:00:00 2001 From: puriphatt Date: Thu, 20 Feb 2025 09:28:42 +0700 Subject: [PATCH] refactor: implement toCamelCase utility function and update quotation stats mapping --- src/pages/05_quotation/MainPage.vue | 5 ++++- src/stores/utils/index.ts | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/05_quotation/MainPage.vue b/src/pages/05_quotation/MainPage.vue index 410a6bbf..4b280ef6 100644 --- a/src/pages/05_quotation/MainPage.vue +++ b/src/pages/05_quotation/MainPage.vue @@ -12,6 +12,7 @@ import useMyBranch from 'stores/my-branch'; import { useQuotationForm } from './form'; import { hslaColors } from './constants'; import { pageTabs, columnQuotation } from './constants'; +import { toCamelCase } from 'stores/utils'; // NOTE Import Types import { CustomerBranchCreate, CustomerType } from 'stores/customer/types'; @@ -393,7 +394,9 @@ async function storeDataLocal(id: string) { quotationStats[ pageState.currentTab === 'Invoice' ? 'paymentInProcess' - : (pageState.currentTab.toLowerCase() as keyof typeof quotationStats) + : (toCamelCase( + pageState.currentTab, + ) as keyof typeof quotationStats) ] }} diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index 94463327..3298ebf7 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -609,3 +609,9 @@ export function getEmployeeName( ['tha']: `${typeof employee.namePrefix === 'string' ? useOptionStore().mapOption(employee.namePrefix) : ''} ${employee.firstName} ${employee.lastName}`, }[opts?.locale || 'eng']; } + +export function toCamelCase(text: string): string { + return text + .replace(/[^a-zA-Z0-9]+(.)/g, (match, chr) => chr.toUpperCase()) + .replace(/^[A-Z]/, (match) => match.toLowerCase()); +}