Compare commits

...

2 Commits

1 changed files with 23 additions and 12 deletions

View File

@ -15,7 +15,6 @@ import {
MenuItem,
Paper,
Select,
Snackbar,
Tab,
Tabs,
TextField,
@ -153,12 +152,22 @@ function ReportHtmlFrame({ html }: { html: string }) {
const iframe = iframeRef.current;
if (!iframe) return;
let resizeObserver: ResizeObserver | null = null;
const updateHeight = () => {
try {
const doc = iframe.contentDocument || iframe.contentWindow?.document;
if (doc?.body) {
const newHeight = doc.body.scrollHeight + 20;
const newHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight) + 40;
if (newHeight > 50) setHeight(newHeight);
if (!resizeObserver) {
resizeObserver = new ResizeObserver(() => {
const h = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight) + 40;
if (h > 50) setHeight(h);
});
resizeObserver.observe(doc.body);
}
}
} catch { /* cross-origin safety */ }
};
@ -169,6 +178,7 @@ function ReportHtmlFrame({ html }: { html: string }) {
return () => {
iframe.removeEventListener('load', updateHeight);
timers.forEach(clearTimeout);
resizeObserver?.disconnect();
};
}, [html]);
@ -176,6 +186,7 @@ function ReportHtmlFrame({ html }: { html: string }) {
<iframe
ref={iframeRef}
srcDoc={html}
scrolling="no"
style={{
width: '100%',
height,
@ -286,7 +297,7 @@ function WeeklyReport({ installationId, installationName, installationEmail }: W
const [autoSend, setAutoSend] = useState({ sendWeekly: false, sendMonthly: false, sendYearly: false });
const [autoSendDirty, setAutoSendDirty] = useState(false);
const [savingAutoSend, setSavingAutoSend] = useState(false);
const [autoSendSnackbar, setAutoSendSnackbar] = useState<string | null>(null);
const [autoSendStatus, setAutoSendStatus] = useState<{ message: string; severity: 'success' | 'error' } | null>(null);
useEffect(() => {
axiosConfig.get('/GetEmailPreference', { params: { installationId } })
@ -309,9 +320,11 @@ function WeeklyReport({ installationId, installationName, installationEmail }: W
params: { installationId, ...autoSend }
});
setAutoSendDirty(false);
setAutoSendSnackbar(intl.formatMessage({ id: 'autoSendSaved', defaultMessage: 'Auto-send preferences saved.' }));
setAutoSendStatus({ message: intl.formatMessage({ id: 'autoSendSaved', defaultMessage: 'Auto-send preferences saved.' }), severity: 'success' });
setTimeout(() => setAutoSendStatus(null), 4000);
} catch {
setAutoSendSnackbar(intl.formatMessage({ id: 'autoSendSaveFailed', defaultMessage: 'Failed to save auto-send preferences.' }));
setAutoSendStatus({ message: intl.formatMessage({ id: 'autoSendSaveFailed', defaultMessage: 'Failed to save auto-send preferences.' }), severity: 'error' });
setTimeout(() => setAutoSendStatus(null), 4000);
} finally {
setSavingAutoSend(false);
}
@ -527,15 +540,13 @@ function WeeklyReport({ installationId, installationName, installationEmail }: W
<FormattedMessage id="autoSendNoEmail" defaultMessage="Set email address in Information tab to enable auto-send" />
</Typography>
)}
{autoSendStatus && (
<Typography variant="caption" sx={{ color: autoSendStatus.severity === 'success' ? '#27ae60' : '#e74c3c', ml: 1, textTransform: 'uppercase', fontWeight: 600 }}>
{autoSendStatus.message}
</Typography>
)}
</Box>
<Snackbar
open={!!autoSendSnackbar}
autoHideDuration={4000}
onClose={() => setAutoSendSnackbar(null)}
message={autoSendSnackbar}
/>
<Box sx={{ display: tabs[safeTab]?.key === 'daily' ? 'block' : 'none', minHeight: '50vh' }}>
<DailySection installationId={installationId} onHasData={setDailyHasData} onPeriodChange={(date: string) => setReportPeriods(prev => ({ ...prev, daily: { start: date, end: date } }))} />
</Box>