Files
PolyMPR/routes/(apps)/notes/(_islands)/AdminConsultNotes.tsx
T
djalim 5ba8b8cb68 feat(ui): implement full UI layer for all modules
Add interactive island components and server partials for notes,
students, and admin modules, following the Figma prototype design.

- static/styles/ui.css: shared component library (buttons, tables,
  chips, cards, filters, tabs, form inputs)
- notes: NotesView (student grade view with UE cards, promo tabs,
  weighted averages), AdminConsultNotes, AdminUEs islands + partials
- students: ConsultStudents (list/filter/delete), AdminPromotions
  (CRUD) islands + partials
- admin: AdminModules, AdminUsers, AdminRoles islands + partials
- All partials use State type with unknown cast for session access

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 22:54:10 +02:00

146 lines
4.3 KiB
TypeScript

import { useEffect, useState } from "preact/hooks";
type Student = {
numEtud: number;
nom: string;
prenom: string;
idPromo: string;
};
type Promotion = { id: string; annee: string | null };
export default function AdminConsultNotes() {
const [students, setStudents] = useState<Student[]>([]);
const [promos, setPromos] = useState<Promotion[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [filterPromo, setFilterPromo] = useState("");
const [filterNom, setFilterNom] = useState("");
const [filterPrenom, setFilterPrenom] = useState("");
const [applied, setApplied] = useState({
promo: "",
nom: "",
prenom: "",
});
useEffect(() => {
async function load() {
try {
const [sRes, pRes] = await Promise.all([
fetch("/students/api/students"),
fetch("/students/api/promotions"),
]);
if (!sRes.ok) throw new Error("Impossible de charger les étudiants");
setStudents(await sRes.json());
if (pRes.ok) setPromos(await pRes.json());
} catch (e) {
setError(e instanceof Error ? e.message : "Erreur");
} finally {
setLoading(false);
}
}
load();
}, []);
const filtered = students.filter((s) => {
if (applied.promo && s.idPromo !== applied.promo) return false;
if (
applied.nom &&
!s.nom.toLowerCase().includes(applied.nom.toLowerCase())
) return false;
if (
applied.prenom &&
!s.prenom.toLowerCase().includes(applied.prenom.toLowerCase())
) return false;
return true;
});
function applyFilters() {
setApplied({ promo: filterPromo, nom: filterNom, prenom: filterPrenom });
}
return (
<div class="page-content">
<div class="toolbar">
<h2 class="page-title">Consulter les Notes</h2>
</div>
{error && <p class="state-error">{error}</p>}
<div class="filters">
<select
class="filter-select"
value={filterPromo}
onChange={(e) =>
setFilterPromo((e.target as HTMLSelectElement).value)}
>
<option value="">Toutes les promos</option>
{promos.map((p) => <option key={p.id} value={p.id}>{p.id}</option>)}
</select>
<input
class="filter-input"
placeholder="Nom"
value={filterNom}
onInput={(e) => setFilterNom((e.target as HTMLInputElement).value)}
/>
<input
class="filter-input"
placeholder="Prénom"
value={filterPrenom}
onInput={(e) => setFilterPrenom((e.target as HTMLInputElement).value)}
/>
<button type="button" class="btn btn-primary" onClick={applyFilters}>
Filtrer
</button>
</div>
{loading
? <p class="state-loading">Chargement</p>
: (
<div class="data-table-wrap">
<table class="data-table">
<thead>
<tr>
<th>Promo</th>
<th>Nom</th>
<th>Prénom</th>
<th>N° Étudiant</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{filtered.length === 0
? (
<tr>
<td colspan={5} class="state-empty">
Aucun étudiant trouvé
</td>
</tr>
)
: filtered.map((s) => (
<tr key={s.numEtud}>
<td class="col-promo">{s.idPromo}</td>
<td>{s.nom}</td>
<td>{s.prenom}</td>
<td class="col-dim">{s.numEtud}</td>
<td>
<div class="col-actions">
<a
class="btn btn-sm btn-secondary"
href={`/notes/edition/${s.numEtud}`}
f-client-nav={false}
>
édit
</a>
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
);
}