Laravel 13 + Livewire/Volt app for managing client organizations, documents, passwords, flexible assets, virtual machines, contacts, domains, todos, shortcuts, and role-based user administration.
112 lines
4.4 KiB
PHP
112 lines
4.4 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use Livewire\Attributes\Url;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
new class extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
#[Url]
|
|
public string $search = '';
|
|
|
|
public function delete(int $userId): void
|
|
{
|
|
if ($userId === auth()->id()) {
|
|
session()->flash('error', 'Vous ne pouvez pas supprimer votre propre compte.');
|
|
|
|
return;
|
|
}
|
|
|
|
$user = User::findOrFail($userId);
|
|
$user->delete();
|
|
|
|
session()->flash('status', "Utilisateur « {$user->name} » supprimé.");
|
|
}
|
|
|
|
public function with(): array
|
|
{
|
|
return [
|
|
'users' => User::query()
|
|
->when($this->search, fn ($query) => $query->where(function ($q) {
|
|
$q->where('name', 'like', "%{$this->search}%")
|
|
->orWhere('email', 'like', "%{$this->search}%");
|
|
}))
|
|
->orderBy('name')
|
|
->paginate(15),
|
|
];
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div>
|
|
<div class="mb-6 flex items-center justify-between">
|
|
<h1 class="text-2xl font-semibold text-slate-900">Utilisateurs</h1>
|
|
<a href="{{ route('users.create') }}"
|
|
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
|
+ Nouvel utilisateur
|
|
</a>
|
|
</div>
|
|
|
|
@if (session('error'))
|
|
<div class="mb-4 rounded border border-red-200 bg-red-50 px-4 py-2 text-sm text-red-700">
|
|
{{ session('error') }}
|
|
</div>
|
|
@endif
|
|
|
|
<input type="text" wire:model.live.debounce.300ms="search" placeholder="Filtrer par nom ou email..."
|
|
class="mb-4 w-full max-w-sm rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
|
|
|
<div class="overflow-x-auto rounded border border-slate-200 bg-white">
|
|
<table class="min-w-full divide-y divide-slate-200 text-sm">
|
|
<thead class="bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500">
|
|
<tr>
|
|
<th class="px-4 py-3">Nom</th>
|
|
<th class="px-4 py-3">Email</th>
|
|
<th class="px-4 py-3">Rôle</th>
|
|
<th class="px-4 py-3">Organisations</th>
|
|
<th class="px-4 py-3"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="divide-y divide-slate-100">
|
|
@forelse ($users as $user)
|
|
<tr wire:key="user-{{ $user->id }}">
|
|
<td class="px-4 py-3">
|
|
<a href="{{ route('users.edit', $user) }}" class="font-medium text-slate-900 hover:underline">
|
|
{{ $user->name }}
|
|
</a>
|
|
@if ($user->id === auth()->id())
|
|
<span class="ml-2 rounded-full bg-slate-100 px-2 py-0.5 text-xs font-medium text-slate-600">Vous</span>
|
|
@endif
|
|
</td>
|
|
<td class="px-4 py-3 text-slate-600">{{ $user->email }}</td>
|
|
<td class="px-4 py-3 text-slate-600">{{ $user->getRoleNames()->implode(', ') ?: '—' }}</td>
|
|
<td class="px-4 py-3 text-slate-600">{{ $user->is_msp_staff ? 'Toutes (staff)' : $user->organizations->count() }}</td>
|
|
<td class="px-4 py-3 text-right whitespace-nowrap">
|
|
<a href="{{ route('users.edit', $user) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
|
|
@unless ($user->id === auth()->id())
|
|
<button type="button"
|
|
wire:click="delete({{ $user->id }})"
|
|
wire:confirm="Supprimer cet utilisateur ? Cette action est irréversible."
|
|
class="ml-3 text-red-500 hover:text-red-700">
|
|
Supprimer
|
|
</button>
|
|
@endunless
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="5" class="px-4 py-6 text-center text-slate-400">Aucun utilisateur pour le moment.</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
{{ $users->links() }}
|
|
</div>
|
|
</div>
|