feat: 그룹 사용자 선택 삭제 기능
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { keepPreviousData, useQuery } from "@tanstack/react-query";
|
||||
import {
|
||||
keepPreviousData,
|
||||
useQuery,
|
||||
useQueryClient,
|
||||
} from "@tanstack/react-query";
|
||||
import {
|
||||
getCoreRowModel,
|
||||
useReactTable,
|
||||
@@ -10,21 +14,26 @@ import {
|
||||
} from "@tanstack/react-table";
|
||||
import { Button, DataTable } from "@common/components";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import { useAlertStore } from "@/shared/lib";
|
||||
import { columns } from "../model/group-users-table-columns";
|
||||
import { GroupUsersApi } from "../api/group-users-service";
|
||||
import { AdditionalUserDialog } from "./additional-user-dialog";
|
||||
|
||||
type GroupUsersSectionProps = {
|
||||
groupId?: string;
|
||||
};
|
||||
|
||||
function GroupUsersSection({ groupId }: GroupUsersSectionProps) {
|
||||
const queryClient = useQueryClient();
|
||||
const alert = useAlertStore((state) => state.setMessage);
|
||||
|
||||
const [pagination, setPagination] = useState<PaginationState>({
|
||||
pageIndex: 0,
|
||||
pageSize: 10,
|
||||
});
|
||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
|
||||
|
||||
const { data: groupUsersList, refetch } = useQuery({
|
||||
const { data: groupUsersList } = useQuery({
|
||||
queryKey: [ENDPOINT.CMS_SERVICE.GROUP_USERS, groupId, pagination],
|
||||
queryFn: () =>
|
||||
GroupUsersApi.findPageGroupUser({
|
||||
@@ -55,11 +64,19 @@ function GroupUsersSection({ groupId }: GroupUsersSectionProps) {
|
||||
if (selectedRows.length === 0 || !groupId) return;
|
||||
|
||||
try {
|
||||
for (const userUnqId of selectedRows) {
|
||||
await GroupUsersApi.deleteGroupUser(groupId, userUnqId);
|
||||
}
|
||||
refetch();
|
||||
setRowSelection({});
|
||||
const usersToDelete = selectedRows.map((userUnqId) => ({
|
||||
mode: "D",
|
||||
groupId,
|
||||
userUnqId,
|
||||
}));
|
||||
|
||||
await GroupUsersApi.saveGroupUser(usersToDelete);
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [ENDPOINT.CMS_SERVICE.GROUP_USERS, groupId],
|
||||
});
|
||||
alert("사용자 삭제를 완료했습니다.", () => {
|
||||
setRowSelection({});
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
@@ -71,7 +88,7 @@ function GroupUsersSection({ groupId }: GroupUsersSectionProps) {
|
||||
<div className="card-header">
|
||||
<h3 className="text-2xl font-medium text-label">그룹 사용자 목록</h3>
|
||||
<div className="flex gap-2">
|
||||
<Button>등록</Button>
|
||||
<AdditionalUserDialog groupId={groupId} />
|
||||
<Button
|
||||
color="red"
|
||||
disabled={table.getSelectedRowModel().rows.length === 0}
|
||||
|
||||
Reference in New Issue
Block a user