resolve issues with new features

This commit is contained in:
Matthias Hochmeister
2026-03-12 16:42:21 +01:00
parent 5aa309b97a
commit 68586b01dc
19 changed files with 526 additions and 109 deletions

View File

@@ -26,6 +26,7 @@ import {
Timer,
Info,
ExpandMore,
PictureAsPdf as PdfIcon,
} from '@mui/icons-material';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { Navigate } from 'react-router-dom';
@@ -75,6 +76,10 @@ function AdminSettings() {
adminServices: 15,
});
// State for PDF header/footer
const [pdfHeader, setPdfHeader] = useState('');
const [pdfFooter, setPdfFooter] = useState('');
// Fetch all settings
const { data: settings, isLoading } = useQuery({
queryKey: ['admin-settings'],
@@ -103,6 +108,11 @@ function AdminSettings() {
adminServices: intervalsSetting.value.adminServices ?? 15,
});
}
const pdfHeaderSetting = settings.find((s) => s.key === 'pdf_header');
if (pdfHeaderSetting?.value != null) setPdfHeader(pdfHeaderSetting.value);
const pdfFooterSetting = settings.find((s) => s.key === 'pdf_footer');
if (pdfFooterSetting?.value != null) setPdfFooter(pdfFooterSetting.value);
}
}, [settings]);
@@ -131,6 +141,33 @@ function AdminSettings() {
},
});
// Mutation for saving PDF settings
const pdfHeaderMutation = useMutation({
mutationFn: (value: string) => settingsApi.update('pdf_header', value),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['admin-settings'] });
queryClient.invalidateQueries({ queryKey: ['pdf-settings'] });
},
});
const pdfFooterMutation = useMutation({
mutationFn: (value: string) => settingsApi.update('pdf_footer', value),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['admin-settings'] });
queryClient.invalidateQueries({ queryKey: ['pdf-settings'] });
},
});
const handleSavePdfSettings = async () => {
try {
await Promise.all([
pdfHeaderMutation.mutateAsync(pdfHeader),
pdfFooterMutation.mutateAsync(pdfFooter),
]);
showSuccess('PDF-Einstellungen gespeichert');
} catch {
showError('Fehler beim Speichern der PDF-Einstellungen');
}
};
if (!isAdmin) {
return <Navigate to="/dashboard" replace />;
}
@@ -373,7 +410,53 @@ function AdminSettings() {
</CardContent>
</Card>
{/* Section 3: Info */}
{/* Section 3: PDF Settings */}
<Card>
<CardContent>
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
<PdfIcon color="primary" sx={{ mr: 2 }} />
<Typography variant="h6">PDF-Einstellungen</Typography>
</Box>
<Divider sx={{ mb: 2 }} />
<Typography variant="body2" color="text.secondary" sx={{ mb: 2 }}>
Kopf- und Fußzeile für Kalender-PDF-Exporte. Zeilenumbrüche werden übernommen, <strong>**fett**</strong> erzeugt fettgedruckten Text.
</Typography>
<Stack spacing={2}>
<TextField
label="PDF Kopfzeile"
value={pdfHeader}
onChange={(e) => setPdfHeader(e.target.value)}
multiline
minRows={2}
maxRows={6}
fullWidth
size="small"
/>
<TextField
label="PDF Fußzeile"
value={pdfFooter}
onChange={(e) => setPdfFooter(e.target.value)}
multiline
minRows={2}
maxRows={6}
fullWidth
size="small"
/>
<Box>
<Button
onClick={handleSavePdfSettings}
variant="contained"
size="small"
disabled={pdfHeaderMutation.isPending || pdfFooterMutation.isPending}
>
Speichern
</Button>
</Box>
</Stack>
</CardContent>
</Card>
{/* Section 4: Info */}
<Card>
<CardContent>
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>