diff --git a/app/(tabs)/diary.tsx b/app/(tabs)/diary.tsx index 4abafe2..6c1afbf 100644 --- a/app/(tabs)/diary.tsx +++ b/app/(tabs)/diary.tsx @@ -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( diff --git a/locales/en.json b/locales/en.json index 39a661c..9b85a18 100644 --- a/locales/en.json +++ b/locales/en.json @@ -199,6 +199,9 @@ "cancelTripConfirmTitle": "Cancel Request Confirmation", "cancelTripConfirmMessage": "Are you sure you want to cancel the approval request? The trip will be reset to initial status.", "cancelTripError": "Unable to cancel request. Please try again.", + "noCrewErrorTitle": "Cannot Send for Approval", + "noCrewErrorMessage": "This trip has no crew members. Please add crew members before sending for approval.", + "sendApprovalError": "Unable to send approval request. Please try again.", "crew": { "title": "Crew Members", "loading": "Loading crew members...", diff --git a/locales/vi.json b/locales/vi.json index 59c49fd..c498741 100644 --- a/locales/vi.json +++ b/locales/vi.json @@ -199,6 +199,9 @@ "cancelTripConfirmTitle": "Xác nhận hủy yêu cầu", "cancelTripConfirmMessage": "Bạn có chắc chắn muốn hủy yêu cầu phê duyệt? Chuyến đi sẽ trở về trạng thái đã khởi tạo.", "cancelTripError": "Không thể hủy yêu cầu. Vui lòng thử lại.", + "noCrewErrorTitle": "Không thể gửi phê duyệt", + "noCrewErrorMessage": "Chuyến đi chưa có thuyền viên. Vui lòng thêm thuyền viên trước khi gửi phê duyệt.", + "sendApprovalError": "Không thể gửi yêu cầu phê duyệt. Vui lòng thử lại.", "crew": { "title": "Danh sách thuyền viên", "loading": "Đang tải danh sách thuyền viên...",