From 32ec18f7f226fb3259acbf851c33aed58b41e14a Mon Sep 17 00:00:00 2001 From: Duradundi Date: Wed, 9 Sep 2026 19:49:21 +0530 Subject: [PATCH] refactor: centralize hospital and warehouse defaults into defaults.ts --- .../src/components/KpiMonthlyReportCard.tsx | 7 ++++--- asm_app/src/components/PpmKpiReportCard.tsx | 9 +++++---- asm_app/src/config/api.ts | 4 +++- asm_app/src/config/defaults.ts | 18 ++++++++++++++++++ asm_app/src/pages/AssetDetail.tsx | 3 ++- asm_app/src/pages/PPMPlanner.tsx | 3 ++- asm_app/src/pages/WorkOrderDetail.tsx | 6 ++---- 7 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 asm_app/src/config/defaults.ts diff --git a/asm_app/src/components/KpiMonthlyReportCard.tsx b/asm_app/src/components/KpiMonthlyReportCard.tsx index 8829ebc..fc2d36f 100644 --- a/asm_app/src/components/KpiMonthlyReportCard.tsx +++ b/asm_app/src/components/KpiMonthlyReportCard.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { FaExternalLinkAlt } from 'react-icons/fa'; +import { DEFAULT_REPORT_HOSPITAL, DEFAULT_HOSPITAL_LOGO } from '../config/defaults'; const CIVIL_PARENT_TYPE = 'Civil works-الأعمال المدنية'; @@ -242,7 +243,7 @@ const KpiMonthlyReportCard: React.FC = ({ const logoExtension: 'png' | 'jpeg' = 'png'; try { const baseUrl = import.meta.env.BASE_URL || '/'; - const logoUrl = `${baseUrl}${baseUrl.endsWith('/') ? '' : '/'}kfsh-logo.png`; + const logoUrl = `${baseUrl}${baseUrl.endsWith('/') ? '' : '/'}${DEFAULT_HOSPITAL_LOGO}`; const logoRes = await fetch(logoUrl); if (logoRes.ok) { const arrayBuffer = await logoRes.arrayBuffer(); @@ -305,7 +306,7 @@ const KpiMonthlyReportCard: React.FC = ({ ws.addImage(logoId, { tl: { col: 0, row: 0 }, br: { col: 3, row: 1 }, editAs: 'oneCell' }); ws.mergeCells('D1:K1'); const r1 = ws.getCell('D1'); - r1.value = 'King Fahad Specialist Hospital'; + r1.value = DEFAULT_REPORT_HOSPITAL; styleCell(r1, { bold: true, size: 13, h: 'center', brd: false }); ws.mergeCells('L1:M1'); const targetCell = ws.getCell('L1'); @@ -314,7 +315,7 @@ const KpiMonthlyReportCard: React.FC = ({ } else { ws.mergeCells('A1:K1'); const r1 = ws.getCell('A1'); - r1.value = 'King Fahad Specialist Hospital'; + r1.value = DEFAULT_REPORT_HOSPITAL; styleCell(r1, { bold: true, size: 13, h: 'center', brd: false }); ws.mergeCells('L1:M1'); const targetCell = ws.getCell('L1'); diff --git a/asm_app/src/components/PpmKpiReportCard.tsx b/asm_app/src/components/PpmKpiReportCard.tsx index 5dfdd52..c6ba4e7 100644 --- a/asm_app/src/components/PpmKpiReportCard.tsx +++ b/asm_app/src/components/PpmKpiReportCard.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { FaExternalLinkAlt } from 'react-icons/fa'; +import { DEFAULT_REPORT_HOSPITAL, DEFAULT_CLUSTER_NAME, DEFAULT_HOSPITAL_LOGO, DEFAULT_CLUSTER_LOGO } from '../config/defaults'; // ── Props ───────────────────────────────────────────────────────────────────── interface PpmKpiReportCardProps { @@ -162,8 +163,8 @@ const PpmKpiReportCard: React.FC = ({ }; const [logoLeft, logoRight] = await Promise.all([ - loadLogo('kfsh-logo.png'), - loadLogo('ehc-logo.png'), + loadLogo(DEFAULT_HOSPITAL_LOGO), + loadLogo(DEFAULT_CLUSTER_LOGO), ]); // ── Build workbook ──────────────────────────────────────────────────────── @@ -226,7 +227,7 @@ const PpmKpiReportCard: React.FC = ({ ws.addImage(id, { tl: { col: 0, row: 0 }, br: { col: 2, row: 3 }, editAs: 'oneCell' }); } else { const c = ws.getCell('A1'); - c.value = 'King Fahad Specialist Hospital'; + c.value = DEFAULT_REPORT_HOSPITAL; styleCell(c, { bold: true, size: 10, h: 'center', brd: false }); } @@ -235,7 +236,7 @@ const PpmKpiReportCard: React.FC = ({ ws.addImage(id, { tl: { col: 3, row: 0 }, br: { col: 5, row: 3 }, editAs: 'oneCell' }); } else { const c = ws.getCell('D1'); - c.value = 'Eastern Health Cluster'; + c.value = DEFAULT_CLUSTER_NAME; styleCell(c, { bold: true, size: 10, h: 'center', brd: false }); } diff --git a/asm_app/src/config/api.ts b/asm_app/src/config/api.ts index 0b3c105..0ccb506 100644 --- a/asm_app/src/config/api.ts +++ b/asm_app/src/config/api.ts @@ -1,3 +1,5 @@ +import { DEFAULT_FRAPPE_BASE_URL } from './defaults'; + // API Configuration Types interface ApiConfig { BASE_URL: string; @@ -10,7 +12,7 @@ const API_CONFIG: ApiConfig = { // Backend URL - Use proxy in development, direct URL in production BASE_URL: import.meta.env.DEV ? '' // Use relative URLs in development (goes through Vite proxy) - : import.meta.env.VITE_FRAPPE_BASE_URL || 'https://kfsh-dammam-asm.seeraarabia.com', + : import.meta.env.VITE_FRAPPE_BASE_URL || DEFAULT_FRAPPE_BASE_URL, // API Endpoints ENDPOINTS: { diff --git a/asm_app/src/config/defaults.ts b/asm_app/src/config/defaults.ts new file mode 100644 index 0000000..cf97d07 --- /dev/null +++ b/asm_app/src/config/defaults.ts @@ -0,0 +1,18 @@ +/** + * Default Application Configurations & Fallbacks + * Centralized constants for hospital/tenant names, default warehouses, logos, and endpoints. + */ + +export const DEFAULT_HOSPITAL = 'King Fahad Specialist Hospital - Dammam'; +export const DEFAULT_WAREHOUSE = 'Stores - KFSH-D'; + +// Report-specific titles and branding +export const DEFAULT_REPORT_HOSPITAL = 'King Fahad Specialist Hospital'; +export const DEFAULT_CLUSTER_NAME = 'Eastern Health Cluster'; + +// Default logos +export const DEFAULT_HOSPITAL_LOGO = 'kfsh-logo.png'; +export const DEFAULT_CLUSTER_LOGO = 'ehc-logo.png'; + +// Fallback Frappe Backend Base URL +export const DEFAULT_FRAPPE_BASE_URL = 'https://kfsh-dammam-asm.seeraarabia.com'; diff --git a/asm_app/src/pages/AssetDetail.tsx b/asm_app/src/pages/AssetDetail.tsx index 71210e3..b8526a1 100644 --- a/asm_app/src/pages/AssetDetail.tsx +++ b/asm_app/src/pages/AssetDetail.tsx @@ -12,6 +12,7 @@ import { openHtmlReport, showReportBlockedMessage, toAbsoluteSiteUrl } from '../ import LinkField from '../components/LinkField'; import apiService from '../services/apiService'; +import { DEFAULT_HOSPITAL } from '../config/defaults'; import { useWorkflow } from '../hooks/useWorkflow'; import WorkflowActions from '../components/WorkflowActions'; @@ -352,7 +353,7 @@ const { // Set company and asset_owner_company if new asset or company not set if (isNewAsset || !prev.company) { - const defaultCompany = user.custom_site_name || 'King Fahad Specialist Hospital - Dammam'; + const defaultCompany = user.custom_site_name || DEFAULT_HOSPITAL; updates.company = defaultCompany; updates.asset_owner_company = defaultCompany; } diff --git a/asm_app/src/pages/PPMPlanner.tsx b/asm_app/src/pages/PPMPlanner.tsx index cbea0fb..36913d7 100644 --- a/asm_app/src/pages/PPMPlanner.tsx +++ b/asm_app/src/pages/PPMPlanner.tsx @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom'; import ppmPlannerService, { type BulkScheduleData } from '../services/ppmPlannerService'; import { FaFilter, FaCalendar, FaCheckCircle, FaSearch, FaArrowLeft, FaSpinner } from 'react-icons/fa'; import LinkField from '../components/LinkField'; +import { DEFAULT_HOSPITAL } from '../config/defaults'; // Updated Asset interface to match backend API response interface Asset { @@ -36,7 +37,7 @@ interface AssetFilters { } /** Default Hospital/Company for PPM Planner asset filter (must match Company `name` in ERP). */ -const DEFAULT_PPM_PLANNER_HOSPITAL = 'King Fahad Specialist Hospital - Dammam'; +const DEFAULT_PPM_PLANNER_HOSPITAL = DEFAULT_HOSPITAL; const ACTIVE_ASSET_LINK_FILTERS: Record = { docstatus: 1, diff --git a/asm_app/src/pages/WorkOrderDetail.tsx b/asm_app/src/pages/WorkOrderDetail.tsx index 56f64dc..d612890 100644 --- a/asm_app/src/pages/WorkOrderDetail.tsx +++ b/asm_app/src/pages/WorkOrderDetail.tsx @@ -15,6 +15,7 @@ import LinkField from '../components/LinkField'; import WorkflowActions from '../components/WorkflowActions'; import apiService from '../services/apiService'; import API_CONFIG from '../config/api'; +import { DEFAULT_HOSPITAL, DEFAULT_WAREHOUSE } from '../config/defaults'; import CommentSection from '../components/CommentSection'; import DeleteRequestButton from '../components/DeleteRequestButton'; @@ -381,7 +382,7 @@ const WorkOrderDetail: React.FC = () => { custom_type?: string; custom_civil_work_category?: string; }>({ - company: 'King Fahad Specialist Hospital - Dammam', + company: DEFAULT_HOSPITAL, work_order_type: '', custom_type:'Corrective', custom_civil_work_category: '', @@ -2245,9 +2246,6 @@ useEffect(() => { return userRoles.includes('Work Control') || isSystemManager; }, [userRoles, isSystemManager]); - // Default warehouse for new stock items - Updated to new value - const DEFAULT_WAREHOUSE = 'Stores - KFSH-D'; - // Stock warnings state const [stockWarnings, setStockWarnings] = useState>({});