refactor: centralize hospital and warehouse defaults into defaults.ts
This commit is contained in:
parent
8f04e6b475
commit
32ec18f7f2
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { FaExternalLinkAlt } from 'react-icons/fa';
|
import { FaExternalLinkAlt } from 'react-icons/fa';
|
||||||
|
import { DEFAULT_REPORT_HOSPITAL, DEFAULT_HOSPITAL_LOGO } from '../config/defaults';
|
||||||
|
|
||||||
const CIVIL_PARENT_TYPE = 'Civil works-الأعمال المدنية';
|
const CIVIL_PARENT_TYPE = 'Civil works-الأعمال المدنية';
|
||||||
|
|
||||||
@ -242,7 +243,7 @@ const KpiMonthlyReportCard: React.FC<KpiMonthlyReportCardProps> = ({
|
|||||||
const logoExtension: 'png' | 'jpeg' = 'png';
|
const logoExtension: 'png' | 'jpeg' = 'png';
|
||||||
try {
|
try {
|
||||||
const baseUrl = import.meta.env.BASE_URL || '/';
|
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);
|
const logoRes = await fetch(logoUrl);
|
||||||
if (logoRes.ok) {
|
if (logoRes.ok) {
|
||||||
const arrayBuffer = await logoRes.arrayBuffer();
|
const arrayBuffer = await logoRes.arrayBuffer();
|
||||||
@ -305,7 +306,7 @@ const KpiMonthlyReportCard: React.FC<KpiMonthlyReportCardProps> = ({
|
|||||||
ws.addImage(logoId, { tl: { col: 0, row: 0 }, br: { col: 3, row: 1 }, editAs: 'oneCell' });
|
ws.addImage(logoId, { tl: { col: 0, row: 0 }, br: { col: 3, row: 1 }, editAs: 'oneCell' });
|
||||||
ws.mergeCells('D1:K1');
|
ws.mergeCells('D1:K1');
|
||||||
const r1 = ws.getCell('D1');
|
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 });
|
styleCell(r1, { bold: true, size: 13, h: 'center', brd: false });
|
||||||
ws.mergeCells('L1:M1');
|
ws.mergeCells('L1:M1');
|
||||||
const targetCell = ws.getCell('L1');
|
const targetCell = ws.getCell('L1');
|
||||||
@ -314,7 +315,7 @@ const KpiMonthlyReportCard: React.FC<KpiMonthlyReportCardProps> = ({
|
|||||||
} else {
|
} else {
|
||||||
ws.mergeCells('A1:K1');
|
ws.mergeCells('A1:K1');
|
||||||
const r1 = ws.getCell('A1');
|
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 });
|
styleCell(r1, { bold: true, size: 13, h: 'center', brd: false });
|
||||||
ws.mergeCells('L1:M1');
|
ws.mergeCells('L1:M1');
|
||||||
const targetCell = ws.getCell('L1');
|
const targetCell = ws.getCell('L1');
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { FaExternalLinkAlt } from 'react-icons/fa';
|
import { FaExternalLinkAlt } from 'react-icons/fa';
|
||||||
|
import { DEFAULT_REPORT_HOSPITAL, DEFAULT_CLUSTER_NAME, DEFAULT_HOSPITAL_LOGO, DEFAULT_CLUSTER_LOGO } from '../config/defaults';
|
||||||
|
|
||||||
// ── Props ─────────────────────────────────────────────────────────────────────
|
// ── Props ─────────────────────────────────────────────────────────────────────
|
||||||
interface PpmKpiReportCardProps {
|
interface PpmKpiReportCardProps {
|
||||||
@ -162,8 +163,8 @@ const PpmKpiReportCard: React.FC<PpmKpiReportCardProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const [logoLeft, logoRight] = await Promise.all([
|
const [logoLeft, logoRight] = await Promise.all([
|
||||||
loadLogo('kfsh-logo.png'),
|
loadLogo(DEFAULT_HOSPITAL_LOGO),
|
||||||
loadLogo('ehc-logo.png'),
|
loadLogo(DEFAULT_CLUSTER_LOGO),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// ── Build workbook ────────────────────────────────────────────────────────
|
// ── Build workbook ────────────────────────────────────────────────────────
|
||||||
@ -226,7 +227,7 @@ const PpmKpiReportCard: React.FC<PpmKpiReportCardProps> = ({
|
|||||||
ws.addImage(id, { tl: { col: 0, row: 0 }, br: { col: 2, row: 3 }, editAs: 'oneCell' });
|
ws.addImage(id, { tl: { col: 0, row: 0 }, br: { col: 2, row: 3 }, editAs: 'oneCell' });
|
||||||
} else {
|
} else {
|
||||||
const c = ws.getCell('A1');
|
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 });
|
styleCell(c, { bold: true, size: 10, h: 'center', brd: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,7 +236,7 @@ const PpmKpiReportCard: React.FC<PpmKpiReportCardProps> = ({
|
|||||||
ws.addImage(id, { tl: { col: 3, row: 0 }, br: { col: 5, row: 3 }, editAs: 'oneCell' });
|
ws.addImage(id, { tl: { col: 3, row: 0 }, br: { col: 5, row: 3 }, editAs: 'oneCell' });
|
||||||
} else {
|
} else {
|
||||||
const c = ws.getCell('D1');
|
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 });
|
styleCell(c, { bold: true, size: 10, h: 'center', brd: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import { DEFAULT_FRAPPE_BASE_URL } from './defaults';
|
||||||
|
|
||||||
// API Configuration Types
|
// API Configuration Types
|
||||||
interface ApiConfig {
|
interface ApiConfig {
|
||||||
BASE_URL: string;
|
BASE_URL: string;
|
||||||
@ -10,7 +12,7 @@ const API_CONFIG: ApiConfig = {
|
|||||||
// Backend URL - Use proxy in development, direct URL in production
|
// Backend URL - Use proxy in development, direct URL in production
|
||||||
BASE_URL: import.meta.env.DEV
|
BASE_URL: import.meta.env.DEV
|
||||||
? '' // Use relative URLs in development (goes through Vite proxy)
|
? '' // 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
|
// API Endpoints
|
||||||
ENDPOINTS: {
|
ENDPOINTS: {
|
||||||
|
|||||||
18
asm_app/src/config/defaults.ts
Normal file
18
asm_app/src/config/defaults.ts
Normal file
@ -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';
|
||||||
@ -12,6 +12,7 @@ import { openHtmlReport, showReportBlockedMessage, toAbsoluteSiteUrl } from '../
|
|||||||
|
|
||||||
import LinkField from '../components/LinkField';
|
import LinkField from '../components/LinkField';
|
||||||
import apiService from '../services/apiService';
|
import apiService from '../services/apiService';
|
||||||
|
import { DEFAULT_HOSPITAL } from '../config/defaults';
|
||||||
|
|
||||||
import { useWorkflow } from '../hooks/useWorkflow';
|
import { useWorkflow } from '../hooks/useWorkflow';
|
||||||
import WorkflowActions from '../components/WorkflowActions';
|
import WorkflowActions from '../components/WorkflowActions';
|
||||||
@ -352,7 +353,7 @@ const {
|
|||||||
|
|
||||||
// Set company and asset_owner_company if new asset or company not set
|
// Set company and asset_owner_company if new asset or company not set
|
||||||
if (isNewAsset || !prev.company) {
|
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.company = defaultCompany;
|
||||||
updates.asset_owner_company = defaultCompany;
|
updates.asset_owner_company = defaultCompany;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom';
|
|||||||
import ppmPlannerService, { type BulkScheduleData } from '../services/ppmPlannerService';
|
import ppmPlannerService, { type BulkScheduleData } from '../services/ppmPlannerService';
|
||||||
import { FaFilter, FaCalendar, FaCheckCircle, FaSearch, FaArrowLeft, FaSpinner } from 'react-icons/fa';
|
import { FaFilter, FaCalendar, FaCheckCircle, FaSearch, FaArrowLeft, FaSpinner } from 'react-icons/fa';
|
||||||
import LinkField from '../components/LinkField';
|
import LinkField from '../components/LinkField';
|
||||||
|
import { DEFAULT_HOSPITAL } from '../config/defaults';
|
||||||
|
|
||||||
// Updated Asset interface to match backend API response
|
// Updated Asset interface to match backend API response
|
||||||
interface Asset {
|
interface Asset {
|
||||||
@ -36,7 +37,7 @@ interface AssetFilters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Default Hospital/Company for PPM Planner asset filter (must match Company `name` in ERP). */
|
/** 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<string, unknown> = {
|
const ACTIVE_ASSET_LINK_FILTERS: Record<string, unknown> = {
|
||||||
docstatus: 1,
|
docstatus: 1,
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import LinkField from '../components/LinkField';
|
|||||||
import WorkflowActions from '../components/WorkflowActions';
|
import WorkflowActions from '../components/WorkflowActions';
|
||||||
import apiService from '../services/apiService';
|
import apiService from '../services/apiService';
|
||||||
import API_CONFIG from '../config/api';
|
import API_CONFIG from '../config/api';
|
||||||
|
import { DEFAULT_HOSPITAL, DEFAULT_WAREHOUSE } from '../config/defaults';
|
||||||
import CommentSection from '../components/CommentSection';
|
import CommentSection from '../components/CommentSection';
|
||||||
|
|
||||||
import DeleteRequestButton from '../components/DeleteRequestButton';
|
import DeleteRequestButton from '../components/DeleteRequestButton';
|
||||||
@ -381,7 +382,7 @@ const WorkOrderDetail: React.FC = () => {
|
|||||||
custom_type?: string;
|
custom_type?: string;
|
||||||
custom_civil_work_category?: string;
|
custom_civil_work_category?: string;
|
||||||
}>({
|
}>({
|
||||||
company: 'King Fahad Specialist Hospital - Dammam',
|
company: DEFAULT_HOSPITAL,
|
||||||
work_order_type: '',
|
work_order_type: '',
|
||||||
custom_type:'Corrective',
|
custom_type:'Corrective',
|
||||||
custom_civil_work_category: '',
|
custom_civil_work_category: '',
|
||||||
@ -2245,9 +2246,6 @@ useEffect(() => {
|
|||||||
return userRoles.includes('Work Control') || isSystemManager;
|
return userRoles.includes('Work Control') || isSystemManager;
|
||||||
}, [userRoles, isSystemManager]);
|
}, [userRoles, isSystemManager]);
|
||||||
|
|
||||||
// Default warehouse for new stock items - Updated to new value
|
|
||||||
const DEFAULT_WAREHOUSE = 'Stores - KFSH-D';
|
|
||||||
|
|
||||||
// Stock warnings state
|
// Stock warnings state
|
||||||
const [stockWarnings, setStockWarnings] = useState<Record<number, string>>({});
|
const [stockWarnings, setStockWarnings] = useState<Record<number, string>>({});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user