501 lines
16 KiB
HTML
501 lines
16 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Gestion des Tickets - Admin</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1400px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 20px;
|
|
padding: 30px;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
h1 {
|
|
color: #333;
|
|
margin-bottom: 10px;
|
|
font-size: 32px;
|
|
}
|
|
|
|
.subtitle {
|
|
color: #666;
|
|
margin-bottom: 30px;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.login-section {
|
|
background: #f8f9fa;
|
|
padding: 30px;
|
|
border-radius: 10px;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.login-form {
|
|
display: flex;
|
|
gap: 15px;
|
|
align-items: end;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.form-group {
|
|
flex: 1;
|
|
min-width: 200px;
|
|
}
|
|
|
|
label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
color: #333;
|
|
font-weight: 600;
|
|
}
|
|
|
|
input {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #ddd;
|
|
border-radius: 8px;
|
|
font-size: 14px;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
input:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.btn {
|
|
padding: 12px 30px;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.stats {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 20px;
|
|
margin-bottom: 30px;
|
|
}
|
|
|
|
.stat-card {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
text-align: center;
|
|
}
|
|
|
|
.stat-number {
|
|
font-size: 36px;
|
|
font-weight: bold;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.stat-label {
|
|
font-size: 14px;
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.filters {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-bottom: 20px;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.filter-btn {
|
|
padding: 10px 20px;
|
|
border: 2px solid #667eea;
|
|
background: white;
|
|
color: #667eea;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
font-weight: 600;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.filter-btn.active {
|
|
background: #667eea;
|
|
color: white;
|
|
}
|
|
|
|
.tickets-grid {
|
|
display: grid;
|
|
gap: 15px;
|
|
}
|
|
|
|
.ticket-card {
|
|
background: white;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 10px;
|
|
padding: 20px;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.ticket-card:hover {
|
|
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.ticket-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.ticket-code {
|
|
font-size: 20px;
|
|
font-weight: bold;
|
|
color: #333;
|
|
}
|
|
|
|
.ticket-status {
|
|
padding: 6px 15px;
|
|
border-radius: 20px;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
}
|
|
|
|
.status-pending {
|
|
background: #fff3cd;
|
|
color: #856404;
|
|
}
|
|
|
|
.status-claimed {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
}
|
|
|
|
.status-rejected {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
}
|
|
|
|
.ticket-info {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
|
gap: 15px;
|
|
}
|
|
|
|
.info-group {
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.info-label {
|
|
font-size: 12px;
|
|
color: #666;
|
|
margin-bottom: 3px;
|
|
}
|
|
|
|
.info-value {
|
|
font-size: 14px;
|
|
color: #333;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.prize-badge {
|
|
display: inline-block;
|
|
padding: 4px 12px;
|
|
background: #e3f2fd;
|
|
color: #1565c0;
|
|
border-radius: 5px;
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
margin-top: 5px;
|
|
}
|
|
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 60px 20px;
|
|
color: #666;
|
|
}
|
|
|
|
.empty-state-icon {
|
|
font-size: 64px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: #667eea;
|
|
font-size: 18px;
|
|
}
|
|
|
|
.error {
|
|
background: #f8d7da;
|
|
color: #721c24;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
border-left: 4px solid #721c24;
|
|
}
|
|
|
|
.success {
|
|
background: #d4edda;
|
|
color: #155724;
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
border-left: 4px solid #155724;
|
|
}
|
|
|
|
.hidden {
|
|
display: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🎫 Gestion des Tickets</h1>
|
|
<p class="subtitle">Interface d'administration</p>
|
|
|
|
<!-- Section de connexion -->
|
|
<div id="loginSection" class="login-section">
|
|
<h2 style="margin-bottom: 20px;">Connexion Admin</h2>
|
|
<div class="login-form">
|
|
<div class="form-group">
|
|
<label>Email</label>
|
|
<input type="email" id="emailInput" value="admin@thetiptop.com" placeholder="admin@thetiptop.com">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Mot de passe</label>
|
|
<input type="password" id="passwordInput" value="Admin123!" placeholder="Admin123!">
|
|
</div>
|
|
<button class="btn btn-primary" onclick="login()">Se connecter</button>
|
|
</div>
|
|
<div id="loginError" class="error hidden"></div>
|
|
</div>
|
|
|
|
<!-- Section des tickets (cachée par défaut) -->
|
|
<div id="ticketsSection" class="hidden">
|
|
<div id="successMessage" class="success hidden"></div>
|
|
|
|
<!-- Statistiques -->
|
|
<div id="statsContainer" class="stats"></div>
|
|
|
|
<!-- Filtres -->
|
|
<div class="filters">
|
|
<button class="filter-btn active" onclick="filterTickets('ALL')">Tous</button>
|
|
<button class="filter-btn" onclick="filterTickets('PENDING')">En attente</button>
|
|
<button class="filter-btn" onclick="filterTickets('CLAIMED')">Validés</button>
|
|
<button class="filter-btn" onclick="filterTickets('REJECTED')">Rejetés</button>
|
|
</div>
|
|
|
|
<!-- Liste des tickets -->
|
|
<div id="loadingMessage" class="loading hidden">Chargement des tickets...</div>
|
|
<div id="ticketsContainer" class="tickets-grid"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const API_URL = 'http://localhost:4000/api';
|
|
let authToken = null;
|
|
let allTickets = [];
|
|
let currentFilter = 'ALL';
|
|
|
|
// Connexion
|
|
async function login() {
|
|
const email = document.getElementById('emailInput').value;
|
|
const password = document.getElementById('passwordInput').value;
|
|
const errorDiv = document.getElementById('loginError');
|
|
|
|
errorDiv.classList.add('hidden');
|
|
|
|
try {
|
|
const response = await fetch(`${API_URL}/auth/login`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ email, password })
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
authToken = data.token || data.data.token;
|
|
document.getElementById('loginSection').classList.add('hidden');
|
|
document.getElementById('ticketsSection').classList.remove('hidden');
|
|
document.getElementById('successMessage').textContent = `Connecté en tant que ${data.user?.firstName || data.data.user.firstName} (${data.user?.role || data.data.user.role})`;
|
|
document.getElementById('successMessage').classList.remove('hidden');
|
|
loadTickets();
|
|
} else {
|
|
errorDiv.textContent = data.message || 'Erreur de connexion';
|
|
errorDiv.classList.remove('hidden');
|
|
}
|
|
} catch (error) {
|
|
errorDiv.textContent = 'Erreur de connexion au serveur';
|
|
errorDiv.classList.remove('hidden');
|
|
}
|
|
}
|
|
|
|
// Charger les tickets
|
|
async function loadTickets() {
|
|
const loadingDiv = document.getElementById('loadingMessage');
|
|
const ticketsContainer = document.getElementById('ticketsContainer');
|
|
|
|
loadingDiv.classList.remove('hidden');
|
|
ticketsContainer.innerHTML = '';
|
|
|
|
try {
|
|
const response = await fetch(`${API_URL}/admin/tickets?limit=100`, {
|
|
headers: {
|
|
'Authorization': `Bearer ${authToken}`
|
|
}
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
allTickets = data.data.tickets;
|
|
displayStats();
|
|
filterTickets(currentFilter);
|
|
} else {
|
|
ticketsContainer.innerHTML = `<div class="error">Erreur: ${data.message}</div>`;
|
|
}
|
|
} catch (error) {
|
|
ticketsContainer.innerHTML = `<div class="error">Erreur de chargement: ${error.message}</div>`;
|
|
} finally {
|
|
loadingDiv.classList.add('hidden');
|
|
}
|
|
}
|
|
|
|
// Afficher les statistiques
|
|
function displayStats() {
|
|
const stats = {
|
|
total: allTickets.length,
|
|
pending: allTickets.filter(t => t.status === 'PENDING').length,
|
|
claimed: allTickets.filter(t => t.status === 'CLAIMED').length,
|
|
rejected: allTickets.filter(t => t.status === 'REJECTED').length
|
|
};
|
|
|
|
document.getElementById('statsContainer').innerHTML = `
|
|
<div class="stat-card">
|
|
<div class="stat-number">${stats.total}</div>
|
|
<div class="stat-label">Total</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number">${stats.pending}</div>
|
|
<div class="stat-label">En attente</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number">${stats.claimed}</div>
|
|
<div class="stat-label">Validés</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-number">${stats.rejected}</div>
|
|
<div class="stat-label">Rejetés</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
// Filtrer les tickets
|
|
function filterTickets(status) {
|
|
currentFilter = status;
|
|
|
|
// Mettre à jour les boutons
|
|
document.querySelectorAll('.filter-btn').forEach(btn => {
|
|
btn.classList.remove('active');
|
|
});
|
|
event.target.classList.add('active');
|
|
|
|
// Filtrer et afficher
|
|
const filtered = status === 'ALL'
|
|
? allTickets
|
|
: allTickets.filter(t => t.status === status);
|
|
|
|
displayTickets(filtered);
|
|
}
|
|
|
|
// Afficher les tickets
|
|
function displayTickets(tickets) {
|
|
const container = document.getElementById('ticketsContainer');
|
|
|
|
if (tickets.length === 0) {
|
|
container.innerHTML = `
|
|
<div class="empty-state">
|
|
<div class="empty-state-icon">🎫</div>
|
|
<h3>Aucun ticket trouvé</h3>
|
|
<p>Aucun ticket ne correspond à ce filtre</p>
|
|
</div>
|
|
`;
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = tickets.map(ticket => {
|
|
const statusClass = `status-${ticket.status.toLowerCase()}`;
|
|
const playedDate = new Date(ticket.played_at).toLocaleString('fr-FR');
|
|
const claimedDate = ticket.claimed_at ? new Date(ticket.claimed_at).toLocaleString('fr-FR') : '-';
|
|
|
|
return `
|
|
<div class="ticket-card">
|
|
<div class="ticket-header">
|
|
<span class="ticket-code">${ticket.code}</span>
|
|
<span class="ticket-status ${statusClass}">${ticket.status}</span>
|
|
</div>
|
|
<div class="ticket-info">
|
|
<div class="info-group">
|
|
<div class="info-label">Client</div>
|
|
<div class="info-value">${ticket.user_name}</div>
|
|
<div class="info-value" style="font-size: 12px; color: #666;">${ticket.user_email}</div>
|
|
</div>
|
|
<div class="info-group">
|
|
<div class="info-label">Prix</div>
|
|
<div class="info-value">${ticket.prize_name}</div>
|
|
<span class="prize-badge">${ticket.prize_type}</span>
|
|
</div>
|
|
<div class="info-group">
|
|
<div class="info-label">Joué le</div>
|
|
<div class="info-value">${playedDate}</div>
|
|
</div>
|
|
${ticket.validated_by_name ? `
|
|
<div class="info-group">
|
|
<div class="info-label">Validé par</div>
|
|
<div class="info-value">${ticket.validated_by_name}</div>
|
|
<div class="info-value" style="font-size: 12px; color: #666;">${claimedDate}</div>
|
|
</div>
|
|
` : ''}
|
|
</div>
|
|
</div>
|
|
`;
|
|
}).join('');
|
|
}
|
|
|
|
// Permettre la connexion avec Enter
|
|
document.getElementById('passwordInput').addEventListener('keypress', (e) => {
|
|
if (e.key === 'Enter') login();
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|