Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | 'use client';
import { useUpdateBlackListMutation } from '@lib/api/mutations';
import { useGetBlackListQuery } from '@lib/api/queries';
import { HeaderContainer } from '@lib/components/styledComponents';
import useModalState from '@lib/hooks/useModalState';
import { BlackListResponseDto } from '@uniquegood/realworld-adventure-interface';
import { Button, Input, Table, message } from 'antd';
import { ColumnsType } from 'antd/es/table';
import React from 'react';
import styled from 'styled-components';
import ConfirmDeleteModal from '@lib/components/ConfirmDeleteModal';
import AddBlackListModal from './Modal/AddBlackListModal';
import ConfirmAddModal from './Modal/ConfirmAddModal';
export default function UserBlackListPage() {
const [keyword, setKeyword] = React.useState('');
const { data: blackList, isLoading: isBlackListLoading } = useGetBlackListQuery();
const { mutateAsync: updateBlackList } = useUpdateBlackListMutation();
const { openModal, closeModal, modal } = useModalState();
const {
openModal: openAddConfirmModal,
closeModal: closeAddConfirmModal,
modal: addConfirmModal
} = useModalState();
const {
openModal: openDeleteConfirmModal,
closeModal: closeDeleteConfirmModal,
modal: deleteConfirmModal
} = useModalState();
const handleAddBlackListClick = () => {
openModal({});
};
const handleAddClick = async (id: string) => {
try {
openAddConfirmModal({
onOk: async () => {
try {
const data = await updateBlackList({
userId: id,
isAdd: true
});
if (data.success) {
message.success('블랙리스트에 추가되었습니다.');
closeModal();
closeAddConfirmModal();
}
} catch (e) {
message.error('블랙리스트 추가에 실패했습니다.');
closeAddConfirmModal();
}
}
});
} catch (e) {
message.error('블랙리스트 추가에 실패했습니다.');
}
};
const handleDeleteClick = async (userId: string) => {
try {
openDeleteConfirmModal({
title: '정말 해당 유저를 블랙 리스트에서 해제하시겠어요?',
onOk: async () => {
try {
const data = await updateBlackList({
userId,
isAdd: false
});
if (data.success) {
message.success('블랙리스트 해제되었습니다.');
closeDeleteConfirmModal();
}
} catch (e) {
message.error('블랙리스트 해제에 실패했습니다.');
}
}
});
} catch {
message.error('블랙리스트 해제에 실패했습니다.');
}
};
const columns: ColumnsType<BlackListResponseDto> = [
{
title: '유저 ID',
dataIndex: 'userId',
key: 'userId'
},
{
title: '이름',
dataIndex: 'name',
key: 'name'
},
{
title: '이메일',
dataIndex: 'email',
key: 'email'
},
{
title: '동작',
render: (_, record) => {
return (
<Button type="default" size="small" onClick={() => handleDeleteClick(record.userId)}>
블랙리스트 해제
</Button>
);
}
}
];
return (
<>
<HeaderContainer>
<h1>블랙리스트 조회</h1>
</HeaderContainer>
<Toolbar>
<Input.Search
placeholder="검색 키워드를 입력해주세요."
enterButton
onSearch={(value) => setKeyword(value.trim())}
style={{ width: '300px', marginBottom: '16px' }}
/>
<Button type="primary" onClick={handleAddBlackListClick}>
블랙리스트 추가하기
</Button>
</Toolbar>
<Table
dataSource={blackList?.data?.filter(
(item) =>
item.name.includes(keyword) ||
item.userId.includes(keyword) ||
item.email.includes(keyword)
)}
columns={columns}
pagination={false}
loading={isBlackListLoading}
rowKey="userId"
/>
<AddBlackListModal modalData={modal} closeModal={closeModal} onRowClick={handleAddClick} />
<ConfirmAddModal modalData={addConfirmModal} />
<ConfirmDeleteModal modalData={deleteConfirmModal} />
</>
);
}
const Toolbar = styled.div`
display: flex;
justify-content: space-between;
`;
|