Files
frontend/apps/cs/src/pages/module/model/role-authorizations-table-columns.tsx
T

54 lines
1.5 KiB
TypeScript

import type { ColumnDef } from "@tanstack/react-table";
import type { UseFormReturn } from "react-hook-form";
import { Checkbox } from "@common/components";
import type { RoleAuthorizations } from "./role-authorizations-interface";
import type { RoleAuthorizationsFormData } from "./role-authorizations-interface";
export const createColumns = (
form: UseFormReturn<RoleAuthorizationsFormData>,
): ColumnDef<RoleAuthorizations>[] => [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={form
.watch("roleAuthorizations")
.every((role) => role.authYn === "Y")}
onCheckedChange={(checked) => {
table.getRowModel().rows.forEach((row, index) => {
form.setValue(
`roleAuthorizations.${index}.authYn`,
checked ? "Y" : "N",
);
});
}}
className="h-4 w-4 rounded border-gray-300"
/>
),
cell: ({ row }) => (
<Checkbox
checked={form.watch(`roleAuthorizations.${row.index}.authYn`) === "Y"}
onCheckedChange={(checked) => {
form.setValue(
`roleAuthorizations.${row.index}.authYn`,
checked ? "Y" : "N",
);
}}
className="h-4 w-4 rounded border-gray-300"
/>
),
},
{
accessorKey: "roleId",
header: "권한ID",
},
{
accessorKey: "roleName",
header: "권한명",
},
{
accessorKey: "roleContent",
header: "권한설명",
},
];