import { useWrStore } from "@/app/store"; import { sttnHeadListType } from "@/app/store/ruseFcltMng/fcltSttn/rainSttn/headList"; import { Form, FormControl, FormField, FormItem, FormLabel, } from "@common/business_components/ui"; import { Button, Checkbox } from "@common/components/ui"; import { zodResolver } from "@hookform/resolvers/zod"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; export default function HeadChModal({ headList, type }: { headList: z.infer, type: string }) { const { rainChSttnHead, rswtChSttnHead, htdflChSttnHead, pbnstChSttnHead } = useWrStore((state) => state); const items = headList.map(item => ({ id: item.id, title: item.title, val: item.visible })); const form = useForm>({ resolver: zodResolver(sttnHeadListType), defaultValues: headList, }); useEffect(() => { form.reset(headList); }, [headList, form]); const rawValues = form.watch(); const values: Array<{ visible: boolean }> = Array.isArray(rawValues) ? rawValues : Object.values(rawValues); const allChecked = values.every((v) => v.visible); const toggleAll = (checked: boolean) => { const newValues = values.map((v) => ({ ...v, visible: checked })); form.reset(newValues); }; const onSubmit = (valueList: z.infer) => { if (type === 'RNB') { rainChSttnHead(valueList) } else if (type === 'RST') { rswtChSttnHead(valueList) } else if (type === 'HTB') { htdflChSttnHead(valueList) } else if (type === 'PBN') { pbnstChSttnHead(valueList) } } return ( <>

조회항목 설정

{/* 전체 선택/해제 체크박스 */} toggleAll(checked as boolean)} /> 전체 {items.map((item, index) => ( { return ( { field.onChange(checked); return; } } /> {item.title} ); }} /> ))}
); }