Cập nhật API thêm trip (validate)

This commit is contained in:
2025-12-22 15:22:06 +07:00
parent 12fb7c48ed
commit 67e9fc22a3
9 changed files with 228 additions and 86 deletions

View File

@@ -19,7 +19,7 @@ import { queryLastTrip } from "@/controller/TripController";
import { showErrorToast } from "@/services/toast_service";
interface AutoFillSectionProps {
onAutoFill: (tripData: Model.Trip, selectedShipId: string) => void;
onAutoFill: (tripData: Model.Trip, selectedThingId: string) => void;
}
export default function AutoFillSection({ onAutoFill }: AutoFillSectionProps) {
@@ -36,7 +36,7 @@ export default function AutoFillSection({ onAutoFill }: AutoFillSectionProps) {
things
?.filter((thing) => thing.id != null)
.map((thing) => ({
id: thing.id as string,
thingId: thing.id as string,
shipName: thing.metadata?.ship_name || "",
})) || [];
@@ -46,17 +46,17 @@ export default function AutoFillSection({ onAutoFill }: AutoFillSectionProps) {
return ship.shipName.toLowerCase().includes(searchLower);
});
const handleSelectShip = async (shipId: string) => {
const handleSelectShip = async (thingId: string) => {
setIsLoading(true);
try {
const response = await queryLastTrip(shipId);
const response = await queryLastTrip(thingId);
if (response.data) {
// Close the modal first before showing alert
setIsOpen(false);
setSearchText("");
// Pass shipId (thingId) along with trip data for filling ShipSelector
onAutoFill(response.data, shipId);
// Pass thingId along with trip data for filling ShipSelector
onAutoFill(response.data, thingId);
// Use Alert instead of Toast so it appears above all modals
Alert.alert(
@@ -182,9 +182,9 @@ export default function AutoFillSection({ onAutoFill }: AutoFillSectionProps) {
{filteredShips.length > 0 ? (
filteredShips.map((ship) => (
<TouchableOpacity
key={ship.id}
key={ship.thingId}
style={[styles.option, themedStyles.option]}
onPress={() => handleSelectShip(ship.id)}
onPress={() => handleSelectShip(ship.thingId)}
>
<View style={styles.optionContent}>
<Ionicons