diff --git a/frontend-admin/src/api/api_delivery.ts b/frontend-admin/src/api/api_delivery.ts index 615f0286..dcea78a7 100644 --- a/frontend-admin/src/api/api_delivery.ts +++ b/frontend-admin/src/api/api_delivery.ts @@ -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) { diff --git a/frontend-admin/src/screens/delivery/DashboardScreen.tsx b/frontend-admin/src/screens/delivery/DashboardScreen.tsx index 61f4b52f..b62c5235 100644 --- a/frontend-admin/src/screens/delivery/DashboardScreen.tsx +++ b/frontend-admin/src/screens/delivery/DashboardScreen.tsx @@ -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(null); + const [cancelModal, setCancelModal] = useState<{ + visible: boolean; + deliveryId: number | null; + reason: string; + }>({ visible: false, deliveryId: null, reason: "" }); const STATUS_COLORS: Record = 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" && ( -