vernova/resources/views/settings/partials/users.blade.php
2026-07-26 19:58:27 +03:30

204 lines
13 KiB
PHP

<div class="space-y-6">
<!-- Add User Button -->
<div class="flex justify-end">
<button type="button" onclick="document.getElementById('addUserModal').classList.remove('hidden')"
class="inline-flex items-center gap-2 px-4 py-2 bg-teal-600 text-white text-sm font-medium rounded-lg hover:bg-teal-700 transition-colors">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/></svg>
{{ __('settings.add_user') }}
</button>
</div>
<!-- Users Table -->
<div class="overflow-x-auto">
<table class="w-full">
<thead class="bg-gray-50 border-b border-gray-200">
<tr>
<th class="px-4 py-3 text-start text-xs font-medium text-gray-500">{{ __('settings.user_name') }}</th>
<th class="px-4 py-3 text-start text-xs font-medium text-gray-500">{{ __('settings.user_email') }}</th>
<th class="px-4 py-3 text-start text-xs font-medium text-gray-500">{{ __('settings.user_role') }}</th>
<th class="px-4 py-3 text-start text-xs font-medium text-gray-500">{{ __('common.status') }}</th>
<th class="px-4 py-3 text-start text-xs font-medium text-gray-500">{{ __('common.actions') }}</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100">
@forelse($users as $user)
<tr class="hover:bg-gray-50 transition-colors">
<td class="px-4 py-3">
<div class="flex items-center gap-3">
<div class="w-8 h-8 bg-teal-50 text-teal-700 rounded-full flex items-center justify-center text-sm font-semibold">
{{ mb_strtoupper(mb_substr($user->name, 0, 1)) }}
</div>
<span class="text-sm font-medium text-gray-900">{{ $user->name }}</span>
</div>
</td>
<td class="px-4 py-3 text-sm text-gray-600" dir="ltr">{{ $user->email }}</td>
<td class="px-4 py-3">
@foreach($user->roles as $role)
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-teal-50 text-teal-700">
{{ $role->name }}
</span>
@endforeach
@if($user->roles->isEmpty())
<span class="text-xs text-gray-400"></span>
@endif
</td>
<td class="px-4 py-3">
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium
{{ $user->is_active ? 'bg-emerald-50 text-emerald-700' : 'bg-red-50 text-red-700' }}">
{{ $user->is_active ? __('settings.active') : __('settings.inactive') }}
</span>
</td>
<td class="px-4 py-3">
<div class="flex items-center gap-2">
<button type="button" onclick="editUser({{ $user->id }}, '{{ $user->name }}', '{{ $user->email }}', '{{ $user->roles->first()?->name ?? '' }}', {{ $user->is_active ? 'true' : 'false' }})"
class="px-2 py-1 text-xs font-medium text-teal-700 bg-teal-50 rounded hover:bg-teal-100 transition-colors">
{{ __('common.edit') }}
</button>
@if($user->id !== auth()->id())
<form method="POST" action="{{ route('settings.users.toggle', $user) }}" class="inline">
@csrf @method('PATCH')
<button type="submit"
class="px-2 py-1 text-xs font-medium {{ $user->is_active ? 'text-red-700 bg-red-50 hover:bg-red-100' : 'text-emerald-700 bg-emerald-50 hover:bg-emerald-100' }} rounded transition-colors">
{{ $user->is_active ? __('settings.deactivate') : __('settings.activate') }}
</button>
</form>
@endif
</div>
</td>
</tr>
@empty
<tr>
<td colspan="5" class="text-center py-8 text-gray-400">{{ __('settings.no_users') }}</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
<!-- Add User Modal -->
<div id="addUserModal" class="hidden fixed inset-0 z-50 overflow-y-auto">
<div class="flex items-center justify-center min-h-screen px-4 pt-4 pb-20">
<div class="fixed inset-0 bg-gray-900/50 transition-opacity" onclick="document.getElementById('addUserModal').classList.add('hidden')"></div>
<div class="relative bg-white rounded-xl shadow-xl max-w-md w-full p-6 z-10">
<h3 class="text-lg font-bold text-gray-900 mb-4">{{ __('settings.add_user') }}</h3>
<form method="POST" action="{{ route('settings.users.store') }}" class="space-y-4">
@csrf
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('settings.user_name') }}</label>
<input type="text" name="name" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('settings.user_email') }}</label>
<input type="email" name="email" required dir="ltr"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('auth.password') }}</label>
<input type="password" name="password" required dir="ltr"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('auth.password') }} ({{ __('settings.confirm') }})</label>
<input type="password" name="password_confirmation" required dir="ltr"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('settings.user_role') }}</label>
<select name="role"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
<option value=""> {{ __('common.select') }} </option>
<option value="admin">{{ __('settings.role_admin') }}</option>
<option value="project-manager">{{ __('settings.role_manager') }}</option>
<option value="accountant">{{ __('settings.role_accountant') }}</option>
<option value="employee">{{ __('settings.role_employee') }}</option>
</select>
</div>
<div class="flex justify-end gap-3 pt-2">
<button type="button" onclick="document.getElementById('addUserModal').classList.add('hidden')"
class="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors">
{{ __('common.cancel') }}
</button>
<button type="submit" class="px-4 py-2 text-sm font-medium text-white bg-teal-600 rounded-lg hover:bg-teal-700 transition-colors">
{{ __('common.create') }}
</button>
</div>
</form>
</div>
</div>
</div>
<!-- Edit User Modal -->
<div id="editUserModal" class="hidden fixed inset-0 z-50 overflow-y-auto">
<div class="flex items-center justify-center min-h-screen px-4 pt-4 pb-20">
<div class="fixed inset-0 bg-gray-900/50 transition-opacity" onclick="document.getElementById('editUserModal').classList.add('hidden')"></div>
<div class="relative bg-white rounded-xl shadow-xl max-w-md w-full p-6 z-10">
<h3 class="text-lg font-bold text-gray-900 mb-4">{{ __('settings.edit_user') }}</h3>
<form id="editUserForm" method="POST" action="" class="space-y-4">
@csrf @method('PUT')
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('settings.user_name') }}</label>
<input type="text" name="name" id="edit_name" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('settings.user_email') }}</label>
<input type="email" name="email" id="edit_email" required dir="ltr"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('auth.password') }} ({{ __('settings.password_help') }})</label>
<input type="password" name="password" id="edit_password" dir="ltr"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('auth.password') }} ({{ __('settings.confirm') }})</label>
<input type="password" name="password_confirmation" id="edit_password_confirmation" dir="ltr"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">{{ __('settings.user_role') }}</label>
<select name="role" id="edit_role"
class="w-full px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-teal-500 focus:border-teal-500">
<option value=""> {{ __('common.select') }} </option>
<option value="admin">{{ __('settings.role_admin') }}</option>
<option value="project-manager">{{ __('settings.role_manager') }}</option>
<option value="accountant">{{ __('settings.role_accountant') }}</option>
<option value="employee">{{ __('settings.role_employee') }}</option>
</select>
</div>
<div class="flex items-center gap-3">
<input type="checkbox" name="is_active" id="edit_is_active" value="1"
class="w-4 h-4 rounded border-gray-300 text-teal-600 focus:ring-teal-500">
<label for="edit_is_active" class="text-sm font-medium text-gray-700">{{ __('settings.active') }}</label>
</div>
<div class="flex justify-end gap-3 pt-2">
<button type="button" onclick="document.getElementById('editUserModal').classList.add('hidden')"
class="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors">
{{ __('common.cancel') }}
</button>
<button type="submit" class="px-4 py-2 text-sm font-medium text-white bg-teal-600 rounded-lg hover:bg-teal-700 transition-colors">
{{ __('common.save_changes') }}
</button>
</div>
</form>
</div>
</div>
</div>
@push('scripts')
<script>
function editUser(id, name, email, role, isActive) {
document.getElementById('editUserForm').action = '{{ route("settings.users.update", ["user" => "__ID__"]) }}'.replace('__ID__', id);
document.getElementById('edit_name').value = name;
document.getElementById('edit_email').value = email;
document.getElementById('edit_role').value = role;
document.getElementById('edit_is_active').checked = isActive;
document.getElementById('edit_password').value = '';
document.getElementById('edit_password_confirmation').value = '';
document.getElementById('editUserModal').classList.remove('hidden');
}
</script>
@endpush