chore: fix userscreen & change pass
This commit is contained in:
@@ -10,11 +10,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (d *Database) CreateClient(client *models.Client) error {
|
func (d *Database) CreateClient(client *models.Client) error {
|
||||||
query := `INSERT INTO clients (username, password, nom, prenom, telephone, command, point, point_zipette, amende, created_at)
|
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, CURRENT_TIMESTAMP)
|
VALUES ($1, $2, $3, $4, $5, 0, 0, 0, 0.0, $6, CURRENT_TIMESTAMP)
|
||||||
RETURNING id, created_at`
|
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.ID,
|
||||||
&client.CreatedAt,
|
&client.CreatedAt,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -308,11 +308,12 @@ func AdminCreateClient(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client := &models.Client{
|
client := &models.Client{
|
||||||
Username: req.Username,
|
Username: req.Username,
|
||||||
Password: string(hashed),
|
Password: string(hashed),
|
||||||
Nom: strings.TrimSpace(req.Nom),
|
Nom: strings.TrimSpace(req.Nom),
|
||||||
Prenom: strings.TrimSpace(req.Prenom),
|
Prenom: strings.TrimSpace(req.Prenom),
|
||||||
Telephone: normalizedPhone,
|
Telephone: normalizedPhone,
|
||||||
|
MustChangePassword: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := database.CreateClient(client); err != nil {
|
if err := database.CreateClient(client); err != nil {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
createClientByAdmin,
|
createClientByAdmin,
|
||||||
createUserByAdmin,
|
createUserByAdmin,
|
||||||
creditClientReferral,
|
creditClientReferral,
|
||||||
|
getSettings,
|
||||||
} from "../../api/api_admin";
|
} from "../../api/api_admin";
|
||||||
import type { ClientResponse } from "../../api/types";
|
import type { ClientResponse } from "../../api/types";
|
||||||
import LoadingSpinner from "../../components/ui/LoadingSpinner";
|
import LoadingSpinner from "../../components/ui/LoadingSpinner";
|
||||||
@@ -126,6 +127,10 @@ export default function UsersScreen() {
|
|||||||
const [clients, setClients] = useState<ClientResponse[]>([]);
|
const [clients, setClients] = useState<ClientResponse[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
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 [filter, setFilter] = useState<RoleFilter>("all");
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
@@ -174,12 +179,20 @@ export default function UsersScreen() {
|
|||||||
// --------------------------------------------------
|
// --------------------------------------------------
|
||||||
const loadData = useCallback(async () => {
|
const loadData = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const [usersData, clientsData] = await Promise.all([
|
const [usersData, clientsData, settingsRes] = await Promise.all([
|
||||||
getAllUsers(),
|
getAllUsers(),
|
||||||
getAllClients(),
|
getAllClients(),
|
||||||
|
getSettings(),
|
||||||
]);
|
]);
|
||||||
setUsers(usersData);
|
setUsers(usersData);
|
||||||
setClients(clientsData);
|
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 {
|
} catch {
|
||||||
/* ignore */
|
/* ignore */
|
||||||
}
|
}
|
||||||
@@ -778,39 +791,36 @@ export default function UsersScreen() {
|
|||||||
</Text>
|
</Text>
|
||||||
<Text style={styles.statLabel}>Cmd</Text>
|
<Text style={styles.statLabel}>Cmd</Text>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.stat}>
|
{pointsEnabled && poolNames.map((name, i) => {
|
||||||
<Text
|
let value: number;
|
||||||
style={[
|
let color: string;
|
||||||
styles.statValue,
|
if (i === 0) { value = item.clientData!.point; color = colors.success; }
|
||||||
{ color: colors.success },
|
else if (i === 1) { value = item.clientData!.points_zipette; color = colors.info; }
|
||||||
]}
|
else {
|
||||||
>
|
const key = poolKeys[i] ?? "";
|
||||||
{item.clientData.point}
|
value = item.clientData!.points_extra?.[key] ?? 0;
|
||||||
</Text>
|
color = colors.warning;
|
||||||
<Text style={styles.statLabel}>Points</Text>
|
}
|
||||||
</View>
|
return (
|
||||||
<View style={styles.stat}>
|
<View key={i} style={styles.stat}>
|
||||||
<Text
|
<Text style={[styles.statValue, { color }]}>{value}</Text>
|
||||||
style={[
|
<Text style={styles.statLabel}>{name}</Text>
|
||||||
styles.statValue,
|
</View>
|
||||||
{ color: colors.info },
|
);
|
||||||
]}
|
})}
|
||||||
>
|
{amendeEnabled && (
|
||||||
{item.clientData.points_zipette}
|
<View style={styles.stat}>
|
||||||
</Text>
|
<Text
|
||||||
<Text style={styles.statLabel}>Zipette</Text>
|
style={[
|
||||||
</View>
|
styles.statValue,
|
||||||
<View style={styles.stat}>
|
{ color: colors.warning },
|
||||||
<Text
|
]}
|
||||||
style={[
|
>
|
||||||
styles.statValue,
|
{item.clientData.amende}
|
||||||
{ color: colors.warning },
|
</Text>
|
||||||
]}
|
<Text style={styles.statLabel}>Amendes</Text>
|
||||||
>
|
</View>
|
||||||
{item.clientData.amende}
|
)}
|
||||||
</Text>
|
|
||||||
<Text style={styles.statLabel}>Amendes</Text>
|
|
||||||
</View>
|
|
||||||
<View style={styles.stat}>
|
<View style={styles.stat}>
|
||||||
<Text
|
<Text
|
||||||
style={[
|
style={[
|
||||||
|
|||||||
Reference in New Issue
Block a user