new features
This commit is contained in:
@@ -28,7 +28,7 @@ import VeranstaltungKategorien from './pages/VeranstaltungKategorien';
|
||||
import Wissen from './pages/Wissen';
|
||||
import Bestellungen from './pages/Bestellungen';
|
||||
import BestellungDetail from './pages/BestellungDetail';
|
||||
import Shop from './pages/Shop';
|
||||
import Ausruestungsanfrage from './pages/Ausruestungsanfrage';
|
||||
import Issues from './pages/Issues';
|
||||
import AdminDashboard from './pages/AdminDashboard';
|
||||
import AdminSettings from './pages/AdminSettings';
|
||||
@@ -237,10 +237,10 @@ function App() {
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/shop"
|
||||
path="/ausruestungsanfrage"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<Shop />
|
||||
<Ausruestungsanfrage />
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -19,11 +19,11 @@ import {
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { bestellungApi } from '../../services/bestellung';
|
||||
import { shopApi } from '../../services/shop';
|
||||
import { ausruestungsanfrageApi } from '../../services/ausruestungsanfrage';
|
||||
import { BESTELLUNG_STATUS_LABELS, BESTELLUNG_STATUS_COLORS } from '../../types/bestellung.types';
|
||||
import { SHOP_STATUS_LABELS, SHOP_STATUS_COLORS } from '../../types/shop.types';
|
||||
import { AUSRUESTUNG_STATUS_LABELS, AUSRUESTUNG_STATUS_COLORS } from '../../types/ausruestungsanfrage.types';
|
||||
import type { BestellungStatus } from '../../types/bestellung.types';
|
||||
import type { ShopAnfrageStatus } from '../../types/shop.types';
|
||||
import type { AusruestungAnfrageStatus } from '../../types/ausruestungsanfrage.types';
|
||||
|
||||
function BestellungenTab() {
|
||||
const navigate = useNavigate();
|
||||
@@ -35,8 +35,8 @@ function BestellungenTab() {
|
||||
});
|
||||
|
||||
const { data: requests, isLoading: requestsLoading } = useQuery({
|
||||
queryKey: ['admin-shop-requests'],
|
||||
queryFn: () => shopApi.getRequests({ status: 'offen' }),
|
||||
queryKey: ['admin-ausruestungsanfrage-requests'],
|
||||
queryFn: () => ausruestungsanfrageApi.getRequests({ status: 'offen' }),
|
||||
});
|
||||
|
||||
const formatCurrency = (value?: number) =>
|
||||
@@ -44,11 +44,11 @@ function BestellungenTab() {
|
||||
|
||||
return (
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 3 }}>
|
||||
{/* Pending Shop Requests */}
|
||||
{/* Pending Ausrüstungsanfragen */}
|
||||
{(requests?.length ?? 0) > 0 && (
|
||||
<Paper sx={{ p: 2 }}>
|
||||
<Typography variant="h6" gutterBottom>
|
||||
Offene Shop-Anfragen ({requests?.length})
|
||||
Offene Ausrüstungsanfragen ({requests?.length})
|
||||
</Typography>
|
||||
{requestsLoading ? (
|
||||
<CircularProgress size={24} />
|
||||
@@ -69,14 +69,14 @@ function BestellungenTab() {
|
||||
key={req.id}
|
||||
hover
|
||||
sx={{ cursor: 'pointer' }}
|
||||
onClick={() => navigate('/shop?tab=2')}
|
||||
onClick={() => navigate('/ausruestungsanfrage?tab=2')}
|
||||
>
|
||||
<TableCell>{req.id}</TableCell>
|
||||
<TableCell>{req.anfrager_name || '–'}</TableCell>
|
||||
<TableCell>
|
||||
<Chip
|
||||
label={SHOP_STATUS_LABELS[req.status as ShopAnfrageStatus]}
|
||||
color={SHOP_STATUS_COLORS[req.status as ShopAnfrageStatus]}
|
||||
label={AUSRUESTUNG_STATUS_LABELS[req.status as AusruestungAnfrageStatus]}
|
||||
color={AUSRUESTUNG_STATUS_COLORS[req.status as AusruestungAnfrageStatus]}
|
||||
size="small"
|
||||
/>
|
||||
</TableCell>
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
CircularProgress, Divider,
|
||||
} from '@mui/material';
|
||||
import DeleteSweepIcon from '@mui/icons-material/DeleteSweep';
|
||||
import RestartAltIcon from '@mui/icons-material/RestartAlt';
|
||||
import { api } from '../../services/api';
|
||||
import { useNotification } from '../../contexts/NotificationContext';
|
||||
|
||||
@@ -25,6 +26,18 @@ const SECTIONS: CleanupSection[] = [
|
||||
{ key: 'equipment-history', label: 'Ausruestungs-Wartungslog', description: 'Alte Ausruestungs-Wartungseintraege entfernen.', defaultDays: 730 },
|
||||
];
|
||||
|
||||
interface ResetSection {
|
||||
key: string;
|
||||
label: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
const RESET_SECTIONS: ResetSection[] = [
|
||||
{ key: 'reset-bestellungen', label: 'Bestellungen zuruecksetzen', description: 'Alle Bestellungen, Positionen, Dateien, Erinnerungen und Historie loeschen und Nummern zuruecksetzen.' },
|
||||
{ key: 'reset-ausruestung-anfragen', label: 'Ausruestungsanfragen zuruecksetzen', description: 'Alle Ausruestungsanfragen und zugehoerige Positionen loeschen und Nummern zuruecksetzen.' },
|
||||
{ key: 'reset-issues', label: 'Issues zuruecksetzen', description: 'Alle Issues und Kommentare loeschen und Nummern zuruecksetzen.' },
|
||||
];
|
||||
|
||||
interface SectionState {
|
||||
days: number;
|
||||
previewCount: number | null;
|
||||
@@ -41,6 +54,13 @@ export default function DataManagementTab() {
|
||||
const [confirmDialog, setConfirmDialog] = useState<{ key: string; label: string; count: number } | null>(null);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
|
||||
// Reset sections state
|
||||
const [resetStates, setResetStates] = useState<Record<string, { previewCount: number | null; loading: boolean }>>(() =>
|
||||
Object.fromEntries(RESET_SECTIONS.map(s => [s.key, { previewCount: null, loading: false }]))
|
||||
);
|
||||
const [resetConfirmDialog, setResetConfirmDialog] = useState<{ key: string; label: string; count: number } | null>(null);
|
||||
const [resetDeleting, setResetDeleting] = useState(false);
|
||||
|
||||
const updateState = useCallback((key: string, partial: Partial<SectionState>) => {
|
||||
setStates(prev => ({ ...prev, [key]: { ...prev[key], ...partial } }));
|
||||
}, []);
|
||||
@@ -76,6 +96,34 @@ export default function DataManagementTab() {
|
||||
}
|
||||
}, [confirmDialog, states, updateState, showSuccess, showError]);
|
||||
|
||||
const handleResetPreview = useCallback(async (key: string) => {
|
||||
setResetStates(prev => ({ ...prev, [key]: { previewCount: null, loading: true } }));
|
||||
try {
|
||||
const res = await api.delete(`/api/admin/cleanup/${key}`);
|
||||
setResetStates(prev => ({ ...prev, [key]: { previewCount: res.data.data.count, loading: false } }));
|
||||
} catch {
|
||||
showError('Vorschau konnte nicht geladen werden');
|
||||
setResetStates(prev => ({ ...prev, [key]: { ...prev[key], loading: false } }));
|
||||
}
|
||||
}, [showError]);
|
||||
|
||||
const handleResetDelete = useCallback(async () => {
|
||||
if (!resetConfirmDialog) return;
|
||||
const { key } = resetConfirmDialog;
|
||||
setResetDeleting(true);
|
||||
try {
|
||||
const res = await api.delete(`/api/admin/cleanup/${key}?confirm=true`);
|
||||
const deleted = res.data.data.count;
|
||||
showSuccess(`${deleted} Eintraege geloescht und Nummern zurueckgesetzt`);
|
||||
setResetStates(prev => ({ ...prev, [key]: { previewCount: null, loading: false } }));
|
||||
} catch {
|
||||
showError('Zuruecksetzen fehlgeschlagen');
|
||||
} finally {
|
||||
setResetDeleting(false);
|
||||
setResetConfirmDialog(null);
|
||||
}
|
||||
}, [resetConfirmDialog, showSuccess, showError]);
|
||||
|
||||
return (
|
||||
<Box sx={{ maxWidth: 800 }}>
|
||||
<Typography variant="h6" sx={{ mb: 1 }}>Datenverwaltung</Typography>
|
||||
@@ -165,6 +213,81 @@ export default function DataManagementTab() {
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
|
||||
{/* ---- Reset / Truncate sections ---- */}
|
||||
<Divider sx={{ my: 4 }} />
|
||||
<Typography variant="h6" sx={{ mb: 1 }}>Daten zuruecksetzen</Typography>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
|
||||
Alle Eintraege loeschen und Nummern (IDs) auf 1 zuruecksetzen. Abhaengige Daten werden ebenfalls geloescht.
|
||||
</Typography>
|
||||
|
||||
{RESET_SECTIONS.map((section) => {
|
||||
const rs = resetStates[section.key];
|
||||
return (
|
||||
<Paper key={section.key} sx={{ p: 3, mb: 2 }}>
|
||||
<Typography variant="subtitle1" fontWeight={600}>{section.label}</Typography>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 2 }}>{section.description}</Typography>
|
||||
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, flexWrap: 'wrap' }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="small"
|
||||
onClick={() => handleResetPreview(section.key)}
|
||||
disabled={rs?.loading}
|
||||
startIcon={rs?.loading ? <CircularProgress size={16} /> : undefined}
|
||||
>
|
||||
Vorschau
|
||||
</Button>
|
||||
|
||||
{rs?.previewCount !== null && rs?.previewCount !== undefined && (
|
||||
<>
|
||||
<Alert severity={rs.previewCount > 0 ? 'warning' : 'info'} sx={{ py: 0 }}>
|
||||
{rs.previewCount} {rs.previewCount === 1 ? 'Eintrag' : 'Eintraege'} vorhanden
|
||||
</Alert>
|
||||
|
||||
{rs.previewCount > 0 && (
|
||||
<Button
|
||||
variant="contained"
|
||||
color="error"
|
||||
size="small"
|
||||
startIcon={<RestartAltIcon />}
|
||||
onClick={() => setResetConfirmDialog({ key: section.key, label: section.label, count: rs.previewCount! })}
|
||||
>
|
||||
Zuruecksetzen
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Paper>
|
||||
);
|
||||
})}
|
||||
|
||||
<Dialog open={!!resetConfirmDialog} onClose={() => !resetDeleting && setResetConfirmDialog(null)}>
|
||||
<DialogTitle>Daten zuruecksetzen?</DialogTitle>
|
||||
<DialogContent>
|
||||
<DialogContentText>
|
||||
{resetConfirmDialog && (
|
||||
<>
|
||||
<strong>{resetConfirmDialog.count}</strong> {resetConfirmDialog.count === 1 ? 'Eintrag' : 'Eintraege'} aus <strong>{resetConfirmDialog.label}</strong> werden
|
||||
unwiderruflich geloescht und die Nummerierung auf 1 zurueckgesetzt. Dieser Vorgang kann nicht rueckgaengig gemacht werden.
|
||||
</>
|
||||
)}
|
||||
</DialogContentText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => setResetConfirmDialog(null)} disabled={resetDeleting}>Abbrechen</Button>
|
||||
<Button
|
||||
onClick={handleResetDelete}
|
||||
color="error"
|
||||
variant="contained"
|
||||
disabled={resetDeleting}
|
||||
startIcon={resetDeleting ? <CircularProgress size={16} /> : <RestartAltIcon />}
|
||||
>
|
||||
{resetDeleting ? 'Wird zurueckgesetzt...' : 'Endgueltig zuruecksetzen'}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
import { useState } from 'react';
|
||||
import { useState, useRef, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
Box, Paper, Typography, Button, Autocomplete, TextField,
|
||||
Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions,
|
||||
CircularProgress,
|
||||
Accordion, AccordionDetails, AccordionSummary,
|
||||
Box, Button, Card, CardContent, Checkbox, Chip, Paper, Typography,
|
||||
Autocomplete, TextField, Dialog, DialogTitle, DialogContent,
|
||||
DialogContentText, DialogActions, CircularProgress, FormControlLabel,
|
||||
IconButton, Tooltip,
|
||||
} from '@mui/material';
|
||||
import DeleteIcon from '@mui/icons-material/Delete';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||
import SyncIcon from '@mui/icons-material/Sync';
|
||||
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { adminApi } from '../../services/admin';
|
||||
import { useNotification } from '../../contexts/NotificationContext';
|
||||
import type { UserOverview } from '../../types/admin.types';
|
||||
|
||||
export default function DebugTab() {
|
||||
const queryClient = useQueryClient();
|
||||
const { showSuccess, showError } = useNotification();
|
||||
|
||||
// ── Profile deletion ──
|
||||
const { data: users = [], isLoading: usersLoading } = useQuery<UserOverview[]>({
|
||||
queryKey: ['admin', 'users'],
|
||||
queryFn: adminApi.getUsers,
|
||||
@@ -38,14 +45,55 @@ export default function DebugTab() {
|
||||
}
|
||||
};
|
||||
|
||||
// ── FDISK Sync ──
|
||||
const logBoxRef = useRef<HTMLDivElement>(null);
|
||||
const [force, setForce] = useState(false);
|
||||
|
||||
const { data: syncData, isLoading: syncLoading, isError: syncError } = useQuery({
|
||||
queryKey: ['admin', 'fdisk-sync', 'logs'],
|
||||
queryFn: adminApi.fdiskSyncLogs,
|
||||
refetchInterval: 5000,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (logBoxRef.current) {
|
||||
logBoxRef.current.scrollTop = logBoxRef.current.scrollHeight;
|
||||
}
|
||||
}, [syncData?.logs.length]);
|
||||
|
||||
const triggerMutation = useMutation({
|
||||
mutationFn: (forceSync: boolean) => adminApi.fdiskSyncTrigger(forceSync),
|
||||
onSuccess: () => {
|
||||
showSuccess('Sync gestartet');
|
||||
queryClient.invalidateQueries({ queryKey: ['admin', 'fdisk-sync', 'logs'] });
|
||||
},
|
||||
onError: (err: unknown) => {
|
||||
const msg = (err as { response?: { status?: number } })?.response?.status === 409
|
||||
? 'Sync läuft bereits'
|
||||
: 'Sync konnte nicht gestartet werden';
|
||||
showError(msg);
|
||||
},
|
||||
});
|
||||
|
||||
const running = syncData?.running ?? false;
|
||||
|
||||
const copyLogs = useCallback(() => {
|
||||
const text = (syncData?.logs ?? []).map((e) => e.line).join('\n');
|
||||
navigator.clipboard.writeText(text).then(
|
||||
() => showSuccess('Logs kopiert'),
|
||||
() => showError('Kopieren fehlgeschlagen'),
|
||||
);
|
||||
}, [syncData?.logs, showSuccess, showError]);
|
||||
|
||||
return (
|
||||
<Box sx={{ maxWidth: 600 }}>
|
||||
<Box>
|
||||
<Typography variant="h6" sx={{ mb: 1 }}>Debug-Werkzeuge</Typography>
|
||||
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
|
||||
Werkzeuge fuer Fehlersuche und Datenbereinigung.
|
||||
</Typography>
|
||||
|
||||
<Paper sx={{ p: 3 }}>
|
||||
{/* Profile deletion */}
|
||||
<Paper sx={{ p: 3, mb: 3, maxWidth: 600 }}>
|
||||
<Typography variant="subtitle1" fontWeight={600} sx={{ mb: 1 }}>
|
||||
Profildaten loeschen
|
||||
</Typography>
|
||||
@@ -80,6 +128,111 @@ export default function DebugTab() {
|
||||
</Box>
|
||||
</Paper>
|
||||
|
||||
{/* FDISK Sync */}
|
||||
<Accordion defaultExpanded={false}>
|
||||
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
||||
<Typography variant="subtitle1" fontWeight={600}>FDISK Synchronisation</Typography>
|
||||
</AccordionSummary>
|
||||
<AccordionDetails>
|
||||
<Card variant="outlined">
|
||||
<CardContent sx={{ display: 'flex', alignItems: 'center', gap: 2, flexWrap: 'wrap' }}>
|
||||
<Box sx={{ flex: 1 }}>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
Synchronisiert Mitgliederdaten und Ausbildungen aus FDISK in die Datenbank.
|
||||
Läuft automatisch täglich um Mitternacht.
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1.5 }}>
|
||||
<Chip
|
||||
label={running ? 'Läuft…' : 'Bereit'}
|
||||
color={running ? 'warning' : 'success'}
|
||||
size="small"
|
||||
icon={running ? <CircularProgress size={12} color="inherit" /> : undefined}
|
||||
/>
|
||||
<Button
|
||||
variant="contained"
|
||||
startIcon={<SyncIcon />}
|
||||
onClick={() => triggerMutation.mutate(force)}
|
||||
disabled={running || triggerMutation.isPending}
|
||||
>
|
||||
Jetzt synchronisieren
|
||||
</Button>
|
||||
</Box>
|
||||
<FormControlLabel
|
||||
control={<Checkbox checked={force} onChange={(e) => setForce(e.target.checked)} />}
|
||||
label="Alle Mitglieder erzwungen synchronisieren"
|
||||
/>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
<Card variant="outlined" sx={{ mt: 2 }}>
|
||||
<CardContent>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mb: 1 }}>
|
||||
<Typography variant="subtitle2">Protokoll (letzte 500 Zeilen)</Typography>
|
||||
<Tooltip title="Logs kopieren">
|
||||
<span>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={copyLogs}
|
||||
disabled={!syncData?.logs?.length}
|
||||
>
|
||||
<ContentCopyIcon fontSize="small" />
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
{syncLoading && (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', py: 4 }}>
|
||||
<CircularProgress size={28} />
|
||||
</Box>
|
||||
)}
|
||||
{syncError && (
|
||||
<Typography color="error" variant="body2">
|
||||
Sync-Dienst nicht erreichbar. Läuft der fdisk-sync Container?
|
||||
</Typography>
|
||||
)}
|
||||
{!syncLoading && !syncError && (
|
||||
<Box
|
||||
ref={logBoxRef}
|
||||
sx={{
|
||||
fontFamily: 'monospace',
|
||||
fontSize: '0.75rem',
|
||||
bgcolor: 'grey.900',
|
||||
color: 'grey.100',
|
||||
borderRadius: 1,
|
||||
p: 1.5,
|
||||
maxHeight: 500,
|
||||
overflowY: 'auto',
|
||||
whiteSpace: 'pre-wrap',
|
||||
wordBreak: 'break-all',
|
||||
}}
|
||||
>
|
||||
{(syncData?.logs ?? []).length === 0 ? (
|
||||
<Typography variant="caption" color="grey.500">Noch keine Logs vorhanden.</Typography>
|
||||
) : (
|
||||
(syncData?.logs ?? []).map((entry, i) => (
|
||||
<Box
|
||||
key={i}
|
||||
component="span"
|
||||
sx={{
|
||||
display: 'block',
|
||||
color: entry.line.includes('ERROR') || entry.line.includes('WARN')
|
||||
? (entry.line.includes('ERROR') ? 'error.light' : 'warning.light')
|
||||
: 'inherit',
|
||||
}}
|
||||
>
|
||||
{entry.line}
|
||||
</Box>
|
||||
))
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</AccordionDetails>
|
||||
</Accordion>
|
||||
|
||||
{/* Delete confirmation dialog */}
|
||||
<Dialog open={confirmOpen} onClose={() => !deleting && setConfirmOpen(false)}>
|
||||
<DialogTitle>Profildaten loeschen?</DialogTitle>
|
||||
<DialogContent>
|
||||
|
||||
@@ -99,7 +99,7 @@ const PERMISSION_SUB_GROUPS: Record<string, Record<string, string[]>> = {
|
||||
'Erinnerungen': ['manage_reminders'],
|
||||
'Widget': ['widget'],
|
||||
},
|
||||
shop: {
|
||||
ausruestungsanfrage: {
|
||||
'Katalog': ['view', 'manage_catalog'],
|
||||
'Anfragen': ['create_request', 'approve_requests', 'link_orders', 'view_overview', 'order_for_user'],
|
||||
'Widget': ['widget'],
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import { Card, CardContent, Typography, Box, Chip, List, ListItem, ListItemText, Divider, Skeleton } from '@mui/material';
|
||||
import { Store } from '@mui/icons-material';
|
||||
import { Build } from '@mui/icons-material';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { shopApi } from '../../services/shop';
|
||||
import { SHOP_STATUS_LABELS, SHOP_STATUS_COLORS } from '../../types/shop.types';
|
||||
import type { ShopAnfrageStatus } from '../../types/shop.types';
|
||||
import { ausruestungsanfrageApi } from '../../services/ausruestungsanfrage';
|
||||
import { AUSRUESTUNG_STATUS_LABELS, AUSRUESTUNG_STATUS_COLORS } from '../../types/ausruestungsanfrage.types';
|
||||
import type { AusruestungAnfrageStatus } from '../../types/ausruestungsanfrage.types';
|
||||
|
||||
function ShopWidget() {
|
||||
function AusruestungsanfrageWidget() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { data: requests, isLoading, isError } = useQuery({
|
||||
queryKey: ['shop-widget-requests'],
|
||||
queryFn: () => shopApi.getRequests({ status: 'offen' }),
|
||||
queryKey: ['ausruestungsanfrage-widget-requests'],
|
||||
queryFn: () => ausruestungsanfrageApi.getRequests({ status: 'offen' }),
|
||||
refetchInterval: 5 * 60 * 1000,
|
||||
retry: 1,
|
||||
});
|
||||
@@ -20,7 +20,7 @@ function ShopWidget() {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Typography variant="h6" gutterBottom>Shop-Anfragen</Typography>
|
||||
<Typography variant="h6" gutterBottom>Ausrüstungsanfragen</Typography>
|
||||
<Skeleton variant="rectangular" height={60} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
@@ -31,7 +31,7 @@ function ShopWidget() {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Typography variant="h6" gutterBottom>Shop-Anfragen</Typography>
|
||||
<Typography variant="h6" gutterBottom>Ausrüstungsanfragen</Typography>
|
||||
<Typography variant="body2" color="text.secondary">
|
||||
Anfragen konnten nicht geladen werden.
|
||||
</Typography>
|
||||
@@ -46,9 +46,9 @@ function ShopWidget() {
|
||||
return (
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Typography variant="h6" gutterBottom>Shop-Anfragen</Typography>
|
||||
<Typography variant="h6" gutterBottom>Ausrüstungsanfragen</Typography>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1, color: 'text.secondary' }}>
|
||||
<Store fontSize="small" />
|
||||
<Build fontSize="small" />
|
||||
<Typography variant="body2">Keine offenen Anfragen</Typography>
|
||||
</Box>
|
||||
</CardContent>
|
||||
@@ -60,7 +60,7 @@ function ShopWidget() {
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 1 }}>
|
||||
<Typography variant="h6">Shop-Anfragen</Typography>
|
||||
<Typography variant="h6">Ausrüstungsanfragen</Typography>
|
||||
<Chip label={`${pendingCount} offen`} size="small" color="warning" />
|
||||
</Box>
|
||||
<List dense disablePadding>
|
||||
@@ -70,7 +70,7 @@ function ShopWidget() {
|
||||
<ListItem
|
||||
disablePadding
|
||||
sx={{ cursor: 'pointer', py: 0.5, '&:hover': { bgcolor: 'action.hover' } }}
|
||||
onClick={() => navigate('/shop?tab=2')}
|
||||
onClick={() => navigate('/ausruestungsanfrage?tab=2')}
|
||||
>
|
||||
<ListItemText
|
||||
primary={`Anfrage #${req.id}`}
|
||||
@@ -79,8 +79,8 @@ function ShopWidget() {
|
||||
secondaryTypographyProps={{ variant: 'caption' }}
|
||||
/>
|
||||
<Chip
|
||||
label={SHOP_STATUS_LABELS[req.status as ShopAnfrageStatus]}
|
||||
color={SHOP_STATUS_COLORS[req.status as ShopAnfrageStatus]}
|
||||
label={AUSRUESTUNG_STATUS_LABELS[req.status as AusruestungAnfrageStatus]}
|
||||
color={AUSRUESTUNG_STATUS_COLORS[req.status as AusruestungAnfrageStatus]}
|
||||
size="small"
|
||||
sx={{ ml: 1 }}
|
||||
/>
|
||||
@@ -93,7 +93,7 @@ function ShopWidget() {
|
||||
variant="caption"
|
||||
color="primary"
|
||||
sx={{ cursor: 'pointer', mt: 1, display: 'block' }}
|
||||
onClick={() => navigate('/shop?tab=2')}
|
||||
onClick={() => navigate('/ausruestungsanfrage?tab=2')}
|
||||
>
|
||||
Alle {pendingCount} Anfragen anzeigen
|
||||
</Typography>
|
||||
@@ -103,4 +103,4 @@ function ShopWidget() {
|
||||
);
|
||||
}
|
||||
|
||||
export default ShopWidget;
|
||||
export default AusruestungsanfrageWidget;
|
||||
@@ -19,4 +19,4 @@ export { default as BannerWidget } from './BannerWidget';
|
||||
export { default as LinksWidget } from './LinksWidget';
|
||||
export { default as WidgetGroup } from './WidgetGroup';
|
||||
export { default as BestellungenWidget } from './BestellungenWidget';
|
||||
export { default as ShopWidget } from './ShopWidget';
|
||||
export { default as AusruestungsanfrageWidget } from './AusruestungsanfrageWidget';
|
||||
|
||||
@@ -4,14 +4,13 @@ import {
|
||||
Toolbar,
|
||||
Typography,
|
||||
IconButton,
|
||||
Button,
|
||||
Menu,
|
||||
MenuItem,
|
||||
Avatar,
|
||||
ListItemIcon,
|
||||
Divider,
|
||||
Box,
|
||||
Tooltip,
|
||||
Menu,
|
||||
MenuItem,
|
||||
} from '@mui/material';
|
||||
import {
|
||||
LocalFireDepartment,
|
||||
@@ -19,14 +18,11 @@ import {
|
||||
Settings,
|
||||
Logout,
|
||||
Menu as MenuIcon,
|
||||
Launch,
|
||||
Chat,
|
||||
} from '@mui/icons-material';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useAuth } from '../../contexts/AuthContext';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import NotificationBell from './NotificationBell';
|
||||
import { configApi } from '../../services/config';
|
||||
import { useLayout } from '../../contexts/LayoutContext';
|
||||
|
||||
interface HeaderProps {
|
||||
@@ -38,14 +34,6 @@ function Header({ onMenuClick }: HeaderProps) {
|
||||
const navigate = useNavigate();
|
||||
const { toggleChatPanel } = useLayout();
|
||||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
||||
const [toolsAnchorEl, setToolsAnchorEl] = useState<null | HTMLElement>(null);
|
||||
|
||||
const { data: externalLinks } = useQuery({
|
||||
queryKey: ['external-links'],
|
||||
queryFn: () => configApi.getExternalLinks(),
|
||||
staleTime: 10 * 60 * 1000,
|
||||
enabled: !!user,
|
||||
});
|
||||
|
||||
const handleMenuOpen = (event: React.MouseEvent<HTMLElement>) => {
|
||||
setAnchorEl(event.currentTarget);
|
||||
@@ -55,14 +43,6 @@ function Header({ onMenuClick }: HeaderProps) {
|
||||
setAnchorEl(null);
|
||||
};
|
||||
|
||||
const handleToolsOpen = (event: React.MouseEvent<HTMLElement>) => {
|
||||
setToolsAnchorEl(event.currentTarget);
|
||||
};
|
||||
|
||||
const handleToolsClose = () => {
|
||||
setToolsAnchorEl(null);
|
||||
};
|
||||
|
||||
const handleProfile = () => {
|
||||
handleMenuClose();
|
||||
navigate('/profile');
|
||||
@@ -78,11 +58,6 @@ function Header({ onMenuClick }: HeaderProps) {
|
||||
logout();
|
||||
};
|
||||
|
||||
const handleOpenExternal = (url: string) => {
|
||||
handleToolsClose();
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
};
|
||||
|
||||
// Get initials for avatar
|
||||
const getInitials = () => {
|
||||
if (!user) return '?';
|
||||
@@ -90,19 +65,6 @@ function Header({ onMenuClick }: HeaderProps) {
|
||||
return initials || user.name?.[0] || '?';
|
||||
};
|
||||
|
||||
const linkEntries = externalLinks
|
||||
? Object.entries(externalLinks).filter(([key, url]) => key !== 'customLinks' && !!url)
|
||||
: [];
|
||||
|
||||
const customLinks: Array<{ name: string; url: string }> =
|
||||
externalLinks?.customLinks ?? [];
|
||||
|
||||
const linkLabels: Record<string, string> = {
|
||||
nextcloud: 'Nextcloud Dateien',
|
||||
bookstack: 'Wissensdatenbank',
|
||||
vikunja: 'Aufgabenverwaltung',
|
||||
};
|
||||
|
||||
return (
|
||||
<AppBar
|
||||
position="fixed"
|
||||
@@ -128,72 +90,6 @@ function Header({ onMenuClick }: HeaderProps) {
|
||||
|
||||
{user && (
|
||||
<>
|
||||
{(linkEntries.length > 0 || customLinks.length > 0) && (
|
||||
<>
|
||||
<Button
|
||||
variant="text"
|
||||
color="inherit"
|
||||
onClick={handleToolsOpen}
|
||||
size="small"
|
||||
startIcon={<Launch />}
|
||||
aria-label="FF Rems Tools"
|
||||
aria-controls="tools-menu"
|
||||
aria-haspopup="true"
|
||||
sx={{ display: { xs: 'none', sm: 'inline-flex' } }}
|
||||
>
|
||||
FF Rems Tools
|
||||
</Button>
|
||||
<Tooltip title="FF Rems Tools">
|
||||
<IconButton
|
||||
color="inherit"
|
||||
onClick={handleToolsOpen}
|
||||
size="small"
|
||||
aria-label="FF Rems Tools"
|
||||
sx={{ display: { xs: 'inline-flex', sm: 'none' } }}
|
||||
>
|
||||
<Launch />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<Menu
|
||||
id="tools-menu"
|
||||
anchorEl={toolsAnchorEl}
|
||||
open={Boolean(toolsAnchorEl)}
|
||||
onClose={handleToolsClose}
|
||||
anchorOrigin={{
|
||||
vertical: 'bottom',
|
||||
horizontal: 'right',
|
||||
}}
|
||||
transformOrigin={{
|
||||
vertical: 'top',
|
||||
horizontal: 'right',
|
||||
}}
|
||||
PaperProps={{
|
||||
elevation: 3,
|
||||
sx: { minWidth: 180, mt: 1 },
|
||||
}}
|
||||
>
|
||||
{linkEntries.map(([key, url]) => (
|
||||
<MenuItem key={key} onClick={() => handleOpenExternal(url)}>
|
||||
<ListItemIcon>
|
||||
<Launch fontSize="small" />
|
||||
</ListItemIcon>
|
||||
{linkLabels[key] || key}
|
||||
</MenuItem>
|
||||
))}
|
||||
{customLinks.length > 0 && linkEntries.length > 0 && <Divider />}
|
||||
{customLinks.map((link, index) => (
|
||||
<MenuItem key={`custom-${index}`} onClick={() => handleOpenExternal(link.url)}>
|
||||
<ListItemIcon>
|
||||
<Launch fontSize="small" />
|
||||
</ListItemIcon>
|
||||
{link.name}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Tooltip title="Chat">
|
||||
<IconButton
|
||||
color="inherit"
|
||||
|
||||
@@ -26,7 +26,6 @@ import {
|
||||
ExpandMore,
|
||||
ExpandLess,
|
||||
LocalShipping,
|
||||
Store,
|
||||
BugReport,
|
||||
} from '@mui/icons-material';
|
||||
import { useNavigate, useLocation } from 'react-router-dom';
|
||||
@@ -62,11 +61,10 @@ const adminSubItems: SubItem[] = [
|
||||
{ text: 'Broadcast', path: '/admin?tab=3' },
|
||||
{ text: 'Banner', path: '/admin?tab=4' },
|
||||
{ text: 'Wartung', path: '/admin?tab=5' },
|
||||
{ text: 'FDISK Sync', path: '/admin?tab=6' },
|
||||
{ text: 'Berechtigungen', path: '/admin?tab=7' },
|
||||
{ text: 'Bestellungen', path: '/admin?tab=8' },
|
||||
{ text: 'Datenverwaltung', path: '/admin?tab=9' },
|
||||
{ text: 'Debug', path: '/admin?tab=10' },
|
||||
{ text: 'Berechtigungen', path: '/admin?tab=6' },
|
||||
{ text: 'Bestellungen', path: '/admin?tab=7' },
|
||||
{ text: 'Datenverwaltung', path: '/admin?tab=8' },
|
||||
{ text: 'Debug', path: '/admin?tab=9' },
|
||||
];
|
||||
|
||||
const baseNavigationItems: NavigationItem[] = [
|
||||
@@ -86,7 +84,7 @@ const baseNavigationItems: NavigationItem[] = [
|
||||
text: 'Fahrzeuge',
|
||||
icon: <DirectionsCar />,
|
||||
path: '/fahrzeuge',
|
||||
permission: 'fahrzeuge:access',
|
||||
permission: 'fahrzeuge:view',
|
||||
},
|
||||
{
|
||||
text: 'Ausrüstung',
|
||||
@@ -123,18 +121,18 @@ const baseNavigationItems: NavigationItem[] = [
|
||||
permission: 'bestellungen:view',
|
||||
},
|
||||
{
|
||||
text: 'Shop',
|
||||
icon: <Store />,
|
||||
path: '/shop',
|
||||
text: 'Ausrüstungsanfragen',
|
||||
icon: <Build />,
|
||||
path: '/ausruestungsanfrage',
|
||||
// subItems computed dynamically in navigationItems useMemo
|
||||
permission: 'shop:view',
|
||||
permission: 'ausruestungsanfrage:view',
|
||||
},
|
||||
{
|
||||
text: 'Issues',
|
||||
icon: <BugReport />,
|
||||
path: '/issues',
|
||||
// subItems computed dynamically in navigationItems useMemo
|
||||
permission: 'issues:create',
|
||||
permission: 'issues:view_own',
|
||||
},
|
||||
];
|
||||
|
||||
@@ -187,24 +185,27 @@ function Sidebar({ mobileOpen, onMobileClose }: SidebarProps) {
|
||||
permission: 'fahrzeuge:view',
|
||||
};
|
||||
|
||||
// Build Shop sub-items dynamically based on permissions (tab order must match Shop.tsx)
|
||||
const shopSubItems: SubItem[] = [];
|
||||
let shopTabIdx = 0;
|
||||
if (hasPermission('shop:create_request')) { shopSubItems.push({ text: 'Meine Anfragen', path: `/shop?tab=${shopTabIdx}` }); shopTabIdx++; }
|
||||
if (hasPermission('shop:approve_requests')) { shopSubItems.push({ text: 'Alle Anfragen', path: `/shop?tab=${shopTabIdx}` }); shopTabIdx++; }
|
||||
if (hasPermission('shop:view_overview')) { shopSubItems.push({ text: 'Übersicht', path: `/shop?tab=${shopTabIdx}` }); shopTabIdx++; }
|
||||
shopSubItems.push({ text: 'Katalog', path: `/shop?tab=${shopTabIdx}` });
|
||||
// Build Ausrüstungsanfrage sub-items dynamically based on permissions (tab order must match Ausruestungsanfrage.tsx)
|
||||
const ausruestungSubItems: SubItem[] = [];
|
||||
let ausruestungTabIdx = 0;
|
||||
if (hasPermission('ausruestungsanfrage:create_request')) { ausruestungSubItems.push({ text: 'Meine Anfragen', path: `/ausruestungsanfrage?tab=${ausruestungTabIdx}` }); ausruestungTabIdx++; }
|
||||
if (hasPermission('ausruestungsanfrage:approve_requests')) { ausruestungSubItems.push({ text: 'Alle Anfragen', path: `/ausruestungsanfrage?tab=${ausruestungTabIdx}` }); ausruestungTabIdx++; }
|
||||
if (hasPermission('ausruestungsanfrage:view_overview')) { ausruestungSubItems.push({ text: 'Übersicht', path: `/ausruestungsanfrage?tab=${ausruestungTabIdx}` }); ausruestungTabIdx++; }
|
||||
ausruestungSubItems.push({ text: 'Katalog', path: `/ausruestungsanfrage?tab=${ausruestungTabIdx}` });
|
||||
|
||||
// Build Issues sub-items dynamically (tab order must match Issues.tsx)
|
||||
const issuesSubItems: SubItem[] = [{ text: 'Meine Issues', path: '/issues?tab=0' }];
|
||||
if (hasPermission('issues:view_all')) {
|
||||
issuesSubItems.push({ text: 'Alle Issues', path: '/issues?tab=1' });
|
||||
}
|
||||
if (hasPermission('issues:manage')) {
|
||||
issuesSubItems.push({ text: 'Erledigte Issues', path: `/issues?tab=${issuesSubItems.length}` });
|
||||
}
|
||||
|
||||
const items = baseNavigationItems
|
||||
.map((item) => {
|
||||
if (item.path === '/fahrzeuge') return fahrzeugeItem;
|
||||
if (item.path === '/shop') return { ...item, subItems: shopSubItems };
|
||||
if (item.path === '/ausruestungsanfrage') return { ...item, subItems: ausruestungSubItems };
|
||||
if (item.path === '/issues') return { ...item, subItems: issuesSubItems };
|
||||
return item;
|
||||
})
|
||||
|
||||
@@ -14,7 +14,7 @@ export const WIDGETS = [
|
||||
{ key: 'adminStatus', label: 'Admin Status', defaultVisible: true },
|
||||
{ key: 'links', label: 'Links', defaultVisible: true },
|
||||
{ key: 'bestellungen', label: 'Bestellungen', defaultVisible: true },
|
||||
{ key: 'shopRequests', label: 'Shop-Anfragen', defaultVisible: true },
|
||||
{ key: 'ausruestungsanfragen', label: 'Ausrüstungsanfragen', defaultVisible: true },
|
||||
] as const;
|
||||
|
||||
export type WidgetKey = typeof WIDGETS[number]['key'];
|
||||
|
||||
@@ -8,7 +8,6 @@ import UserOverviewTab from '../components/admin/UserOverviewTab';
|
||||
import NotificationBroadcastTab from '../components/admin/NotificationBroadcastTab';
|
||||
import BannerManagementTab from '../components/admin/BannerManagementTab';
|
||||
import ServiceModeTab from '../components/admin/ServiceModeTab';
|
||||
import FdiskSyncTab from '../components/admin/FdiskSyncTab';
|
||||
import PermissionMatrixTab from '../components/admin/PermissionMatrixTab';
|
||||
import BestellungenTab from '../components/admin/BestellungenTab';
|
||||
import DataManagementTab from '../components/admin/DataManagementTab';
|
||||
@@ -26,7 +25,7 @@ function TabPanel({ children, value, index }: TabPanelProps) {
|
||||
return <Box sx={{ pt: 3 }}>{children}</Box>;
|
||||
}
|
||||
|
||||
const ADMIN_TAB_COUNT = 11;
|
||||
const ADMIN_TAB_COUNT = 10;
|
||||
|
||||
function AdminDashboard() {
|
||||
const navigate = useNavigate();
|
||||
@@ -58,7 +57,6 @@ function AdminDashboard() {
|
||||
<Tab label="Broadcast" />
|
||||
<Tab label="Banner" />
|
||||
<Tab label="Wartung" />
|
||||
<Tab label="FDISK Sync" />
|
||||
<Tab label="Berechtigungen" />
|
||||
<Tab label="Bestellungen" />
|
||||
<Tab label="Datenverwaltung" />
|
||||
@@ -85,18 +83,15 @@ function AdminDashboard() {
|
||||
<ServiceModeTab />
|
||||
</TabPanel>
|
||||
<TabPanel value={tab} index={6}>
|
||||
<FdiskSyncTab />
|
||||
</TabPanel>
|
||||
<TabPanel value={tab} index={7}>
|
||||
<PermissionMatrixTab />
|
||||
</TabPanel>
|
||||
<TabPanel value={tab} index={8}>
|
||||
<TabPanel value={tab} index={7}>
|
||||
<BestellungenTab />
|
||||
</TabPanel>
|
||||
<TabPanel value={tab} index={9}>
|
||||
<TabPanel value={tab} index={8}>
|
||||
<DataManagementTab />
|
||||
</TabPanel>
|
||||
<TabPanel value={tab} index={10}>
|
||||
<TabPanel value={tab} index={9}>
|
||||
<DebugTab />
|
||||
</TabPanel>
|
||||
</DashboardLayout>
|
||||
|
||||
@@ -17,15 +17,15 @@ import DashboardLayout from '../components/dashboard/DashboardLayout';
|
||||
import ChatAwareFab from '../components/shared/ChatAwareFab';
|
||||
import { useNotification } from '../contexts/NotificationContext';
|
||||
import { usePermissionContext } from '../contexts/PermissionContext';
|
||||
import { shopApi } from '../services/shop';
|
||||
import { ausruestungsanfrageApi } from '../services/ausruestungsanfrage';
|
||||
import { bestellungApi } from '../services/bestellung';
|
||||
import { SHOP_STATUS_LABELS, SHOP_STATUS_COLORS } from '../types/shop.types';
|
||||
import type { ShopArtikel, ShopArtikelFormData, ShopAnfrageFormItem, ShopAnfrageDetailResponse, ShopAnfrageStatus, ShopAnfrage, ShopOverview } from '../types/shop.types';
|
||||
import { AUSRUESTUNG_STATUS_LABELS, AUSRUESTUNG_STATUS_COLORS } from '../types/ausruestungsanfrage.types';
|
||||
import type { AusruestungArtikel, AusruestungArtikelFormData, AusruestungAnfrageFormItem, AusruestungAnfrageDetailResponse, AusruestungAnfrageStatus, AusruestungAnfrage, AusruestungOverview } from '../types/ausruestungsanfrage.types';
|
||||
import type { Bestellung } from '../types/bestellung.types';
|
||||
|
||||
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function formatOrderId(r: ShopAnfrage): string {
|
||||
function formatOrderId(r: AusruestungAnfrage): string {
|
||||
if (r.bestell_jahr && r.bestell_nummer) {
|
||||
return `${r.bestell_jahr}/${String(r.bestell_nummer).padStart(3, '0')}`;
|
||||
}
|
||||
@@ -46,8 +46,8 @@ function KatalogTab() {
|
||||
const { hasPermission } = usePermissionContext();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const canManage = hasPermission('shop:manage_catalog');
|
||||
const canCreate = hasPermission('shop:create_request');
|
||||
const canManage = hasPermission('ausruestungsanfrage:manage_catalog');
|
||||
const canCreate = hasPermission('ausruestungsanfrage:create_request');
|
||||
|
||||
const [filterKategorie, setFilterKategorie] = useState<string>('');
|
||||
const [draft, setDraft] = useState<DraftItem[]>([]);
|
||||
@@ -55,38 +55,38 @@ function KatalogTab() {
|
||||
const [submitOpen, setSubmitOpen] = useState(false);
|
||||
const [submitNotizen, setSubmitNotizen] = useState('');
|
||||
const [artikelDialogOpen, setArtikelDialogOpen] = useState(false);
|
||||
const [editArtikel, setEditArtikel] = useState<ShopArtikel | null>(null);
|
||||
const [artikelForm, setArtikelForm] = useState<ShopArtikelFormData>({ bezeichnung: '' });
|
||||
const [editArtikel, setEditArtikel] = useState<AusruestungArtikel | null>(null);
|
||||
const [artikelForm, setArtikelForm] = useState<AusruestungArtikelFormData>({ bezeichnung: '' });
|
||||
|
||||
const { data: items = [], isLoading } = useQuery({
|
||||
queryKey: ['shop', 'items', filterKategorie],
|
||||
queryFn: () => shopApi.getItems(filterKategorie ? { kategorie: filterKategorie } : undefined),
|
||||
queryKey: ['ausruestungsanfrage', 'items', filterKategorie],
|
||||
queryFn: () => ausruestungsanfrageApi.getItems(filterKategorie ? { kategorie: filterKategorie } : undefined),
|
||||
});
|
||||
|
||||
const { data: categories = [] } = useQuery({
|
||||
queryKey: ['shop', 'categories'],
|
||||
queryFn: () => shopApi.getCategories(),
|
||||
queryKey: ['ausruestungsanfrage', 'categories'],
|
||||
queryFn: () => ausruestungsanfrageApi.getCategories(),
|
||||
});
|
||||
|
||||
const createItemMut = useMutation({
|
||||
mutationFn: (data: ShopArtikelFormData) => shopApi.createItem(data),
|
||||
onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['shop'] }); showSuccess('Artikel erstellt'); setArtikelDialogOpen(false); },
|
||||
mutationFn: (data: AusruestungArtikelFormData) => ausruestungsanfrageApi.createItem(data),
|
||||
onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['ausruestungsanfrage'] }); showSuccess('Artikel erstellt'); setArtikelDialogOpen(false); },
|
||||
onError: () => showError('Fehler beim Erstellen'),
|
||||
});
|
||||
const updateItemMut = useMutation({
|
||||
mutationFn: ({ id, data }: { id: number; data: Partial<ShopArtikelFormData> }) => shopApi.updateItem(id, data),
|
||||
onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['shop'] }); showSuccess('Artikel aktualisiert'); setArtikelDialogOpen(false); },
|
||||
mutationFn: ({ id, data }: { id: number; data: Partial<AusruestungArtikelFormData> }) => ausruestungsanfrageApi.updateItem(id, data),
|
||||
onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['ausruestungsanfrage'] }); showSuccess('Artikel aktualisiert'); setArtikelDialogOpen(false); },
|
||||
onError: () => showError('Fehler beim Aktualisieren'),
|
||||
});
|
||||
const deleteItemMut = useMutation({
|
||||
mutationFn: (id: number) => shopApi.deleteItem(id),
|
||||
onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['shop'] }); showSuccess('Artikel gelöscht'); },
|
||||
mutationFn: (id: number) => ausruestungsanfrageApi.deleteItem(id),
|
||||
onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['ausruestungsanfrage'] }); showSuccess('Artikel gelöscht'); },
|
||||
onError: () => showError('Fehler beim Löschen'),
|
||||
});
|
||||
const createRequestMut = useMutation({
|
||||
mutationFn: ({ items, notizen }: { items: ShopAnfrageFormItem[]; notizen?: string }) => shopApi.createRequest(items, notizen),
|
||||
mutationFn: ({ items, notizen }: { items: AusruestungAnfrageFormItem[]; notizen?: string }) => ausruestungsanfrageApi.createRequest(items, notizen),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['shop'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['ausruestungsanfrage'] });
|
||||
showSuccess('Anfrage gesendet');
|
||||
setDraft([]);
|
||||
setSubmitOpen(false);
|
||||
@@ -95,7 +95,7 @@ function KatalogTab() {
|
||||
onError: () => showError('Fehler beim Senden der Anfrage'),
|
||||
});
|
||||
|
||||
const addToDraft = (item: ShopArtikel) => {
|
||||
const addToDraft = (item: AusruestungArtikel) => {
|
||||
setDraft(prev => {
|
||||
const existing = prev.find(d => d.artikel_id === item.id);
|
||||
if (existing) return prev.map(d => d.artikel_id === item.id ? { ...d, menge: d.menge + 1 } : d);
|
||||
@@ -121,7 +121,7 @@ function KatalogTab() {
|
||||
setArtikelForm({ bezeichnung: '' });
|
||||
setArtikelDialogOpen(true);
|
||||
};
|
||||
const openEditArtikel = (a: ShopArtikel) => {
|
||||
const openEditArtikel = (a: AusruestungArtikel) => {
|
||||
setEditArtikel(a);
|
||||
setArtikelForm({ bezeichnung: a.bezeichnung, beschreibung: a.beschreibung, kategorie: a.kategorie });
|
||||
setArtikelDialogOpen(true);
|
||||
@@ -279,78 +279,180 @@ function KatalogTab() {
|
||||
|
||||
function MeineAnfragenTab() {
|
||||
const [expandedId, setExpandedId] = useState<number | null>(null);
|
||||
const { hasPermission } = usePermissionContext();
|
||||
const queryClient = useQueryClient();
|
||||
const { showSuccess, showError } = useNotification();
|
||||
|
||||
const canCreate = hasPermission('ausruestungsanfrage:create_request');
|
||||
|
||||
const [createDialogOpen, setCreateDialogOpen] = useState(false);
|
||||
const [newBezeichnung, setNewBezeichnung] = useState('');
|
||||
const [newBemerkung, setNewBemerkung] = useState('');
|
||||
const [selectedArtikel, setSelectedArtikel] = useState<AusruestungArtikel[]>([]);
|
||||
|
||||
const { data: requests = [], isLoading } = useQuery({
|
||||
queryKey: ['shop', 'myRequests'],
|
||||
queryFn: () => shopApi.getMyRequests(),
|
||||
queryKey: ['ausruestungsanfrage', 'myRequests'],
|
||||
queryFn: () => ausruestungsanfrageApi.getMyRequests(),
|
||||
});
|
||||
|
||||
const { data: detail } = useQuery<ShopAnfrageDetailResponse>({
|
||||
queryKey: ['shop', 'request', expandedId],
|
||||
queryFn: () => shopApi.getRequest(expandedId!),
|
||||
const { data: detail } = useQuery<AusruestungAnfrageDetailResponse>({
|
||||
queryKey: ['ausruestungsanfrage', 'request', expandedId],
|
||||
queryFn: () => ausruestungsanfrageApi.getRequest(expandedId!),
|
||||
enabled: expandedId != null,
|
||||
});
|
||||
|
||||
const { data: catalogItems = [] } = useQuery({
|
||||
queryKey: ['ausruestungsanfrage', 'items-for-create'],
|
||||
queryFn: () => ausruestungsanfrageApi.getItems({ aktiv: true }),
|
||||
enabled: createDialogOpen,
|
||||
});
|
||||
|
||||
const createMut = useMutation({
|
||||
mutationFn: ({ items, notizen }: { items: AusruestungAnfrageFormItem[]; notizen?: string }) =>
|
||||
ausruestungsanfrageApi.createRequest(items, notizen),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['ausruestungsanfrage'] });
|
||||
showSuccess('Anfrage erstellt');
|
||||
setCreateDialogOpen(false);
|
||||
setNewBezeichnung('');
|
||||
setNewBemerkung('');
|
||||
setSelectedArtikel([]);
|
||||
},
|
||||
onError: () => showError('Fehler beim Erstellen der Anfrage'),
|
||||
});
|
||||
|
||||
const handleCreateSubmit = () => {
|
||||
const items: AusruestungAnfrageFormItem[] = [];
|
||||
|
||||
// Add selected catalog items
|
||||
for (const a of selectedArtikel) {
|
||||
items.push({ artikel_id: a.id, bezeichnung: a.bezeichnung, menge: 1 });
|
||||
}
|
||||
|
||||
// Add free-text item if provided
|
||||
const text = newBezeichnung.trim();
|
||||
if (text) {
|
||||
items.push({ bezeichnung: text, menge: 1 });
|
||||
}
|
||||
|
||||
if (items.length === 0) return;
|
||||
|
||||
createMut.mutate({ items, notizen: newBemerkung || undefined });
|
||||
};
|
||||
|
||||
if (isLoading) return <Typography color="text.secondary">Lade Anfragen...</Typography>;
|
||||
if (requests.length === 0) return <Typography color="text.secondary">Keine Anfragen vorhanden.</Typography>;
|
||||
if (requests.length === 0 && !canCreate) return <Typography color="text.secondary">Keine Anfragen vorhanden.</Typography>;
|
||||
|
||||
return (
|
||||
<TableContainer component={Paper} variant="outlined">
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell width={40} />
|
||||
<TableCell>Anfrage</TableCell>
|
||||
<TableCell>Status</TableCell>
|
||||
<TableCell>Positionen</TableCell>
|
||||
<TableCell>Erstellt am</TableCell>
|
||||
<TableCell>Admin Notizen</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{requests.map(r => (
|
||||
<>
|
||||
<TableRow key={r.id} hover sx={{ cursor: 'pointer' }} onClick={() => setExpandedId(prev => prev === r.id ? null : r.id)}>
|
||||
<TableCell>{expandedId === r.id ? <ExpandLess fontSize="small" /> : <ExpandMore fontSize="small" />}</TableCell>
|
||||
<TableCell>{formatOrderId(r)}</TableCell>
|
||||
<TableCell><Chip label={SHOP_STATUS_LABELS[r.status]} color={SHOP_STATUS_COLORS[r.status]} size="small" /></TableCell>
|
||||
<TableCell>{r.positionen_count ?? r.items_count ?? '-'}</TableCell>
|
||||
<TableCell>{new Date(r.erstellt_am).toLocaleDateString('de-AT')}</TableCell>
|
||||
<TableCell>{r.admin_notizen || '-'}</TableCell>
|
||||
<Box>
|
||||
{requests.length === 0 ? (
|
||||
<Typography color="text.secondary" sx={{ mb: 2 }}>Keine Anfragen vorhanden.</Typography>
|
||||
) : (
|
||||
<TableContainer component={Paper} variant="outlined">
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell width={40} />
|
||||
<TableCell>Anfrage</TableCell>
|
||||
<TableCell>Status</TableCell>
|
||||
<TableCell>Positionen</TableCell>
|
||||
<TableCell>Erstellt am</TableCell>
|
||||
<TableCell>Admin Notizen</TableCell>
|
||||
</TableRow>
|
||||
{expandedId === r.id && (
|
||||
<TableRow key={`${r.id}-detail`}>
|
||||
<TableCell colSpan={6} sx={{ py: 0 }}>
|
||||
<Collapse in timeout="auto" unmountOnExit>
|
||||
<Box sx={{ p: 2 }}>
|
||||
{r.notizen && <Typography variant="body2" sx={{ mb: 1 }}>Notizen: {r.notizen}</Typography>}
|
||||
{detail ? (
|
||||
<>
|
||||
{detail.positionen.map(p => (
|
||||
<Typography key={p.id} variant="body2">- {p.menge}x {p.bezeichnung}{p.notizen ? ` (${p.notizen})` : ''}</Typography>
|
||||
))}
|
||||
{detail.linked_bestellungen && detail.linked_bestellungen.length > 0 && (
|
||||
<Box sx={{ mt: 1 }}>
|
||||
<Typography variant="caption" color="text.secondary">Verknüpfte Bestellungen:</Typography>
|
||||
{detail.linked_bestellungen.map(b => (
|
||||
<Chip key={b.id} label={`#${b.id} ${b.bezeichnung}`} size="small" sx={{ ml: 0.5 }} />
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{requests.map(r => (
|
||||
<>
|
||||
<TableRow key={r.id} hover sx={{ cursor: 'pointer' }} onClick={() => setExpandedId(prev => prev === r.id ? null : r.id)}>
|
||||
<TableCell>{expandedId === r.id ? <ExpandLess fontSize="small" /> : <ExpandMore fontSize="small" />}</TableCell>
|
||||
<TableCell>{formatOrderId(r)}</TableCell>
|
||||
<TableCell><Chip label={AUSRUESTUNG_STATUS_LABELS[r.status]} color={AUSRUESTUNG_STATUS_COLORS[r.status]} size="small" /></TableCell>
|
||||
<TableCell>{r.positionen_count ?? r.items_count ?? '-'}</TableCell>
|
||||
<TableCell>{new Date(r.erstellt_am).toLocaleDateString('de-AT')}</TableCell>
|
||||
<TableCell>{r.admin_notizen || '-'}</TableCell>
|
||||
</TableRow>
|
||||
{expandedId === r.id && (
|
||||
<TableRow key={`${r.id}-detail`}>
|
||||
<TableCell colSpan={6} sx={{ py: 0 }}>
|
||||
<Collapse in timeout="auto" unmountOnExit>
|
||||
<Box sx={{ p: 2 }}>
|
||||
{r.notizen && <Typography variant="body2" sx={{ mb: 1 }}>Notizen: {r.notizen}</Typography>}
|
||||
{detail ? (
|
||||
<>
|
||||
{detail.positionen.map(p => (
|
||||
<Typography key={p.id} variant="body2">- {p.menge}x {p.bezeichnung}{p.notizen ? ` (${p.notizen})` : ''}</Typography>
|
||||
))}
|
||||
</Box>
|
||||
{detail.linked_bestellungen && detail.linked_bestellungen.length > 0 && (
|
||||
<Box sx={{ mt: 1 }}>
|
||||
<Typography variant="caption" color="text.secondary">Verknüpfte Bestellungen:</Typography>
|
||||
{detail.linked_bestellungen.map(b => (
|
||||
<Chip key={b.id} label={`#${b.id} ${b.bezeichnung}`} size="small" sx={{ ml: 0.5 }} />
|
||||
))}
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<Typography variant="body2" color="text.secondary">Lade Details...</Typography>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<Typography variant="body2" color="text.secondary">Lade Details...</Typography>
|
||||
)}
|
||||
</Box>
|
||||
</Collapse>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
</Box>
|
||||
</Collapse>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
</>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
)}
|
||||
|
||||
{/* Create Request Dialog */}
|
||||
<Dialog open={createDialogOpen} onClose={() => setCreateDialogOpen(false)} maxWidth="sm" fullWidth>
|
||||
<DialogTitle>Neue Ausrüstungsanfrage</DialogTitle>
|
||||
<DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 2, pt: 2 }}>
|
||||
<TextField
|
||||
label="Bezeichnung"
|
||||
placeholder="Was wird benötigt?"
|
||||
value={newBezeichnung}
|
||||
onChange={e => setNewBezeichnung(e.target.value)}
|
||||
fullWidth
|
||||
/>
|
||||
<Autocomplete
|
||||
multiple
|
||||
options={catalogItems}
|
||||
getOptionLabel={o => o.bezeichnung}
|
||||
value={selectedArtikel}
|
||||
onChange={(_, v) => setSelectedArtikel(v)}
|
||||
renderInput={params => <TextField {...params} label="Aus Katalog auswählen (optional)" />}
|
||||
/>
|
||||
<TextField
|
||||
label="Bemerkung (optional)"
|
||||
value={newBemerkung}
|
||||
onChange={e => setNewBemerkung(e.target.value)}
|
||||
multiline
|
||||
rows={2}
|
||||
fullWidth
|
||||
/>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => setCreateDialogOpen(false)}>Abbrechen</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={handleCreateSubmit}
|
||||
disabled={createMut.isPending || (!newBezeichnung.trim() && selectedArtikel.length === 0)}
|
||||
>
|
||||
Anfrage erstellen
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
|
||||
{/* FAB for creating new request */}
|
||||
{canCreate && (
|
||||
<ChatAwareFab onClick={() => setCreateDialogOpen(true)} aria-label="Neue Anfrage erstellen">
|
||||
<AddIcon />
|
||||
</ChatAwareFab>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -368,13 +470,13 @@ function AlleAnfragenTab() {
|
||||
const [selectedBestellung, setSelectedBestellung] = useState<Bestellung | null>(null);
|
||||
|
||||
const { data: requests = [], isLoading } = useQuery({
|
||||
queryKey: ['shop', 'requests', statusFilter],
|
||||
queryFn: () => shopApi.getRequests(statusFilter ? { status: statusFilter } : undefined),
|
||||
queryKey: ['ausruestungsanfrage', 'requests', statusFilter],
|
||||
queryFn: () => ausruestungsanfrageApi.getRequests(statusFilter ? { status: statusFilter } : undefined),
|
||||
});
|
||||
|
||||
const { data: detail } = useQuery<ShopAnfrageDetailResponse>({
|
||||
queryKey: ['shop', 'request', expandedId],
|
||||
queryFn: () => shopApi.getRequest(expandedId!),
|
||||
const { data: detail } = useQuery<AusruestungAnfrageDetailResponse>({
|
||||
queryKey: ['ausruestungsanfrage', 'request', expandedId],
|
||||
queryFn: () => ausruestungsanfrageApi.getRequest(expandedId!),
|
||||
enabled: expandedId != null,
|
||||
});
|
||||
|
||||
@@ -385,9 +487,9 @@ function AlleAnfragenTab() {
|
||||
});
|
||||
|
||||
const statusMut = useMutation({
|
||||
mutationFn: ({ id, status, notes }: { id: number; status: string; notes?: string }) => shopApi.updateRequestStatus(id, status, notes),
|
||||
mutationFn: ({ id, status, notes }: { id: number; status: string; notes?: string }) => ausruestungsanfrageApi.updateRequestStatus(id, status, notes),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['shop'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['ausruestungsanfrage'] });
|
||||
showSuccess('Status aktualisiert');
|
||||
setActionDialog(null);
|
||||
setAdminNotizen('');
|
||||
@@ -396,9 +498,9 @@ function AlleAnfragenTab() {
|
||||
});
|
||||
|
||||
const linkMut = useMutation({
|
||||
mutationFn: ({ anfrageId, bestellungId }: { anfrageId: number; bestellungId: number }) => shopApi.linkToOrder(anfrageId, bestellungId),
|
||||
mutationFn: ({ anfrageId, bestellungId }: { anfrageId: number; bestellungId: number }) => ausruestungsanfrageApi.linkToOrder(anfrageId, bestellungId),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['shop'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['ausruestungsanfrage'] });
|
||||
showSuccess('Verknüpfung erstellt');
|
||||
setLinkDialog(null);
|
||||
setSelectedBestellung(null);
|
||||
@@ -419,8 +521,8 @@ function AlleAnfragenTab() {
|
||||
<InputLabel>Status Filter</InputLabel>
|
||||
<Select value={statusFilter} label="Status Filter" onChange={e => setStatusFilter(e.target.value)}>
|
||||
<MenuItem value="">Alle</MenuItem>
|
||||
{(Object.keys(SHOP_STATUS_LABELS) as ShopAnfrageStatus[]).map(s => (
|
||||
<MenuItem key={s} value={s}>{SHOP_STATUS_LABELS[s]}</MenuItem>
|
||||
{(Object.keys(AUSRUESTUNG_STATUS_LABELS) as AusruestungAnfrageStatus[]).map(s => (
|
||||
<MenuItem key={s} value={s}>{AUSRUESTUNG_STATUS_LABELS[s]}</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
@@ -448,7 +550,7 @@ function AlleAnfragenTab() {
|
||||
<TableCell>{expandedId === r.id ? <ExpandLess fontSize="small" /> : <ExpandMore fontSize="small" />}</TableCell>
|
||||
<TableCell>{formatOrderId(r)}</TableCell>
|
||||
<TableCell>{r.anfrager_name || r.anfrager_id}</TableCell>
|
||||
<TableCell><Chip label={SHOP_STATUS_LABELS[r.status]} color={SHOP_STATUS_COLORS[r.status]} size="small" /></TableCell>
|
||||
<TableCell><Chip label={AUSRUESTUNG_STATUS_LABELS[r.status]} color={AUSRUESTUNG_STATUS_COLORS[r.status]} size="small" /></TableCell>
|
||||
<TableCell>{r.positionen_count ?? r.items_count ?? '-'}</TableCell>
|
||||
<TableCell>{new Date(r.erstellt_am).toLocaleDateString('de-AT')}</TableCell>
|
||||
<TableCell onClick={e => e.stopPropagation()}>
|
||||
@@ -570,9 +672,9 @@ function AlleAnfragenTab() {
|
||||
// ─── Overview Tab ────────────────────────────────────────────────────────────
|
||||
|
||||
function UebersichtTab() {
|
||||
const { data: overview, isLoading } = useQuery<ShopOverview>({
|
||||
queryKey: ['shop', 'overview'],
|
||||
queryFn: () => shopApi.getOverview(),
|
||||
const { data: overview, isLoading } = useQuery<AusruestungOverview>({
|
||||
queryKey: ['ausruestungsanfrage', 'overview'],
|
||||
queryFn: () => ausruestungsanfrageApi.getOverview(),
|
||||
});
|
||||
|
||||
if (isLoading) return <Typography color="text.secondary">Lade Übersicht...</Typography>;
|
||||
@@ -631,14 +733,14 @@ function UebersichtTab() {
|
||||
|
||||
// ─── Main Page ──────────────────────────────────────────────────────────────
|
||||
|
||||
export default function Shop() {
|
||||
export default function Ausruestungsanfrage() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const { hasPermission } = usePermissionContext();
|
||||
|
||||
const canView = hasPermission('shop:view');
|
||||
const canCreate = hasPermission('shop:create_request');
|
||||
const canApprove = hasPermission('shop:approve_requests');
|
||||
const canViewOverview = hasPermission('shop:view_overview');
|
||||
const canView = hasPermission('ausruestungsanfrage:view');
|
||||
const canCreate = hasPermission('ausruestungsanfrage:create_request');
|
||||
const canApprove = hasPermission('ausruestungsanfrage:approve_requests');
|
||||
const canViewOverview = hasPermission('ausruestungsanfrage:view_overview');
|
||||
|
||||
const tabCount = 1 + (canCreate ? 1 : 0) + (canApprove ? 1 : 0) + (canViewOverview ? 1 : 0);
|
||||
|
||||
@@ -672,7 +774,7 @@ export default function Shop() {
|
||||
|
||||
return (
|
||||
<DashboardLayout>
|
||||
<Typography variant="h5" fontWeight={700} sx={{ mb: 2 }}>Shop</Typography>
|
||||
<Typography variant="h5" fontWeight={700} sx={{ mb: 2 }}>Ausrüstungsanfragen</Typography>
|
||||
|
||||
<Box sx={{ borderBottom: 1, borderColor: 'divider', mb: 3 }}>
|
||||
<Tabs value={activeTab} onChange={handleTabChange} variant="scrollable" scrollButtons="auto">
|
||||
@@ -100,7 +100,7 @@ export default function BestellungDetail() {
|
||||
const [deleteReminderTarget, setDeleteReminderTarget] = useState<number | null>(null);
|
||||
|
||||
// ── Query ──
|
||||
const { data, isLoading, isError } = useQuery({
|
||||
const { data, isLoading, isError, error, refetch } = useQuery({
|
||||
queryKey: ['bestellung', orderId],
|
||||
queryFn: () => bestellungApi.getOrder(orderId),
|
||||
enabled: !!orderId,
|
||||
@@ -263,11 +263,17 @@ export default function BestellungDetail() {
|
||||
}
|
||||
|
||||
if (isError || !bestellung) {
|
||||
const is404 = (error as any)?.response?.status === 404 || !bestellung;
|
||||
return (
|
||||
<DashboardLayout>
|
||||
<Box sx={{ p: 4, textAlign: 'center' }}>
|
||||
<Typography color="error">Bestellung nicht gefunden.</Typography>
|
||||
<Button sx={{ mt: 2 }} onClick={() => navigate('/bestellungen')}>Zurück</Button>
|
||||
<Typography color="error">
|
||||
{is404 ? 'Bestellung nicht gefunden.' : 'Fehler beim Laden der Bestellung.'}
|
||||
</Typography>
|
||||
{!is404 && (
|
||||
<Button sx={{ mt: 2 }} variant="outlined" onClick={() => refetch()}>Erneut versuchen</Button>
|
||||
)}
|
||||
<Button sx={{ mt: 2, ml: !is404 ? 1 : 0 }} onClick={() => navigate('/bestellungen')}>Zurück</Button>
|
||||
</Box>
|
||||
</DashboardLayout>
|
||||
);
|
||||
|
||||
@@ -29,7 +29,7 @@ import LinksWidget from '../components/dashboard/LinksWidget';
|
||||
import BannerWidget from '../components/dashboard/BannerWidget';
|
||||
import WidgetGroup from '../components/dashboard/WidgetGroup';
|
||||
import BestellungenWidget from '../components/dashboard/BestellungenWidget';
|
||||
import ShopWidget from '../components/dashboard/ShopWidget';
|
||||
import AusruestungsanfrageWidget from '../components/dashboard/AusruestungsanfrageWidget';
|
||||
import { preferencesApi } from '../services/settings';
|
||||
import { configApi } from '../services/config';
|
||||
import { WidgetKey } from '../constants/widgets';
|
||||
@@ -141,10 +141,10 @@ function Dashboard() {
|
||||
</Fade>
|
||||
)}
|
||||
|
||||
{hasPermission('shop:widget') && widgetVisible('shopRequests') && (
|
||||
{hasPermission('ausruestungsanfrage:widget') && widgetVisible('ausruestungsanfragen') && (
|
||||
<Fade in={!dataLoading} timeout={600} style={{ transitionDelay: '470ms' }}>
|
||||
<Box>
|
||||
<ShopWidget />
|
||||
<AusruestungsanfrageWidget />
|
||||
</Box>
|
||||
</Fade>
|
||||
)}
|
||||
|
||||
@@ -3,7 +3,7 @@ import {
|
||||
Box, Tab, Tabs, Typography, Table, TableBody, TableCell, TableContainer,
|
||||
TableHead, TableRow, Paper, Chip, IconButton, Button, Dialog, DialogTitle,
|
||||
DialogContent, DialogActions, TextField, MenuItem, Select, FormControl,
|
||||
InputLabel, Collapse, Divider, CircularProgress,
|
||||
InputLabel, Collapse, Divider, CircularProgress, FormControlLabel, Switch,
|
||||
} from '@mui/material';
|
||||
import {
|
||||
Add as AddIcon, Delete as DeleteIcon, ExpandMore, ExpandLess,
|
||||
@@ -216,7 +216,7 @@ function IssueRow({
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
{canManage && (
|
||||
{(canManage || isOwner) && (
|
||||
<Box sx={{ display: 'flex', gap: 1, mb: 2, flexWrap: 'wrap' }}>
|
||||
<FormControl size="small" sx={{ minWidth: 160 }}>
|
||||
<InputLabel>Status</InputLabel>
|
||||
@@ -232,19 +232,21 @@ function IssueRow({
|
||||
<MenuItem value="abgelehnt">Abgelehnt</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
<FormControl size="small" sx={{ minWidth: 140 }}>
|
||||
<InputLabel>Priorität</InputLabel>
|
||||
<Select
|
||||
value={issue.prioritaet}
|
||||
label="Priorität"
|
||||
onChange={(e) => updateMut.mutate({ prioritaet: e.target.value as Issue['prioritaet'] })}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<MenuItem value="niedrig">Niedrig</MenuItem>
|
||||
<MenuItem value="mittel">Mittel</MenuItem>
|
||||
<MenuItem value="hoch">Hoch</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
{canManage && (
|
||||
<FormControl size="small" sx={{ minWidth: 140 }}>
|
||||
<InputLabel>Priorität</InputLabel>
|
||||
<Select
|
||||
value={issue.prioritaet}
|
||||
label="Priorität"
|
||||
onChange={(e) => updateMut.mutate({ prioritaet: e.target.value as Issue['prioritaet'] })}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<MenuItem value="niedrig">Niedrig</MenuItem>
|
||||
<MenuItem value="mittel">Mittel</MenuItem>
|
||||
<MenuItem value="hoch">Hoch</MenuItem>
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
|
||||
@@ -328,9 +330,6 @@ function IssueTable({ issues, canManage, userId }: { issues: Issue[]; canManage:
|
||||
|
||||
export default function Issues() {
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const tabParam = parseInt(searchParams.get('tab') || '0', 10);
|
||||
const tab = isNaN(tabParam) || tabParam < 0 || tabParam > 1 ? 0 : tabParam;
|
||||
|
||||
const { showSuccess, showError } = useNotification();
|
||||
const { hasPermission } = usePermissionContext();
|
||||
const { user } = useAuth();
|
||||
@@ -341,6 +340,11 @@ export default function Issues() {
|
||||
const canCreate = hasPermission('issues:create');
|
||||
const userId = user?.id || '';
|
||||
|
||||
const tabParam = parseInt(searchParams.get('tab') || '0', 10);
|
||||
const maxTab = canManage ? 2 : (canViewAll ? 1 : 0);
|
||||
const tab = isNaN(tabParam) || tabParam < 0 || tabParam > maxTab ? 0 : tabParam;
|
||||
|
||||
const [showDone, setShowDone] = useState(false);
|
||||
const [createOpen, setCreateOpen] = useState(false);
|
||||
const [form, setForm] = useState<CreateIssuePayload>({ titel: '', typ: 'bug', prioritaet: 'mittel' });
|
||||
|
||||
@@ -365,6 +369,8 @@ export default function Issues() {
|
||||
};
|
||||
|
||||
const myIssues = issues.filter((i: Issue) => i.erstellt_von === userId);
|
||||
const myIssuesFiltered = myIssues.filter((i: Issue) => showDone || (i.status !== 'erledigt' && i.status !== 'abgelehnt'));
|
||||
const doneIssues = issues.filter((i: Issue) => i.status === 'erledigt' || i.status === 'abgelehnt');
|
||||
|
||||
return (
|
||||
<DashboardLayout>
|
||||
@@ -374,15 +380,21 @@ export default function Issues() {
|
||||
<Tabs value={tab} onChange={handleTabChange} sx={{ mb: 0 }}>
|
||||
<Tab label="Meine Issues" />
|
||||
{canViewAll && <Tab label="Alle Issues" />}
|
||||
{canManage && <Tab label="Erledigte Issues" />}
|
||||
</Tabs>
|
||||
|
||||
<TabPanel value={tab} index={0}>
|
||||
<FormControlLabel
|
||||
control={<Switch checked={showDone} onChange={(e) => setShowDone(e.target.checked)} size="small" />}
|
||||
label="Erledigte anzeigen"
|
||||
sx={{ mb: 1 }}
|
||||
/>
|
||||
{isLoading ? (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', py: 4 }}>
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
) : (
|
||||
<IssueTable issues={myIssues} canManage={canManage} userId={userId} />
|
||||
<IssueTable issues={myIssuesFiltered} canManage={canManage} userId={userId} />
|
||||
)}
|
||||
</TabPanel>
|
||||
|
||||
@@ -397,6 +409,18 @@ export default function Issues() {
|
||||
)}
|
||||
</TabPanel>
|
||||
)}
|
||||
|
||||
{canManage && (
|
||||
<TabPanel value={tab} index={canViewAll ? 2 : 1}>
|
||||
{isLoading ? (
|
||||
<Box sx={{ display: 'flex', justifyContent: 'center', py: 4 }}>
|
||||
<CircularProgress />
|
||||
</Box>
|
||||
) : (
|
||||
<IssueTable issues={doneIssues} canManage={canManage} userId={userId} />
|
||||
)}
|
||||
</TabPanel>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
{/* Create Issue Dialog */}
|
||||
|
||||
80
frontend/src/services/ausruestungsanfrage.ts
Normal file
80
frontend/src/services/ausruestungsanfrage.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { api } from './api';
|
||||
import type {
|
||||
AusruestungArtikel,
|
||||
AusruestungArtikelFormData,
|
||||
AusruestungAnfrage,
|
||||
AusruestungAnfrageDetailResponse,
|
||||
AusruestungAnfrageFormItem,
|
||||
AusruestungOverview,
|
||||
} from '../types/ausruestungsanfrage.types';
|
||||
|
||||
export const ausruestungsanfrageApi = {
|
||||
// ── Catalog Items ──
|
||||
getItems: async (filters?: { kategorie?: string; aktiv?: boolean }): Promise<AusruestungArtikel[]> => {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.kategorie) params.set('kategorie', filters.kategorie);
|
||||
if (filters?.aktiv !== undefined) params.set('aktiv', String(filters.aktiv));
|
||||
const r = await api.get(`/api/ausruestungsanfragen/items?${params.toString()}`);
|
||||
return r.data.data;
|
||||
},
|
||||
getItem: async (id: number): Promise<AusruestungArtikel> => {
|
||||
const r = await api.get(`/api/ausruestungsanfragen/items/${id}`);
|
||||
return r.data.data;
|
||||
},
|
||||
createItem: async (data: AusruestungArtikelFormData): Promise<AusruestungArtikel> => {
|
||||
const r = await api.post('/api/ausruestungsanfragen/items', data);
|
||||
return r.data.data;
|
||||
},
|
||||
updateItem: async (id: number, data: Partial<AusruestungArtikelFormData>): Promise<AusruestungArtikel> => {
|
||||
const r = await api.patch(`/api/ausruestungsanfragen/items/${id}`, data);
|
||||
return r.data.data;
|
||||
},
|
||||
deleteItem: async (id: number): Promise<void> => {
|
||||
await api.delete(`/api/ausruestungsanfragen/items/${id}`);
|
||||
},
|
||||
getCategories: async (): Promise<string[]> => {
|
||||
const r = await api.get('/api/ausruestungsanfragen/categories');
|
||||
return r.data.data;
|
||||
},
|
||||
|
||||
// ── Requests ──
|
||||
getRequests: async (filters?: { status?: string }): Promise<AusruestungAnfrage[]> => {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.status) params.set('status', filters.status);
|
||||
const r = await api.get(`/api/ausruestungsanfragen/requests?${params.toString()}`);
|
||||
return r.data.data;
|
||||
},
|
||||
getMyRequests: async (): Promise<AusruestungAnfrage[]> => {
|
||||
const r = await api.get('/api/ausruestungsanfragen/requests/my');
|
||||
return r.data.data;
|
||||
},
|
||||
getRequest: async (id: number): Promise<AusruestungAnfrageDetailResponse> => {
|
||||
const r = await api.get(`/api/ausruestungsanfragen/requests/${id}`);
|
||||
return r.data.data;
|
||||
},
|
||||
createRequest: async (items: AusruestungAnfrageFormItem[], notizen?: string): Promise<AusruestungAnfrage> => {
|
||||
const r = await api.post('/api/ausruestungsanfragen/requests', { items, notizen });
|
||||
return r.data.data;
|
||||
},
|
||||
updateRequestStatus: async (id: number, status: string, admin_notizen?: string): Promise<AusruestungAnfrage> => {
|
||||
const r = await api.patch(`/api/ausruestungsanfragen/requests/${id}/status`, { status, admin_notizen });
|
||||
return r.data.data;
|
||||
},
|
||||
deleteRequest: async (id: number): Promise<void> => {
|
||||
await api.delete(`/api/ausruestungsanfragen/requests/${id}`);
|
||||
},
|
||||
|
||||
// ── Linking ──
|
||||
linkToOrder: async (anfrageId: number, bestellungId: number): Promise<void> => {
|
||||
await api.post(`/api/ausruestungsanfragen/requests/${anfrageId}/link`, { bestellung_id: bestellungId });
|
||||
},
|
||||
unlinkFromOrder: async (anfrageId: number, bestellungId: number): Promise<void> => {
|
||||
await api.delete(`/api/ausruestungsanfragen/requests/${anfrageId}/link/${bestellungId}`);
|
||||
},
|
||||
|
||||
// ── Overview ──
|
||||
getOverview: async (): Promise<AusruestungOverview> => {
|
||||
const r = await api.get('/api/ausruestungsanfragen/overview');
|
||||
return r.data.data;
|
||||
},
|
||||
};
|
||||
@@ -1,80 +0,0 @@
|
||||
import { api } from './api';
|
||||
import type {
|
||||
ShopArtikel,
|
||||
ShopArtikelFormData,
|
||||
ShopAnfrage,
|
||||
ShopAnfrageDetailResponse,
|
||||
ShopAnfrageFormItem,
|
||||
ShopOverview,
|
||||
} from '../types/shop.types';
|
||||
|
||||
export const shopApi = {
|
||||
// ── Catalog Items ──
|
||||
getItems: async (filters?: { kategorie?: string; aktiv?: boolean }): Promise<ShopArtikel[]> => {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.kategorie) params.set('kategorie', filters.kategorie);
|
||||
if (filters?.aktiv !== undefined) params.set('aktiv', String(filters.aktiv));
|
||||
const r = await api.get(`/api/shop/items?${params.toString()}`);
|
||||
return r.data.data;
|
||||
},
|
||||
getItem: async (id: number): Promise<ShopArtikel> => {
|
||||
const r = await api.get(`/api/shop/items/${id}`);
|
||||
return r.data.data;
|
||||
},
|
||||
createItem: async (data: ShopArtikelFormData): Promise<ShopArtikel> => {
|
||||
const r = await api.post('/api/shop/items', data);
|
||||
return r.data.data;
|
||||
},
|
||||
updateItem: async (id: number, data: Partial<ShopArtikelFormData>): Promise<ShopArtikel> => {
|
||||
const r = await api.patch(`/api/shop/items/${id}`, data);
|
||||
return r.data.data;
|
||||
},
|
||||
deleteItem: async (id: number): Promise<void> => {
|
||||
await api.delete(`/api/shop/items/${id}`);
|
||||
},
|
||||
getCategories: async (): Promise<string[]> => {
|
||||
const r = await api.get('/api/shop/categories');
|
||||
return r.data.data;
|
||||
},
|
||||
|
||||
// ── Requests ──
|
||||
getRequests: async (filters?: { status?: string }): Promise<ShopAnfrage[]> => {
|
||||
const params = new URLSearchParams();
|
||||
if (filters?.status) params.set('status', filters.status);
|
||||
const r = await api.get(`/api/shop/requests?${params.toString()}`);
|
||||
return r.data.data;
|
||||
},
|
||||
getMyRequests: async (): Promise<ShopAnfrage[]> => {
|
||||
const r = await api.get('/api/shop/requests/my');
|
||||
return r.data.data;
|
||||
},
|
||||
getRequest: async (id: number): Promise<ShopAnfrageDetailResponse> => {
|
||||
const r = await api.get(`/api/shop/requests/${id}`);
|
||||
return r.data.data;
|
||||
},
|
||||
createRequest: async (items: ShopAnfrageFormItem[], notizen?: string): Promise<ShopAnfrage> => {
|
||||
const r = await api.post('/api/shop/requests', { items, notizen });
|
||||
return r.data.data;
|
||||
},
|
||||
updateRequestStatus: async (id: number, status: string, admin_notizen?: string): Promise<ShopAnfrage> => {
|
||||
const r = await api.patch(`/api/shop/requests/${id}/status`, { status, admin_notizen });
|
||||
return r.data.data;
|
||||
},
|
||||
deleteRequest: async (id: number): Promise<void> => {
|
||||
await api.delete(`/api/shop/requests/${id}`);
|
||||
},
|
||||
|
||||
// ── Linking ──
|
||||
linkToOrder: async (anfrageId: number, bestellungId: number): Promise<void> => {
|
||||
await api.post(`/api/shop/requests/${anfrageId}/link`, { bestellung_id: bestellungId });
|
||||
},
|
||||
unlinkFromOrder: async (anfrageId: number, bestellungId: number): Promise<void> => {
|
||||
await api.delete(`/api/shop/requests/${anfrageId}/link/${bestellungId}`);
|
||||
},
|
||||
|
||||
// ── Overview ──
|
||||
getOverview: async (): Promise<ShopOverview> => {
|
||||
const r = await api.get('/api/shop/overview');
|
||||
return r.data.data;
|
||||
},
|
||||
};
|
||||
@@ -1,8 +1,8 @@
|
||||
// Shop (Internal Ordering) types
|
||||
// Ausrüstungsanfrage (Equipment Request) types
|
||||
|
||||
// ── Catalog Items ──
|
||||
|
||||
export interface ShopArtikel {
|
||||
export interface AusruestungArtikel {
|
||||
id: number;
|
||||
bezeichnung: string;
|
||||
beschreibung?: string;
|
||||
@@ -15,7 +15,7 @@ export interface ShopArtikel {
|
||||
aktualisiert_am: string;
|
||||
}
|
||||
|
||||
export interface ShopArtikelFormData {
|
||||
export interface AusruestungArtikelFormData {
|
||||
bezeichnung: string;
|
||||
beschreibung?: string;
|
||||
kategorie?: string;
|
||||
@@ -25,9 +25,9 @@ export interface ShopArtikelFormData {
|
||||
|
||||
// ── Requests ──
|
||||
|
||||
export type ShopAnfrageStatus = 'offen' | 'genehmigt' | 'abgelehnt' | 'bestellt' | 'erledigt';
|
||||
export type AusruestungAnfrageStatus = 'offen' | 'genehmigt' | 'abgelehnt' | 'bestellt' | 'erledigt';
|
||||
|
||||
export const SHOP_STATUS_LABELS: Record<ShopAnfrageStatus, string> = {
|
||||
export const AUSRUESTUNG_STATUS_LABELS: Record<AusruestungAnfrageStatus, string> = {
|
||||
offen: 'Offen',
|
||||
genehmigt: 'Genehmigt',
|
||||
abgelehnt: 'Abgelehnt',
|
||||
@@ -35,7 +35,7 @@ export const SHOP_STATUS_LABELS: Record<ShopAnfrageStatus, string> = {
|
||||
erledigt: 'Erledigt',
|
||||
};
|
||||
|
||||
export const SHOP_STATUS_COLORS: Record<ShopAnfrageStatus, 'default' | 'info' | 'error' | 'primary' | 'success'> = {
|
||||
export const AUSRUESTUNG_STATUS_COLORS: Record<AusruestungAnfrageStatus, 'default' | 'info' | 'error' | 'primary' | 'success'> = {
|
||||
offen: 'default',
|
||||
genehmigt: 'info',
|
||||
abgelehnt: 'error',
|
||||
@@ -43,11 +43,11 @@ export const SHOP_STATUS_COLORS: Record<ShopAnfrageStatus, 'default' | 'info' |
|
||||
erledigt: 'success',
|
||||
};
|
||||
|
||||
export interface ShopAnfrage {
|
||||
export interface AusruestungAnfrage {
|
||||
id: number;
|
||||
anfrager_id: string;
|
||||
anfrager_name?: string;
|
||||
status: ShopAnfrageStatus;
|
||||
status: AusruestungAnfrageStatus;
|
||||
notizen?: string;
|
||||
admin_notizen?: string;
|
||||
bearbeitet_von?: string;
|
||||
@@ -60,7 +60,7 @@ export interface ShopAnfrage {
|
||||
items_count?: number;
|
||||
}
|
||||
|
||||
export interface ShopAnfragePosition {
|
||||
export interface AusruestungAnfragePosition {
|
||||
id: number;
|
||||
anfrage_id: number;
|
||||
artikel_id?: number;
|
||||
@@ -70,7 +70,7 @@ export interface ShopAnfragePosition {
|
||||
erstellt_am: string;
|
||||
}
|
||||
|
||||
export interface ShopAnfrageFormItem {
|
||||
export interface AusruestungAnfrageFormItem {
|
||||
artikel_id?: number;
|
||||
bezeichnung: string;
|
||||
menge: number;
|
||||
@@ -79,22 +79,22 @@ export interface ShopAnfrageFormItem {
|
||||
|
||||
// ── API Response Types ──
|
||||
|
||||
export interface ShopAnfrageDetailResponse {
|
||||
anfrage: ShopAnfrage;
|
||||
positionen: ShopAnfragePosition[];
|
||||
export interface AusruestungAnfrageDetailResponse {
|
||||
anfrage: AusruestungAnfrage;
|
||||
positionen: AusruestungAnfragePosition[];
|
||||
linked_bestellungen?: { id: number; bezeichnung: string; status: string }[];
|
||||
}
|
||||
|
||||
// ── Overview ──
|
||||
|
||||
export interface ShopOverviewItem {
|
||||
export interface AusruestungOverviewItem {
|
||||
bezeichnung: string;
|
||||
total_menge: number;
|
||||
anfrage_count: number;
|
||||
}
|
||||
|
||||
export interface ShopOverview {
|
||||
items: ShopOverviewItem[];
|
||||
export interface AusruestungOverview {
|
||||
items: AusruestungOverviewItem[];
|
||||
pending_count: number;
|
||||
approved_count: number;
|
||||
total_items: number;
|
||||
Reference in New Issue
Block a user