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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | 'use client';
import { Button, Table, Tooltip, message, Image, Pagination, Modal, Input, Select } from 'antd';
import styled from 'styled-components';
import useModalState from '@lib/hooks/useModalState';
import { useGetRewardsQuery, useGetTotalQuestsQuery } from '@lib/api/queries';
import React from 'react';
import { useDeleteRewardMutation } from '@lib/api/mutations';
import { ColumnsType } from 'antd/es/table';
import {
ManageRewardResponseDto,
ManageRewardResponseDtoExpirationPeriodEnum,
ManageRewardResponseDtoRewardTypeEnum
} from '@uniquegood/realworld-adventure-interface';
import { expirationPeriodToString, rewardTypeToString } from '@lib/constants/reward';
import { useRouter } from 'next/navigation';
import useBreakpoint from '@lib/hooks/useBreakpoint';
import ConfirmDeleteModal from '@lib/components/ConfirmDeleteModal';
import CreateModal from './Modal/CreateModal';
import DrawListModal from './Modal/DrawListModal';
import RewardCard from './RewardCard';
import ChangeGiftshowModal from './Modal/ChangeGiftshowModal';
export default function RewardPage() {
const { isBreakpoint } = useBreakpoint({ breakpoint: 992 });
const {
openModal: openCreateModal,
closeModal: closeCreateModal,
modal: createModal
} = useModalState();
const {
openModal: openConfirmModal,
closeModal: closeConfirmModal,
modal: confirmModal
} = useModalState();
const {
openModal: openDrawListModal,
closeModal: closeDrawListModal,
modal: drawListModal
} = useModalState();
const {
openModal: openChangeGiftshowModal,
closeModal: closeChangeGiftshowModal,
modal: changeGiftshowModal
} = useModalState();
const [currentPage, setCurrentPage] = React.useState(0);
const [keyword, setKeyword] = React.useState('');
const [questId, setQuestId] = React.useState('');
const [currentDrawList, setCurrentDrawList] = React.useState<ManageRewardResponseDto[]>([]);
const [pageSize, setPageSize] = React.useState(20);
const router = useRouter();
const { data, isLoading } = useGetRewardsQuery({
page: currentPage,
size: pageSize,
keyword,
questId
});
const { data: totalRewards } = useGetTotalQuestsQuery();
const { mutateAsync } = useDeleteRewardMutation();
const handleSearch = (value: string) => {
setKeyword(value);
setCurrentPage(0);
};
const columns: ColumnsType<
Omit<ManageRewardResponseDto, 'children'> & {
drawRewards?: Array<ManageRewardResponseDto> | null;
}
> = [
{
key: 'id',
dataIndex: 'id',
title: 'ID',
width: 200,
ellipsis: true,
render: (value) => <Tooltip title={value}>{value}</Tooltip>
},
{
key: 'name',
dataIndex: 'name',
title: '이름'
},
{
key: 'description',
dataIndex: 'description',
title: '설명'
},
{
key: 'rewardType',
dataIndex: 'rewardType',
title: '보상 타입',
render: (value: ManageRewardResponseDtoRewardTypeEnum) => rewardTypeToString[value]
},
{
key: 'imageUrl',
dataIndex: 'imageUrl',
title: '이미지',
width: 125,
align: 'center',
render: (value) => {
return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events
<div
onClick={(e) => {
e.stopPropagation();
}}
>
<Image width={100} height={100} style={{ objectFit: 'contain' }} src={value} />
</div>
);
}
},
{
key: 'buttonName',
dataIndex: 'buttonName',
title: '버튼 텍스트'
},
{
key: 'remainingCount',
dataIndex: 'remainingCount',
title: '잔여 보상 개수'
},
{
key: 'expirationPeriod',
dataIndex: 'expirationPeriod',
title: '만료 기간',
render: (value) =>
value ? expirationPeriodToString[value as ManageRewardResponseDtoExpirationPeriodEnum] : '-'
},
{
key: 'drawRewards',
dataIndex: 'drawRewards',
title: '뽑기 목록',
render: (value, record) => {
if (record.rewardType === ManageRewardResponseDtoRewardTypeEnum.Draw) {
return (
<Button
onClick={(e) => {
e.stopPropagation();
setCurrentDrawList(value || []);
openDrawListModal({});
}}
>
뽑기 목록 보기
</Button>
);
}
return '-';
}
},
{
key: 'note',
dataIndex: 'note',
title: '메모'
},
{
title: '동작',
render: (record) => {
return (
<>
{record.rewardType === 'GiftShow' && (
<Button
size="small"
onClick={(e) => {
e.stopPropagation();
openChangeGiftshowModal({
children: (
<ChangeGiftshowModal
rewardId={record.id}
prevCustomData={record.customData}
closeModal={closeChangeGiftshowModal}
/>
)
});
}}
style={{ marginRight: '4px' }}
>
기프티쇼 변경
</Button>
)}
<Button
danger
size="small"
onClick={async (e: React.MouseEvent) => {
e.stopPropagation();
openConfirmModal({
title: '정말 삭제하시겠어요?',
onOk: async () => {
const { success } = await mutateAsync(record.id);
if (success) {
message.success('보상 삭제에 성공했습니다');
closeConfirmModal();
} else {
message.error('보상 삭제에 실패했습니다');
}
}
});
}}
>
삭제
</Button>
</>
);
}
}
];
return (
<>
<HeaderContainer>
<h1>보상 관리</h1>
</HeaderContainer>
<div>
<HeaderControllerContainer>
<div style={{ display: 'flex', gap: '8px' }}>
<Input.Search
placeholder="검색어를 입력해주세요."
style={{ width: '300px' }}
enterButton
onSearch={handleSearch}
/>
<Select
options={[
{ label: '전체 보상 보기', value: null },
...(totalRewards?.data?.map((totalReward) => ({
label: totalReward.title,
value: totalReward.questId
})) || [])
]}
onChange={(value) => setQuestId(value)}
placeholder="퀘스트에 속한 보물을 조회할 수 있습니다."
showSearch
filterOption={(input, option) => {
return option?.label?.includes(input) || false;
}}
style={{ width: '300px' }}
/>
</div>
<Button onClick={() => openCreateModal({})}>보상 생성</Button>
</HeaderControllerContainer>
</div>
{isBreakpoint ? (
<>
{data?.data.content?.map((reward) => (
<RewardCard
title={reward.name}
description={reward.description}
rewardType={reward.rewardType}
imageUrl={reward.imageUrl || ''}
remainingCount={reward.remainingCount || 0}
expirationPeriod={reward.expirationPeriod || ''}
memo={reward.note || ''}
onClick={() => {
router.push(`/rewards/${reward.id}`);
}}
/>
))}
<Pagination
pageSize={pageSize}
showSizeChanger={false}
current={currentPage + 1}
onChange={(page) => setCurrentPage(page - 1)}
total={data?.data?.totalElements}
style={{ textAlign: 'center' }}
/>
</>
) : (
<Table
dataSource={data?.data.content}
columns={columns}
loading={isLoading}
rowKey="id"
pagination={{
pageSize,
current: currentPage + 1,
onChange: (page) => setCurrentPage(page - 1),
total: data?.data?.totalElements,
onShowSizeChange(current, size) {
setPageSize(size);
}
}}
onRow={(record) => ({
onClick: () => {
router.push(`/rewards/${record.id}`);
}
})}
/>
)}
<CreateModal modalData={createModal} closeModal={closeCreateModal} />
<ConfirmDeleteModal modalData={confirmModal} />
<DrawListModal
modalData={drawListModal}
closeModal={closeDrawListModal}
drawList={currentDrawList}
/>
<Modal {...changeGiftshowModal} title="기프티쇼 변경" footer={false} />
</>
);
}
const HeaderContainer = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
`;
const HeaderControllerContainer = styled.div`
display: grid;
grid-auto-flow: column;
grid-auto-columns: min-content;
justify-content: space-between;
gap: 8px;
margin-bottom: 16px;
`;
|