하수재이용 등록 수정
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead";
|
||||
import type { TableUpperProps } from "@/app/store/common/type/header";
|
||||
import type { chHeadType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
|
||||
import type { customPbnst as OriginalCustomPbnst } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
|
||||
import { selectClass, type TableUpperProps } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
import { DatePicker, SelectBox, type SelectDataType } from "@common/business_components/ui";
|
||||
import {
|
||||
DatePicker,
|
||||
SelectBox,
|
||||
type SelectDataType,
|
||||
} from "@common/business_components/ui";
|
||||
import {
|
||||
Checkbox,
|
||||
Input,
|
||||
@@ -20,43 +24,41 @@ type RuseMngTableProps = {
|
||||
tableData: any[];
|
||||
headList: TableUpperProps[];
|
||||
upHeadList: chHeadType[];
|
||||
code?: { name: string, val: SelectDataType[] }[];
|
||||
onTableSet?:(item:any)=> void;
|
||||
code?: { name: string; val: SelectDataType[] }[];
|
||||
onTableSet?: (item: any) => void;
|
||||
indexMng?: number;
|
||||
indexBiz?: number;
|
||||
};
|
||||
|
||||
const RuseMngTable = React.forwardRef<any, RuseMngTableProps>(
|
||||
({
|
||||
tableData,
|
||||
headList,
|
||||
upHeadList,
|
||||
code,
|
||||
onTableSet
|
||||
}, ref) => {
|
||||
(
|
||||
{ tableData, headList, upHeadList, code, onTableSet, indexMng, indexBiz },
|
||||
ref
|
||||
) => {
|
||||
const [tableState, setTableState] = useState([...tableData]);
|
||||
useEffect(() => {
|
||||
if (ref && typeof ref === "object" && "current" in ref) {
|
||||
ref.current = tableState;
|
||||
}
|
||||
if(onTableSet)
|
||||
onTableSet (tableState)
|
||||
}, [tableState,onTableSet]);
|
||||
if (onTableSet) onTableSet(tableState);
|
||||
}, [tableState, onTableSet]);
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if(tableData)
|
||||
setTableState(tableData);
|
||||
if (tableData) setTableState(tableData);
|
||||
}, [tableData]);
|
||||
return (
|
||||
<>
|
||||
<Table variant="secondary">
|
||||
<Table key={`table-${indexMng}-${indexBiz}`} variant="secondary">
|
||||
<TableHeader className="font-bold">
|
||||
{upHeadList ? (
|
||||
headMakeprfmnc(headList, upHeadList)
|
||||
) : (
|
||||
<TableRow key={"table-row-test"}>
|
||||
{headList.map((head) => (
|
||||
<TableHead key={"table-head-row " + head.id} className={`border border-gray-600 px-2 py-1 `}>
|
||||
<TableHead
|
||||
key={"table-head-row " + head.id}
|
||||
className={`border border-gray-600 px-2 py-1 `}
|
||||
>
|
||||
{head.title}
|
||||
</TableHead>
|
||||
))}
|
||||
@@ -71,54 +73,58 @@ const RuseMngTable = React.forwardRef<any, RuseMngTableProps>(
|
||||
<TableCell
|
||||
key={`${head.id}-${j}`}
|
||||
className="text-center whitespace-nowrap"
|
||||
onClick={() => { }}
|
||||
onClick={() => {}}
|
||||
>
|
||||
{head.edit === true ? (
|
||||
<Input
|
||||
className={`${head.type === "number" ? "text-right" : "text-center"} !text-xl`}
|
||||
type={head.type}
|
||||
onChange={(txt) => {
|
||||
setTableState(prev => {
|
||||
setTableState((prev) => {
|
||||
const next = [...prev];
|
||||
next[i] = { ...next[i], [head.id]: txt.target.value };
|
||||
next[i] = {
|
||||
...next[i],
|
||||
[head.id]: txt.target.value,
|
||||
};
|
||||
return next;
|
||||
})
|
||||
});
|
||||
}}
|
||||
value={head.type === "number" ?
|
||||
Number(tableState[i][head.id])||0 : tableState[i][head.id] || ""
|
||||
value={
|
||||
head.type === "number"
|
||||
? Number(tableState[i][head.id]) || 0
|
||||
: tableState[i][head.id] || ""
|
||||
}
|
||||
/>
|
||||
) : head.type === "select" ? (
|
||||
<SelectBox
|
||||
label=""
|
||||
selectArray={code?.find(item => item.name === head.selectData)?.val ?? []}
|
||||
value={
|
||||
tableState[i][head.id] || ""
|
||||
selectArray={
|
||||
code?.find((item) => item.name === head.selectData)
|
||||
?.val ?? []
|
||||
}
|
||||
value={tableState[i][head.id] || ""}
|
||||
className={""}
|
||||
selectClass={selectClass}
|
||||
onSelectValue={(val) => {
|
||||
setTableState((prev) => {
|
||||
prev[i][head.id] = val
|
||||
return [...prev]
|
||||
})
|
||||
prev[i][head.id] = val;
|
||||
return [...prev];
|
||||
});
|
||||
}}
|
||||
></SelectBox>
|
||||
) : head.type === "date" ? (
|
||||
<DatePicker
|
||||
mode="single"
|
||||
field={{
|
||||
value:
|
||||
tableState[i][head.id], // Provide a default Date value
|
||||
value: tableState[i][head.id], // Provide a default Date value
|
||||
onChange: (date) => {
|
||||
setTableState(prev => {
|
||||
setTableState((prev) => {
|
||||
const next = [...prev];
|
||||
next[i] = { ...next[i], [head.id]: date };
|
||||
return next;
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
}}
|
||||
selectClass={"w-full"}
|
||||
/>
|
||||
) : head.type === "checkbox" ? (
|
||||
@@ -128,14 +134,12 @@ const RuseMngTable = React.forwardRef<any, RuseMngTableProps>(
|
||||
onCheckedChange={(checked) => {
|
||||
console.log("checked", checked);
|
||||
setTableState((prev) => {
|
||||
prev[i][head.id] = checked
|
||||
return [...prev]
|
||||
})
|
||||
prev[i][head.id] = checked;
|
||||
return [...prev];
|
||||
});
|
||||
}}
|
||||
>
|
||||
</Checkbox>
|
||||
) :
|
||||
(
|
||||
></Checkbox>
|
||||
) : (
|
||||
`${item[head.id] || ""}`
|
||||
)}
|
||||
</TableCell>
|
||||
@@ -146,5 +150,6 @@ const RuseMngTable = React.forwardRef<any, RuseMngTableProps>(
|
||||
</Table>
|
||||
</>
|
||||
);
|
||||
})
|
||||
export default RuseMngTable;
|
||||
}
|
||||
);
|
||||
export default RuseMngTable;
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead";
|
||||
import type { TableUpperProps } from "@/app/store/common/type/header";
|
||||
import type { chHeadType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
|
||||
import type { customPbnst as OriginalCustomPbnst } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg";
|
||||
|
||||
import {
|
||||
DatePicker,
|
||||
FormField,
|
||||
FormUi,
|
||||
SelectBox,
|
||||
type SelectDataType,
|
||||
} from "@common/business_components/ui";
|
||||
import {
|
||||
Checkbox,
|
||||
Input,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@common/components/ui";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
type RuseMngTableProps = {
|
||||
tableData: any[];
|
||||
headList: TableUpperProps[];
|
||||
upHeadList: chHeadType[];
|
||||
code?: { name: string; val: SelectDataType[] }[];
|
||||
onTableSet?: (item: any) => void;
|
||||
indexMng?: number;
|
||||
indexBiz?: number;
|
||||
form?: any;
|
||||
formNm?:string
|
||||
};
|
||||
|
||||
const RuseMngTableForm = React.forwardRef<any, RuseMngTableProps>(
|
||||
({ tableData, headList, upHeadList, code, onTableSet, indexMng, form,formNm,indexBiz }, ref) => {
|
||||
// const [tableState, setTableState] = useState([...tableData]);
|
||||
|
||||
// // useEffect(() => {
|
||||
|
||||
// // if (ref && typeof ref === "object" && "current" in ref) {
|
||||
// // ref.current = tableState;
|
||||
// // }
|
||||
// // if (onTableSet) onTableSet(tableState);
|
||||
// // }, [tableState, onTableSet]);
|
||||
|
||||
// useEffect(() => {
|
||||
|
||||
// if (tableData)
|
||||
// setTableState(tableData);
|
||||
// }, [tableData]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Table key={`table-${indexMng}-${indexBiz}`} variant="secondary">
|
||||
<TableHeader className="font-bold">
|
||||
{upHeadList ? (
|
||||
headMakeprfmnc(headList, upHeadList)
|
||||
) : (
|
||||
<TableRow key={"table-row-test"}>
|
||||
{headList.map((head) => (
|
||||
<TableHead
|
||||
key={"table-head-row " + head.id}
|
||||
className={`border border-gray-600 px-2 py-1 `}
|
||||
>
|
||||
{head.title}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
)}
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{tableData.map((item, i) => (
|
||||
<TableRow key={i}>
|
||||
{headList.map((head, j) => (
|
||||
<TableCell
|
||||
key={`${head.id}-${j}`}
|
||||
className="text-center whitespace-nowrap"
|
||||
onClick={() => {}}
|
||||
>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name={
|
||||
typeof indexMng === "number" &&
|
||||
indexMng >= 0 &&
|
||||
typeof indexBiz === "number" &&
|
||||
indexBiz >= 0?
|
||||
`items.${indexMng}.fcBizs.${indexBiz}.${formNm}.${i}.${head.id}`:
|
||||
typeof indexMng === "number" && indexMng >= 0?
|
||||
`items.${indexMng}.${formNm}.${i}.${head.id}`:
|
||||
`items.${indexMng}.${formNm}.${i}.${head.id}`}
|
||||
render={({ field }) => (
|
||||
<FormUi label="">
|
||||
{head.edit === true ? (
|
||||
<Input
|
||||
className={`${head.type === "number" ? "text-right" : "text-center"} !text-xl`}
|
||||
type={head.type}
|
||||
onChange={(txt) => {
|
||||
field.onChange(txt.target.value);
|
||||
}}
|
||||
value={
|
||||
head.type === "number"
|
||||
? (Number(field.value) ?? 0)
|
||||
: field.value || ""
|
||||
}
|
||||
/>
|
||||
) : head.type === "select" ? (
|
||||
<SelectBox
|
||||
label=""
|
||||
selectArray={
|
||||
code?.find(
|
||||
(item) => item.name === head.selectData
|
||||
)?.val ?? []
|
||||
}
|
||||
value={
|
||||
field.value || ""
|
||||
}
|
||||
className={""}
|
||||
selectClass={selectClass}
|
||||
onSelectValue={(val) => {
|
||||
field.onChange(val);
|
||||
}}
|
||||
></SelectBox>
|
||||
) : head.type === "date" ? (
|
||||
<DatePicker
|
||||
mode="single"
|
||||
field={{
|
||||
value: field.value || new Date(),
|
||||
onChange: (date: Date | undefined) =>
|
||||
field.onChange(date),
|
||||
}}
|
||||
selectClass={"w-full"}
|
||||
/>
|
||||
) : head.type === "checkbox" ? (
|
||||
<Checkbox
|
||||
className=""
|
||||
checked={ field.value || false}
|
||||
onCheckedChange={(checked) => {
|
||||
field.onChange(checked);
|
||||
|
||||
}}
|
||||
></Checkbox>
|
||||
) : (
|
||||
`${item[head.id] || ""}`
|
||||
)}
|
||||
</FormUi>
|
||||
)}
|
||||
/>
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</>
|
||||
);
|
||||
}
|
||||
);
|
||||
export default RuseMngTableForm;
|
||||
Reference in New Issue
Block a user