chore: update

This commit is contained in:
2026-03-14 12:22:38 +01:00
parent 0523ed6356
commit 9d52f3193a
4 changed files with 58 additions and 74 deletions
+9 -2
View File
@@ -74,13 +74,14 @@ export const resetClientPenalties = async (clientUsername: string) => {
return { success: true, message: data.message };
};
// pool: 0 = pool principal (point), 1 = pool secondaire (point_zipette), -1 = tous
export const resetClientPoints = async (
clientUsername: string,
resetCancellationsPoints: boolean = false,
pool: number = -1,
) => {
const { data } = await apiClient.post(
`${API}/client/${clientUsername}/point/reset`,
{ reset_cancellations_points: resetCancellationsPoints },
{ pool },
);
return { success: true, message: data.message };
};
@@ -349,6 +350,8 @@ export interface PublicSettings {
show_amende_score: boolean;
points_enabled: boolean;
points_separated: boolean;
pool_names: string[];
pool_keys: string[];
}
export const registerCabinePushToken = async (
@@ -399,6 +402,8 @@ export const getPublicSettings = async (): Promise<PublicSettings> => {
show_amende_score: data.show_amende_score ?? true,
points_enabled: data.points_enabled ?? true,
points_separated: data.points_separated ?? true,
pool_names: data.pool_names ?? [],
pool_keys: data.pool_keys ?? [],
};
} catch {
return {
@@ -406,6 +411,8 @@ export const getPublicSettings = async (): Promise<PublicSettings> => {
show_amende_score: true,
points_enabled: true,
points_separated: true,
pool_names: [],
pool_keys: [],
};
}
};
+1
View File
@@ -28,6 +28,7 @@ export interface ClientResponse {
command: number;
point: number;
points_zipette: number;
points_extra: Record<string, number>;
amende: number;
cancellations_count: number;
last_penalty_reason?: string;
@@ -965,7 +965,10 @@ export default function SettingsScreen() {
</View>
{/* Gestion des types de points */}
<View style={{ paddingHorizontal: spacing.l, paddingBottom: spacing.m, borderTopWidth: 1, borderTopColor: colors.border, paddingTop: spacing.m }}>
<View
pointerEvents={settings.points_enabled ? "auto" : "none"}
style={{ paddingHorizontal: spacing.l, paddingBottom: spacing.m, borderTopWidth: 1, borderTopColor: colors.border, paddingTop: spacing.m, opacity: settings.points_enabled ? 1 : 0.4 }}
>
<Text style={[s.rowLabel, { marginBottom: spacing.s }]}>Types de points</Text>
<Text style={[s.rowDesc, { marginBottom: spacing.m }]}>
Créez vos propres types de points. Le 1er type colonne principale, le 2e colonne secondaire.
@@ -988,17 +991,15 @@ export default function SettingsScreen() {
</View>
);
})}
{pools.length < 2 && (
<TouchableOpacity
onPress={addPool}
style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs, marginTop: spacing.xs }}
>
<Ionicons name="add-circle-outline" size={18} color={colors.accent} />
<Text style={{ fontSize: fontSize.sm, color: colors.accent, fontWeight: "600" }}>
Ajouter un type
</Text>
</TouchableOpacity>
)}
<TouchableOpacity
onPress={addPool}
style={{ flexDirection: "row", alignItems: "center", gap: spacing.xs, marginTop: spacing.xs }}
>
<Ionicons name="add-circle-outline" size={18} color={colors.accent} />
<Text style={{ fontSize: fontSize.sm, color: colors.accent, fontWeight: "600" }}>
Ajouter un type
</Text>
</TouchableOpacity>
</View>
</View>
@@ -22,6 +22,8 @@ export default function UsersScreen() {
show_amende_score: true,
points_enabled: true,
points_separated: true,
pool_names: [],
pool_keys: [],
});
const [penaltyModal, setPenaltyModal] = useState<{
visible: boolean;
@@ -70,29 +72,17 @@ export default function UsersScreen() {
);
};
const handleResetPoints = (username: string) => {
const handleResetPool = (username: string, poolIdx: number) => {
const poolNames = appSettings.pool_names;
const poolName = poolIdx >= 0 && poolIdx < poolNames.length
? poolNames[poolIdx]
: "tous les points";
showConfirm(
"Reset points",
`Réinitialiser les points de ${username} ?`,
`Reset ${poolName}`,
`Réinitialiser les points "${poolName}" de ${username} ?`,
async () => {
try {
await resetClientPoints(username);
await loadData();
} catch (e: any) {
showError("Erreur", e.message);
}
},
"Reset",
);
};
const handleResetZipette = (username: string) => {
showConfirm(
"Reset points zipette",
`Réinitialiser les points zipette de ${username} ?`,
async () => {
try {
await resetClientPoints(username, true);
await resetClientPoints(username, poolIdx);
await loadData();
} catch (e: any) {
showError("Erreur", e.message);
@@ -146,31 +136,23 @@ export default function UsersScreen() {
{item.prenom} {item.nom} - {item.telephone}
</Text>
<View style={styles.statsRow}>
{appSettings.points_enabled && (
appSettings.points_separated ? (
<>
<View style={styles.stat}>
<Text style={[styles.statValue, { color: colors.success }]}>
{item.point}
</Text>
<Text style={styles.statLabel}>Points</Text>
</View>
<View style={styles.stat}>
<Text style={[styles.statValue, { color: colors.info }]}>
{item.points_zipette}
</Text>
<Text style={styles.statLabel}>Zipette</Text>
</View>
</>
) : (
<View style={styles.stat}>
<Text style={[styles.statValue, { color: colors.success }]}>
{item.point}
</Text>
<Text style={styles.statLabel}>Points</Text>
{appSettings.points_enabled && appSettings.pool_names.map((name, i) => {
let value: number;
let color: string;
if (i === 0) { value = item.point; color = colors.success; }
else if (i === 1) { value = item.points_zipette; color = colors.info; }
else {
const key = appSettings.pool_keys[i] ?? "";
value = item.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>
)
)}
);
})}
{appSettings.show_amende_score && (
<View style={styles.stat}>
<Text style={[styles.statValue, { color: colors.warning }]}>
@@ -195,22 +177,15 @@ export default function UsersScreen() {
variant="outline"
/>
)}
{appSettings.points_enabled && (
<>
<Button
title="Reset points"
onPress={() => handleResetPoints(item.username)}
size="sm"
variant="outline"
/>
<Button
title="Reset zipette"
onPress={() => handleResetZipette(item.username)}
size="sm"
variant="outline"
/>
</>
)}
{appSettings.points_enabled && appSettings.pool_names.map((name, i) => (
<Button
key={i}
title={`Reset ${name}`}
onPress={() => handleResetPool(item.username, i)}
size="sm"
variant="outline"
/>
))}
</View>
</Card>
);