diff --git a/apps/cs/src/pages/groups/model/group-menu-authority-table-columns.tsx b/apps/cs/src/pages/groups/model/group-menu-authority-table-columns.tsx index 0a56a6701..3e26e1106 100644 --- a/apps/cs/src/pages/groups/model/group-menu-authority-table-columns.tsx +++ b/apps/cs/src/pages/groups/model/group-menu-authority-table-columns.tsx @@ -11,6 +11,7 @@ export const createColumns = ( form: UseFormReturn, ): ColumnDef[] => { const getCurrentRow = (i: number) => form.watch("menuAuthority")[i]; + const menuAuthorityData = form.watch("menuAuthority"); const handleCheckedChange = (i: number, key: keyof MenuAuthorityPayload) => (checked: boolean) => { @@ -20,6 +21,19 @@ export const createColumns = ( form.setValue(`menuAuthority.${i}.${key}`, checked ? "Y" : "N"); }; + const handleHeaderCheckedChange = (key: keyof MenuAuthorityPayload) => (checked: boolean) => { + menuAuthorityData.forEach((_, index) => { + if (getCurrentRow(index)?.mode === "R") { + form.setValue(`menuAuthority.${index}.mode`, "U"); + } + form.setValue(`menuAuthority.${index}.${key}`, checked ? "Y" : "N"); + }); + }; + + const isAllChecked = (key: keyof MenuAuthorityPayload) => { + return menuAuthorityData.every((item) => item?.[key] === "Y"); + }; + return [ { accessorKey: "menuNm", @@ -27,7 +41,41 @@ export const createColumns = ( }, { accessorKey: "mngAuthrtYn", - header: "관리권한", + header: () => ( +
+ 관리권한 + { + if (checked) { + // 관리권한 체크시 모든 권한 체크 + menuAuthorityData.forEach((_, index) => { + if (getCurrentRow(index)?.mode === "R") { + form.setValue(`menuAuthority.${index}.mode`, "U"); + } + form.setValue(`menuAuthority.${index}.regAuthrtYn`, "Y"); + form.setValue(`menuAuthority.${index}.mdfcnAuthrtYn`, "Y"); + form.setValue(`menuAuthority.${index}.delAuthrtYn`, "Y"); + form.setValue(`menuAuthority.${index}.inqAuthrtYn`, "Y"); + form.setValue(`menuAuthority.${index}.mngAuthrtYn`, "Y"); + }); + } else { + // 관리권한 해제시 모든 권한 해제 + menuAuthorityData.forEach((_, index) => { + if (getCurrentRow(index)?.mode === "R") { + form.setValue(`menuAuthority.${index}.mode`, "U"); + } + form.setValue(`menuAuthority.${index}.regAuthrtYn`, "N"); + form.setValue(`menuAuthority.${index}.mdfcnAuthrtYn`, "N"); + form.setValue(`menuAuthority.${index}.delAuthrtYn`, "N"); + form.setValue(`menuAuthority.${index}.inqAuthrtYn`, "N"); + form.setValue(`menuAuthority.${index}.mngAuthrtYn`, "N"); + }); + } + }} + /> +
+ ), cell: ({ row }) => { return ( ( +
+ 등록권한 + { + if (checked) { + // 등록권한 체크시 조회권한도 체크 + menuAuthorityData.forEach((_, index) => { + if (getCurrentRow(index)?.mode === "R") { + form.setValue(`menuAuthority.${index}.mode`, "U"); + } + form.setValue(`menuAuthority.${index}.inqAuthrtYn`, "Y"); + form.setValue(`menuAuthority.${index}.regAuthrtYn`, "Y"); + }); + } else { + // 등록권한 해제시 해당 권한만 해제 + handleHeaderCheckedChange("regAuthrtYn")(false); + } + }} + /> +
+ ), cell: ({ row }) => { return ( ( +
+ 수정권한 + +
+ ), cell: ({ row }) => { return ( ( +
+ 삭제권한 + +
+ ), cell: ({ row }) => { return ( ( +
+ 조회권한 + +
+ ), cell: ({ row }) => { return ( MenuAuthorityApi.getGroupMenuAuthorityList({ groupId }), + queryFn: () => MenuAuthorityApi.getGroupMenuAuthorityList({ groupId, useYn: "Y" }), enabled: open && !!groupId, }); @@ -82,7 +82,7 @@ function MenuAuthorityDialog({ groupId }: MenuAuthorityDialogProps) { 메뉴권한 - + 그룹별 메뉴 권한