import { excelToPbnPrfData } from "@/app/store/prfmncReg/pbnstPrfmncReg/excel"; import { pbnPrfRegExcelZod } from "@/app/store/prfmncReg/pbnstPrfmncReg/headList"; import type { FcPrfType, PrfType, } from "@/app/store/prfmncReg/pbnstPrfmncReg/type"; import { yearOptions } from "@/components/lib/func/commom"; import { FormField, FormUi, SelectBox, Form, Title, filePicked, } from "@common/business_components/ui"; import { Button, Input } from "@common/components/ui"; import { zodResolver } from "@hookform/resolvers/zod"; import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import toast from "react-hot-toast"; import type { z } from "zod"; export default function PbnPrfExcelModal({ data, setIsExcelOPen, setModalExcelData, }: { data: FcPrfType; setIsExcelOPen: (open: boolean) => void; setModalExcelData: (excelData: PrfType) => void; }) { const [file, setFile] = useState(null); const [excelData, setExcelData] = useState(); const form = useForm>({ resolver: zodResolver(pbnPrfRegExcelZod), defaultValues: { ym: String(new Date().getFullYear()), }, }); const handleFileChange = (e: React.ChangeEvent) => { const selectedFile = e.target.files?.[0]; if (selectedFile) { setFile(selectedFile); } }; const onSubmit = (values: z.infer) => { if (excelData) { ////TODO: 궅이 서브밋을 써야하는 이유가 있는지 ? console.log("values ", values); // prfmnRegData(1,'41', excelData as unknown as PrfType); 활성화시 스토어 활성화 칠요 setModalExcelData(excelData as unknown as PrfType); setIsExcelOPen(false); } }; useEffect(() => { if (data && data.bscFctNm) form.setValue("pbnstRuseFcltId", data.pbnstRuseFcltId); form.setValue("bscFctNm", data.bscFctNm || ""); form.setValue("pbnstRuseFcltNm", data.ruseUtztnFcltNm); }, [data]); useEffect(() => { if (file) { const isFile = file; if (form.getValues("ym").length < 1) { toast.error("파일업로드 이전에 등록년도를 작성해주세요 "); setFile(null); return; } if (isFile) { filePicked(isFile, 0).then((res) => { if (res !== undefined) setExcelData( excelToPbnPrfData( res as unknown as JSON[], form.getValues("ym"), form.getValues("pbnstRuseFcltId") ) as PrfType[] ); }); } } }, [file]); return ( <>

{"점검정보 입력"}

( field.onChange(val)} /> )} />
( )} />
( )} />
( {/* { if (files) setFiles(files); }} fileTypes="xlsx" maxFiles={1} > */}
{ console.log(" field. valus", field.value); if (file) handleFileChange(file); }} accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
)} />
); }