mirror of
https://github.com/donpat1to/Schichtenplaner.git
synced 2025-11-30 22:45:46 +01:00
added roll depending users
This commit is contained in:
@@ -2,17 +2,16 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const { v4: uuidv4 } = require('uuid');
|
const { v4: uuidv4 } = require('uuid');
|
||||||
const bcrypt = require('bcryptjs');
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const PORT = 3002;
|
const PORT = 3002;
|
||||||
|
|
||||||
// IN-MEMORY STORE für Mitarbeiter (mit gehashten Passwörtern)
|
// IN-MEMORY STORE für Mitarbeiter
|
||||||
let employees = [
|
let employees = [
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
email: 'admin@schichtplan.de',
|
email: 'admin@schichtplan.de',
|
||||||
password: '$2a$10$8K1p/a0dRTlB0ZQ1.5Q.2e5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q', // admin123
|
password: 'admin123', // Klartext für Test
|
||||||
name: 'Admin User',
|
name: 'Admin User',
|
||||||
role: 'admin',
|
role: 'admin',
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@@ -24,7 +23,7 @@ let employees = [
|
|||||||
{
|
{
|
||||||
id: '2',
|
id: '2',
|
||||||
email: 'instandhalter@schichtplan.de',
|
email: 'instandhalter@schichtplan.de',
|
||||||
password: '$2a$10$8K1p/a0dRTlB0ZQ1.5Q.2e5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q5Q', // instandhalter123
|
password: 'instandhalter123',
|
||||||
name: 'Max Instandhalter',
|
name: 'Max Instandhalter',
|
||||||
role: 'instandhalter',
|
role: 'instandhalter',
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@@ -32,6 +31,30 @@ let employees = [
|
|||||||
department: 'Produktion',
|
department: 'Produktion',
|
||||||
createdAt: new Date().toISOString(),
|
createdAt: new Date().toISOString(),
|
||||||
lastLogin: new Date().toISOString()
|
lastLogin: new Date().toISOString()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '3',
|
||||||
|
email: 'mitarbeiter1@schichtplan.de',
|
||||||
|
password: 'user123',
|
||||||
|
name: 'Anna Müller',
|
||||||
|
role: 'user',
|
||||||
|
isActive: true,
|
||||||
|
phone: '+49 123 456791',
|
||||||
|
department: 'Logistik',
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
lastLogin: new Date().toISOString()
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '4',
|
||||||
|
email: 'mitarbeiter2@schichtplan.de',
|
||||||
|
password: 'user123',
|
||||||
|
name: 'Tom Schmidt',
|
||||||
|
role: 'user',
|
||||||
|
isActive: true,
|
||||||
|
phone: '+49 123 456792',
|
||||||
|
department: 'Produktion',
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
lastLogin: new Date().toISOString()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -51,18 +74,19 @@ app.get('/api/health', (req: any, res: any) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Login Route für ALLE Benutzer
|
|
||||||
app.post('/api/auth/login', async (req: any, res: any) => {
|
app.post('/api/auth/login', async (req: any, res: any) => {
|
||||||
try {
|
try {
|
||||||
const { email, password } = req.body;
|
const { email, password } = req.body;
|
||||||
|
|
||||||
console.log('🔐 Login attempt for:', email);
|
console.log('🔐 Login attempt for:', email);
|
||||||
|
console.log('📧 Email:', email);
|
||||||
|
console.log('🔑 Password length:', password?.length);
|
||||||
|
|
||||||
if (!email || !password) {
|
if (!email || !password) {
|
||||||
return res.status(400).json({ error: 'Email and password are required' });
|
return res.status(400).json({ error: 'Email and password are required' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Benutzer in der employees Liste suchen
|
// Benutzer suchen
|
||||||
const user = employees.find(emp => emp.email === email && emp.isActive);
|
const user = employees.find(emp => emp.email === email && emp.isActive);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
@@ -70,20 +94,15 @@ app.post('/api/auth/login', async (req: any, res: any) => {
|
|||||||
return res.status(401).json({ error: 'Invalid credentials' });
|
return res.status(401).json({ error: 'Invalid credentials' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passwort vergleichen
|
console.log('🔍 User found:', user.email);
|
||||||
// Für Test: Wenn Passwort nicht gehasht ist (neue Benutzer), direkt vergleichen
|
console.log('💾 Stored password:', user.password);
|
||||||
let isPasswordValid = false;
|
console.log('↔️ Password match:', password === user.password);
|
||||||
|
|
||||||
if (user.password.startsWith('$2a$')) {
|
// Passwort-Überprüfung
|
||||||
// Gehashtes Passwort (bcrypt)
|
const isPasswordValid = password === user.password;
|
||||||
isPasswordValid = await bcrypt.compare(password, user.password);
|
|
||||||
} else {
|
|
||||||
// Klartext-Passwort (für Test)
|
|
||||||
isPasswordValid = password === user.password;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isPasswordValid) {
|
if (!isPasswordValid) {
|
||||||
console.log('❌ Invalid password for:', email);
|
console.log('❌ Password invalid for:', email);
|
||||||
return res.status(401).json({ error: 'Invalid credentials' });
|
return res.status(401).json({ error: 'Invalid credentials' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +126,7 @@ app.post('/api/auth/login', async (req: any, res: any) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// EMPLOYEE ROUTES mit In-Memory Store
|
// EMPLOYEE ROUTES
|
||||||
app.get('/api/employees', async (req: any, res: any) => {
|
app.get('/api/employees', async (req: any, res: any) => {
|
||||||
try {
|
try {
|
||||||
console.log('📋 Fetching employees - Total:', employees.length);
|
console.log('📋 Fetching employees - Total:', employees.length);
|
||||||
@@ -139,19 +158,22 @@ app.post('/api/employees', async (req: any, res: any) => {
|
|||||||
return res.status(400).json({ error: 'Password must be at least 6 characters long' });
|
return res.status(400).json({ error: 'Password must be at least 6 characters long' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rollen-Validierung
|
||||||
|
const validRoles = ['admin', 'instandhalter', 'user'];
|
||||||
|
if (!validRoles.includes(role)) {
|
||||||
|
return res.status(400).json({ error: 'Ungültige Rolle' });
|
||||||
|
}
|
||||||
|
|
||||||
// Check if email already exists
|
// Check if email already exists
|
||||||
if (employees.find(emp => emp.email === email)) {
|
if (employees.find(emp => emp.email === email)) {
|
||||||
return res.status(409).json({ error: 'Email already exists' });
|
return res.status(409).json({ error: 'Email already exists' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Passwort hashen für neue Benutzer
|
// NEUEN Benutzer erstellen
|
||||||
const hashedPassword = await bcrypt.hash(password, 10);
|
|
||||||
|
|
||||||
// Neuen Mitarbeiter erstellen
|
|
||||||
const newEmployee = {
|
const newEmployee = {
|
||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
email,
|
email,
|
||||||
password: hashedPassword, // Gehashtes Passwort speichern
|
password: password, // Klartext speichern für einfachen Test
|
||||||
name,
|
name,
|
||||||
role,
|
role,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
@@ -161,10 +183,14 @@ app.post('/api/employees', async (req: any, res: any) => {
|
|||||||
lastLogin: ''
|
lastLogin: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
// Zum Store hinzufügen
|
|
||||||
employees.push(newEmployee);
|
employees.push(newEmployee);
|
||||||
|
|
||||||
console.log('✅ Employee created. Total employees:', employees.length);
|
console.log('✅ Employee created:', {
|
||||||
|
email: newEmployee.email,
|
||||||
|
name: newEmployee.name,
|
||||||
|
role: newEmployee.role
|
||||||
|
});
|
||||||
|
console.log('📊 Total employees:', employees.length);
|
||||||
|
|
||||||
// Response ohne Passwort
|
// Response ohne Passwort
|
||||||
const { password: _, ...employeeWithoutPassword } = newEmployee;
|
const { password: _, ...employeeWithoutPassword } = newEmployee;
|
||||||
@@ -189,7 +215,7 @@ app.put('/api/employees/:id', async (req: any, res: any) => {
|
|||||||
return res.status(404).json({ error: 'Employee not found' });
|
return res.status(404).json({ error: 'Employee not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mitarbeiter aktualisieren (Passwort bleibt unverändert)
|
// Mitarbeiter aktualisieren
|
||||||
employees[employeeIndex] = {
|
employees[employeeIndex] = {
|
||||||
...employees[employeeIndex],
|
...employees[employeeIndex],
|
||||||
name: name || employees[employeeIndex].name,
|
name: name || employees[employeeIndex].name,
|
||||||
@@ -221,7 +247,7 @@ app.delete('/api/employees/:id', async (req: any, res: any) => {
|
|||||||
return res.status(404).json({ error: 'Employee not found' });
|
return res.status(404).json({ error: 'Employee not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Soft delete - set isActive to false
|
// Soft delete
|
||||||
employees[employeeIndex].isActive = false;
|
employees[employeeIndex].isActive = false;
|
||||||
|
|
||||||
console.log('✅ Employee deactivated:', employees[employeeIndex].name);
|
console.log('✅ Employee deactivated:', employees[employeeIndex].name);
|
||||||
@@ -232,38 +258,7 @@ app.delete('/api/employees/:id', async (req: any, res: any) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get current user profile
|
// Availability Routes
|
||||||
app.get('/api/auth/me', async (req: any, res: any) => {
|
|
||||||
try {
|
|
||||||
// Einfache Mock-Implementation
|
|
||||||
// In einer echten App würde man den Token verifizieren
|
|
||||||
const token = req.headers.authorization?.replace('Bearer ', '');
|
|
||||||
|
|
||||||
if (!token) {
|
|
||||||
return res.status(401).json({ error: 'No token provided' });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Einfache Token-"Validierung" für Demo
|
|
||||||
const tokenParts = token.split('-');
|
|
||||||
const userId = tokenParts[tokenParts.length - 1];
|
|
||||||
|
|
||||||
const user = employees.find(emp => emp.id === userId && emp.isActive);
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
return res.status(401).json({ error: 'Invalid token' });
|
|
||||||
}
|
|
||||||
|
|
||||||
// User ohne Passwort zurückgeben
|
|
||||||
const { password, ...userWithoutPassword } = user;
|
|
||||||
res.json(userWithoutPassword);
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error getting user profile:', error);
|
|
||||||
res.status(500).json({ error: 'Internal server error' });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Availability Routes (Mock)
|
|
||||||
app.get('/api/employees/:employeeId/availabilities', async (req: any, res: any) => {
|
app.get('/api/employees/:employeeId/availabilities', async (req: any, res: any) => {
|
||||||
try {
|
try {
|
||||||
const { employeeId } = req.params;
|
const { employeeId } = req.params;
|
||||||
@@ -284,7 +279,7 @@ app.get('/api/employees/:employeeId/availabilities', async (req: any, res: any)
|
|||||||
dayOfWeek: day,
|
dayOfWeek: day,
|
||||||
startTime: slot.start,
|
startTime: slot.start,
|
||||||
endTime: slot.end,
|
endTime: slot.end,
|
||||||
isAvailable: day >= 1 && day <= 5 // Nur Mo-Fr verfügbar
|
isAvailable: day >= 1 && day <= 5
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -301,7 +296,6 @@ app.put('/api/employees/:employeeId/availabilities', async (req: any, res: any)
|
|||||||
const availabilities = req.body;
|
const availabilities = req.body;
|
||||||
|
|
||||||
console.log('💾 Saving availabilities for:', employeeId);
|
console.log('💾 Saving availabilities for:', employeeId);
|
||||||
console.log('Data:', availabilities);
|
|
||||||
|
|
||||||
// Mock erfolgreiches Speichern
|
// Mock erfolgreiches Speichern
|
||||||
res.json(availabilities);
|
res.json(availabilities);
|
||||||
@@ -316,6 +310,13 @@ app.listen(PORT, () => {
|
|||||||
console.log('🎉 BACKEND STARTED SUCCESSFULLY!');
|
console.log('🎉 BACKEND STARTED SUCCESSFULLY!');
|
||||||
console.log(`📍 Port: ${PORT}`);
|
console.log(`📍 Port: ${PORT}`);
|
||||||
console.log(`📍 Health: http://localhost:${PORT}/api/health`);
|
console.log(`📍 Health: http://localhost:${PORT}/api/health`);
|
||||||
console.log('🔐 Login system READY for ALL users!');
|
console.log('');
|
||||||
console.log('👥 Employee management READY with proper authentication!');
|
console.log('🔐 SIMPLE LOGIN READY - Plain text passwords for testing!');
|
||||||
|
console.log('');
|
||||||
|
console.log('📋 TEST ACCOUNTS:');
|
||||||
|
console.log(' 👑 Admin: admin@schichtplan.de / admin123');
|
||||||
|
console.log(' 🔧 Instandhalter: instandhalter@schichtplan.de / instandhalter123');
|
||||||
|
console.log(' 👤 User1: mitarbeiter1@schichtplan.de / user123');
|
||||||
|
console.log(' 👤 User2: mitarbeiter2@schichtplan.de / user123');
|
||||||
|
console.log(' 👤 Patrick: patrick@patrick.de / 12345678');
|
||||||
});
|
});
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/App.tsx
|
// frontend/src/App.tsx - KORRIGIERT
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
||||||
import { AuthProvider, useAuth } from './contexts/AuthContext';
|
import { AuthProvider, useAuth } from './contexts/AuthContext';
|
||||||
@@ -17,77 +17,110 @@ const ProtectedRoute: React.FC<{ children: React.ReactNode; roles?: string[] }>
|
|||||||
roles = ['admin', 'instandhalter', 'user']
|
roles = ['admin', 'instandhalter', 'user']
|
||||||
}) => {
|
}) => {
|
||||||
const { user, loading, hasRole } = useAuth();
|
const { user, loading, hasRole } = useAuth();
|
||||||
|
|
||||||
|
console.log('🔒 ProtectedRoute - User:', user?.email, 'Loading:', loading);
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div style={{ textAlign: 'center', padding: '40px' }}>
|
||||||
|
<div>⏳ Lade Anwendung...</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
console.log('❌ No user, redirecting to login');
|
||||||
|
return <Login />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasRole(roles)) {
|
||||||
|
console.log('❌ Insufficient permissions for:', user.email);
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<div style={{ textAlign: 'center', padding: '40px' }}>
|
<div style={{ textAlign: 'center', padding: '40px' }}>
|
||||||
<div>⏳ Lade Anwendung...</div>
|
<h2>Zugriff verweigert</h2>
|
||||||
|
<p>Sie haben keine Berechtigung für diese Seite.</p>
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user || !hasRole(roles)) {
|
console.log('✅ Access granted for:', user.email);
|
||||||
return <Login />;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <Layout>{children}</Layout>;
|
return <Layout>{children}</Layout>;
|
||||||
};
|
};
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const { user, loading } = useAuth();
|
||||||
|
|
||||||
|
console.log('🏠 App Component - User:', user?.email, 'Loading:', loading);
|
||||||
|
|
||||||
|
// Während des Ladens zeigen wir einen Loading Screen
|
||||||
|
if (loading) {
|
||||||
|
return (
|
||||||
|
<div style={{
|
||||||
|
textAlign: 'center',
|
||||||
|
padding: '100px 20px',
|
||||||
|
fontSize: '18px'
|
||||||
|
}}>
|
||||||
|
<div>⏳ SchichtPlaner wird geladen...</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Router>
|
||||||
|
<Routes>
|
||||||
|
{/* Public Route */}
|
||||||
|
<Route path="/login" element={<Login />} />
|
||||||
|
|
||||||
|
{/* Protected Routes with Layout */}
|
||||||
|
<Route path="/" element={
|
||||||
|
<ProtectedRoute>
|
||||||
|
<Dashboard />
|
||||||
|
</ProtectedRoute>
|
||||||
|
} />
|
||||||
|
|
||||||
|
<Route path="/shift-plans" element={
|
||||||
|
<ProtectedRoute>
|
||||||
|
<ShiftPlanList />
|
||||||
|
</ProtectedRoute>
|
||||||
|
} />
|
||||||
|
|
||||||
|
<Route path="/shift-plans/new" element={
|
||||||
|
<ProtectedRoute roles={['admin', 'instandhalter']}>
|
||||||
|
<ShiftPlanCreate />
|
||||||
|
</ProtectedRoute>
|
||||||
|
} />
|
||||||
|
|
||||||
|
<Route path="/employees" element={
|
||||||
|
<ProtectedRoute roles={['admin', 'instandhalter']}>
|
||||||
|
<EmployeeManagement />
|
||||||
|
</ProtectedRoute>
|
||||||
|
} />
|
||||||
|
|
||||||
|
<Route path="/settings" element={
|
||||||
|
<ProtectedRoute roles={['admin']}>
|
||||||
|
<Settings />
|
||||||
|
</ProtectedRoute>
|
||||||
|
} />
|
||||||
|
|
||||||
|
<Route path="/help" element={
|
||||||
|
<ProtectedRoute>
|
||||||
|
<Help />
|
||||||
|
</ProtectedRoute>
|
||||||
|
} />
|
||||||
|
</Routes>
|
||||||
|
</Router>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hauptkomponente mit AuthProvider
|
||||||
|
function AppWrapper() {
|
||||||
return (
|
return (
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<Router>
|
<App />
|
||||||
<Routes>
|
|
||||||
{/* Public Route */}
|
|
||||||
<Route path="/login" element={<Login />} />
|
|
||||||
|
|
||||||
{/* Protected Routes with Layout */}
|
|
||||||
<Route path="/" element={
|
|
||||||
<ProtectedRoute>
|
|
||||||
<Dashboard />
|
|
||||||
</ProtectedRoute>
|
|
||||||
} />
|
|
||||||
|
|
||||||
<Route path="/shift-plans" element={
|
|
||||||
<ProtectedRoute>
|
|
||||||
<ShiftPlanList />
|
|
||||||
</ProtectedRoute>
|
|
||||||
} />
|
|
||||||
|
|
||||||
<Route path="/shift-plans/new" element={
|
|
||||||
<ProtectedRoute roles={['admin', 'instandhalter']}>
|
|
||||||
<ShiftPlanCreate />
|
|
||||||
</ProtectedRoute>
|
|
||||||
} />
|
|
||||||
|
|
||||||
<Route path="/employees" element={
|
|
||||||
<ProtectedRoute roles={['admin', 'instandhalter']}>
|
|
||||||
<EmployeeManagement />
|
|
||||||
</ProtectedRoute>
|
|
||||||
} />
|
|
||||||
|
|
||||||
<Route path="/settings" element={
|
|
||||||
<ProtectedRoute roles={['admin']}>
|
|
||||||
<Settings />
|
|
||||||
</ProtectedRoute>
|
|
||||||
} />
|
|
||||||
|
|
||||||
<Route path="/help" element={
|
|
||||||
<ProtectedRoute>
|
|
||||||
<Help />
|
|
||||||
</ProtectedRoute>
|
|
||||||
} />
|
|
||||||
|
|
||||||
{/* Legal Pages (ohne Layout für einfacheren Zugang) */}
|
|
||||||
<Route path="/impressum" element={<div>Impressum Seite</div>} />
|
|
||||||
<Route path="/datenschutz" element={<div>Datenschutz Seite</div>} />
|
|
||||||
<Route path="/agb" element={<div>AGB Seite</div>} />
|
|
||||||
</Routes>
|
|
||||||
</Router>
|
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default AppWrapper;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// frontend/src/contexts/AuthContext.tsx
|
// frontend/src/contexts/AuthContext.tsx - KORRIGIERT
|
||||||
import React, { createContext, useContext, useState, useEffect } from 'react';
|
import React, { createContext, useContext, useState, useEffect } from 'react';
|
||||||
import { authService, User, LoginRequest } from '../services/authService';
|
import { authService, User, LoginRequest } from '../services/authService';
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ interface AuthContextType {
|
|||||||
logout: () => void;
|
logout: () => void;
|
||||||
hasRole: (roles: string[]) => boolean;
|
hasRole: (roles: string[]) => boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
refreshUser: () => void; // NEU: Force refresh
|
||||||
}
|
}
|
||||||
|
|
||||||
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
||||||
@@ -15,22 +16,44 @@ const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
|||||||
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||||
const [user, setUser] = useState<User | null>(null);
|
const [user, setUser] = useState<User | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [refreshTrigger, setRefreshTrigger] = useState(0); // NEU: Refresh trigger
|
||||||
|
|
||||||
|
// User beim Start laden
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// User aus localStorage laden beim Start
|
|
||||||
const savedUser = authService.getCurrentUser();
|
const savedUser = authService.getCurrentUser();
|
||||||
if (savedUser) {
|
if (savedUser) {
|
||||||
setUser(savedUser);
|
setUser(savedUser);
|
||||||
|
console.log('✅ User from localStorage:', savedUser.email);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// NEU: User vom Server laden wenn nötig
|
||||||
|
useEffect(() => {
|
||||||
|
if (refreshTrigger > 0) {
|
||||||
|
const loadUserFromServer = async () => {
|
||||||
|
const serverUser = await authService.fetchCurrentUser();
|
||||||
|
if (serverUser) {
|
||||||
|
setUser(serverUser);
|
||||||
|
console.log('✅ User from server:', serverUser.email);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
loadUserFromServer();
|
||||||
|
}
|
||||||
|
}, [refreshTrigger]);
|
||||||
|
|
||||||
const login = async (credentials: LoginRequest) => {
|
const login = async (credentials: LoginRequest) => {
|
||||||
try {
|
try {
|
||||||
|
console.log('🔄 Attempting login...');
|
||||||
const response = await authService.login(credentials);
|
const response = await authService.login(credentials);
|
||||||
setUser(response.user);
|
setUser(response.user);
|
||||||
|
console.log('✅ Login successful, user set:', response.user.email);
|
||||||
|
|
||||||
|
// Force refresh der App
|
||||||
|
setRefreshTrigger(prev => prev + 1);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('AuthContext: Login fehlgeschlagen', error);
|
console.error('❌ Login failed:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -38,6 +61,11 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
const logout = () => {
|
const logout = () => {
|
||||||
authService.logout();
|
authService.logout();
|
||||||
setUser(null);
|
setUser(null);
|
||||||
|
console.log('✅ Logout completed');
|
||||||
|
};
|
||||||
|
|
||||||
|
const refreshUser = () => {
|
||||||
|
setRefreshTrigger(prev => prev + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const hasRole = (roles: string[]) => {
|
const hasRole = (roles: string[]) => {
|
||||||
@@ -49,7 +77,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||||||
login,
|
login,
|
||||||
logout,
|
logout,
|
||||||
hasRole,
|
hasRole,
|
||||||
loading
|
loading,
|
||||||
|
refreshUser // NEU
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
// frontend/src/pages/Auth/Login.tsx
|
// frontend/src/pages/Auth/Login.tsx - KORRIGIERT
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useAuth } from '../../contexts/AuthContext';
|
import { useAuth } from '../../contexts/AuthContext';
|
||||||
|
|
||||||
const Login: React.FC = () => {
|
const Login: React.FC = () => {
|
||||||
const [email, setEmail] = useState('admin@schichtplan.de');
|
const [email, setEmail] = useState('');
|
||||||
const [password, setPassword] = useState('admin123');
|
const [password, setPassword] = useState('');
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
const { login } = useAuth();
|
const { login, user } = useAuth(); // user hinzugefügt für Debugging
|
||||||
|
|
||||||
console.log('Login Komponente - State:', { email, password, error, loading });
|
console.log('🔍 Login Component - Current user:', user);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -18,13 +18,14 @@ const Login: React.FC = () => {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('Login startet mit:', { email });
|
console.log('🚀 Starting login process...');
|
||||||
await login({ email, password });
|
await login({ email, password });
|
||||||
console.log('Login erfolgreich abgeschlossen');
|
console.log('✅ Login process completed');
|
||||||
// Force refresh als Fallback
|
|
||||||
window.location.reload();
|
// Navigation passiert automatisch durch AuthContext
|
||||||
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
console.error('Login Fehler:', err);
|
console.error('❌ Login error:', err);
|
||||||
setError(err.message || 'Login fehlgeschlagen');
|
setError(err.message || 'Login fehlgeschlagen');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -37,10 +38,9 @@ const Login: React.FC = () => {
|
|||||||
margin: '100px auto',
|
margin: '100px auto',
|
||||||
padding: '20px',
|
padding: '20px',
|
||||||
border: '1px solid #ddd',
|
border: '1px solid #ddd',
|
||||||
borderRadius: '8px',
|
borderRadius: '8px'
|
||||||
backgroundColor: '#f9f9f9'
|
|
||||||
}}>
|
}}>
|
||||||
<h2 style={{ textAlign: 'center', marginBottom: '20px' }}>Anmelden</h2>
|
<h2>Anmelden</h2>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div style={{
|
<div style={{
|
||||||
@@ -48,8 +48,7 @@ const Login: React.FC = () => {
|
|||||||
backgroundColor: '#ffe6e6',
|
backgroundColor: '#ffe6e6',
|
||||||
padding: '10px',
|
padding: '10px',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
marginBottom: '15px',
|
marginBottom: '15px'
|
||||||
border: '1px solid #ffcccc'
|
|
||||||
}}>
|
}}>
|
||||||
<strong>Fehler:</strong> {error}
|
<strong>Fehler:</strong> {error}
|
||||||
</div>
|
</div>
|
||||||
@@ -57,7 +56,7 @@ const Login: React.FC = () => {
|
|||||||
|
|
||||||
<form onSubmit={handleSubmit}>
|
<form onSubmit={handleSubmit}>
|
||||||
<div style={{ marginBottom: '15px' }}>
|
<div style={{ marginBottom: '15px' }}>
|
||||||
<label style={{ display: 'block', marginBottom: '5px', fontWeight: 'bold' }}>
|
<label style={{ display: 'block', marginBottom: '5px' }}>
|
||||||
E-Mail:
|
E-Mail:
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -65,18 +64,12 @@ const Login: React.FC = () => {
|
|||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => setEmail(e.target.value)}
|
||||||
required
|
required
|
||||||
style={{
|
style={{ width: '100%', padding: '8px', border: '1px solid #ccc', borderRadius: '4px' }}
|
||||||
width: '100%',
|
|
||||||
padding: '10px',
|
|
||||||
border: '1px solid #ccc',
|
|
||||||
borderRadius: '4px',
|
|
||||||
fontSize: '16px'
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={{ marginBottom: '20px' }}>
|
<div style={{ marginBottom: '15px' }}>
|
||||||
<label style={{ display: 'block', marginBottom: '5px', fontWeight: 'bold' }}>
|
<label style={{ display: 'block', marginBottom: '5px' }}>
|
||||||
Passwort:
|
Passwort:
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
@@ -84,13 +77,7 @@ const Login: React.FC = () => {
|
|||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => setPassword(e.target.value)}
|
||||||
required
|
required
|
||||||
style={{
|
style={{ width: '100%', padding: '8px', border: '1px solid #ccc', borderRadius: '4px' }}
|
||||||
width: '100%',
|
|
||||||
padding: '10px',
|
|
||||||
border: '1px solid #ccc',
|
|
||||||
borderRadius: '4px',
|
|
||||||
fontSize: '16px'
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -99,31 +86,23 @@ const Login: React.FC = () => {
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
padding: '12px',
|
padding: '10px',
|
||||||
backgroundColor: loading ? '#6c757d' : '#007bff',
|
backgroundColor: loading ? '#ccc' : '#007bff',
|
||||||
color: 'white',
|
color: 'white',
|
||||||
border: 'none',
|
border: 'none',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
fontSize: '16px',
|
cursor: loading ? 'not-allowed' : 'pointer'
|
||||||
fontWeight: 'bold',
|
|
||||||
cursor: loading ? 'not-allowed' : 'pointer',
|
|
||||||
transition: 'background-color 0.2s'
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{loading ? '⏳ Anmeldung...' : 'Anmelden'}
|
{loading ? 'Anmeldung...' : 'Anmelden'}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div style={{
|
<div style={{ marginTop: '15px', textAlign: 'center' }}>
|
||||||
marginTop: '20px',
|
<p><strong>Test Accounts:</strong></p>
|
||||||
padding: '15px',
|
<p>admin@schichtplan.de / admin123</p>
|
||||||
backgroundColor: '#e7f3ff',
|
<p>instandhalter@schichtplan.de / instandhalter123</p>
|
||||||
borderRadius: '4px',
|
<p>user@schichtplan.de / user123</p>
|
||||||
border: '1px solid #b3d9ff'
|
|
||||||
}}>
|
|
||||||
<h4 style={{ margin: '0 0 10px 0' }}>Test Account:</h4>
|
|
||||||
<p style={{ margin: '5px 0' }}><strong>Email:</strong> admin@schichtplan.de</p>
|
|
||||||
<p style={{ margin: '5px 0' }}><strong>Passwort:</strong> admin123</p>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Employee, CreateEmployeeRequest, UpdateEmployeeRequest } from '../../../types/employee';
|
import { Employee, CreateEmployeeRequest, UpdateEmployeeRequest } from '../../../types/employee';
|
||||||
import { employeeService } from '../../../services/employeeService';
|
import { employeeService } from '../../../services/employeeService';
|
||||||
|
import { useAuth } from '../../../contexts/AuthContext';
|
||||||
|
|
||||||
interface EmployeeFormProps {
|
interface EmployeeFormProps {
|
||||||
mode: 'create' | 'edit';
|
mode: 'create' | 'edit';
|
||||||
@@ -10,6 +11,13 @@ interface EmployeeFormProps {
|
|||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rollen Definition
|
||||||
|
const ROLE_OPTIONS = [
|
||||||
|
{ value: 'user', label: 'Mitarbeiter', description: 'Kann eigene Schichten einsehen' },
|
||||||
|
{ value: 'instandhalter', label: 'Instandhalter', description: 'Kann Schichtpläne erstellen und Mitarbeiter verwalten' },
|
||||||
|
{ value: 'admin', label: 'Administrator', description: 'Voller Zugriff auf alle Funktionen' }
|
||||||
|
] as const;
|
||||||
|
|
||||||
const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
||||||
mode,
|
mode,
|
||||||
employee,
|
employee,
|
||||||
@@ -27,6 +35,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
});
|
});
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
|
const { hasRole } = useAuth();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (mode === 'edit' && employee) {
|
if (mode === 'edit' && employee) {
|
||||||
@@ -50,6 +59,14 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// NEU: Checkbox für Rollen
|
||||||
|
const handleRoleChange = (roleValue: 'admin' | 'instandhalter' | 'user') => {
|
||||||
|
setFormData(prev => ({
|
||||||
|
...prev,
|
||||||
|
role: roleValue
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -94,6 +111,19 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
return formData.name.trim() && formData.email.trim();
|
return formData.name.trim() && formData.email.trim();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Bestimme welche Rollen der aktuelle Benutzer vergeben darf
|
||||||
|
const getAvailableRoles = () => {
|
||||||
|
if (hasRole(['admin'])) {
|
||||||
|
return ROLE_OPTIONS; // Admins können alle Rollen vergeben
|
||||||
|
}
|
||||||
|
if (hasRole(['instandhalter'])) {
|
||||||
|
return ROLE_OPTIONS.filter(role => role.value !== 'admin'); // Instandhalter können keine Admins erstellen
|
||||||
|
}
|
||||||
|
return ROLE_OPTIONS.filter(role => role.value === 'user'); // Normale User können gar nichts (sollte nicht vorkommen)
|
||||||
|
};
|
||||||
|
|
||||||
|
const availableRoles = getAvailableRoles();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{
|
<div style={{
|
||||||
maxWidth: '600px',
|
maxWidth: '600px',
|
||||||
@@ -146,7 +176,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
required
|
required
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
padding: '10px 12px',
|
padding: '10px',
|
||||||
border: '1px solid #ddd',
|
border: '1px solid #ddd',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
fontSize: '16px'
|
fontSize: '16px'
|
||||||
@@ -173,7 +203,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
required
|
required
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
padding: '10px 12px',
|
padding: '10px',
|
||||||
border: '1px solid #ddd',
|
border: '1px solid #ddd',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
fontSize: '16px'
|
fontSize: '16px'
|
||||||
@@ -202,7 +232,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
minLength={6}
|
minLength={6}
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
padding: '10px 12px',
|
padding: '10px',
|
||||||
border: '1px solid #ddd',
|
border: '1px solid #ddd',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
fontSize: '16px'
|
fontSize: '16px'
|
||||||
@@ -215,40 +245,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Rolle */}
|
|
||||||
<div>
|
|
||||||
<label style={{
|
|
||||||
display: 'block',
|
|
||||||
marginBottom: '8px',
|
|
||||||
fontWeight: 'bold',
|
|
||||||
color: '#2c3e50'
|
|
||||||
}}>
|
|
||||||
Rolle *
|
|
||||||
</label>
|
|
||||||
<select
|
|
||||||
name="role"
|
|
||||||
value={formData.role}
|
|
||||||
onChange={handleChange}
|
|
||||||
required
|
|
||||||
style={{
|
|
||||||
width: '100%',
|
|
||||||
padding: '10px 12px',
|
|
||||||
border: '1px solid #ddd',
|
|
||||||
borderRadius: '4px',
|
|
||||||
fontSize: '16px',
|
|
||||||
backgroundColor: 'white'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<option value="user">Mitarbeiter (User)</option>
|
|
||||||
<option value="instandhalter">Instandhalter</option>
|
|
||||||
<option value="admin">Administrator</option>
|
|
||||||
</select>
|
|
||||||
<div style={{ fontSize: '12px', color: '#7f8c8d', marginTop: '5px' }}>
|
|
||||||
{formData.role === 'admin' && 'Administratoren haben vollen Zugriff auf alle Funktionen.'}
|
|
||||||
{formData.role === 'instandhalter' && 'Instandhalter können Schichtpläne erstellen und Mitarbeiter verwalten.'}
|
|
||||||
{formData.role === 'user' && 'Mitarbeiter können ihre eigenen Schichten und Verfügbarkeiten einsehen.'}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Telefon */}
|
{/* Telefon */}
|
||||||
<div>
|
<div>
|
||||||
@@ -267,7 +264,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
padding: '10px 12px',
|
padding: '10px',
|
||||||
border: '1px solid #ddd',
|
border: '1px solid #ddd',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
fontSize: '16px'
|
fontSize: '16px'
|
||||||
@@ -293,7 +290,7 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: '100%',
|
||||||
padding: '10px 12px',
|
padding: '10px',
|
||||||
border: '1px solid #ddd',
|
border: '1px solid #ddd',
|
||||||
borderRadius: '4px',
|
borderRadius: '4px',
|
||||||
fontSize: '16px'
|
fontSize: '16px'
|
||||||
@@ -302,9 +299,107 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* NEU: Rollen als Checkboxes */}
|
||||||
|
<div>
|
||||||
|
<label style={{
|
||||||
|
display: 'block',
|
||||||
|
marginBottom: '12px',
|
||||||
|
fontWeight: 'bold',
|
||||||
|
color: '#2c3e50'
|
||||||
|
}}>
|
||||||
|
Rolle *
|
||||||
|
</label>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: '12px' }}>
|
||||||
|
{availableRoles.map(role => (
|
||||||
|
<div
|
||||||
|
key={role.value}
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'flex-start',
|
||||||
|
padding: '5px',
|
||||||
|
border: `2px solid ${formData.role === role.value ? '#3498db' : '#e0e0e0'}`,
|
||||||
|
borderRadius: '8px',
|
||||||
|
backgroundColor: formData.role === role.value ? '#f8fafc' : 'white',
|
||||||
|
cursor: 'pointer',
|
||||||
|
transition: 'all 0.2s'
|
||||||
|
}}
|
||||||
|
onClick={() => handleRoleChange(role.value)}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="role"
|
||||||
|
value={role.value}
|
||||||
|
checked={formData.role === role.value}
|
||||||
|
onChange={() => handleRoleChange(role.value)}
|
||||||
|
style={{
|
||||||
|
marginRight: '12px',
|
||||||
|
marginTop: '2px',
|
||||||
|
width: '18px',
|
||||||
|
height: '18px'
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div style={{ flex: 1 }}>
|
||||||
|
<div style={{
|
||||||
|
fontWeight: 'bold',
|
||||||
|
color: '#2c3e50',
|
||||||
|
marginBottom: '4px'
|
||||||
|
}}>
|
||||||
|
{role.label}
|
||||||
|
</div>
|
||||||
|
<div style={{
|
||||||
|
fontSize: '14px',
|
||||||
|
color: '#7f8c8d',
|
||||||
|
lineHeight: '1.4'
|
||||||
|
}}>
|
||||||
|
{role.description}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/* Role Badge */}
|
||||||
|
<div style={{
|
||||||
|
padding: '4px 8px',
|
||||||
|
backgroundColor:
|
||||||
|
role.value === 'admin' ? '#e74c3c' :
|
||||||
|
role.value === 'instandhalter' ? '#3498db' : '#27ae60',
|
||||||
|
color: 'white',
|
||||||
|
borderRadius: '12px',
|
||||||
|
fontSize: '12px',
|
||||||
|
fontWeight: 'bold'
|
||||||
|
}}>
|
||||||
|
{role.value.toUpperCase()}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Info über Berechtigungen */}
|
||||||
|
<div style={{
|
||||||
|
marginTop: '10px',
|
||||||
|
padding: '10px',
|
||||||
|
backgroundColor: '#e8f4fd',
|
||||||
|
border: '1px solid #b6d7e8',
|
||||||
|
borderRadius: '4px',
|
||||||
|
fontSize: '12px',
|
||||||
|
color: '#2c3e50'
|
||||||
|
}}>
|
||||||
|
<strong>Info:</strong> {
|
||||||
|
formData.role === 'admin' ? 'Administratoren haben vollen Zugriff auf alle Funktionen.' :
|
||||||
|
formData.role === 'instandhalter' ? 'Instandhalter können Schichtpläne erstellen und Mitarbeiter verwalten.' :
|
||||||
|
'Mitarbeiter können ihre eigenen Schichten und Verfügbarkeiten einsehen.'
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Aktiv Status (nur beim Bearbeiten) */}
|
{/* Aktiv Status (nur beim Bearbeiten) */}
|
||||||
{mode === 'edit' && (
|
{mode === 'edit' && (
|
||||||
<div style={{ display: 'flex', alignItems: 'center', gap: '10px' }}>
|
<div style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: '10px',
|
||||||
|
padding: '15px',
|
||||||
|
border: '1px solid #e0e0e0',
|
||||||
|
borderRadius: '6px',
|
||||||
|
backgroundColor: '#f8f9fa'
|
||||||
|
}}>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
name="isActive"
|
name="isActive"
|
||||||
@@ -313,9 +408,14 @@ const EmployeeForm: React.FC<EmployeeFormProps> = ({
|
|||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
style={{ width: '18px', height: '18px' }}
|
style={{ width: '18px', height: '18px' }}
|
||||||
/>
|
/>
|
||||||
<label htmlFor="isActive" style={{ fontWeight: 'bold', color: '#2c3e50' }}>
|
<div>
|
||||||
Mitarbeiter ist aktiv
|
<label htmlFor="isActive" style={{ fontWeight: 'bold', color: '#2c3e50', display: 'block' }}>
|
||||||
</label>
|
Mitarbeiter ist aktiv
|
||||||
|
</label>
|
||||||
|
<div style={{ fontSize: '12px', color: '#7f8c8d' }}>
|
||||||
|
Inaktive Mitarbeiter können sich nicht anmelden und werden nicht für Schichten eingeplant.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user