chore: fix userscreen & change pass

This commit is contained in:
2026-03-15 15:21:13 +01:00
parent 42276ca4ff
commit 008aeab231
3 changed files with 53 additions and 42 deletions
+3 -3
View File
@@ -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,
)
+6 -5
View File
@@ -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 {
@@ -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<ClientResponse[]>([]);
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [poolNames, setPoolNames] = useState<string[]>([]);
const [poolKeys, setPoolKeys] = useState<string[]>([]);
const [pointsEnabled, setPointsEnabled] = useState(true);
const [amendeEnabled, setAmendeEnabled] = useState(true);
const [filter, setFilter] = useState<RoleFilter>("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() {
</Text>
<Text style={styles.statLabel}>Cmd</Text>
</View>
<View style={styles.stat}>
<Text
style={[
styles.statValue,
{ color: colors.success },
]}
>
{item.clientData.point}
</Text>
<Text style={styles.statLabel}>Points</Text>
</View>
<View style={styles.stat}>
<Text
style={[
styles.statValue,
{ color: colors.info },
]}
>
{item.clientData.points_zipette}
</Text>
<Text style={styles.statLabel}>Zipette</Text>
</View>
<View style={styles.stat}>
<Text
style={[
styles.statValue,
{ color: colors.warning },
]}
>
{item.clientData.amende}
</Text>
<Text style={styles.statLabel}>Amendes</Text>
</View>
{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 (
<View key={i} style={styles.stat}>
<Text style={[styles.statValue, { color }]}>{value}</Text>
<Text style={styles.statLabel}>{name}</Text>
</View>
);
})}
{amendeEnabled && (
<View style={styles.stat}>
<Text
style={[
styles.statValue,
{ color: colors.warning },
]}
>
{item.clientData.amende}
</Text>
<Text style={styles.statLabel}>Amendes</Text>
</View>
)}
<View style={styles.stat}>
<Text
style={[