From 008aeab231862e661c633da515fe6bf624b97ef9 Mon Sep 17 00:00:00 2001 From: Xor290 Date: Sun, 15 Mar 2026 15:21:13 +0100 Subject: [PATCH] chore: fix userscreen & change pass --- backend/gestion/db/db_clients.go | 6 +- backend/gestion/handlers/auth.go | 11 +-- .../src/screens/admin/UsersScreen.tsx | 78 +++++++++++-------- 3 files changed, 53 insertions(+), 42 deletions(-) diff --git a/backend/gestion/db/db_clients.go b/backend/gestion/db/db_clients.go index aff49376..20510fc4 100644 --- a/backend/gestion/db/db_clients.go +++ b/backend/gestion/db/db_clients.go @@ -10,11 +10,11 @@ import ( ) func (d *Database) CreateClient(client *models.Client) error { - query := `INSERT INTO clients (username, password, nom, prenom, telephone, command, point, point_zipette, amende, created_at) - VALUES ($1, $2, $3, $4, $5, 0, 0, 0, 0.0, CURRENT_TIMESTAMP) + query := `INSERT INTO clients (username, password, nom, prenom, telephone, command, point, point_zipette, amende, must_change_password, created_at) + VALUES ($1, $2, $3, $4, $5, 0, 0, 0, 0.0, $6, CURRENT_TIMESTAMP) RETURNING id, created_at` - err := d.QueryRow(query, client.Username, client.Password, client.Nom, client.Prenom, client.Telephone).Scan( + err := d.QueryRow(query, client.Username, client.Password, client.Nom, client.Prenom, client.Telephone, client.MustChangePassword).Scan( &client.ID, &client.CreatedAt, ) diff --git a/backend/gestion/handlers/auth.go b/backend/gestion/handlers/auth.go index 5a73fe74..c354945b 100644 --- a/backend/gestion/handlers/auth.go +++ b/backend/gestion/handlers/auth.go @@ -308,11 +308,12 @@ func AdminCreateClient(c *gin.Context) { } client := &models.Client{ - Username: req.Username, - Password: string(hashed), - Nom: strings.TrimSpace(req.Nom), - Prenom: strings.TrimSpace(req.Prenom), - Telephone: normalizedPhone, + Username: req.Username, + Password: string(hashed), + Nom: strings.TrimSpace(req.Nom), + Prenom: strings.TrimSpace(req.Prenom), + Telephone: normalizedPhone, + MustChangePassword: true, } if err := database.CreateClient(client); err != nil { diff --git a/frontend-admin/src/screens/admin/UsersScreen.tsx b/frontend-admin/src/screens/admin/UsersScreen.tsx index c380c735..90011d5c 100644 --- a/frontend-admin/src/screens/admin/UsersScreen.tsx +++ b/frontend-admin/src/screens/admin/UsersScreen.tsx @@ -21,6 +21,7 @@ import { createClientByAdmin, createUserByAdmin, creditClientReferral, + getSettings, } from "../../api/api_admin"; import type { ClientResponse } from "../../api/types"; import LoadingSpinner from "../../components/ui/LoadingSpinner"; @@ -126,6 +127,10 @@ export default function UsersScreen() { const [clients, setClients] = useState([]); const [loading, setLoading] = useState(true); const [refreshing, setRefreshing] = useState(false); + const [poolNames, setPoolNames] = useState([]); + const [poolKeys, setPoolKeys] = useState([]); + const [pointsEnabled, setPointsEnabled] = useState(true); + const [amendeEnabled, setAmendeEnabled] = useState(true); const [filter, setFilter] = useState("all"); const [search, setSearch] = useState(""); @@ -174,12 +179,20 @@ export default function UsersScreen() { // -------------------------------------------------- const loadData = useCallback(async () => { try { - const [usersData, clientsData] = await Promise.all([ + const [usersData, clientsData, settingsRes] = await Promise.all([ getAllUsers(), getAllClients(), + getSettings(), ]); setUsers(usersData); setClients(clientsData); + if (settingsRes.success && settingsRes.settings) { + const pools = settingsRes.settings.points_pools ?? []; + setPoolNames(pools.map((p) => p.name)); + setPoolKeys(pools.map((p) => p.key)); + setPointsEnabled(settingsRes.settings.points_enabled ?? true); + setAmendeEnabled(settingsRes.settings.show_amende_score ?? true); + } } catch { /* ignore */ } @@ -778,39 +791,36 @@ export default function UsersScreen() { Cmd - - - {item.clientData.point} - - Points - - - - {item.clientData.points_zipette} - - Zipette - - - - {item.clientData.amende} - - Amendes - + {pointsEnabled && poolNames.map((name, i) => { + let value: number; + let color: string; + if (i === 0) { value = item.clientData!.point; color = colors.success; } + else if (i === 1) { value = item.clientData!.points_zipette; color = colors.info; } + else { + const key = poolKeys[i] ?? ""; + value = item.clientData!.points_extra?.[key] ?? 0; + color = colors.warning; + } + return ( + + {value} + {name} + + ); + })} + {amendeEnabled && ( + + + {item.clientData.amende} + + Amendes + + )}