Merge commit '66df8b21b3939af172a66f8a562faad2dadbca49' into iipbs/wr/hasuReg
This commit is contained in:
@@ -15,7 +15,8 @@ import {
|
||||
SelectBox,
|
||||
type SelectDataType,
|
||||
} from "@common/business_components";
|
||||
import { Button, Input } from "@common/components";
|
||||
import { Button, Checkbox, Input } from "@common/components";
|
||||
import { Check } from "lucide-react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useFieldArray } from "react-hook-form";
|
||||
|
||||
@@ -42,18 +43,15 @@ export default function BdstReg({ form }: { form: any }) {
|
||||
// remove(fields.length - 1);
|
||||
// }
|
||||
// };
|
||||
// 이건 삭제해도되는거
|
||||
const removeSelected = () => {
|
||||
// fields 배열에서 selectedIds 에 포함된 field.id 의 인덱스만 골라내기
|
||||
const idxsToRemove = fields
|
||||
.map((f, i) => selectedIds.includes(f.id) ? i : -1)
|
||||
.filter(i => i > -1)
|
||||
// 내림차순 정렬: 인덱스 뒤쪽부터 제거해야 안전합니다.
|
||||
.sort((a,b) => b - a);
|
||||
.map((item, idx) => selectedIds.includes(item.id) ? idx : -1)
|
||||
.filter(index => index > -1)
|
||||
.sort((prevIndex, nextIndex) => nextIndex - prevIndex);
|
||||
|
||||
remove(idxsToRemove);
|
||||
setSelectedIds([]);
|
||||
};
|
||||
remove(idxsToRemove);
|
||||
setSelectedIds([]);
|
||||
};
|
||||
|
||||
|
||||
const [selectSgg, setSelectSgg] = useState<SelectDataType[] | undefined>();
|
||||
@@ -89,9 +87,6 @@ export default function BdstReg({ form }: { form: any }) {
|
||||
return () => subscription?.unsubscribe();
|
||||
}, [form.form]);
|
||||
|
||||
|
||||
|
||||
// 여기서부터는 자유롭게 삭제 가능
|
||||
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
||||
|
||||
const toggleSelect = (id: string) => {
|
||||
@@ -280,19 +275,13 @@ export default function BdstReg({ form }: { form: any }) {
|
||||
</Button>
|
||||
</div>
|
||||
{fields.map((field, index) => (
|
||||
//여기서부터 자유롭게 삭제 가능
|
||||
<div key={field.id} className="grid grid-cols-[auto,1fr,1fr,1fr] gap-2 mt-4 items-center">
|
||||
{/* 1) 체크박스 */}
|
||||
<div className="col-span-1 flex justify-center mr-4">
|
||||
<input
|
||||
type="checkbox"
|
||||
<Checkbox
|
||||
checked={selectedIds.includes(field.id)}
|
||||
onChange={() => toggleSelect(field.id)}
|
||||
className="h-6 w-6"
|
||||
onCheckedChange={() => toggleSelect(field.id)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 2) 구분 */}
|
||||
<div className="">
|
||||
<FormField
|
||||
control={form.control}
|
||||
@@ -308,8 +297,6 @@ export default function BdstReg({ form }: { form: any }) {
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 3) 허가일 */}
|
||||
<div className="">
|
||||
<FormField
|
||||
control={form.control}
|
||||
@@ -328,8 +315,6 @@ export default function BdstReg({ form }: { form: any }) {
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 4) 면적 */}
|
||||
<div className="">
|
||||
<FormField
|
||||
control={form.control}
|
||||
|
||||
@@ -9,8 +9,8 @@ import {
|
||||
import { Form, FormField } from "@common/business_components/ui/form";
|
||||
import { Button, Input, Label, TableHead, TableRow } from "@common/components";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { use, useEffect, useState } from "react";
|
||||
import { set, useFieldArray, useForm } from "react-hook-form";
|
||||
import { use, useEffect, useRef, useState } from "react";
|
||||
import { z } from "zod";
|
||||
import { useWrStore } from "@/app/store";
|
||||
import {
|
||||
@@ -42,6 +42,10 @@ import RuseMngTable from "@/components/ui/table/pbnstReg/ruseMngTable/ruseMngTab
|
||||
import FcOrgwtsRegModal from "@/components/ui/modal/fcltReg/fcOrgwtsRegModal/fcOrgwtsRegModal";
|
||||
|
||||
export function PbnstBuseForm({ data }: { data: fcBizType[] }) {
|
||||
// const ref = useRef<ppInstlType[] | null>(data[0]?.pplInstls ?? null);
|
||||
const ref = useRef<ppInstlType[] | null>(
|
||||
Array.isArray(data) && data.length > 0 ? data[0]?.pplInstls ?? null : null
|
||||
);
|
||||
const { code, pbnst } = useWrStore((state) => state);
|
||||
const { pbnstBizCycle, pbnstRes } = pbnst;
|
||||
const [getBizCycle, setBizCycle] = useState("1");
|
||||
@@ -66,27 +70,38 @@ const [ isFcOrgwts, setIsFcOrgwts] = useState<boolean>(false);
|
||||
name: "fcOrgwts",
|
||||
});
|
||||
|
||||
const { fields: pplInstls } = useFieldArray({
|
||||
const { fields: pplInstls, append, remove } = useFieldArray({
|
||||
control: form.control,
|
||||
name: "pplInstls",
|
||||
});
|
||||
|
||||
|
||||
const fcOrgwtsReg = () =>{
|
||||
|
||||
const plusHist = () => {
|
||||
append({
|
||||
choose: false,
|
||||
ppMqlt: "",
|
||||
pdmt: "",
|
||||
cpct: "",
|
||||
});
|
||||
};
|
||||
|
||||
console.log("fcOrgwtsReg");
|
||||
//ref로바꿔야함
|
||||
setFcOrgwts({isOpen:true , data:fcOrgwtFiled as fcOrgwtType[]});
|
||||
|
||||
|
||||
}
|
||||
|
||||
const removeSelected = () => {
|
||||
if(!ref.current) return;
|
||||
const selectedIdxs = ref.current
|
||||
.map((item, idx) => (item.choose ? idx : -1))
|
||||
.filter((idx) => idx !== -1);
|
||||
selectedIdxs.reverse().forEach((idx) => remove(idx));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
const index = Number(getBizCycle) - 1;
|
||||
form.reset(data[index]);
|
||||
ref.current = data[index]?.pplInstls ?? null;
|
||||
console.log("form reset with data:", data[index]);
|
||||
|
||||
|
||||
}
|
||||
}, [getBizCycle, data]);
|
||||
|
||||
@@ -202,10 +217,22 @@ const [ isFcOrgwts, setIsFcOrgwts] = useState<boolean>(false);
|
||||
readOnly
|
||||
className="w-32 border-gray-300 rounded pr-8 "
|
||||
/>
|
||||
<Button className="ml-7" size={commonButonSize}>
|
||||
추가등록
|
||||
</Button>
|
||||
<Button size={commonButonSize}>삭제</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size={commonButonSize}
|
||||
className="!text-xl"
|
||||
onClick={plusHist}
|
||||
>
|
||||
추가등록
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size={commonButonSize}
|
||||
className="!text-xl !bg-red-500 !text-white ml-1"
|
||||
onClick={removeSelected}
|
||||
>
|
||||
삭제
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -213,7 +240,8 @@ const [ isFcOrgwts, setIsFcOrgwts] = useState<boolean>(false);
|
||||
tableData={pplInstls}
|
||||
headList={pbnst.pplInstlsHeadLisat}
|
||||
code={ppiSelectList ?? []}
|
||||
/>
|
||||
ref={ref}
|
||||
upHeadList={[]} />
|
||||
</div>
|
||||
|
||||
<MngRegFormDetail
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import { SelectBox } from "@common/business_components";
|
||||
import { FileUpload, FormUi, UiTable } from "@common/business_components/ui";
|
||||
import { Form, FormField } from "@common/business_components/ui/form";
|
||||
import { Button, Input, TableHead, TableRow } from "@common/components";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { use, useEffect, useRef, useState } from "react";
|
||||
import { set, useFieldArray, useForm } from "react-hook-form";
|
||||
import { nullable, z } from "zod";
|
||||
import { useWrStore } from "@/app/store";
|
||||
import {
|
||||
selectClass,
|
||||
type TableUpperProps,
|
||||
} from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
import { FileUpload, FormUi } from "@common/business_components/ui";
|
||||
import { Form, FormField } from "@common/business_components/ui/form";
|
||||
import { Button, Input } from "@common/components";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useFieldArray, useForm } from "react-hook-form";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
commonButonSize,
|
||||
formH1Class,
|
||||
formH2Class,
|
||||
formTableName,
|
||||
formTableName
|
||||
} from "@/components/lib/class/comClass";
|
||||
import RuseMngTable from "@/components/ui/table/pbnstReg/ruseMngTable/ruseMngTable";
|
||||
import { TusClientUpload } from "@/components/lib/useTus_wr/useTusWr";
|
||||
import RuseMngTable from "@/components/ui/table/pbnstReg/ruseMngTable/ruseMngTable";
|
||||
import type { Upload } from "tus-js-client";
|
||||
import {
|
||||
pbnstRegZod,
|
||||
@@ -33,6 +27,7 @@ export type FilesType = {
|
||||
atflCd: String;
|
||||
file: File;
|
||||
};
|
||||
|
||||
export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
const { pbnst, pbnstUpdate } = useWrStore((state) => state);
|
||||
const { pbnstMngUpHeadList } = pbnst;
|
||||
@@ -48,17 +43,42 @@ export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
setProgress(Number(percentage));
|
||||
};
|
||||
|
||||
const ref = useRef<operType[] | null>(data.fcOpers ?? null);
|
||||
const ref = useRef<operType[] | null>(data?.fcOpers ?? null);
|
||||
const form = useForm<z.infer<typeof pbnstRegZod>>({
|
||||
resolver: zodResolver(pbnstRegZod),
|
||||
defaultValues: pbnstRegZod.parse({}),
|
||||
});
|
||||
|
||||
const { fields: fcOpersField } = useFieldArray({
|
||||
|
||||
const { fields: fcOpersField, append, remove } = useFieldArray({
|
||||
control: form.control,
|
||||
name: "fcOpers",
|
||||
});
|
||||
|
||||
const plusHist = () => {
|
||||
append({
|
||||
choose: false,
|
||||
rgtr: "",
|
||||
mdfr: "",
|
||||
pbnstRuseFcltFk: 0,
|
||||
pbnstRuseFcltOperInfoPk: 0,
|
||||
operMthd: "",
|
||||
rprtvBzenty: "",
|
||||
bgngDt: new Date(),
|
||||
endDt: new Date(),
|
||||
});
|
||||
};
|
||||
|
||||
const removeSelected = () => {
|
||||
console.log("ref", ref.current);
|
||||
console.log("fcOpersField", fcOpersField);
|
||||
if(!ref.current) return;
|
||||
const selectedIdxs = ref.current
|
||||
.map((item, idx) => (item.choose ? idx : -1))
|
||||
.filter(idx => idx !== -1);
|
||||
selectedIdxs.reverse().forEach(idx => remove(idx));
|
||||
};
|
||||
|
||||
const onSelectValue = (val: string) => {};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -71,6 +91,9 @@ export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
console.log("submit", values);
|
||||
testFile;
|
||||
// pbnstUpdate(values);
|
||||
values.fcOpers = ref.current || [];
|
||||
console.log("form values:", values);
|
||||
pbnstUpdate(values);
|
||||
}
|
||||
const fileHandler = (files:File[]) => {
|
||||
const setReFiles = [...(relationfiles || [])];
|
||||
@@ -105,8 +128,21 @@ export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
setRelationFiles(setReFiles);
|
||||
};
|
||||
const testFile = () => {
|
||||
if (relationfiles && relationfiles[0])
|
||||
TusClientUpload(relationfiles[0], setUpload);
|
||||
// if (relationfiles && relationfiles[0])
|
||||
// TusClientUpload(relationfiles[0], setUpload, {
|
||||
// handleUploadStart: () => {
|
||||
// console.log("handleUploadStart");
|
||||
// },
|
||||
// handleProgress,
|
||||
// handleResponse: (req, res) => {
|
||||
// console.log("handleResponse req", req);
|
||||
// console.log("handleResponse res", res);
|
||||
// },
|
||||
// handleSuccess: (a) => {
|
||||
// console.log("req", a);
|
||||
|
||||
// },
|
||||
// });
|
||||
};
|
||||
useEffect(() => {
|
||||
console.log("form errors:", form.formState.errors);
|
||||
@@ -132,20 +168,31 @@ export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
<Button type="submit" size={commonButonSize}>
|
||||
저장
|
||||
</Button>
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="h-[200px] overflow-y-auto">
|
||||
<div className="h-[200px] overflow-y-auto">
|
||||
<div className="flex justify-between items-center mx-3 mb-3">
|
||||
<span className={formTableName}>재이용시설 운영정보</span>
|
||||
<div>
|
||||
<Button
|
||||
type="button"
|
||||
size={commonButonSize}
|
||||
className="!text-xl"
|
||||
onClick={() => testFile()}
|
||||
onClick={plusHist}
|
||||
>
|
||||
추가등록
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
size={commonButonSize}
|
||||
className="!text-xl !bg-red-500 !text-white ml-1"
|
||||
onClick={removeSelected}
|
||||
>
|
||||
삭제
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<RuseMngTable
|
||||
tableData={fcOpersField}
|
||||
@@ -158,7 +205,7 @@ export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
<div>
|
||||
<h1 className={formH1Class}>재이용수 공급 가능량</h1>
|
||||
<div className="grid grid-cols-12 gap-4">
|
||||
<div className="col-span-3">
|
||||
<div className="col-span-3 mt-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="fcltCpct"
|
||||
@@ -174,7 +221,7 @@ export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-3">
|
||||
<div className="col-span-3 mt-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="hasuhasu"
|
||||
@@ -190,7 +237,7 @@ export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-3">
|
||||
<div className="col-span-3 mt-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="ruseCpct"
|
||||
@@ -206,7 +253,7 @@ export function PbnstMngForm({ data }: { data: customPbnst }) {
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-3">
|
||||
<div className="col-span-3 mt-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="splyExtraCpct"
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ export default function MngRegFormDetail({
|
||||
onSelect={(date: Date | undefined) =>
|
||||
field.onChange(date)
|
||||
}
|
||||
className={"rounded-lg w-full"}
|
||||
className={"rounded-lg !w-full"}
|
||||
/>
|
||||
) : item.type === "number" ? (
|
||||
<Input placeholder="" type="number" value={field.value??0} onChange={field.onChange} />
|
||||
|
||||
Reference in New Issue
Block a user