call API trip

This commit is contained in:
2025-11-05 23:47:54 +07:00
parent 62b18e5bc0
commit 6288e79622
7 changed files with 115 additions and 3 deletions

View File

@@ -5,10 +5,16 @@ import CrewListTable from "@/components/tripInfo/CrewListTable";
import FishingToolsTable from "@/components/tripInfo/FishingToolsList"; import FishingToolsTable from "@/components/tripInfo/FishingToolsList";
import NetListTable from "@/components/tripInfo/NetListTable"; import NetListTable from "@/components/tripInfo/NetListTable";
import TripCostTable from "@/components/tripInfo/TripCostTable"; import TripCostTable from "@/components/tripInfo/TripCostTable";
import { useTrip } from "@/state/use-trip";
import { useEffect } from "react";
import { Platform, ScrollView, StyleSheet, Text, View } from "react-native"; import { Platform, ScrollView, StyleSheet, Text, View } from "react-native";
import { SafeAreaView } from "react-native-safe-area-context"; import { SafeAreaView } from "react-native-safe-area-context";
export default function TripInfoScreen() { export default function TripInfoScreen() {
const { trip, getTrip } = useTrip();
useEffect(() => {
getTrip();
}, []);
return ( return (
<SafeAreaView style={styles.safeArea} edges={["top", "left", "right"]}> <SafeAreaView style={styles.safeArea} edges={["top", "left", "right"]}>
<View style={styles.header}> <View style={styles.header}>

View File

@@ -1,4 +1,5 @@
import { IconSymbol } from "@/components/ui/icon-symbol"; import { IconSymbol } from "@/components/ui/icon-symbol";
import { useTrip } from "@/state/use-trip";
import React, { useRef, useState } from "react"; import React, { useRef, useState } from "react";
import { Animated, Text, TouchableOpacity, View } from "react-native"; import { Animated, Text, TouchableOpacity, View } from "react-native";
import TripCostDetailModal from "./modal/TripCostDetailModal"; import TripCostDetailModal from "./modal/TripCostDetailModal";
@@ -64,6 +65,7 @@ const TripCostTable: React.FC = () => {
const [modalVisible, setModalVisible] = useState(false); const [modalVisible, setModalVisible] = useState(false);
const animatedHeight = useRef(new Animated.Value(0)).current; const animatedHeight = useRef(new Animated.Value(0)).current;
const tongCong = data.reduce((sum, item) => sum + item.tongChiPhi, 0); const tongCong = data.reduce((sum, item) => sum + item.tongChiPhi, 0);
const { trip, getTrip } = useTrip();
const handleToggle = () => { const handleToggle = () => {
const toValue = collapsed ? contentHeight : 0; const toValue = collapsed ? contentHeight : 0;
@@ -95,6 +97,8 @@ const TripCostTable: React.FC = () => {
// marginBottom: 12, // marginBottom: 12,
}} }}
> >
{/* {trip && <Text></Text>} */}
<Text style={styles.title}>Chi phí chuyến đi</Text> <Text style={styles.title}>Chi phí chuyến đi</Text>
{collapsed && ( {collapsed && (
<Text <Text

View File

@@ -44,5 +44,3 @@ export const API_UPDATE_FISHING_LOGS = "/api/sgw/fishingLog";
export const API_SOS = "/api/sgw/sos"; export const API_SOS = "/api/sgw/sos";
export const API_PATH_SHIP_TRACK_POINTS = "/api/sgw/trackpoints"; export const API_PATH_SHIP_TRACK_POINTS = "/api/sgw/trackpoints";
export const API_GET_ALL_BANZONES = "/api/sgw/banzones"; export const API_GET_ALL_BANZONES = "/api/sgw/banzones";
// Smatec

View File

@@ -0,0 +1,6 @@
import { api } from "@/config";
import { API_GET_TRIP } from "@/constants";
export async function queryTrip() {
return api.get<Model.Trip>(API_GET_TRIP);
}

View File

@@ -1,4 +1,5 @@
import * as AuthController from "./AuthController"; import * as AuthController from "./AuthController";
import * as DeviceController from "./DeviceController"; import * as DeviceController from "./DeviceController";
import * as MapController from "./MapController"; import * as MapController from "./MapController";
export { AuthController, DeviceController, MapController }; import * as TripController from "./TripController";
export { AuthController, DeviceController, MapController, TripController };

View File

@@ -90,4 +90,75 @@ declare namespace Model {
message?: string; message?: string;
started_at?: number; started_at?: number;
} }
// Trip
interface Trip {
id: string;
ship_id: string;
ship_length: number;
vms_id: string;
name: string;
fishing_gears: FishingGear[]; // Dụng cụ đánh cá
crews?: TripCrews[]; // Thuyền viên
departure_time: string; // ISO datetime string
departure_port_id: number;
arrival_time: string; // ISO datetime string
arrival_port_id: number;
fishing_ground_codes: number[];
total_catch_weight: number | null;
total_species_caught: number | null;
trip_cost: TripCost[]; // Chi phí chuyến đi
trip_status: number;
approved_by: string;
notes: string | null;
fishing_logs: FishingLog[] | null; // tuỳ dữ liệu chi tiết có thể định nghĩa thêm
sync: boolean;
}
// Dụng cụ đánh cá
interface FishingGear {
name: string;
number: string;
}
// Thuyền viên
interface TripCrews {
role: string;
joined_at: Date;
left_at: Date | null;
note: string | null;
Person: TripCrewPerson;
}
// Chi phí chuyến đi
interface TripCost {
type: string;
unit: string;
amount: string;
total_cost: string;
cost_per_unit: string;
}
// Thông tin mẻ lưới
interface FishingLog {
fishing_log_id: string;
trip_id: string;
start_at: Date; // ISO datetime
end_at: Date; // ISO datetime
start_lat: number;
start_lon: number;
haul_lat: number;
haul_lon: number;
status: number;
weather_description: string;
info?: FishingLogInfo[]; // Thông tin cá
sync: boolean;
}
// Thông tin cá
interface FishingLogInfo {
fish_species_id?: number;
fish_name?: string;
catch_number?: number;
catch_unit?: string;
fish_size?: number;
fish_rarity?: number;
fish_condition?: string;
gear_usage?: string;
}
} }

26
state/use-trip.ts Normal file
View File

@@ -0,0 +1,26 @@
import { queryTrip } from "@/controller/TripController";
import { create } from "zustand";
type Trip = {
trip: Model.Trip | null;
getTrip: () => Promise<void>;
error: string | null;
loading?: boolean;
};
export const useTrip = create<Trip>((set) => ({
trip: null,
getTrip: async () => {
try {
const response = await queryTrip();
console.log("Trip fetching: ", response.data);
set({ trip: response.data, loading: false });
} catch (error) {
console.error("Error when fetch trip: ", error);
set({ error: "Failed to fetch trip data", loading: false });
set({ trip: null });
}
},
error: null,
}));