feat: improve UserManagement and TicketManagement design
UserManagement: - Add gradient search section with filters - Add stats cards (Total, Clients, Employés, Admins) - Improve table with avatars and better styling - Modernize create/edit employee modals TicketManagement: - Add gradient filter section - Add stats cards (Total, En attente, Réclamés, Rejetés) - Improve table with ticket icons and user avatars - Modernize ticket details modal 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b7b08b1961
commit
8823967782
|
|
@ -1,9 +1,10 @@
|
|||
'use client';
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useState, useEffect, useCallback, useMemo } from 'react';
|
||||
import { adminService } from '@/services/admin.service';
|
||||
import { Ticket } from '@/types';
|
||||
import { StatusBadge, Pagination } from '@/components/ui';
|
||||
import { Search, RefreshCw, X, Ticket as TicketIcon, Clock, CheckCircle, XCircle, Gift, Filter } from 'lucide-react';
|
||||
|
||||
export default function TicketManagement() {
|
||||
const [tickets, setTickets] = useState<Ticket[]>([]);
|
||||
|
|
@ -75,166 +76,217 @@ export default function TicketManagement() {
|
|||
loadTickets();
|
||||
}, [loadTickets]);
|
||||
|
||||
// Calculer les stats des tickets
|
||||
const ticketStats = useMemo(() => {
|
||||
const stats = { pending: 0, claimed: 0, rejected: 0 };
|
||||
tickets.forEach(ticket => {
|
||||
if (ticket.status === 'PENDING') stats.pending++;
|
||||
else if (ticket.status === 'CLAIMED') stats.claimed++;
|
||||
else if (ticket.status === 'REJECTED') stats.rejected++;
|
||||
});
|
||||
return stats;
|
||||
}, [tickets]);
|
||||
|
||||
// Fonction pour obtenir les initiales
|
||||
const getInitials = (firstName?: string, lastName?: string) => {
|
||||
const f = firstName?.charAt(0) || '';
|
||||
const l = lastName?.charAt(0) || '';
|
||||
return (f + l).toUpperCase() || '?';
|
||||
};
|
||||
|
||||
if (loading && tickets.length === 0) {
|
||||
return <div className="text-center py-8">Chargement des tickets...</div>;
|
||||
return (
|
||||
<div className="flex items-center justify-center py-16">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-emerald-600 mx-auto mb-4"></div>
|
||||
<p className="text-gray-600">Chargement des tickets...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<h1 className="text-2xl font-bold">Gestion des Tickets</h1>
|
||||
<button
|
||||
onClick={loadTickets}
|
||||
disabled={loading}
|
||||
className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{loading ? 'Chargement...' : 'Actualiser'}
|
||||
</button>
|
||||
{/* Section filtres avec gradient */}
|
||||
<div className="bg-gradient-to-r from-emerald-600 to-teal-600 rounded-2xl p-6 mb-6">
|
||||
<div className="flex flex-col md:flex-row gap-4 items-center justify-between">
|
||||
<div className="flex gap-3 flex-wrap">
|
||||
<select
|
||||
value={filterPrizeType}
|
||||
onChange={(e) => {
|
||||
setFilterPrizeType(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="px-4 py-3 rounded-xl bg-white/10 backdrop-blur-sm text-white border border-white/20 focus:outline-none focus:ring-2 focus:ring-white/40"
|
||||
>
|
||||
<option value="" className="text-gray-900">Tous les lots</option>
|
||||
<option value="INFUSEUR" className="text-gray-900">Infuseur à thé</option>
|
||||
<option value="THE_GRATUIT" className="text-gray-900">Thé détox/infusion 100g</option>
|
||||
<option value="THE_SIGNATURE" className="text-gray-900">Thé signature 100g</option>
|
||||
<option value="COFFRET_DECOUVERTE" className="text-gray-900">Coffret découverte 39€</option>
|
||||
<option value="COFFRET_PRESTIGE" className="text-gray-900">Coffret prestige 69€</option>
|
||||
</select>
|
||||
|
||||
<select
|
||||
value={filterStatus}
|
||||
onChange={(e) => {
|
||||
setFilterStatus(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="px-4 py-3 rounded-xl bg-white/10 backdrop-blur-sm text-white border border-white/20 focus:outline-none focus:ring-2 focus:ring-white/40"
|
||||
>
|
||||
<option value="" className="text-gray-900">Tous les statuts</option>
|
||||
<option value="PENDING" className="text-gray-900">En attente</option>
|
||||
<option value="REJECTED" className="text-gray-900">Rejeté</option>
|
||||
<option value="CLAIMED" className="text-gray-900">Réclamé</option>
|
||||
</select>
|
||||
|
||||
{(filterStatus || filterPrizeType) && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setFilterStatus('');
|
||||
setFilterPrizeType('');
|
||||
setPage(1);
|
||||
}}
|
||||
className="px-4 py-3 rounded-xl bg-white/20 text-white border border-white/20 hover:bg-white/30 transition-colors flex items-center gap-2"
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
Réinitialiser
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
onClick={loadTickets}
|
||||
disabled={loading}
|
||||
className="flex items-center gap-2 px-5 py-3 bg-white text-emerald-600 rounded-xl font-semibold hover:bg-emerald-50 transition-colors shadow-lg disabled:opacity-50"
|
||||
>
|
||||
<RefreshCw className={`w-5 h-5 ${loading ? 'animate-spin' : ''}`} />
|
||||
{loading ? 'Chargement...' : 'Actualiser'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
|
||||
<p className="font-bold">Erreur de chargement:</p>
|
||||
<p className="mt-1">{error}</p>
|
||||
|
||||
{error.includes('401') && (
|
||||
<div className="mt-3 space-y-2">
|
||||
<p className="text-sm font-medium">✅ Le header Authorization est bien envoyé</p>
|
||||
<p className="text-sm">❌ Mais votre token est invalide ou a expiré</p>
|
||||
<div className="flex gap-2 mt-2">
|
||||
<a
|
||||
href="/login"
|
||||
className="text-sm bg-red-600 text-white px-3 py-1 rounded hover:bg-red-700"
|
||||
>
|
||||
→ Se reconnecter
|
||||
</a>
|
||||
<a
|
||||
href="/admin/diagnostic"
|
||||
className="text-sm bg-blue-600 text-white px-3 py-1 rounded hover:bg-blue-700"
|
||||
>
|
||||
🩺 Diagnostic complet
|
||||
</a>
|
||||
</div>
|
||||
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-4 rounded-xl mb-6">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="w-10 h-10 bg-red-100 rounded-full flex items-center justify-center flex-shrink-0">
|
||||
<X className="w-5 h-5 text-red-600" />
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<p className="font-bold">Erreur de chargement:</p>
|
||||
<p className="mt-1">{error}</p>
|
||||
|
||||
{error.includes('403') && (
|
||||
<div className="mt-3 space-y-2">
|
||||
<p className="text-sm">Vous n'avez pas le rôle ADMIN requis.</p>
|
||||
<a
|
||||
href="/admin/diagnostic"
|
||||
className="inline-block text-sm bg-blue-600 text-white px-3 py-1 rounded hover:bg-blue-700"
|
||||
>
|
||||
🩺 Voir le diagnostic complet
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
{error.includes('401') && (
|
||||
<div className="mt-3 space-y-2">
|
||||
<p className="text-sm">Votre session a expiré ou votre token est invalide.</p>
|
||||
<div className="flex gap-2 mt-2">
|
||||
<a
|
||||
href="/login"
|
||||
className="text-sm bg-red-600 text-white px-4 py-2 rounded-lg hover:bg-red-700 transition-colors"
|
||||
>
|
||||
Se reconnecter
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!error.includes('401') && !error.includes('403') && (
|
||||
<div className="mt-3 space-y-2">
|
||||
<p className="text-sm">Vérifiez que le backend est démarré sur http://localhost:4000</p>
|
||||
<a
|
||||
href="/admin/diagnostic"
|
||||
className="inline-block text-sm bg-blue-600 text-white px-3 py-1 rounded hover:bg-blue-700"
|
||||
>
|
||||
🩺 Lancer le diagnostic
|
||||
</a>
|
||||
{error.includes('403') && (
|
||||
<div className="mt-3">
|
||||
<p className="text-sm">Vous n'avez pas le rôle ADMIN requis.</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!error.includes('401') && !error.includes('403') && (
|
||||
<div className="mt-3">
|
||||
<p className="text-sm">Vérifiez que le backend est démarré.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Info et Filtres */}
|
||||
<div className="mb-4 flex justify-between items-center">
|
||||
<div className="text-sm text-gray-600">
|
||||
{totalTickets > 0 && (
|
||||
<span>
|
||||
{totalTickets} ticket{totalTickets > 1 ? 's' : ''} au total
|
||||
{(filterStatus || filterPrizeType) && ' (filtré)'}
|
||||
</span>
|
||||
)}
|
||||
{/* Stats rapides */}
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
||||
<div className="bg-gradient-to-br from-gray-50 to-gray-100 rounded-xl p-4 border border-gray-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-gray-200 rounded-lg flex items-center justify-center">
|
||||
<TicketIcon className="w-5 h-5 text-gray-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-2xl font-bold text-gray-900">{totalTickets}</p>
|
||||
<p className="text-xs text-gray-500">Total</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
{/* Filtre par type de lot */}
|
||||
<select
|
||||
value={filterPrizeType}
|
||||
onChange={(e) => {
|
||||
setFilterPrizeType(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="border rounded px-3 py-2"
|
||||
>
|
||||
<option value="">Tous les lots</option>
|
||||
<option value="INFUSEUR">Infuseur à thé</option>
|
||||
<option value="THE_GRATUIT">Thé détox/infusion 100g</option>
|
||||
<option value="THE_SIGNATURE">Thé signature 100g</option>
|
||||
<option value="COFFRET_DECOUVERTE">Coffret découverte 39€</option>
|
||||
<option value="COFFRET_PRESTIGE">Coffret prestige 69€</option>
|
||||
</select>
|
||||
|
||||
{/* Filtre par statut */}
|
||||
<select
|
||||
value={filterStatus}
|
||||
onChange={(e) => {
|
||||
setFilterStatus(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="border rounded px-3 py-2"
|
||||
>
|
||||
<option value="">Tous les statuts</option>
|
||||
<option value="PENDING">En attente</option>
|
||||
<option value="REJECTED">Rejeté</option>
|
||||
<option value="CLAIMED">Réclamé</option>
|
||||
</select>
|
||||
|
||||
{/* Bouton pour réinitialiser les filtres */}
|
||||
{(filterStatus || filterPrizeType) && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setFilterStatus('');
|
||||
setFilterPrizeType('');
|
||||
setPage(1);
|
||||
}}
|
||||
className="text-sm text-gray-600 hover:text-gray-900 underline"
|
||||
>
|
||||
Réinitialiser
|
||||
</button>
|
||||
)}
|
||||
<div className="bg-gradient-to-br from-amber-50 to-amber-100 rounded-xl p-4 border border-amber-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-amber-200 rounded-lg flex items-center justify-center">
|
||||
<Clock className="w-5 h-5 text-amber-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-2xl font-bold text-amber-700">{ticketStats.pending}</p>
|
||||
<p className="text-xs text-amber-600">En attente</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-green-50 to-green-100 rounded-xl p-4 border border-green-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-green-200 rounded-lg flex items-center justify-center">
|
||||
<CheckCircle className="w-5 h-5 text-green-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-2xl font-bold text-green-700">{ticketStats.claimed}</p>
|
||||
<p className="text-xs text-green-600">Réclamés</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-red-50 to-red-100 rounded-xl p-4 border border-red-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-red-200 rounded-lg flex items-center justify-center">
|
||||
<XCircle className="w-5 h-5 text-red-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-2xl font-bold text-red-700">{ticketStats.rejected}</p>
|
||||
<p className="text-xs text-red-600">Rejetés</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Table des tickets */}
|
||||
<div className="bg-white rounded-lg shadow overflow-hidden">
|
||||
<table className="min-w-full divide-y divide-gray-200">
|
||||
<thead className="bg-gray-50">
|
||||
<div className="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
|
||||
<table className="min-w-full">
|
||||
<thead className="bg-gradient-to-r from-gray-50 to-gray-100">
|
||||
<tr>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Code Ticket
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Lot Gagné
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Statut
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Joué le
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Utilisé par
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Actions
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
{tickets.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={6} className="px-6 py-12 text-center">
|
||||
<div className="flex flex-col items-center justify-center">
|
||||
<div className="text-6xl mb-4">🎫</div>
|
||||
<div className="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mb-4">
|
||||
<TicketIcon className="w-8 h-8 text-gray-400" />
|
||||
</div>
|
||||
<p className="text-gray-900 font-medium text-lg mb-2">
|
||||
{!error ? 'Aucun ticket trouvé' : 'Impossible de charger les tickets'}
|
||||
</p>
|
||||
|
|
@ -244,68 +296,80 @@ export default function TicketManagement() {
|
|||
: 'Aucun ticket n\'a été créé pour le moment'
|
||||
}
|
||||
</p>
|
||||
{!error && (
|
||||
<p className="text-gray-400 text-xs">
|
||||
Les tickets apparaîtront ici une fois que des utilisateurs auront joué au jeu
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
tickets.map((ticket) => (
|
||||
<tr key={ticket.id} className="hover:bg-gray-50">
|
||||
{/* CODE TICKET */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="text-sm font-mono font-medium text-gray-900">
|
||||
{ticket.code}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* LOT GAGNÉ */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="text-sm font-semibold text-gray-900">
|
||||
{ticket.prize?.name || 'N/A'}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* STATUT */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<StatusBadge type="ticket" value={ticket.status} />
|
||||
</td>
|
||||
|
||||
{/* DISTRIBUÉ LE (date d'utilisation du ticket) */}
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{ticket.playedAt ? new Date(ticket.playedAt).toLocaleDateString('fr-FR', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
}) : '-'}
|
||||
</td>
|
||||
|
||||
{/* UTILISÉ PAR */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="text-sm text-gray-900">
|
||||
{ticket.user ? `${ticket.user.firstName} ${ticket.user.lastName}` : '-'}
|
||||
</div>
|
||||
{ticket.user && (
|
||||
<div className="text-xs text-gray-500">
|
||||
{ticket.user.email}
|
||||
<tr key={ticket.id} className="hover:bg-gray-50 transition-colors">
|
||||
{/* CODE TICKET */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-lg flex items-center justify-center">
|
||||
<TicketIcon className="w-5 h-5 text-white" />
|
||||
</div>
|
||||
<span className="text-sm font-mono font-semibold text-gray-900">
|
||||
{ticket.code}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
</td>
|
||||
|
||||
{/* ACTIONS */}
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium">
|
||||
<button
|
||||
onClick={() => setSelectedTicket(ticket)}
|
||||
className="text-blue-600 hover:text-blue-900"
|
||||
>
|
||||
Détails
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
{/* LOT GAGNÉ */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="flex items-center gap-2">
|
||||
<Gift className="w-4 h-4 text-purple-500" />
|
||||
<span className="text-sm font-medium text-gray-900">
|
||||
{ticket.prize?.name || 'N/A'}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* STATUT */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<StatusBadge type="ticket" value={ticket.status} />
|
||||
</td>
|
||||
|
||||
{/* DISTRIBUÉ LE */}
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{ticket.playedAt ? new Date(ticket.playedAt).toLocaleDateString('fr-FR', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
}) : '-'}
|
||||
</td>
|
||||
|
||||
{/* UTILISÉ PAR */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
{ticket.user ? (
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-8 h-8 bg-gradient-to-br from-blue-500 to-blue-600 rounded-full flex items-center justify-center text-white text-xs font-bold">
|
||||
{getInitials(ticket.user.firstName, ticket.user.lastName)}
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm font-medium text-gray-900">
|
||||
{ticket.user.firstName} {ticket.user.lastName}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">
|
||||
{ticket.user.email}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-gray-400">-</span>
|
||||
)}
|
||||
</td>
|
||||
|
||||
{/* ACTIONS */}
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<button
|
||||
onClick={() => setSelectedTicket(ticket)}
|
||||
className="px-4 py-2 text-sm font-medium text-emerald-600 hover:text-emerald-800 hover:bg-emerald-50 rounded-lg transition-colors"
|
||||
>
|
||||
Détails
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -322,68 +386,98 @@ export default function TicketManagement() {
|
|||
|
||||
{/* Modal détails ticket */}
|
||||
{selectedTicket && (
|
||||
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-lg p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto">
|
||||
<h2 className="text-xl font-bold mb-4">Détails du ticket</h2>
|
||||
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-2xl shadow-2xl max-w-2xl w-full mx-4 max-h-[90vh] overflow-hidden">
|
||||
<div className="bg-gradient-to-r from-emerald-600 to-teal-600 px-6 py-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-xl font-bold text-white">Détails du ticket</h2>
|
||||
<button
|
||||
onClick={() => setSelectedTicket(null)}
|
||||
className="w-8 h-8 bg-white/20 rounded-full flex items-center justify-center text-white hover:bg-white/30 transition-colors"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Code</p>
|
||||
<p className="mt-1 text-sm font-mono">{selectedTicket.code}</p>
|
||||
<div className="p-6 space-y-6 overflow-y-auto max-h-[calc(90vh-140px)]">
|
||||
{/* Code et Statut */}
|
||||
<div className="flex items-center justify-between p-4 bg-gradient-to-r from-gray-50 to-gray-100 rounded-xl">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-12 h-12 bg-gradient-to-br from-emerald-500 to-teal-500 rounded-xl flex items-center justify-center">
|
||||
<TicketIcon className="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs text-gray-500">Code ticket</p>
|
||||
<p className="text-lg font-mono font-bold text-gray-900">{selectedTicket.code}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Statut</p>
|
||||
<p className="mt-1">
|
||||
<StatusBadge type="ticket" value={selectedTicket.status} />
|
||||
</p>
|
||||
<StatusBadge type="ticket" value={selectedTicket.status} />
|
||||
</div>
|
||||
|
||||
{/* Utilisateur */}
|
||||
{selectedTicket.user && (
|
||||
<div className="p-4 bg-blue-50 rounded-xl border border-blue-100">
|
||||
<p className="text-xs text-blue-600 font-semibold mb-2 uppercase">Utilisateur</p>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-gradient-to-br from-blue-500 to-blue-600 rounded-full flex items-center justify-center text-white font-bold">
|
||||
{getInitials(selectedTicket.user.firstName, selectedTicket.user.lastName)}
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-semibold text-gray-900">
|
||||
{selectedTicket.user.firstName} {selectedTicket.user.lastName}
|
||||
</p>
|
||||
<p className="text-sm text-gray-500">{selectedTicket.user.email}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Prix gagné */}
|
||||
<div className="p-4 bg-purple-50 rounded-xl border border-purple-100">
|
||||
<p className="text-xs text-purple-600 font-semibold mb-2 uppercase">Prix gagné</p>
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-gradient-to-br from-purple-500 to-purple-600 rounded-xl flex items-center justify-center">
|
||||
<Gift className="w-5 h-5 text-white" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-semibold text-gray-900">{selectedTicket.prize?.name}</p>
|
||||
<p className="text-sm text-gray-500">{selectedTicket.prize?.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Utilisateur</p>
|
||||
<p className="mt-1 text-sm">
|
||||
{selectedTicket.user ? `${selectedTicket.user.firstName} ${selectedTicket.user.lastName}` : 'N/A'}
|
||||
</p>
|
||||
<p className="text-sm text-gray-500">{selectedTicket.user?.email}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Prix gagné</p>
|
||||
<p className="mt-1 text-sm">{selectedTicket.prize?.name}</p>
|
||||
<p className="text-sm text-gray-500">{selectedTicket.prize?.description}</p>
|
||||
<p className="text-sm font-medium">{selectedTicket.prize?.value}€</p>
|
||||
</div>
|
||||
|
||||
{/* Dates */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Date de jeu</p>
|
||||
<p className="mt-1 text-sm">
|
||||
<div className="p-4 bg-gray-50 rounded-xl">
|
||||
<p className="text-xs text-gray-500 font-semibold mb-1 uppercase">Date de jeu</p>
|
||||
<p className="text-sm font-medium text-gray-900">
|
||||
{selectedTicket.playedAt ? new Date(selectedTicket.playedAt).toLocaleString('fr-FR') : 'N/A'}
|
||||
</p>
|
||||
</div>
|
||||
{selectedTicket.validatedAt && (
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Date de validation</p>
|
||||
<p className="mt-1 text-sm">
|
||||
<div className="p-4 bg-green-50 rounded-xl">
|
||||
<p className="text-xs text-green-600 font-semibold mb-1 uppercase">Date de validation</p>
|
||||
<p className="text-sm font-medium text-gray-900">
|
||||
{new Date(selectedTicket.validatedAt).toLocaleString('fr-FR')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Raison du rejet */}
|
||||
{selectedTicket.rejectionReason && (
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-500">Raison du rejet</p>
|
||||
<p className="mt-1 text-sm text-red-600">{selectedTicket.rejectionReason}</p>
|
||||
<div className="p-4 bg-red-50 rounded-xl border border-red-100">
|
||||
<p className="text-xs text-red-600 font-semibold mb-1 uppercase">Raison du rejet</p>
|
||||
<p className="text-sm text-red-700">{selectedTicket.rejectionReason}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<div className="px-6 py-4 bg-gray-50 border-t">
|
||||
<button
|
||||
onClick={() => setSelectedTicket(null)}
|
||||
className="w-full bg-gray-300 text-gray-700 px-4 py-2 rounded hover:bg-gray-400"
|
||||
className="w-full px-4 py-3 bg-gray-200 text-gray-700 rounded-xl font-semibold hover:bg-gray-300 transition-colors"
|
||||
>
|
||||
Fermer
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { useRouter } from 'next/navigation';
|
|||
import { adminService } from '@/services/admin.service';
|
||||
import { User, CreateEmployeeData, UpdateUserData, PaginatedResponse } from '@/types';
|
||||
import { Pagination } from '@/components/ui';
|
||||
import { Search, UserPlus, X, Filter, RefreshCw, Users, Shield, Briefcase, UserCheck } from 'lucide-react';
|
||||
|
||||
export default function UserManagement() {
|
||||
const router = useRouter();
|
||||
|
|
@ -132,132 +133,238 @@ export default function UserManagement() {
|
|||
}
|
||||
};
|
||||
|
||||
// Fonction pour obtenir les initiales
|
||||
const getInitials = (firstName?: string, lastName?: string) => {
|
||||
const f = firstName?.charAt(0) || '';
|
||||
const l = lastName?.charAt(0) || '';
|
||||
return (f + l).toUpperCase() || '?';
|
||||
};
|
||||
|
||||
// Fonction pour obtenir la couleur de l'avatar selon le rôle
|
||||
const getAvatarColor = (role: string) => {
|
||||
switch (role) {
|
||||
case 'ADMIN':
|
||||
return 'bg-gradient-to-br from-red-500 to-red-600';
|
||||
case 'EMPLOYEE':
|
||||
return 'bg-gradient-to-br from-blue-500 to-blue-600';
|
||||
case 'CLIENT':
|
||||
return 'bg-gradient-to-br from-green-500 to-green-600';
|
||||
default:
|
||||
return 'bg-gradient-to-br from-gray-500 to-gray-600';
|
||||
}
|
||||
};
|
||||
|
||||
// Compter les utilisateurs par rôle
|
||||
const roleStats = useMemo(() => {
|
||||
const stats = { ADMIN: 0, EMPLOYEE: 0, CLIENT: 0 };
|
||||
filteredUsers.forEach(user => {
|
||||
if (user.role in stats) {
|
||||
stats[user.role as keyof typeof stats]++;
|
||||
}
|
||||
});
|
||||
return stats;
|
||||
}, [filteredUsers]);
|
||||
|
||||
if (loading && users.length === 0) {
|
||||
return <div className="text-center py-8">Chargement des utilisateurs...</div>;
|
||||
return (
|
||||
<div className="flex items-center justify-center py-16">
|
||||
<div className="text-center">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto mb-4"></div>
|
||||
<p className="text-gray-600">Chargement des utilisateurs...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<h1 className="text-2xl font-bold">Gestion des Utilisateurs</h1>
|
||||
<button
|
||||
onClick={() => setIsCreateEmployeeModalOpen(true)}
|
||||
className="bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700"
|
||||
>
|
||||
Créer un employé
|
||||
</button>
|
||||
{/* Section recherche avec gradient */}
|
||||
<div className="bg-gradient-to-r from-blue-600 to-indigo-600 rounded-2xl p-6 mb-6">
|
||||
<div className="flex flex-col md:flex-row gap-4 items-center justify-between">
|
||||
<div className="flex-1 w-full">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-4 top-1/2 transform -translate-y-1/2 w-5 h-5 text-blue-200" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Rechercher par nom ou email..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="w-full pl-12 pr-4 py-3 rounded-xl bg-white/10 backdrop-blur-sm text-white placeholder-blue-200 border border-white/20 focus:outline-none focus:ring-2 focus:ring-white/40"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-3">
|
||||
<select
|
||||
value={filterRole}
|
||||
onChange={(e) => {
|
||||
setFilterRole(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="px-4 py-3 rounded-xl bg-white/10 backdrop-blur-sm text-white border border-white/20 focus:outline-none focus:ring-2 focus:ring-white/40"
|
||||
>
|
||||
<option value="" className="text-gray-900">Tous les rôles</option>
|
||||
<option value="CLIENT" className="text-gray-900">Clients</option>
|
||||
<option value="EMPLOYEE" className="text-gray-900">Employés</option>
|
||||
<option value="ADMIN" className="text-gray-900">Administrateurs</option>
|
||||
</select>
|
||||
<select
|
||||
value={filterStatus}
|
||||
onChange={(e) => {
|
||||
setFilterStatus(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="px-4 py-3 rounded-xl bg-white/10 backdrop-blur-sm text-white border border-white/20 focus:outline-none focus:ring-2 focus:ring-white/40"
|
||||
>
|
||||
<option value="" className="text-gray-900">Tous les statuts</option>
|
||||
<option value="active" className="text-gray-900">Actifs</option>
|
||||
<option value="inactive" className="text-gray-900">Inactifs</option>
|
||||
</select>
|
||||
<button
|
||||
onClick={() => setIsCreateEmployeeModalOpen(true)}
|
||||
className="flex items-center gap-2 px-5 py-3 bg-white text-blue-600 rounded-xl font-semibold hover:bg-blue-50 transition-colors shadow-lg"
|
||||
>
|
||||
<UserPlus className="w-5 h-5" />
|
||||
<span className="hidden sm:inline">Nouvel employé</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
|
||||
{error}
|
||||
<div className="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-xl mb-6 flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-red-100 rounded-full flex items-center justify-center">
|
||||
<X className="w-5 h-5 text-red-600" />
|
||||
</div>
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Filtres */}
|
||||
<div className="mb-4 flex flex-wrap gap-4">
|
||||
<div className="flex-1 min-w-[250px]">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Rechercher par nom ou email..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="w-full border rounded px-3 py-2"
|
||||
/>
|
||||
{/* Stats rapides */}
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
|
||||
<div className="bg-gradient-to-br from-gray-50 to-gray-100 rounded-xl p-4 border border-gray-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-gray-200 rounded-lg flex items-center justify-center">
|
||||
<Users className="w-5 h-5 text-gray-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-2xl font-bold text-gray-900">{filteredUsers.length}</p>
|
||||
<p className="text-xs text-gray-500">Total</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-green-50 to-green-100 rounded-xl p-4 border border-green-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-green-200 rounded-lg flex items-center justify-center">
|
||||
<UserCheck className="w-5 h-5 text-green-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-2xl font-bold text-green-700">{roleStats.CLIENT}</p>
|
||||
<p className="text-xs text-green-600">Clients</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-blue-50 to-blue-100 rounded-xl p-4 border border-blue-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-blue-200 rounded-lg flex items-center justify-center">
|
||||
<Briefcase className="w-5 h-5 text-blue-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-2xl font-bold text-blue-700">{roleStats.EMPLOYEE}</p>
|
||||
<p className="text-xs text-blue-600">Employés</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-red-50 to-red-100 rounded-xl p-4 border border-red-200">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="w-10 h-10 bg-red-200 rounded-lg flex items-center justify-center">
|
||||
<Shield className="w-5 h-5 text-red-600" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-2xl font-bold text-red-700">{roleStats.ADMIN}</p>
|
||||
<p className="text-xs text-red-600">Admins</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<select
|
||||
value={filterRole}
|
||||
onChange={(e) => {
|
||||
setFilterRole(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="border rounded px-3 py-2"
|
||||
>
|
||||
<option value="">Tous les rôles</option>
|
||||
<option value="CLIENT">Clients</option>
|
||||
<option value="EMPLOYEE">Employés</option>
|
||||
<option value="ADMIN">Administrateurs</option>
|
||||
</select>
|
||||
<select
|
||||
value={filterStatus}
|
||||
onChange={(e) => {
|
||||
setFilterStatus(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
className="border rounded px-3 py-2"
|
||||
>
|
||||
<option value="">Tous les statuts</option>
|
||||
<option value="active">Actifs</option>
|
||||
<option value="inactive">Inactifs (archivés)</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{/* Table des utilisateurs */}
|
||||
<div className="bg-white rounded-lg shadow overflow-hidden">
|
||||
<table className="min-w-full divide-y divide-gray-200">
|
||||
<thead className="bg-gray-50">
|
||||
<div className="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
|
||||
<table className="min-w-full">
|
||||
<thead className="bg-gradient-to-r from-gray-50 to-gray-100">
|
||||
<tr>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Utilisateur
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Email
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Rôle
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Statut
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Date création
|
||||
</th>
|
||||
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
<th className="px-6 py-4 text-left text-xs font-semibold text-gray-600 uppercase tracking-wider">
|
||||
Actions
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
{filteredUsers.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={6} className="px-6 py-8 text-center text-gray-500">
|
||||
{searchQuery ? 'Aucun résultat pour cette recherche' : 'Aucun utilisateur trouvé'}
|
||||
<td colSpan={5} className="px-6 py-12 text-center">
|
||||
<div className="flex flex-col items-center justify-center">
|
||||
<div className="w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mb-4">
|
||||
<Users className="w-8 h-8 text-gray-400" />
|
||||
</div>
|
||||
<p className="text-gray-500 font-medium">
|
||||
{searchQuery ? 'Aucun résultat pour cette recherche' : 'Aucun utilisateur trouvé'}
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
) : (
|
||||
filteredUsers.map((user) => (
|
||||
<tr key={user.id} className="hover:bg-gray-50">
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="text-sm font-medium text-gray-900">
|
||||
{user.firstName} {user.lastName}
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="text-sm text-gray-500">{user.email}</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<span className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${getRoleBadgeColor(user.role)}`}>
|
||||
{user.role}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<span className={`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${user.isActive !== false ? 'bg-green-100 text-green-800' : 'bg-red-100 text-red-800'}`}>
|
||||
{user.isActive !== false ? 'Actif' : 'Inactif'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{new Date(user.createdAt).toLocaleDateString('fr-FR')}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium">
|
||||
<button
|
||||
onClick={() => router.push(`/admin/utilisateurs/${user.id}`)}
|
||||
className="text-blue-600 hover:text-blue-900"
|
||||
>
|
||||
Détails
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
<tr key={user.id} className="hover:bg-gray-50 transition-colors">
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className={`w-10 h-10 rounded-full flex items-center justify-center text-white font-bold text-sm ${getAvatarColor(user.role)}`}>
|
||||
{getInitials(user.firstName, user.lastName)}
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm font-semibold text-gray-900">
|
||||
{user.firstName} {user.lastName}
|
||||
</div>
|
||||
<div className="text-xs text-gray-500">{user.email}</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<span className={`px-3 py-1 inline-flex text-xs leading-5 font-semibold rounded-full ${getRoleBadgeColor(user.role)}`}>
|
||||
{user.role === 'ADMIN' ? 'Admin' : user.role === 'EMPLOYEE' ? 'Employé' : 'Client'}
|
||||
</span>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<div className="flex items-center gap-2">
|
||||
<div className={`w-2 h-2 rounded-full ${user.isActive !== false ? 'bg-green-500' : 'bg-red-500'}`}></div>
|
||||
<span className={`text-sm font-medium ${user.isActive !== false ? 'text-green-700' : 'text-red-700'}`}>
|
||||
{user.isActive !== false ? 'Actif' : 'Inactif'}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
{new Date(user.createdAt).toLocaleDateString('fr-FR')}
|
||||
</td>
|
||||
<td className="px-6 py-4 whitespace-nowrap">
|
||||
<button
|
||||
onClick={() => router.push(`/admin/utilisateurs/${user.id}`)}
|
||||
className="px-4 py-2 text-sm font-medium text-blue-600 hover:text-blue-800 hover:bg-blue-50 rounded-lg transition-colors"
|
||||
>
|
||||
Détails
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
@ -273,64 +380,80 @@ export default function UserManagement() {
|
|||
|
||||
{/* Modal créer employé */}
|
||||
{isCreateEmployeeModalOpen && (
|
||||
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-lg p-6 max-w-md w-full">
|
||||
<h2 className="text-xl font-bold mb-4">Créer un employé</h2>
|
||||
<form onSubmit={handleCreateEmployee} className="space-y-4">
|
||||
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-2xl shadow-2xl max-w-md w-full mx-4 overflow-hidden">
|
||||
<div className="bg-gradient-to-r from-blue-600 to-indigo-600 px-6 py-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-xl font-bold text-white">Créer un employé</h2>
|
||||
<button
|
||||
onClick={() => setIsCreateEmployeeModalOpen(false)}
|
||||
className="w-8 h-8 bg-white/20 rounded-full flex items-center justify-center text-white hover:bg-white/30 transition-colors"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<form onSubmit={handleCreateEmployee} className="p-6 space-y-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Email</label>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Email</label>
|
||||
<input
|
||||
type="email"
|
||||
value={employeeFormData.email}
|
||||
onChange={(e) => setEmployeeFormData({ ...employeeFormData, email: e.target.value })}
|
||||
className="w-full border rounded px-3 py-2"
|
||||
className="w-full border border-gray-200 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
placeholder="email@exemple.com"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Mot de passe</label>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Mot de passe</label>
|
||||
<input
|
||||
type="password"
|
||||
value={employeeFormData.password}
|
||||
onChange={(e) => setEmployeeFormData({ ...employeeFormData, password: e.target.value })}
|
||||
className="w-full border rounded px-3 py-2"
|
||||
className="w-full border border-gray-200 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
placeholder="••••••••"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Prénom</label>
|
||||
<input
|
||||
type="text"
|
||||
value={employeeFormData.firstName}
|
||||
onChange={(e) => setEmployeeFormData({ ...employeeFormData, firstName: e.target.value })}
|
||||
className="w-full border rounded px-3 py-2"
|
||||
required
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Prénom</label>
|
||||
<input
|
||||
type="text"
|
||||
value={employeeFormData.firstName}
|
||||
onChange={(e) => setEmployeeFormData({ ...employeeFormData, firstName: e.target.value })}
|
||||
className="w-full border border-gray-200 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
placeholder="Jean"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Nom</label>
|
||||
<input
|
||||
type="text"
|
||||
value={employeeFormData.lastName}
|
||||
onChange={(e) => setEmployeeFormData({ ...employeeFormData, lastName: e.target.value })}
|
||||
className="w-full border border-gray-200 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent"
|
||||
placeholder="Dupont"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Nom</label>
|
||||
<input
|
||||
type="text"
|
||||
value={employeeFormData.lastName}
|
||||
onChange={(e) => setEmployeeFormData({ ...employeeFormData, lastName: e.target.value })}
|
||||
className="w-full border rounded px-3 py-2"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2 pt-4">
|
||||
<button
|
||||
type="submit"
|
||||
className="flex-1 bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
|
||||
>
|
||||
Créer
|
||||
</button>
|
||||
<div className="flex gap-3 pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsCreateEmployeeModalOpen(false)}
|
||||
className="flex-1 bg-gray-300 text-gray-700 px-4 py-2 rounded hover:bg-gray-400"
|
||||
className="flex-1 px-4 py-3 bg-gray-100 text-gray-700 rounded-xl font-semibold hover:bg-gray-200 transition-colors"
|
||||
>
|
||||
Annuler
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex-1 px-4 py-3 bg-gradient-to-r from-blue-600 to-indigo-600 text-white rounded-xl font-semibold hover:from-blue-700 hover:to-indigo-700 transition-colors shadow-lg"
|
||||
>
|
||||
Créer l'employé
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
@ -339,36 +462,55 @@ export default function UserManagement() {
|
|||
|
||||
{/* Modal modifier utilisateur */}
|
||||
{isEditUserModalOpen && editingUser && (
|
||||
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-lg p-6 max-w-md w-full">
|
||||
<h2 className="text-xl font-bold mb-4">Modifier l'utilisateur</h2>
|
||||
<form onSubmit={handleUpdateUser} className="space-y-4">
|
||||
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50">
|
||||
<div className="bg-white rounded-2xl shadow-2xl max-w-md w-full mx-4 overflow-hidden">
|
||||
<div className="bg-gradient-to-r from-indigo-600 to-purple-600 px-6 py-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-xl font-bold text-white">Modifier l'utilisateur</h2>
|
||||
<button
|
||||
onClick={() => setIsEditUserModalOpen(false)}
|
||||
className="w-8 h-8 bg-white/20 rounded-full flex items-center justify-center text-white hover:bg-white/30 transition-colors"
|
||||
>
|
||||
<X className="w-5 h-5" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<form onSubmit={handleUpdateUser} className="p-6 space-y-4">
|
||||
<div className="flex items-center gap-4 p-4 bg-gray-50 rounded-xl">
|
||||
<div className={`w-12 h-12 rounded-full flex items-center justify-center text-white font-bold ${getAvatarColor(editingUser.role)}`}>
|
||||
{getInitials(editingUser.firstName, editingUser.lastName)}
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-semibold text-gray-900">{editingUser.firstName} {editingUser.lastName}</p>
|
||||
<p className="text-sm text-gray-500">{editingUser.email}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-sm font-medium mb-1">Rôle</label>
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2">Rôle</label>
|
||||
<select
|
||||
value={userFormData.role}
|
||||
onChange={(e) => setUserFormData({ ...userFormData, role: e.target.value as 'CLIENT' | 'EMPLOYEE' | 'ADMIN' })}
|
||||
className="w-full border rounded px-3 py-2"
|
||||
className="w-full border border-gray-200 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
|
||||
>
|
||||
<option value="CLIENT">Client</option>
|
||||
<option value="EMPLOYEE">Employé</option>
|
||||
<option value="ADMIN">Administrateur</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="flex gap-2 pt-4">
|
||||
<button
|
||||
type="submit"
|
||||
className="flex-1 bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
|
||||
>
|
||||
Mettre à jour
|
||||
</button>
|
||||
<div className="flex gap-3 pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setIsEditUserModalOpen(false)}
|
||||
className="flex-1 bg-gray-300 text-gray-700 px-4 py-2 rounded hover:bg-gray-400"
|
||||
className="flex-1 px-4 py-3 bg-gray-100 text-gray-700 rounded-xl font-semibold hover:bg-gray-200 transition-colors"
|
||||
>
|
||||
Annuler
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex-1 px-4 py-3 bg-gradient-to-r from-indigo-600 to-purple-600 text-white rounded-xl font-semibold hover:from-indigo-700 hover:to-purple-700 transition-colors shadow-lg"
|
||||
>
|
||||
Mettre à jour
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user