// frontend/src/pages/ShiftPlans/ShiftPlanList.tsx import React, { useState, useEffect } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import { useAuth } from '../../contexts/AuthContext'; import { shiftPlanService } from '../../services/shiftPlanService'; import { ShiftPlan } from '../../models/ShiftPlan'; import { useNotification } from '../../contexts/NotificationContext'; import { formatDate } from '../../utils/foramatters'; const ShiftPlanList: React.FC = () => { const { hasRole } = useAuth(); const navigate = useNavigate(); const { showNotification } = useNotification(); const [shiftPlans, setShiftPlans] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { loadShiftPlans(); }, []); const loadShiftPlans = async () => { try { const plans = await shiftPlanService.getShiftPlans(); setShiftPlans(plans); } catch (error) { console.error('Error loading shift plans:', error); showNotification({ type: 'error', title: 'Fehler', message: 'Die Schichtpläne konnten nicht geladen werden.' }); } finally { setLoading(false); } }; const handleDelete = async (id: string) => { if (!window.confirm('Möchten Sie diesen Schichtplan wirklich löschen?')) { return; } try { await shiftPlanService.deleteShiftPlan(id); showNotification({ type: 'success', title: 'Erfolg', message: 'Der Schichtplan wurde erfolgreich gelöscht.' }); loadShiftPlans(); } catch (error) { console.error('Error deleting shift plan:', error); showNotification({ type: 'error', title: 'Fehler', message: 'Der Schichtplan konnte nicht gelöscht werden.' }); } }; if (loading) { return
Lade Schichtpläne...
; } return (

📅 Schichtpläne

{hasRole(['admin', 'instandhalter']) && ( )}
{shiftPlans.length === 0 ? (
📋

Keine Schichtpläne vorhanden

Erstellen Sie Ihren ersten Schichtplan!

) : (
{shiftPlans.map(plan => (

{plan.name}

Zeitraum: {formatDate(plan.startDate)} - {formatDate(plan.endDate)}

Status: {plan.status === 'published' ? 'Veröffentlicht' : 'Entwurf'}

{hasRole(['admin', 'instandhalter']) && ( <> )}
))}
)}
); }; export default ShiftPlanList;