권한관리 수정 일괄 체크되게
This commit is contained in:
@@ -11,6 +11,7 @@ export const createColumns = (
|
||||
form: UseFormReturn<MenuAuthorityFormData>,
|
||||
): ColumnDef<MenuAuthority>[] => {
|
||||
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: () => (
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<span>관리권한</span>
|
||||
<Checkbox
|
||||
checked={isAllChecked("mngAuthrtYn")}
|
||||
onCheckedChange={(checked) => {
|
||||
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");
|
||||
});
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<Checkbox
|
||||
@@ -59,7 +107,29 @@ export const createColumns = (
|
||||
},
|
||||
{
|
||||
accessorKey: "regAuthrtYn",
|
||||
header: "등록권한",
|
||||
header: () => (
|
||||
<div className="flex items-center justify-start gap-2">
|
||||
<span>등록권한</span>
|
||||
<Checkbox
|
||||
checked={isAllChecked("regAuthrtYn")}
|
||||
onCheckedChange={(checked) => {
|
||||
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);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<Checkbox
|
||||
@@ -79,7 +149,15 @@ export const createColumns = (
|
||||
},
|
||||
{
|
||||
accessorKey: "mdfcnAuthrtYn",
|
||||
header: "수정권한 ",
|
||||
header: () => (
|
||||
<div className="flex items-center justify-start gap-2">
|
||||
<span>수정권한</span>
|
||||
<Checkbox
|
||||
checked={isAllChecked("mdfcnAuthrtYn")}
|
||||
onCheckedChange={handleHeaderCheckedChange("mdfcnAuthrtYn")}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<Checkbox
|
||||
@@ -91,7 +169,15 @@ export const createColumns = (
|
||||
},
|
||||
{
|
||||
accessorKey: "delAuthrtYn",
|
||||
header: "삭제권한",
|
||||
header: () => (
|
||||
<div className="flex items-center justify-start gap-2">
|
||||
<span>삭제권한</span>
|
||||
<Checkbox
|
||||
checked={isAllChecked("delAuthrtYn")}
|
||||
onCheckedChange={handleHeaderCheckedChange("delAuthrtYn")}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<Checkbox
|
||||
@@ -103,7 +189,15 @@ export const createColumns = (
|
||||
},
|
||||
{
|
||||
accessorKey: "inqAuthrtYn",
|
||||
header: "조회권한",
|
||||
header: () => (
|
||||
<div className="flex items-center justify-start gap-2">
|
||||
<span>조회권한</span>
|
||||
<Checkbox
|
||||
checked={isAllChecked("inqAuthrtYn")}
|
||||
onCheckedChange={handleHeaderCheckedChange("inqAuthrtYn")}
|
||||
/>
|
||||
</div>
|
||||
),
|
||||
cell: ({ row }) => {
|
||||
return (
|
||||
<Checkbox
|
||||
|
||||
@@ -35,7 +35,7 @@ function MenuAuthorityDialog({ groupId }: MenuAuthorityDialogProps) {
|
||||
|
||||
const query = useQuery({
|
||||
queryKey: [ENDPOINT.CMS_SERVICE.MENU_AUTHRTS, groupId],
|
||||
queryFn: () => MenuAuthorityApi.getGroupMenuAuthorityList({ groupId }),
|
||||
queryFn: () => MenuAuthorityApi.getGroupMenuAuthorityList({ groupId, useYn: "Y" }),
|
||||
enabled: open && !!groupId,
|
||||
});
|
||||
|
||||
@@ -82,7 +82,7 @@ function MenuAuthorityDialog({ groupId }: MenuAuthorityDialogProps) {
|
||||
메뉴권한
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent className="max-w-[60rem]" aria-describedby={undefined}>
|
||||
<DialogContent className="max-w-[80rem]" aria-describedby={undefined}>
|
||||
<DialogHeader>
|
||||
<DialogTitle>그룹별 메뉴 권한</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
Reference in New Issue
Block a user