WIP: 권한 맵핑 기능 구현중
This commit is contained in:
@@ -6,7 +6,7 @@ import type {
|
|||||||
RoleAuthorizationsList,
|
RoleAuthorizationsList,
|
||||||
RoleAuthorizationsData,
|
RoleAuthorizationsData,
|
||||||
RoleAuthorizations,
|
RoleAuthorizations,
|
||||||
} from "../../../entities/role-authorization/model/role-authorization-interface";
|
} from "../model/role-authorization-interface";
|
||||||
|
|
||||||
export class RoleAuthorizationsApiService implements RoleAuthorizationsService {
|
export class RoleAuthorizationsApiService implements RoleAuthorizationsService {
|
||||||
public async getRoleAuthorizationsList(
|
public async getRoleAuthorizationsList(
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
|
||||||
import {
|
import {
|
||||||
getCoreRowModel,
|
getCoreRowModel,
|
||||||
useReactTable,
|
useReactTable,
|
||||||
type ColumnDef,
|
type ColumnDef,
|
||||||
} from "@tanstack/react-table";
|
} from "@tanstack/react-table";
|
||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
@@ -14,11 +14,16 @@ import {
|
|||||||
DataTable,
|
DataTable,
|
||||||
Switch,
|
Switch,
|
||||||
} from "@common/components";
|
} from "@common/components";
|
||||||
import { ENDPOINT } from "@/shared/config";
|
|
||||||
import {
|
import {
|
||||||
AuthorizationsApi,
|
AuthorizationsApi,
|
||||||
type Authorizations,
|
type Authorizations,
|
||||||
} from "@/entities/authorization";
|
} from "@/entities/authorization";
|
||||||
|
import {
|
||||||
|
RoleAuthorizationsApi,
|
||||||
|
type RoleAuthorizationsData,
|
||||||
|
} from "@/entities/role-authorization";
|
||||||
|
import { ENDPOINT } from "@/shared/config";
|
||||||
|
import { useAlertStore } from "@/shared/lib";
|
||||||
|
|
||||||
type MappingRoleDialogProps = {
|
type MappingRoleDialogProps = {
|
||||||
roleId: string;
|
roleId: string;
|
||||||
@@ -27,19 +32,38 @@ type MappingRoleDialogProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function MappingRoleDialog({
|
function MappingRoleDialog({
|
||||||
|
roleId,
|
||||||
open,
|
open,
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
...props
|
...props
|
||||||
}: MappingRoleDialogProps) {
|
}: MappingRoleDialogProps) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const alert = useAlertStore((state) => state.setMessage);
|
||||||
|
|
||||||
const { data: authorizationList } = useQuery({
|
const { data: authorizationList } = useQuery({
|
||||||
queryKey: [ENDPOINT.USER_SERVICE.AUTHORIZATIONS],
|
queryKey: [ENDPOINT.USER_SERVICE.AUTHORIZATIONS],
|
||||||
queryFn: () => AuthorizationsApi.getAuthorizationsList(),
|
queryFn: () => AuthorizationsApi.getAuthorizationsList(),
|
||||||
enabled: open,
|
enabled: open,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { mutate, isPending } = useMutation({
|
||||||
|
mutationFn: (data: RoleAuthorizationsData) =>
|
||||||
|
RoleAuthorizationsApi.createRoleAuthorizations(data),
|
||||||
|
onSuccess: () => {
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.USER_SERVICE.AUTHORIZATIONS],
|
||||||
|
});
|
||||||
|
alert("권한 맵핑이 완료되었습니다.");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const applyRoleAuthorization = (apply: boolean, authorizationNo: number) => {
|
||||||
|
mutate([{ roleId, authorizationNo, authYn: apply ? "Y" : "N" }]);
|
||||||
|
};
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: authorizationList?.content ?? [],
|
data: authorizationList?.content ?? [],
|
||||||
columns,
|
columns: createColumns(isPending, applyRoleAuthorization),
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -52,13 +76,18 @@ function MappingRoleDialog({
|
|||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>모듈 목록</DialogTitle>
|
<DialogTitle>모듈 목록</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DataTable table={table} />
|
<div className="max-h-[40rem] overflow-y-auto">
|
||||||
|
<DataTable table={table} />
|
||||||
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ColumnDef<Authorizations>[] = [
|
const createColumns = (
|
||||||
|
isPending: boolean,
|
||||||
|
applyRoleAuthorization: (apply: boolean, authorizationNo: number) => void,
|
||||||
|
): ColumnDef<Authorizations>[] => [
|
||||||
{
|
{
|
||||||
accessorKey: "authorizationName",
|
accessorKey: "authorizationName",
|
||||||
header: "API명",
|
header: "API명",
|
||||||
@@ -80,7 +109,15 @@ const columns: ColumnDef<Authorizations>[] = [
|
|||||||
{
|
{
|
||||||
id: "action",
|
id: "action",
|
||||||
header: "사용여부",
|
header: "사용여부",
|
||||||
cell: ({ row }) => <Switch />,
|
cell: ({ row }) => (
|
||||||
|
<Switch
|
||||||
|
checked={row.original.useYn === "Y"}
|
||||||
|
onCheckedChange={(apply) =>
|
||||||
|
applyRoleAuthorization(apply, row.original.authorizationNo)
|
||||||
|
}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
),
|
||||||
meta: {
|
meta: {
|
||||||
width: 80,
|
width: 80,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ function THead<T>({ table }: { table: TableInstance<T> }) {
|
|||||||
return (
|
return (
|
||||||
<TableHead
|
<TableHead
|
||||||
key={header.id}
|
key={header.id}
|
||||||
className="sticky top-0"
|
className="sticky top-0 z-10"
|
||||||
colSpan={header.colSpan}
|
colSpan={header.colSpan}
|
||||||
rowSpan={rowSpan}
|
rowSpan={rowSpan}
|
||||||
{...meta}
|
{...meta}
|
||||||
|
|||||||
Reference in New Issue
Block a user