Update from master

This commit is contained in:
2025-11-07 17:56:13 +07:00
parent 53bf2d18e6
commit c02b61163d
5 changed files with 106 additions and 442 deletions

View File

@@ -1,4 +1,5 @@
import Select from "@/components/Select";
import { useFishes } from "@/state/use-fish";
import { zodResolver } from "@hookform/resolvers/zod";
import React from "react";
import { Controller, useFieldArray, useForm } from "react-hook-form";
@@ -14,7 +15,6 @@ interface CreateOrUpdateHaulModalProps {
const UNITS = ["con", "kg", "tấn"] as const;
type Unit = (typeof UNITS)[number];
const UNITS_OPTIONS = UNITS.map((unit) => ({
label: unit,
value: unit.toString(),
@@ -60,9 +60,11 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
},
mode: "onSubmit",
});
const { fishSpecies, getFishSpecies } = useFishes();
const { errors } = formState;
if (!fishSpecies) {
getFishSpecies();
}
const { fields, append, remove } = useFieldArray({
control,
name: "fish",
@@ -70,7 +72,25 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
});
const onSubmit = (values: FormValues) => {
console.log("SUBMIT: ", JSON.stringify(values, null, 2));
// Map form values to the FishingLogInfo-like shape the user requested
const mapped = values.fish.map((f) => {
const meta = fishSpecies!.find((x) => x.id === f.id);
return {
fish_species_id: f.id,
fish_name: meta?.name,
catch_number: f.quantity,
catch_unit: f.unit,
fish_size: f.size,
fish_rarity: meta?.rarity_level,
fish_condition: "",
gear_usage: "",
} as unknown; // inferred shape — keep as unknown to avoid relying on global types here
});
console.log("SUBMIT (FishingLogInfo[]): ", JSON.stringify(mapped, null, 2));
// close modal after submit (you can change this to pass the payload to a parent via prop)
onClose();
};
// Initialize / reset form when modal visibility or haulData changes
@@ -125,7 +145,7 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
<View style={{ marginBottom: 8 }}>
<Text style={{ marginBottom: 4 }}>Tên </Text>
<Select
options={fishesExampleData.map((fish) => ({
options={fishSpecies!.map((fish) => ({
label: fish.name,
value: fish.id,
}))}
@@ -226,6 +246,7 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
</View>
);
};
return (
<Modal
visible={isVisible}
@@ -262,331 +283,3 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
};
export default CreateOrUpdateHaulModal;
const fishesExampleData = [
{
id: 1,
name: "Cá thu",
scientific_name: "Scomberomorus spp.",
group_name: "Cá nổi",
species_code: "TUNA01",
note: "Loài phổ biến ở biển ven bờ và xa bờ",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 2,
name: "Cá nục",
scientific_name: "Decapterus spp.",
group_name: "Cá nổi",
species_code: "MACK01",
note: "Loài cá thương mại nhỏ",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 3,
name: "Cá chim trắng",
scientific_name: "Pampus argenteus",
group_name: "Cá nổi",
species_code: "POMF01",
note: "Thịt ngon, giá trị kinh tế cao",
default_unit: "kg",
rarity_level: 2,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 4,
name: "Cá bống tượng",
scientific_name: "Oxyeleotris marmorata",
group_name: "Cá đáy",
species_code: "GOBY01",
note: "Cá đáy nước ngọt và lợ",
default_unit: "kg",
rarity_level: 2,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 5,
name: "Cá mú đỏ",
scientific_name: "Epinephelus malabaricus",
group_name: "Nhóm mú",
species_code: "GROUP01",
note: "Cá mú đỏ phổ biến tại các rạn san hô",
default_unit: "kg",
rarity_level: 2,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 6,
name: "Cá mú trắng",
scientific_name: "Epinephelus fuscoguttatus",
group_name: "Nhóm mú",
species_code: "GROUP02",
note: "Cá mú trắng rạn san hô",
default_unit: "kg",
rarity_level: 2,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 8,
name: "Cá hồng phớn",
scientific_name: "Nemipterus virgatus",
group_name: "Cá đáy",
species_code: "BREAM01",
note: "Golden threadfin bream, rất phổ biến",
default_unit: "kg",
rarity_level: 3,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 9,
name: "Cá hổ Napoleon",
scientific_name: "Cheilinus undulatus",
group_name: "Rạn san hô",
species_code: "WRASSE01",
note: "Humphead wrasse, loài nguy cấp được bảo vệ",
default_unit: "kg",
rarity_level: 4,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 10,
name: "Cá quỷ biển (Barracuda)",
scientific_name: "Sphyraena barracuda",
group_name: "Cá săn mồi",
species_code: "BARRA01",
note: "Loài cá săn mồi nhanh",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 11,
name: "Cá ngừ đại dương",
scientific_name: "Thunnus albacares",
group_name: "Cá nổi xa bờ",
species_code: "TUNA02",
note: "Tuna phổ biến vùng biển xa",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 12,
name: "Cá nục vằn",
scientific_name: "Scomberomorus commerson",
group_name: "Cá nổi",
species_code: "MACK02",
note: "Mackerel phổ biến ở biển miền Trung",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 13,
name: "Cá song đỏ",
scientific_name: "Lutjanus argentimaculatus",
group_name: "Cá đáy",
species_code: "SNAPPER01",
note: "Mangrove red snapper, giá trị kinh tế cao",
default_unit: "kg",
rarity_level: 2,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 14,
name: "Cá mú cườm",
scientific_name: "Epinephelus coioides",
group_name: "Nhóm mú",
species_code: "GROUP03",
note: "Brown-spotted grouper, phổ biến ở vùng biển",
default_unit: "kg",
rarity_level: 2,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 15,
name: "Cá hồng",
scientific_name: "Lutjanus malabaricus",
group_name: "Cá đáy",
species_code: "SNAPPER02",
note: "Malabar red snapper",
default_unit: "kg",
rarity_level: 2,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 16,
name: "Cá rồng biển",
scientific_name: "Choerodon schoenleinii",
group_name: "Rạn san hô",
species_code: "DRAGON01",
note: "Cá rồng biển, cá cảnh hiếm",
default_unit: "kg",
rarity_level: 3,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 17,
name: "Cá nược",
scientific_name: "Pomatomus saltatrix",
group_name: "Cá nổi",
species_code: "QUEEN01",
note: "Bluefish phổ biến",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 18,
name: "Cá đuối quạt",
scientific_name: "Platyrhina sinensis",
group_name: "Cá mó",
species_code: "RAY01",
note: "Fanray, loài đe dọa",
default_unit: "kg",
rarity_level: 4,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 19,
name: "Cá hổ Thái Lan",
scientific_name: "Datnioides pulcher",
group_name: "Cá nước lợ",
species_code: "TIGER01",
note: "Siamese tigerfish, nguy cấp",
default_unit: "kg",
rarity_level: 4,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 20,
name: "Cá bớp vây vàng",
scientific_name: "Taractes rubescens",
group_name: "Cá nổi xa bờ",
species_code: "POMF02",
note: "Loài cá biển sâu ít gặp",
default_unit: "kg",
rarity_level: 3,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-08-29T06:34:38.785313Z",
is_deleted: false,
},
{
id: 43,
name: "Cá Min Mon",
scientific_name: "Minhmon",
group_name: "Cá béo",
species_code: "Caminhmon",
note: "Cá béo nước cạn",
default_unit: "tạ",
rarity_level: 1,
created_at: "2025-10-01T03:09:59.642716Z",
updated_at: "2025-10-01T03:10:30.977697Z",
is_deleted: true,
},
{
id: 7,
name: "Cá bơn vàng",
scientific_name: "Cynoglossus robustus",
group_name: "Cá đáy",
species_code: "SOLE01",
note: "Cá bơn đáy cát",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-08-29T06:34:38.785313Z",
updated_at: "2025-10-01T03:10:39.927546Z",
is_deleted: false,
},
{
id: 22,
name: "Cá mập",
scientific_name: "Carcharodon",
group_name: "Cá đáy",
species_code: "Carcharodon",
note: "Cá trắng",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-09-25T11:02:20.705804Z",
updated_at: "2025-10-01T03:11:13.631101Z",
is_deleted: true,
},
{
id: 28,
name: "cá cơm",
scientific_name: "cá cơm",
group_name: "cá cơm",
species_code: "cacom",
note: "no cmt",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-09-30T07:35:04.623573Z",
updated_at: "2025-09-30T08:06:18.651249Z",
is_deleted: true,
},
{
id: 29,
name: "cá minh mon",
scientific_name: "cá min mon",
group_name: "1",
species_code: "cá min mon",
note: "no",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-09-30T07:36:04.908601Z",
updated_at: "2025-09-30T08:09:34.361879Z",
is_deleted: true,
},
{
id: 42,
name: "cá mập",
scientific_name: "camap",
group_name: "cá đáy",
species_code: "camap",
note: "no",
default_unit: "kg",
rarity_level: 1,
created_at: "2025-09-30T08:38:14.151734Z",
updated_at: "2025-10-01T03:08:13.025517Z",
is_deleted: true,
},
];

View File

@@ -2,20 +2,6 @@ import React from "react";
import { Text, View } from "react-native";
import styles from "../../style/NetDetailModal.styles";
interface NetDetail {
id: string;
stt: string;
trangThai: string;
thoiGianBatDau?: string;
thoiGianKetThuc?: string;
viTriHaThu?: string;
viTriThuLuoi?: string;
doSauHaThu?: string;
doSauThuLuoi?: string;
catchList?: any[];
ghiChu?: string;
}
interface InfoSectionProps {
netData?: Model.FishingLog;
isCompleted: boolean;
@@ -49,22 +35,22 @@ export const InfoSection: React.FC<InfoSectionProps> = ({
? new Date(netData.end_at).toLocaleString()
: "Chưa cập nhật",
},
{
label: "Vị trí hạ thu",
value: netData.viTriHaThu || "Chưa cập nhật",
},
{
label: "Vị trí thu lưới",
value: netData.viTriThuLuoi || "Chưa cập nhật",
},
{
label: "Độ sâu hạ thu",
value: netData.doSauHaThu || "Chưa cập nhật",
},
{
label: "Độ sâu thu lưới",
value: netData.doSauThuLuoi || "Chưa cập nhật",
},
// {
// label: "Vị trí hạ thu",
// value: netData.viTriHaThu || "Chưa cập nhật",
// },
// {
// label: "Vị trí thu lưới",
// value: netData.viTriThuLuoi || "Chưa cập nhật",
// },
// {
// label: "Độ sâu hạ thu",
// value: netData.doSauHaThu || "Chưa cập nhật",
// },
// {
// label: "Độ sâu thu lưới",
// value: netData.doSauThuLuoi || "Chưa cập nhật",
// },
];
return (