diff --git a/components/tripInfo/NetListTable.tsx b/components/tripInfo/NetListTable.tsx index 7bde79c..949d931 100644 --- a/components/tripInfo/NetListTable.tsx +++ b/components/tripInfo/NetListTable.tsx @@ -160,13 +160,6 @@ const NetListTable: React.FC = () => { setModalVisible(false); }} netData={selectedNet} - stt={ - selectedNet - ? data.findIndex( - (item) => item.fishing_log_id === selectedNet.fishing_log_id - ) + 1 - : undefined - } /> */} ); diff --git a/components/tripInfo/modal/CreateOrUpdateHaulModal.tsx b/components/tripInfo/modal/CreateOrUpdateHaulModal.tsx index 4800af8..0950202 100644 --- a/components/tripInfo/modal/CreateOrUpdateHaulModal.tsx +++ b/components/tripInfo/modal/CreateOrUpdateHaulModal.tsx @@ -1,11 +1,20 @@ import Select from "@/components/Select"; +import { IconSymbol } from "@/components/ui/icon-symbol"; import { useFishes } from "@/state/use-fish"; import { zodResolver } from "@hookform/resolvers/zod"; import React from "react"; import { Controller, useFieldArray, useForm } from "react-hook-form"; -import { Button, FlatList, Modal, Text, TextInput, View } from "react-native"; +import { + Modal, + ScrollView, + Text, + TextInput, + TouchableOpacity, + View, +} from "react-native"; import { z } from "zod"; import { InfoSection } from "./NetDetailModal/components"; +import styles from "./style/CreateOrUpdateHaulModal.styles"; interface CreateOrUpdateHaulModalProps { isVisible: boolean; @@ -52,9 +61,13 @@ const CreateOrUpdateHaulModal: React.FC = ({ isVisible, onClose, fishingLog, - fishingLogIndex + fishingLogIndex, }) => { const [isCreateMode, setIsCreateMode] = React.useState(!fishingLog?.info); + const [isEditing, setIsEditing] = React.useState(false); + const [expandedFishIndices, setExpandedFishIndices] = React.useState< + number[] + >([]); const { control, handleSubmit, formState, watch, reset } = useForm({ resolver: zodResolver(formSchema), @@ -74,6 +87,12 @@ const CreateOrUpdateHaulModal: React.FC = ({ keyName: "_id", // tránh đụng key }); + const handleToggleExpanded = (index: number) => { + setExpandedFishIndices((prev) => + prev.includes(index) ? prev.filter((i) => i !== index) : [...prev, index] + ); + }; + const onSubmit = (values: FormValues) => { // Map form values to the FishingLogInfo-like shape the user requested const mapped = values.fish.map((f) => { @@ -102,6 +121,8 @@ const CreateOrUpdateHaulModal: React.FC = ({ // when modal closed, clear form to default reset({ fish: [defaultItem()] }); setIsCreateMode(true); + setIsEditing(false); + setExpandedFishIndices([]); return; } @@ -110,6 +131,8 @@ const CreateOrUpdateHaulModal: React.FC = ({ // explicit null -> start with a single default item reset({ fish: [defaultItem()] }); setIsCreateMode(true); + setIsEditing(true); // allow editing for new haul + setExpandedFishIndices([0]); // expand first item } else if (Array.isArray(fishingLog?.info) && fishingLog?.info.length > 0) { // map FishingLogInfo -> form rows const mapped = fishingLog.info.map((h) => ({ @@ -120,132 +143,212 @@ const CreateOrUpdateHaulModal: React.FC = ({ })); reset({ fish: mapped as any }); setIsCreateMode(false); + setIsEditing(false); // view mode by default + setExpandedFishIndices([]); // all collapsed } else { // undefined or empty array -> default reset({ fish: [defaultItem()] }); setIsCreateMode(true); + setIsEditing(true); // allow editing for new haul + setExpandedFishIndices([0]); // expand first item } }, [isVisible, fishingLog?.info, reset]); - const renderRow = ({ item, index }: { item: any; index: number }) => { + const renderRow = (item: any, index: number) => { + const isExpanded = expandedFishIndices.includes(index); + return ( - - - Loài cá #{index + 1} - - - {/* Species dropdown */} - ( - - Tên cá - ({ - label: unit.label, - value: unit.value, - }))} - value={value} - onChange={onChange} - placeholder="Chọn đơn vị" - /> - {errors.fish?.[index]?.unit && ( - - {errors.fish[index]?.unit?.message as string} - - )} - - )} - /> - - {/* Size (optional) */} - ( - - - Kích thước (cm) — tùy chọn - - - onChange(t ? Number(t.replace(/,/g, ".")) : undefined) - } - style={{ padding: 10, borderWidth: 1, borderRadius: 6 }} - /> - {errors.fish?.[index]?.size && ( - - {errors.fish[index]?.size?.message as string} - - )} - - )} - /> - - {/* Remove row */} - -