feat: 모듈 API 권한 관리 작업

This commit is contained in:
2025-04-17 14:10:47 +09:00
parent b05d407304
commit 524d08b620
12 changed files with 48 additions and 24 deletions
@@ -13,11 +13,13 @@ export interface RoleAuthorizations {
roleContent: string;
useYn: string;
authorizationNo: number;
authYn: string;
}
export const roleAuthorizationsSchema = z.object({
roleId: z.string(),
authorizationNo: z.number(),
authYn: z.string(),
});
export const roleAuthorizationsFormSchema = z.object({
@@ -1,25 +1,39 @@
import { type ColumnDef } from "@tanstack/react-table";
import type { RoleAuthorizations } from "./role-authorizations-interface";
import { Checkbox } from "@common/components/ui";
import type { UseFormReturn } from "react-hook-form";
import type { RoleAuthorizationsFormData } from "./role-authorizations-interface";
export const columns: ColumnDef<RoleAuthorizations>[] = [
export const createColumns = (
form: UseFormReturn<RoleAuthorizationsFormData>,
): ColumnDef<RoleAuthorizations>[] => [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={table.getIsAllPageRowsSelected()}
onClick={(e) => e.stopPropagation()}
onCheckedChange={(checked) =>
table.toggleAllPageRowsSelected(!!checked)
}
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={row.getIsSelected()}
onClick={(e) => e.stopPropagation()}
onCheckedChange={(checked) => row.toggleSelected(!!checked)}
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"
/>
),
@@ -32,7 +32,7 @@ import {
type RoleAuthorizationsFormData,
type RoleAuthorizationsData,
} from "../model/role-authorizations-interface";
import { columns } from "../model/role-authorizations-table-columns";
import { createColumns } from "../model/role-authorizations-table-columns";
import type { Authorizations } from "../model/authorizations-interface";
import { RoleAuthorizationsApi } from "../api/role-authorization-service";
@@ -70,13 +70,20 @@ function ManagementAuthorityDialog({
const form = useForm<RoleAuthorizationsFormData>({
resolver: zodResolver(roleAuthorizationsFormSchema),
values: {
roleAuthorizations: roleAuthorizationList?.content ?? [],
roleAuthorizations:
roleAuthorizationList?.content.map(
({ roleId, authorizationNo, useYn }) => ({
roleId,
authorizationNo,
authYn: useYn,
}),
) ?? [],
},
});
const table = useReactTable({
data: roleAuthorizationList?.content ?? [],
columns,
columns: createColumns(form),
state: {
rowSelection,
},