From c6e34de03d3977a0e684d48bbe345e14db6325cf Mon Sep 17 00:00:00 2001 From: donpat1to Date: Sat, 11 Oct 2025 00:24:51 +0200 Subject: [PATCH] fixed database migrations --- .../pages/Employees/EmployeeManagement.tsx | 211 +++++++----------- frontend/src/services/shiftTemplateService.ts | 2 +- frontend/src/types/shiftTemplate.ts | 1 + 3 files changed, 84 insertions(+), 130 deletions(-) diff --git a/frontend/src/pages/Employees/EmployeeManagement.tsx b/frontend/src/pages/Employees/EmployeeManagement.tsx index 64bd421..aade6e0 100644 --- a/frontend/src/pages/Employees/EmployeeManagement.tsx +++ b/frontend/src/pages/Employees/EmployeeManagement.tsx @@ -1,4 +1,4 @@ -// frontend/src/pages/Employees/EmployeeManagement.tsx - MIT NOTIFICATION SYSTEM +// frontend/src/pages/Employees/EmployeeManagement.tsx - VOLLSTÄNDIG import React, { useState, useEffect } from 'react'; import { Employee } from '../../types/employee'; import { employeeService } from '../../services/employeeService'; @@ -15,8 +15,8 @@ const EmployeeManagement: React.FC = () => { const [loading, setLoading] = useState(true); const [viewMode, setViewMode] = useState('list'); const [selectedEmployee, setSelectedEmployee] = useState(null); - const { hasRole } = useAuth(); - const { showNotification, confirmDialog } = useNotification(); + const { hasRole, user: currentUser } = useAuth(); + const { showNotification } = useNotification(); useEffect(() => { loadEmployees(); @@ -25,15 +25,10 @@ const EmployeeManagement: React.FC = () => { const loadEmployees = async () => { try { setLoading(true); - console.log('🔄 Loading employees...'); - - // Add cache-busting parameter to prevent browser caching const data = await employeeService.getEmployees(); - console.log('✅ Employees loaded:', data); - setEmployees(data); } catch (err: any) { - console.error('❌ Error loading employees:', err); + console.error('Error loading employees:', err); showNotification({ type: 'error', title: 'Fehler', @@ -84,73 +79,58 @@ const EmployeeManagement: React.FC = () => { }); }; - // Verbesserte Lösch-Funktion mit BestĂ€tigungs-Dialog const handleDeleteEmployee = async (employee: Employee) => { - try { - // BestĂ€tigungs-Dialog basierend auf Rolle - let confirmMessage = `Möchten Sie den Mitarbeiter "${employee.name}" wirklich PERMANENT LÖSCHEN?\n\nDie Daten des Mitarbeiters werden unwiderruflich gelöscht. Diese Aktion kann nicht rĂŒckgĂ€ngig gemacht werden.`; - let confirmTitle = 'Mitarbeiter löschen'; + // Warnung basierend auf Rolle + let confirmMessage = `Möchten Sie den Mitarbeiter "${employee.name}" wirklich löschen?\n\nDiese Aktion kann nicht rĂŒckgĂ€ngig gemacht werden.`; + + if (employee.role === 'admin') { + const adminCount = employees.filter(emp => + emp.role === 'admin' && emp.isActive + ).length; - if (employee.role === 'admin') { - const adminCount = employees.filter(emp => - emp.role === 'admin' && emp.isActive - ).length; - - if (adminCount <= 1) { - showNotification({ - type: 'error', - title: 'Aktion nicht möglich', - message: 'Mindestens ein Administrator muss im System verbleiben' - }); - return; - } - - confirmTitle = 'Administrator löschen'; - confirmMessage = `Möchten Sie den Administrator "${employee.name}" wirklich PERMANENT LÖSCHEN?\n\nAchtung: Diese Aktion ist permanent und kann nicht rĂŒckgĂ€ngig gemacht werden.`; - } - - const confirmed = await confirmDialog({ - title: confirmTitle, - message: confirmMessage, - confirmText: 'Permanent löschen', - cancelText: 'Abbrechen', - type: 'warning' - }); - - if (!confirmed) return; - - console.log('Starting deletion process for employee:', employee.name); - await employeeService.deleteEmployee(employee.id); - console.log('Employee deleted, reloading list'); - - // Force a fresh reload of employees - const updatedEmployees = await employeeService.getEmployees(); - setEmployees(updatedEmployees); - - showNotification({ - type: 'success', - title: 'Erfolg', - message: `Mitarbeiter "${employee.name}" wurde erfolgreich gelöscht` - }); - - } catch (err: any) { - if (err.message.includes('Mindestens ein Administrator')) { + if (adminCount <= 1) { showNotification({ type: 'error', title: 'Aktion nicht möglich', - message: err.message - }); - } else { - showNotification({ - type: 'error', - title: 'Fehler', - message: 'Mitarbeiter konnte nicht gelöscht werden' + message: 'Es muss mindestens ein aktiver Administrator im System verbleiben.' }); + return; } + confirmMessage += '\n\n⚠ Achtung: Dieser Benutzer ist ein Administrator!'; + } + + if (!window.confirm(confirmMessage)) { + return; + } + + try { + await employeeService.deleteEmployee(employee.id); + await loadEmployees(); + showNotification({ + type: 'success', + title: 'Erfolg', + message: `Mitarbeiter "${employee.name}" wurde gelöscht` + }); + } catch (err: any) { + console.error('Error deleting employee:', err); + showNotification({ + type: 'error', + title: 'Fehler', + message: 'Mitarbeiter konnte nicht gelöscht werden: ' + err.message + }); } }; - if (loading && viewMode === 'list') { + const handleAvailabilitySaved = () => { + showNotification({ + type: 'success', + title: 'Erfolg', + message: 'VerfĂŒgbarkeiten wurden gespeichert' + }); + setViewMode('list'); + }; + + if (loading) { return (
⏳ Lade Mitarbeiter...
@@ -159,69 +139,42 @@ const EmployeeManagement: React.FC = () => { } return ( -
-
-
-

đŸ‘„ Mitarbeiter Verwaltung

-

- {employees.length} Mitarbeiter gefunden -

-
- - {viewMode === 'list' && hasRole(['admin']) && ( - - )} - - {viewMode !== 'list' && ( - - )} -
- - {/* Inhalt basierend auf View Mode */} +
{viewMode === 'list' && ( - + <> +
+

đŸ‘„ Mitarbeiterverwaltung

+ {hasRole(['admin', 'instandhalter']) && ( + + )} +
+ + + )} {viewMode === 'create' && ( @@ -244,7 +197,7 @@ const EmployeeManagement: React.FC = () => { {viewMode === 'availability' && selectedEmployee && ( )} diff --git a/frontend/src/services/shiftTemplateService.ts b/frontend/src/services/shiftTemplateService.ts index 05f0238..ac3014b 100644 --- a/frontend/src/services/shiftTemplateService.ts +++ b/frontend/src/services/shiftTemplateService.ts @@ -2,7 +2,7 @@ import { TemplateShift } from '../types/shiftTemplate'; import { authService } from './authService'; -const API_BASE = 'http://localhost:3001/api/shift-templates'; +const API_BASE = 'http://localhost:3002/api/shift-templates'; export const shiftTemplateService = { async getTemplates(): Promise { diff --git a/frontend/src/types/shiftTemplate.ts b/frontend/src/types/shiftTemplate.ts index 05e2ffe..a771cfe 100644 --- a/frontend/src/types/shiftTemplate.ts +++ b/frontend/src/types/shiftTemplate.ts @@ -11,6 +11,7 @@ export interface TemplateShift { export interface TemplateShiftSlot { id: string; + templateId?: string; dayOfWeek: number; timeRange: TemplateShiftTimeRange; requiredEmployees: number;