LMIV-SNACKAUTOMAT/resources/views/admin/users/edit.blade.php

154 lines
6.4 KiB
PHP

@extends('layouts.admin')
@section('title', 'Benutzer bearbeiten')
@section('content')
<div class="max-w-2xl mx-auto">
<div class="mb-8">
<h1 class="text-3xl font-bold text-gray-900">Benutzer bearbeiten</h1>
<p class="text-gray-600 mt-2">Bearbeiten Sie die Daten von {{ $user->name }}</p>
</div>
<div class="bg-white shadow rounded-lg p-6">
<form action="{{ route('admin.users.update', $user) }}" method="POST" class="space-y-6">
@csrf
@method('PUT')
<!-- Name -->
<div>
<label for="name" class="block text-sm font-medium text-gray-700">
Name *
</label>
<input type="text"
id="name"
name="name"
value="{{ old('name', $user->name) }}"
required
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
@error('name')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- E-Mail -->
<div>
<label for="email" class="block text-sm font-medium text-gray-700">
E-Mail-Adresse *
</label>
<input type="email"
id="email"
name="email"
value="{{ old('email', $user->email) }}"
required
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
@error('email')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Passwort (optional bei Edit) -->
<div>
<label for="password" class="block text-sm font-medium text-gray-700">
Neues Passwort
</label>
<input type="password"
id="password"
name="password"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
<p class="mt-1 text-sm text-gray-500">
Lassen Sie das Feld leer, um das aktuelle Passwort beizubehalten
</p>
@error('password')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Passwort bestätigen -->
<div>
<label for="password_confirmation" class="block text-sm font-medium text-gray-700">
Neues Passwort bestätigen
</label>
<input type="password"
id="password_confirmation"
name="password_confirmation"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
</div>
<!-- Rolle -->
<div>
<label for="role" class="block text-sm font-medium text-gray-700">
Rolle *
</label>
<select id="role"
name="role"
required
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
<option value="">Rolle auswählen</option>
<option value="tenant_admin" {{ old('role', $user->role) === 'tenant_admin' ? 'selected' : '' }}>
Mandanten-Admin
</option>
<option value="super_admin" {{ old('role', $user->role) === 'super_admin' ? 'selected' : '' }}>
Super Admin
</option>
</select>
@error('role')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Mandant -->
<div>
<label for="tenant_id" class="block text-sm font-medium text-gray-700">
Mandant
</label>
<select id="tenant_id"
name="tenant_id"
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500">
<option value="">Kein Mandant (nur für Super Admins)</option>
@foreach($tenants as $tenant)
<option value="{{ $tenant->id }}" {{ old('tenant_id', $user->tenant_id) == $tenant->id ? 'selected' : '' }}>
{{ $tenant->name }}
</option>
@endforeach
</select>
<p class="mt-1 text-sm text-gray-500">
Mandanten-Admins benötigen einen Mandanten, Super Admins können alle Mandanten verwalten
</p>
@error('tenant_id')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- Buttons -->
<div class="flex items-center justify-end space-x-4 pt-4 border-t">
<a href="{{ route('admin.users.index') }}"
class="px-4 py-2 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 transition-colors">
Abbrechen
</a>
<button type="submit"
class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 transition-colors">
Benutzer aktualisieren
</button>
</div>
</form>
</div>
</div>
<script>
document.getElementById('role').addEventListener('change', function() {
const tenantSelect = document.getElementById('tenant_id');
const isTenantAdmin = this.value === 'tenant_admin';
if (isTenantAdmin) {
tenantSelect.required = true;
tenantSelect.parentElement.querySelector('label').innerHTML = 'Mandant *';
} else {
tenantSelect.required = false;
tenantSelect.parentElement.querySelector('label').innerHTML = 'Mandant';
}
});
// Initial check
document.getElementById('role').dispatchEvent(new Event('change'));
</script>
@endsection