From dab7c59857d4d2791ebc7aaf09c2fbac62298b81 Mon Sep 17 00:00:00 2001 From: "Prit V. Vasani" Date: Sat, 10 Oct 2026 08:32:16 +0000 Subject: [PATCH] fix(invoices): print/PDF links open on the API origin, not the SPA window.open('/api/v1/invoices/..') resolved to the frontend origin (:3000) -> 404. Now use the tenant-aware API_BASE_URL (exported from services/api), so the links open cafe1.localhost:4969 where the routes live. Verified 401 (auth) on the API, not 404. Lint 0, build OK. --- cafe-management-sys/src/pages/admin/AdminInvoices.jsx | 6 +++--- cafe-management-sys/src/services/api.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cafe-management-sys/src/pages/admin/AdminInvoices.jsx b/cafe-management-sys/src/pages/admin/AdminInvoices.jsx index c1efbf3..3f4047d 100644 --- a/cafe-management-sys/src/pages/admin/AdminInvoices.jsx +++ b/cafe-management-sys/src/pages/admin/AdminInvoices.jsx @@ -23,7 +23,7 @@ import Refresh from '@mui/icons-material/Refresh'; import ReceiptLong from '@mui/icons-material/ReceiptLong'; import Print from '@mui/icons-material/Print'; import Download from '@mui/icons-material/Download'; -import { invoicesAPI, activityAPI, unwrap } from '../../services/api'; +import { invoicesAPI, activityAPI, API_BASE_URL, unwrap } from '../../services/api'; import ErrorState from '../../components/common/ErrorState'; import useOpsEvents from '../../hooks/useOpsEvents'; import { formatMoney } from '../../utils/formatMoney'; @@ -86,12 +86,12 @@ const AdminInvoices = () => { const printInvoice = (inv, mode = paper) => { const id = inv._id || inv.id; - window.open(`/api/v1/invoices/${id}/print?mode=${mode}`, '_blank'); + window.open(`${API_BASE_URL}/invoices/${id}/print?mode=${mode}`, '_blank'); }; const downloadPdf = (inv, format = 'a4') => { const id = inv._id || inv.id; - window.open(`/api/v1/invoices/${id}/pdf?format=${format}&download=1`, '_blank'); + window.open(`${API_BASE_URL}/invoices/${id}/pdf?format=${format}&download=1`, '_blank'); }; return ( diff --git a/cafe-management-sys/src/services/api.js b/cafe-management-sys/src/services/api.js index 8546e7c..938cf0d 100644 --- a/cafe-management-sys/src/services/api.js +++ b/cafe-management-sys/src/services/api.js @@ -55,7 +55,7 @@ export const resolveApiBaseUrl = ( } }; -const API_BASE_URL = resolveApiBaseUrl(RAW_API_URL); +export const API_BASE_URL = resolveApiBaseUrl(RAW_API_URL); // Helper function to get auth token (sessionStorage preferred, localStorage fallback) const getAuthToken = () => {