✨ Added user management: improved user interface with notifications, confirmation modal for deletion, and integration of a service to load and delete users.
parent
9a0e36fa7c
commit
7acce35ec0
@ -1,24 +1,67 @@
|
|||||||
<div class="container mx-auto px-4 py-8">
|
<div class="container mx-auto px-4 py-8">
|
||||||
<h1 class="text-3xl font-bold mb-8">Gestion des utilisateurs</h1>
|
<h1 class="text-3xl font-bold mb-8 dark:text-white">Gestion des utilisateurs</h1>
|
||||||
|
|
||||||
|
<!-- Message de notification -->
|
||||||
|
<div *ngIf="message"
|
||||||
|
[class]="messageType === 'success' ? 'bg-green-100 border-green-400 text-green-700' : 'bg-red-100 border-red-400 text-red-700'"
|
||||||
|
class="px-4 py-3 rounded relative mb-4 border"
|
||||||
|
role="alert">
|
||||||
|
<span class="block sm:inline">{{ message }}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="bg-white rounded-lg shadow overflow-hidden">
|
<div class="bg-white rounded-lg shadow overflow-hidden">
|
||||||
<table class="min-w-full divide-y divide-gray-200">
|
<table class="min-w-full divide-y divide-gray-200">
|
||||||
<thead class="bg-gray-50">
|
<thead class="bg-gray-50">
|
||||||
<tr>
|
<tr>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom d'utilisateur</th>
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nom d'utilisateur</th>
|
||||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Statut</th>
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Statut</th>
|
||||||
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody class="bg-white divide-y divide-gray-200">
|
<tbody class="bg-white divide-y divide-gray-200">
|
||||||
<tr *ngFor="let user of users">
|
<tr *ngFor="let user of users">
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap">{{ user.uid }}</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap">{{ user.username }}</td>
|
<td class="px-6 py-4 whitespace-nowrap">{{ user.username }}</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap">
|
<td class="px-6 py-4 whitespace-nowrap">
|
||||||
<span [class]="user.is_admin ? 'text-green-600' : 'text-gray-600'">
|
<span [class]="user.is_admin ? 'text-green-600' : 'text-gray-600'">
|
||||||
{{ user.is_admin ? 'Administrateur' : 'Utilisateur' }}
|
{{ user.is_admin ? 'Administrateur' : 'Utilisateur' }}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap">
|
||||||
|
<button (click)="openDeleteModal(user)"
|
||||||
|
class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded disabled:opacity-50" [disabled]="user.is_admin">
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Modal de confirmation -->
|
||||||
|
<div *ngIf="showConfirmModal"
|
||||||
|
class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full flex items-center justify-center">
|
||||||
|
<div class="relative p-5 border w-96 shadow-lg rounded-md bg-white">
|
||||||
|
<div class="mt-3 text-center">
|
||||||
|
<h3 class="text-lg leading-6 font-medium text-gray-900">Confirmer la suppression</h3>
|
||||||
|
<div class="mt-2 px-7 py-3">
|
||||||
|
<p class="text-sm text-gray-500">
|
||||||
|
Êtes-vous sûr de vouloir supprimer l'utilisateur <span class="font-semibold">{{ userToDelete?.username }}</span> ?
|
||||||
|
Cette action est irréversible.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="flex justify-center space-x-4 mt-4">
|
||||||
|
<button (click)="closeModal()"
|
||||||
|
class="px-4 py-2 bg-gray-300 text-gray-700 rounded hover:bg-gray-400">
|
||||||
|
Annuler
|
||||||
|
</button>
|
||||||
|
<button (click)="confirmDelete()"
|
||||||
|
class="px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600">
|
||||||
|
Confirmer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
@ -0,0 +1,5 @@
|
|||||||
|
export interface UserDTO {
|
||||||
|
uid: string;
|
||||||
|
username: string;
|
||||||
|
is_admin: boolean;
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { environment } from '../../environment';
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { AuthService } from './auth.service';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { UserDTO } from '../model/UserDTO';
|
||||||
|
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
})
|
||||||
|
export class UsersService {
|
||||||
|
constructor(private http: HttpClient, private authService: AuthService) {}
|
||||||
|
|
||||||
|
public loadUsers(): Observable<UserDTO[]> {
|
||||||
|
return this.http.get<UserDTO[]>(`${environment.apiURL}/admin/users`, {
|
||||||
|
headers: this.authService.getAuthHeaders(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public deleteUser(uid: string): Observable<{message: string}> {
|
||||||
|
return this.http.delete<{message: string}>(`${environment.apiURL}/admin/user/${uid}`, {
|
||||||
|
headers: this.authService.getAuthHeaders(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue