call API trip
This commit is contained in:
@@ -5,10 +5,16 @@ import CrewListTable from "@/components/tripInfo/CrewListTable";
|
||||
import FishingToolsTable from "@/components/tripInfo/FishingToolsList";
|
||||
import NetListTable from "@/components/tripInfo/NetListTable";
|
||||
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 { SafeAreaView } from "react-native-safe-area-context";
|
||||
|
||||
export default function TripInfoScreen() {
|
||||
const { trip, getTrip } = useTrip();
|
||||
useEffect(() => {
|
||||
getTrip();
|
||||
}, []);
|
||||
return (
|
||||
<SafeAreaView style={styles.safeArea} edges={["top", "left", "right"]}>
|
||||
<View style={styles.header}>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { IconSymbol } from "@/components/ui/icon-symbol";
|
||||
import { useTrip } from "@/state/use-trip";
|
||||
import React, { useRef, useState } from "react";
|
||||
import { Animated, Text, TouchableOpacity, View } from "react-native";
|
||||
import TripCostDetailModal from "./modal/TripCostDetailModal";
|
||||
@@ -64,6 +65,7 @@ const TripCostTable: React.FC = () => {
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
const animatedHeight = useRef(new Animated.Value(0)).current;
|
||||
const tongCong = data.reduce((sum, item) => sum + item.tongChiPhi, 0);
|
||||
const { trip, getTrip } = useTrip();
|
||||
|
||||
const handleToggle = () => {
|
||||
const toValue = collapsed ? contentHeight : 0;
|
||||
@@ -95,6 +97,8 @@ const TripCostTable: React.FC = () => {
|
||||
// marginBottom: 12,
|
||||
}}
|
||||
>
|
||||
{/* {trip && <Text></Text>} */}
|
||||
|
||||
<Text style={styles.title}>Chi phí chuyến đi</Text>
|
||||
{collapsed && (
|
||||
<Text
|
||||
|
||||
@@ -44,5 +44,3 @@ export const API_UPDATE_FISHING_LOGS = "/api/sgw/fishingLog";
|
||||
export const API_SOS = "/api/sgw/sos";
|
||||
export const API_PATH_SHIP_TRACK_POINTS = "/api/sgw/trackpoints";
|
||||
export const API_GET_ALL_BANZONES = "/api/sgw/banzones";
|
||||
|
||||
// Smatec
|
||||
|
||||
6
controller/TripController.ts
Normal file
6
controller/TripController.ts
Normal 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);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as AuthController from "./AuthController";
|
||||
import * as DeviceController from "./DeviceController";
|
||||
import * as MapController from "./MapController";
|
||||
export { AuthController, DeviceController, MapController };
|
||||
import * as TripController from "./TripController";
|
||||
export { AuthController, DeviceController, MapController, TripController };
|
||||
|
||||
71
controller/typings.d.ts
vendored
71
controller/typings.d.ts
vendored
@@ -90,4 +90,75 @@ declare namespace Model {
|
||||
message?: string;
|
||||
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
26
state/use-trip.ts
Normal 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,
|
||||
}));
|
||||
Reference in New Issue
Block a user