feat: 관리자 삭제 기능 작업
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import dayjs from "dayjs";
|
||||
import { memo } from "react";
|
||||
import type { ColumnDef } from "@tanstack/react-table";
|
||||
import type { AdminUserList } from "@/entities/user";
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||
import { Button } from "@common/components";
|
||||
import { PasswordResetDialog, type AdminUserList } from "@/entities/user";
|
||||
import { GroupUsersApi, type GroupUserSaveData } from "@/entities/group-user";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import { useAlertStore, useMutationWrapper } from "@/shared/lib";
|
||||
import { ManagerIpDialog } from "../ui/manager-ip-dialog";
|
||||
|
||||
export const columns: ColumnDef<AdminUserList["content"][number]>[] = [
|
||||
@@ -23,11 +30,11 @@ export const columns: ColumnDef<AdminUserList["content"][number]>[] = [
|
||||
header: "관리자명",
|
||||
},
|
||||
{
|
||||
accessorKey: "userStateCodeName",
|
||||
accessorKey: "groupNm",
|
||||
header: "관리자구분",
|
||||
},
|
||||
{
|
||||
accessorKey: "groupNm",
|
||||
accessorKey: "ogdpSeNm",
|
||||
header: "소속",
|
||||
},
|
||||
{
|
||||
@@ -43,7 +50,63 @@ export const columns: ColumnDef<AdminUserList["content"][number]>[] = [
|
||||
id: "action",
|
||||
header: "관리",
|
||||
cell: ({ row }) => {
|
||||
return <ManagerIpDialog userUnqId={row.original.userUnqId} />;
|
||||
return (
|
||||
<ActionCell
|
||||
userUnqId={row.original.userUnqId}
|
||||
groupId={row.original.groupId}
|
||||
/>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const ActionCell = memo(
|
||||
({ userUnqId, groupId }: { userUnqId: string; groupId: string }) => {
|
||||
const queryClient = useQueryClient();
|
||||
const { confirm } = useConfirm();
|
||||
const alert = useAlertStore((state) => state.setMessage);
|
||||
|
||||
const { mutate: onDelete } = useMutationWrapper({
|
||||
mutationFn: (data: GroupUserSaveData) =>
|
||||
GroupUsersApi.saveGroupUser([data]),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [ENDPOINT.USER_SERVICE.USERS],
|
||||
});
|
||||
alert("삭제되었습니다.");
|
||||
},
|
||||
});
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (await confirm("관리자를 삭제하시겠습니까?")) {
|
||||
onDelete({
|
||||
mode: "D",
|
||||
groupId,
|
||||
userUnqId,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex justify-center gap-2">
|
||||
<ManagerIpDialog userUnqId={userUnqId} />
|
||||
<PasswordResetDialog userUnqId={userUnqId}>
|
||||
<Button size="sm" color="gray">
|
||||
비밀번호 초기화
|
||||
</Button>
|
||||
</PasswordResetDialog>
|
||||
<Button size="sm" color="red" onClick={handleDelete}>
|
||||
삭제
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
(prevProps, nextProps) => {
|
||||
return (
|
||||
prevProps.userUnqId === nextProps.userUnqId &&
|
||||
prevProps.groupId === nextProps.groupId
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
ActionCell.displayName = "ActionCell";
|
||||
|
||||
Reference in New Issue
Block a user