chore: fix reset point

This commit is contained in:
2026-03-06 20:08:51 +01:00
parent 9b7ce74d7b
commit 03c414e930
2 changed files with 96 additions and 9 deletions
+2 -1
View File
@@ -142,11 +142,12 @@ export const updateDeliveryStatus = async (
status: string,
latitude: number,
longitude: number,
notes?: string,
): Promise<{ success: boolean; message?: string; error?: string }> => {
try {
const { data } = await apiClient.put(
`${API}/deliveries/${deliveryId}/status`,
{ status, latitude, longitude },
{ status, latitude, longitude, ...(notes ? { notes } : {}) },
);
return { success: true, message: data.message };
} catch (error: any) {
@@ -19,6 +19,7 @@ import {
Modal,
StatusBar,
ScrollView,
TextInput,
} from "react-native";
import Geolocation from "@react-native-community/geolocation";
import { Ionicons } from "@expo/vector-icons";
@@ -105,6 +106,11 @@ export default function DashboardScreen() {
const [detailsDelivery, setDetailsDelivery] =
useState<EnrichedDelivery | null>(null);
const [cancelModal, setCancelModal] = useState<{
visible: boolean;
deliveryId: number | null;
reason: string;
}>({ visible: false, deliveryId: null, reason: "" });
const STATUS_COLORS: Record<string, string> = useMemo(
() => ({
@@ -483,6 +489,26 @@ export default function DashboardScreen() {
}
};
const handleCancelDelivery = async () => {
if (!cancelModal.deliveryId) return;
const lat = lastCoords?.lat || 0;
const lng = lastCoords?.lng || 0;
const res = await updateDeliveryStatus(
cancelModal.deliveryId,
"cancelled",
lat,
lng,
cancelModal.reason || "Client absent",
);
setCancelModal({ visible: false, deliveryId: null, reason: "" });
if (res.success) {
showSuccess("Succès", "Livraison annulée");
loadData();
} else {
showError("Erreur", res.error || "Erreur");
}
};
const openNavigation = (address: string) => {
const encoded = encodeURIComponent(address);
const wazeApp = `waze://?q=${encoded}&navigate=yes`;
@@ -673,14 +699,24 @@ export default function DashboardScreen() {
/>
)}
{item.status === "arrived" && (
<Button
title="Terminer la livraison"
onPress={() => handleCompleteDelivery(item.id)}
style={{
marginTop: spacing.s,
backgroundColor: colors.accent,
}}
/>
<View style={{ flexDirection: "row", gap: spacing.s, marginTop: spacing.s }}>
<Button
title="Terminer"
onPress={() => handleCompleteDelivery(item.id)}
style={{ flex: 1, backgroundColor: colors.accent }}
/>
<Button
title="Annuler"
onPress={() =>
setCancelModal({
visible: true,
deliveryId: item.id,
reason: "",
})
}
style={{ flex: 1, backgroundColor: colors.danger }}
/>
</View>
)}
</Card>
);
@@ -1418,6 +1454,29 @@ export default function DashboardScreen() {
fontSize: fontSize.sm,
fontWeight: "600",
},
cancelInput: {
borderWidth: 1,
borderColor: colors.border,
borderRadius: borderRadius.m,
padding: spacing.m,
color: colors.textWhite,
backgroundColor: colors.bgSecondary,
minHeight: 80,
textAlignVertical: "top",
marginBottom: spacing.m,
},
cancelConfirmBtn: {
backgroundColor: colors.danger,
borderRadius: borderRadius.m,
padding: spacing.m,
alignItems: "center",
},
cancelConfirmText: {
color: colors.textWhite,
fontWeight: "700",
fontSize: fontSize.md,
},
}),
[colors],
);
@@ -1720,6 +1779,33 @@ export default function DashboardScreen() {
ListHeaderComponent={renderHeader()}
/>
{/* Modal annulation livraison */}
<DetailsModal
visible={cancelModal.visible}
onClose={() =>
setCancelModal({ visible: false, deliveryId: null, reason: "" })
}
title="Annuler la livraison"
icon="close-circle-outline"
>
<TextInput
style={styles.cancelInput}
placeholder="Motif (ex: client absent)..."
placeholderTextColor={colors.textMuted}
value={cancelModal.reason}
onChangeText={(t) =>
setCancelModal((prev) => ({ ...prev, reason: t }))
}
multiline
/>
<TouchableOpacity
style={styles.cancelConfirmBtn}
onPress={handleCancelDelivery}
>
<Text style={styles.cancelConfirmText}>Confirmer l'annulation</Text>
</TouchableOpacity>
</DetailsModal>
<AlertModal
visible={alert.visible}
type={alert.type}