diff --git a/packages/esm-report-app/src/api/api.ts b/packages/esm-report-app/src/api/api.ts index 9eedf948..8532af55 100644 --- a/packages/esm-report-app/src/api/api.ts +++ b/packages/esm-report-app/src/api/api.ts @@ -24,13 +24,14 @@ const fetcher = async (url) => { } }; -async function postData(url: string, ac = new AbortController()) { +async function postData(data: ReportData, url: string, ac = new AbortController()) { const response = await openmrsFetch(url, { signal: ac.signal, - method: 'GET', + method: 'POST', headers: { 'Content-Type': 'application/json', }, + body: JSON.stringify(data), }); return response.data; diff --git a/packages/esm-report-app/src/reports-dashboard/report-summary/ReportSummary.tsx b/packages/esm-report-app/src/reports-dashboard/report-summary/ReportSummary.tsx index a93a94b1..2b152117 100644 --- a/packages/esm-report-app/src/reports-dashboard/report-summary/ReportSummary.tsx +++ b/packages/esm-report-app/src/reports-dashboard/report-summary/ReportSummary.tsx @@ -18,7 +18,7 @@ import styles from './ReportSummary.css'; import reportMapping from '../report-loader/reportMapping.json'; import { generateReportData, getSPReports } from '../../api/api'; -const ReportSummary: React.FC = ({ rows }) => { +const ReportSummary: React.FC = ({ rows = [] }) => { const [loading, setLoading] = useState(false); const [refreshLoading, setRefreshLoading] = useState(false); const [currentRows, setCurrentRows] = useState([]); @@ -35,21 +35,24 @@ const ReportSummary: React.FC = ({ rows }) => { ]; useEffect(() => { - const rowsWithButtons = rows.map((row) => { - const reportMappingEntry = reportMapping.find((entry) => entry.report_uuid === row.uuid); - return { - ...row, - view: reportMappingEntry ? ( - - ) : null, - download: , - }; - }); - setCurrentRows(rowsWithButtons); + if (rows && Array.isArray(rows)) { + const rowsWithButtons = rows.map((row) => { + const reportMappingEntry = reportMapping.find((entry) => entry.report_uuid === row.uuid); + return { + ...row, + id: row.log_id, + view: reportMappingEntry ? ( + + ) : null, + download: , + }; + }); + setCurrentRows(rowsWithButtons); + } }, [rows]); const handleViewClick = async (report_uuid, report_id) => { @@ -69,22 +72,24 @@ const ReportSummary: React.FC = ({ rows }) => { const handleRefresh = () => { setRefreshLoading(true); try { - const rowsWithButtons = rows.map((row) => { - const reportMappingEntry = reportMapping.find((entry) => entry.report_uuid === row.uuid); - return { - ...row, - view: reportMappingEntry ? ( - - ) : null, - download: , - }; - }); - window.location.reload(); - setCurrentRows(rowsWithButtons); + if (rows && Array.isArray(rows)) { + const rowsWithButtons = rows.map((row) => { + const reportMappingEntry = reportMapping.find((entry) => entry.report_uuid === row.uuid); + return { + ...row, + id: row.log_id, + view: reportMappingEntry ? ( + + ) : null, + download: , + }; + }); + setCurrentRows(rowsWithButtons); + } } catch (error) { console.error('Error refreshing data:', error); } finally { @@ -122,7 +127,7 @@ const ReportSummary: React.FC = ({ rows }) => { {row.cells.map((cell) => ( - {cell.value} + {cell.value} ))} )) @@ -135,7 +140,6 @@ const ReportSummary: React.FC = ({ rows }) => { )} /> - {/* {}} /> */} );