This commit is contained in:
@@ -6,8 +6,8 @@ import {
|
||||
StyleSheet,
|
||||
RefreshControl,
|
||||
TouchableOpacity,
|
||||
Alert,
|
||||
} from "react-native";
|
||||
import AlertModal from "../../components/ui/AlertModal";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { useFocusEffect } from "@react-navigation/native";
|
||||
import { useTheme } from "../../context/ThemeContext";
|
||||
@@ -197,6 +197,8 @@ export default function StatsScreen() {
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [resetting, setResetting] = useState<StatSection | null>(null);
|
||||
const [prodSort, setProdSort] = useState<ProdSort>("quantity");
|
||||
const [confirmModal, setConfirmModal] = useState<{ section: StatSection; label: string } | null>(null);
|
||||
const [errorModal, setErrorModal] = useState<string | null>(null);
|
||||
|
||||
const loadStats = useCallback(async () => {
|
||||
try {
|
||||
@@ -215,25 +217,21 @@ export default function StatsScreen() {
|
||||
};
|
||||
|
||||
const handleReset = (section: StatSection, label: string) => {
|
||||
Alert.alert(
|
||||
`Réinitialiser — ${label}`,
|
||||
"Les données de cette section repartiront de zéro. Les commandes restent en base.\n\nConfirmer ?",
|
||||
[
|
||||
{ text: "Annuler", style: "cancel" },
|
||||
{
|
||||
text: "Réinitialiser",
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
setResetting(section);
|
||||
try {
|
||||
await resetAdminStats(section);
|
||||
await loadStats();
|
||||
} catch { /* ignore */ }
|
||||
setResetting(null);
|
||||
},
|
||||
},
|
||||
],
|
||||
);
|
||||
setConfirmModal({ section, label });
|
||||
};
|
||||
|
||||
const doReset = async () => {
|
||||
if (!confirmModal) return;
|
||||
const { section } = confirmModal;
|
||||
setConfirmModal(null);
|
||||
setResetting(section);
|
||||
try {
|
||||
await resetAdminStats(section);
|
||||
await loadStats();
|
||||
} catch (e: any) {
|
||||
setErrorModal(e?.response?.data?.error || e?.message || "Impossible de réinitialiser");
|
||||
}
|
||||
setResetting(null);
|
||||
};
|
||||
|
||||
// Produits triés selon le sélecteur
|
||||
@@ -271,6 +269,24 @@ export default function StatsScreen() {
|
||||
));
|
||||
|
||||
return (
|
||||
<>
|
||||
<AlertModal
|
||||
visible={confirmModal !== null}
|
||||
type="confirm"
|
||||
title={`Réinitialiser — ${confirmModal?.label ?? ""}`}
|
||||
message={`Les données "${confirmModal?.label ?? ""}" repartiront de zéro.\nLes commandes restent en base.`}
|
||||
confirmText="Réinitialiser"
|
||||
cancelText="Annuler"
|
||||
onClose={() => setConfirmModal(null)}
|
||||
onConfirm={doReset}
|
||||
/>
|
||||
<AlertModal
|
||||
visible={errorModal !== null}
|
||||
type="error"
|
||||
title="Erreur"
|
||||
message={errorModal ?? ""}
|
||||
onClose={() => setErrorModal(null)}
|
||||
/>
|
||||
<ScrollView
|
||||
style={styles.container}
|
||||
contentContainerStyle={styles.content}
|
||||
@@ -561,5 +577,6 @@ export default function StatsScreen() {
|
||||
)}
|
||||
</Section>
|
||||
</ScrollView>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user