cập nhật modal add/edit fishingLog và sửa lỗi event ở map
This commit is contained in:
@@ -5,11 +5,13 @@ import React from "react";
|
||||
import { Controller, useFieldArray, useForm } from "react-hook-form";
|
||||
import { Button, FlatList, Modal, Text, TextInput, View } from "react-native";
|
||||
import { z } from "zod";
|
||||
import { InfoSection } from "./NetDetailModal/components";
|
||||
|
||||
interface CreateOrUpdateHaulModalProps {
|
||||
isVisible: boolean;
|
||||
onClose: () => void;
|
||||
haulData?: Model.FishingLogInfo[] | null;
|
||||
fishingLog?: Model.FishingLog | null;
|
||||
fishingLogIndex?: number;
|
||||
}
|
||||
|
||||
const UNITS = ["con", "kg", "tấn"] as const;
|
||||
@@ -49,9 +51,10 @@ const defaultItem = (): FormValues["fish"][number] => ({
|
||||
const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
||||
isVisible,
|
||||
onClose,
|
||||
haulData,
|
||||
fishingLog,
|
||||
fishingLogIndex
|
||||
}) => {
|
||||
const [isCreateMode, setIsCreateMode] = React.useState(!haulData);
|
||||
const [isCreateMode, setIsCreateMode] = React.useState(!fishingLog?.info);
|
||||
const { control, handleSubmit, formState, watch, reset } =
|
||||
useForm<FormValues>({
|
||||
resolver: zodResolver(formSchema),
|
||||
@@ -102,14 +105,14 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
||||
return;
|
||||
}
|
||||
|
||||
// when modal opened, populate based on haulData
|
||||
if (haulData === null) {
|
||||
// when modal opened, populate based on fishingLog
|
||||
if (fishingLog?.info === null) {
|
||||
// explicit null -> start with a single default item
|
||||
reset({ fish: [defaultItem()] });
|
||||
setIsCreateMode(true);
|
||||
} else if (Array.isArray(haulData) && haulData.length > 0) {
|
||||
} else if (Array.isArray(fishingLog?.info) && fishingLog?.info.length > 0) {
|
||||
// map FishingLogInfo -> form rows
|
||||
const mapped = haulData.map((h) => ({
|
||||
const mapped = fishingLog.info.map((h) => ({
|
||||
id: h.fish_species_id ?? -1,
|
||||
quantity: (h.catch_number as number) ?? 1,
|
||||
unit: (h.catch_unit as Unit) ?? (defaultItem().unit as Unit),
|
||||
@@ -122,7 +125,7 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
||||
reset({ fish: [defaultItem()] });
|
||||
setIsCreateMode(true);
|
||||
}
|
||||
}, [isVisible, haulData, reset]);
|
||||
}, [isVisible, fishingLog?.info, reset]);
|
||||
const renderRow = ({ item, index }: { item: any; index: number }) => {
|
||||
return (
|
||||
<View
|
||||
@@ -255,6 +258,7 @@ const CreateOrUpdateHaulModal: React.FC<CreateOrUpdateHaulModalProps> = ({
|
||||
onRequestClose={onClose}
|
||||
>
|
||||
<Text>{isCreateMode ? "Create Haul" : "Update Haul"}</Text>
|
||||
<InfoSection fishingLog={fishingLog!} stt={fishingLogIndex} />
|
||||
<FlatList
|
||||
data={fields}
|
||||
keyExtractor={(it) => it._id}
|
||||
|
||||
@@ -11,7 +11,6 @@ import {
|
||||
import styles from "../style/NetDetailModal.styles";
|
||||
import { CatchSectionHeader } from "./components/CatchSectionHeader";
|
||||
import { FishCardList } from "./components/FishCardList";
|
||||
import { InfoSection } from "./components/InfoSection";
|
||||
import { NotesSection } from "./components/NotesSection";
|
||||
|
||||
interface NetDetailModalProps {
|
||||
@@ -320,11 +319,11 @@ const NetDetailModal: React.FC<NetDetailModalProps> = ({
|
||||
{/* Content */}
|
||||
<ScrollView style={styles.content}>
|
||||
{/* Thông tin chung */}
|
||||
<InfoSection
|
||||
{/* <InfoSection
|
||||
netData={netData ?? undefined}
|
||||
isCompleted={isCompleted}
|
||||
stt={stt}
|
||||
/>
|
||||
/> */}
|
||||
|
||||
{/* Danh sách cá bắt được */}
|
||||
<CatchSectionHeader totalCatch={totalCatch} />
|
||||
|
||||
@@ -3,53 +3,52 @@ import { Text, View } from "react-native";
|
||||
import styles from "../../style/NetDetailModal.styles";
|
||||
|
||||
interface InfoSectionProps {
|
||||
netData?: Model.FishingLog;
|
||||
isCompleted: boolean;
|
||||
fishingLog?: Model.FishingLog;
|
||||
stt?: number;
|
||||
}
|
||||
|
||||
export const InfoSection: React.FC<InfoSectionProps> = ({
|
||||
netData,
|
||||
isCompleted,
|
||||
fishingLog,
|
||||
stt,
|
||||
}) => {
|
||||
if (!netData) {
|
||||
if (!fishingLog) {
|
||||
return null;
|
||||
}
|
||||
const infoItems = [
|
||||
{ label: "Số thứ tự", value: `Mẻ ${stt}` },
|
||||
{
|
||||
label: "Trạng thái",
|
||||
value: netData.status === 1 ? "Đã hoàn thành" : "Chưa hoàn thành",
|
||||
value: fishingLog.status === 1 ? "Đã hoàn thành" : "Chưa hoàn thành",
|
||||
isStatus: true,
|
||||
},
|
||||
{
|
||||
label: "Thời gian bắt đầu",
|
||||
value: netData.start_at
|
||||
? new Date(netData.start_at).toLocaleString()
|
||||
value: fishingLog.start_at
|
||||
? new Date(fishingLog.start_at).toLocaleString()
|
||||
: "Chưa cập nhật",
|
||||
},
|
||||
{
|
||||
label: "Thời gian kết thúc",
|
||||
value: netData.start_at
|
||||
? new Date(netData.end_at).toLocaleString()
|
||||
: "Chưa cập nhật",
|
||||
value:
|
||||
fishingLog.end_at !== "0001-01-01T00:00:00Z"
|
||||
? new Date(fishingLog.end_at).toLocaleString()
|
||||
: "-",
|
||||
},
|
||||
// {
|
||||
// label: "Vị trí hạ thu",
|
||||
// value: netData.viTriHaThu || "Chưa cập nhật",
|
||||
// value: fishingLog.viTriHaThu || "Chưa cập nhật",
|
||||
// },
|
||||
// {
|
||||
// label: "Vị trí thu lưới",
|
||||
// value: netData.viTriThuLuoi || "Chưa cập nhật",
|
||||
// value: fishingLog.viTriThuLuoi || "Chưa cập nhật",
|
||||
// },
|
||||
// {
|
||||
// label: "Độ sâu hạ thu",
|
||||
// value: netData.doSauHaThu || "Chưa cập nhật",
|
||||
// value: fishingLog.doSauHaThu || "Chưa cập nhật",
|
||||
// },
|
||||
// {
|
||||
// label: "Độ sâu thu lưới",
|
||||
// value: netData.doSauThuLuoi || "Chưa cập nhật",
|
||||
// value: fishingLog.doSauThuLuoi || "Chưa cập nhật",
|
||||
// },
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user