Cập nhật validate có thuyển viên trong chuyến đi -> gửi chuyển đi

This commit is contained in:
2025-12-30 17:10:18 +07:00
parent 499bd76f5e
commit 88bdaeb3a6
3 changed files with 28 additions and 1 deletions

View File

@@ -226,6 +226,22 @@ export default function diary() {
const { tripApproveRequest } = await import(
"@/controller/TripController"
);
const { queryTripCrew } = await import(
"@/controller/TripCrewController"
);
// Kiểm tra xem có thuyền viên không trước khi gửi phê duyệt
const crewResponse = await queryTripCrew(tripId);
const tripCrews = crewResponse.data?.trip_crews || [];
// Nếu response 204 hoặc không có thuyền viên
if (crewResponse.status === 204 || tripCrews.length === 0) {
Alert.alert(
t("diary.noCrewErrorTitle"),
t("diary.noCrewErrorMessage")
);
return;
}
// Gọi API gửi yêu cầu phê duyệt
await tripApproveRequest(tripId);
@@ -248,9 +264,14 @@ export default function diary() {
}, 100);
} catch (error) {
console.error("❌ Error sending trip for approval:", error);
Alert.alert(
t("common.error") || "Lỗi",
t("diary.sendApprovalError") ||
"Không thể gửi yêu cầu phê duyệt. Vui lòng thử lại."
);
}
},
[payloadTrips, getTripsList]
[payloadTrips, getTripsList, t]
);
const handleDeleteTrip = useCallback(