From 640538bcbdbc2219d57f4fed549c52d0fb7dce90 Mon Sep 17 00:00:00 2001 From: fahed Date: Tue, 28 Apr 2026 14:42:31 +0300 Subject: [PATCH] feat(report): page shell with two-column layout and PDF download action --- src/components/Report/index.tsx | 92 +++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/components/Report/index.tsx diff --git a/src/components/Report/index.tsx b/src/components/Report/index.tsx new file mode 100644 index 0000000..eefc9a1 --- /dev/null +++ b/src/components/Report/index.tsx @@ -0,0 +1,92 @@ +import React, { useState, useCallback } from 'react'; +import { pdf } from '@react-pdf/renderer'; +import type { MuseumRecord } from '../../types'; +import { DEFAULT_CONFIG, computeReportData } from './reportHelpers'; +import type { ReportConfig } from './reportHelpers'; +import { ReportDocument } from './ReportDocument'; +import ReportForm from './ReportForm'; +import ReportPreview from './ReportPreview'; +import { getUniqueMuseums, getUniqueChannels } from '../../services/dataService'; + +interface Props { + data: MuseumRecord[]; +} + +export default function ReportPage({ data }: Props) { + const [config, setConfig] = useState(DEFAULT_CONFIG); + const [generating, setGenerating] = useState(false); + + const allMuseums = getUniqueMuseums(data); + const allChannels = getUniqueChannels(data); + + const patch = useCallback((p: Partial) => setConfig(c => ({ ...c, ...p })), []); + + const handleGenerate = async () => { + setGenerating(true); + try { + const reportData = computeReportData(data, config); + const blob = await pdf().toBlob(); + const url = URL.createObjectURL(blob); + const a = document.createElement('a'); + const slug = (config.clientName || 'report').toLowerCase().replace(/\s+/g, '-'); + a.href = url; + a.download = `hihala-${slug}-${config.startDate.slice(0, 7)}.pdf`; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); + } catch (err) { + console.error('PDF generation failed:', err); + alert('Failed to generate PDF. Please try again.'); + } finally { + setGenerating(false); + } + }; + + return ( +
+
+

Report Builder

+

Configure and download a client-ready PDF report.

+
+ +
+
+ +
+
+
+ +
+
+
+ +
+ +
+
+ ); +}