chore: fix reset point
This commit is contained in:
@@ -142,11 +142,12 @@ export const updateDeliveryStatus = async (
|
|||||||
status: string,
|
status: string,
|
||||||
latitude: number,
|
latitude: number,
|
||||||
longitude: number,
|
longitude: number,
|
||||||
|
notes?: string,
|
||||||
): Promise<{ success: boolean; message?: string; error?: string }> => {
|
): Promise<{ success: boolean; message?: string; error?: string }> => {
|
||||||
try {
|
try {
|
||||||
const { data } = await apiClient.put(
|
const { data } = await apiClient.put(
|
||||||
`${API}/deliveries/${deliveryId}/status`,
|
`${API}/deliveries/${deliveryId}/status`,
|
||||||
{ status, latitude, longitude },
|
{ status, latitude, longitude, ...(notes ? { notes } : {}) },
|
||||||
);
|
);
|
||||||
return { success: true, message: data.message };
|
return { success: true, message: data.message };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
Modal,
|
Modal,
|
||||||
StatusBar,
|
StatusBar,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
|
TextInput,
|
||||||
} from "react-native";
|
} from "react-native";
|
||||||
import Geolocation from "@react-native-community/geolocation";
|
import Geolocation from "@react-native-community/geolocation";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
import { Ionicons } from "@expo/vector-icons";
|
||||||
@@ -105,6 +106,11 @@ export default function DashboardScreen() {
|
|||||||
|
|
||||||
const [detailsDelivery, setDetailsDelivery] =
|
const [detailsDelivery, setDetailsDelivery] =
|
||||||
useState<EnrichedDelivery | null>(null);
|
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(
|
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 openNavigation = (address: string) => {
|
||||||
const encoded = encodeURIComponent(address);
|
const encoded = encodeURIComponent(address);
|
||||||
const wazeApp = `waze://?q=${encoded}&navigate=yes`;
|
const wazeApp = `waze://?q=${encoded}&navigate=yes`;
|
||||||
@@ -673,14 +699,24 @@ export default function DashboardScreen() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{item.status === "arrived" && (
|
{item.status === "arrived" && (
|
||||||
<Button
|
<View style={{ flexDirection: "row", gap: spacing.s, marginTop: spacing.s }}>
|
||||||
title="Terminer la livraison"
|
<Button
|
||||||
onPress={() => handleCompleteDelivery(item.id)}
|
title="Terminer"
|
||||||
style={{
|
onPress={() => handleCompleteDelivery(item.id)}
|
||||||
marginTop: spacing.s,
|
style={{ flex: 1, backgroundColor: colors.accent }}
|
||||||
backgroundColor: colors.accent,
|
/>
|
||||||
}}
|
<Button
|
||||||
/>
|
title="Annuler"
|
||||||
|
onPress={() =>
|
||||||
|
setCancelModal({
|
||||||
|
visible: true,
|
||||||
|
deliveryId: item.id,
|
||||||
|
reason: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
style={{ flex: 1, backgroundColor: colors.danger }}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
@@ -1418,6 +1454,29 @@ export default function DashboardScreen() {
|
|||||||
fontSize: fontSize.sm,
|
fontSize: fontSize.sm,
|
||||||
fontWeight: "600",
|
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],
|
[colors],
|
||||||
);
|
);
|
||||||
@@ -1720,6 +1779,33 @@ export default function DashboardScreen() {
|
|||||||
ListHeaderComponent={renderHeader()}
|
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
|
<AlertModal
|
||||||
visible={alert.visible}
|
visible={alert.visible}
|
||||||
type={alert.type}
|
type={alert.type}
|
||||||
|
|||||||
Reference in New Issue
Block a user