118 lines
3.3 KiB
TypeScript
118 lines
3.3 KiB
TypeScript
import type { ColumnDef } from "@tanstack/react-table";
|
|
import type { UseFormReturn } from "react-hook-form";
|
|
import { Checkbox } from "@common/components";
|
|
import type {
|
|
MenuAuthority,
|
|
MenuAuthorityFormData,
|
|
MenuAuthorityPayload,
|
|
} from "./menu-authority-interface";
|
|
|
|
export const createColumns = (
|
|
form: UseFormReturn<MenuAuthorityFormData>,
|
|
): ColumnDef<MenuAuthority>[] => {
|
|
const getCurrentRow = (i: number) => form.watch("menuAuthority")[i];
|
|
|
|
const handleCheckedChange =
|
|
(i: number, key: keyof MenuAuthorityPayload) => (checked: boolean) => {
|
|
if (getCurrentRow(i)?.mode === "R") {
|
|
form.setValue(`menuAuthority.${i}.mode`, "U");
|
|
}
|
|
form.setValue(`menuAuthority.${i}.${key}`, checked ? "Y" : "N");
|
|
};
|
|
|
|
return [
|
|
{
|
|
accessorKey: "groupNm",
|
|
header: "그룹명",
|
|
},
|
|
{
|
|
accessorKey: "mngAuthrtYn",
|
|
header: "관리권한",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<Checkbox
|
|
checked={getCurrentRow(row.index)?.mngAuthrtYn === "Y"}
|
|
onCheckedChange={(checked) => {
|
|
if (checked) {
|
|
handleCheckedChange(
|
|
row.index,
|
|
"regAuthrtYn",
|
|
)(checked as boolean);
|
|
handleCheckedChange(
|
|
row.index,
|
|
"mdfcnAuthrtYn",
|
|
)(checked as boolean);
|
|
handleCheckedChange(
|
|
row.index,
|
|
"delAuthrtYn",
|
|
)(checked as boolean);
|
|
handleCheckedChange(
|
|
row.index,
|
|
"inqAuthrtYn",
|
|
)(checked as boolean);
|
|
}
|
|
handleCheckedChange(row.index, "mngAuthrtYn")(checked as boolean);
|
|
}}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "regAuthrtYn",
|
|
header: "등록권한",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<Checkbox
|
|
checked={getCurrentRow(row.index)?.regAuthrtYn === "Y"}
|
|
onCheckedChange={(checked) => {
|
|
if (checked) {
|
|
handleCheckedChange(
|
|
row.index,
|
|
"inqAuthrtYn",
|
|
)(checked as boolean);
|
|
}
|
|
handleCheckedChange(row.index, "regAuthrtYn")(checked as boolean);
|
|
}}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "mdfcnAuthrtYn",
|
|
header: "수정권한 ",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<Checkbox
|
|
checked={getCurrentRow(row.index)?.mdfcnAuthrtYn === "Y"}
|
|
onCheckedChange={handleCheckedChange(row.index, "mdfcnAuthrtYn")}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "delAuthrtYn",
|
|
header: "삭제권한",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<Checkbox
|
|
checked={getCurrentRow(row.index)?.delAuthrtYn === "Y"}
|
|
onCheckedChange={handleCheckedChange(row.index, "delAuthrtYn")}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "inqAuthrtYn",
|
|
header: "조회권한",
|
|
cell: ({ row }) => {
|
|
return (
|
|
<Checkbox
|
|
checked={getCurrentRow(row.index)?.inqAuthrtYn === "Y"}
|
|
onCheckedChange={handleCheckedChange(row.index, "inqAuthrtYn")}
|
|
/>
|
|
);
|
|
},
|
|
},
|
|
];
|
|
};
|