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 | 'use client';
import {
useGetFestivalNfcsQuery,
useGetFestivalQuery,
useGetTotalFestivalNfcsQuery
} from '@lib/api/queries';
import useModalState from '@lib/hooks/useModalState';
import { NFCRegistryInfoDto } from '@uniquegood/realworld-adventure-interface';
import { Button, Table, message } from 'antd';
import { ColumnsType } from 'antd/es/table';
import styled from 'styled-components';
import { useDeleteFestivalNfcMutation, useDeleteFestivalNfcsMutation } from '@lib/api/mutations';
import React from 'react';
import { downloadExcel } from '@lib/utils/excel';
import ConfirmDeleteModal from '@lib/components/ConfirmDeleteModal';
import CreateFestivalNfcModal from './Modal/CreateFestivalNfcModal';
import ModifyFestivalNfcModal from './Modal/ModifyFestivalNfcModal';
import ExcelModal from './Modal/ExcelModal';
interface FestivalsNfcPageProps {
festivalId: string;
}
export default function FestivalsNfcPage({ festivalId }: FestivalsNfcPageProps) {
const {
openModal: openCreateModal,
closeModal: closeCreateModal,
modal: createModal
} = useModalState();
const {
openModal: openModifyModal,
closeModal: closeModifyModal,
modal: modifyModal
} = useModalState();
const {
openModal: openExcelModal,
closeModal: closeExcelModal,
modal: excelModal
} = useModalState();
const {
openModal: openConfirmModal,
closeModal: closeConfirmModal,
modal: confirmModal
} = useModalState();
const [currentNfcRegistryId, setCurrentNfcRegistryId] = React.useState('');
const [currentPage, setCurrentPage] = React.useState(0);
const [selectedRowKeys, setSelectedRowKeys] = React.useState<string[]>([]);
const hasSelection = React.useMemo(() => selectedRowKeys.length > 0, [selectedRowKeys]);
const { data: festival } = useGetFestivalQuery(festivalId);
const { data: nfcList } = useGetFestivalNfcsQuery(festivalId, currentPage, 20);
const { data: totalNfcList } = useGetTotalFestivalNfcsQuery(festivalId);
const modifiedNfcList = React.useMemo(() => {
if (!nfcList?.data?.content) return [];
const { totalElements, pageIndex } = nfcList.data;
return nfcList.data.content.map((nfc, index) => ({
...nfc,
index: totalElements - pageIndex * 20 - index
}));
}, [nfcList?.data?.content]);
const { mutateAsync: deleteNfc } = useDeleteFestivalNfcMutation(festivalId);
const { mutateAsync: deleteNfcs } = useDeleteFestivalNfcsMutation(festivalId);
const handleDownloadClick = () => {
// 엑셀 다운로드 기능 구현
downloadExcel({
keys: ['nfcId', 'latitude', 'longitude', 'description'],
header: {
nfcId: 'NFC 고유 ID',
latitude: '위도',
longitude: '경도',
description: '설명'
},
data:
totalNfcList?.data?.content.map((item) => ({
nfcId: item.nfcId,
latitude: String(item.latitude),
longitude: String(item.longitude),
description: item.description || ''
})) || [],
fileName: `${festival?.data?.title} NFC 목록`,
type: 'csv'
});
};
const handleNfcsDelete = async () => {
const { success } = await deleteNfcs(selectedRowKeys);
if (success) {
message.success('NFC를 삭제했습니다.');
setSelectedRowKeys([]);
closeConfirmModal();
}
};
const columns: ColumnsType<NFCRegistryInfoDto> = [
{
key: 'index',
dataIndex: 'index',
align: 'center'
},
{
key: 'nfcId',
dataIndex: 'nfcId',
title: 'NFC 고유 ID'
},
{
key: 'latitude',
dataIndex: 'latitude',
title: '위도'
},
{
key: 'longitude',
dataIndex: 'longitude',
title: '경도'
},
{
key: 'description',
dataIndex: 'description',
title: '설명'
},
{
title: '동작',
render: (record) => (
<Button
danger
onClick={(e) => {
e.stopPropagation();
openConfirmModal({
onOk: async () => {
const { success } = await deleteNfc(record.nfcRegistryId);
if (success) {
message.success('NFC를 삭제했습니다.');
closeConfirmModal();
} else {
message.error('NFC 삭제에 실패했습니다.');
}
},
title: '정말 삭제하시겠어요?'
});
}}
>
삭제
</Button>
)
}
];
return (
<>
<HeaderContainer>
<h1>{festival?.data?.title} NFC 관리</h1>
<HeaderControllerContainer>
<Button
onClick={handleDownloadClick}
style={{ border: '1px solid #10793f', color: '#10793f' }}
>
NFC 목록 다운로드
</Button>
<Button
onClick={() => openExcelModal({})}
style={{ backgroundColor: '#10793f', color: '#fff' }}
>
엑셀로 추가하기
</Button>
<Button onClick={() => openCreateModal({})}>NFC 추가하기</Button>
</HeaderControllerContainer>
</HeaderContainer>
<CountContainer>
등록된 NFC 개수 <Count>{nfcList?.data?.totalElements}개</Count>
</CountContainer>
{hasSelection && (
<Button
type="primary"
danger
onClick={() => {
openConfirmModal({
title: '선택한 NFC를 삭제하시겠어요?',
onOk: handleNfcsDelete
});
}}
style={{ marginBottom: '8px' }}
>
선택 삭제
</Button>
)}
<Table
columns={columns}
dataSource={modifiedNfcList}
onRow={(record) => ({
onClick: () => {
setCurrentNfcRegistryId(record.nfcRegistryId);
openModifyModal({});
}
})}
pagination={{
showSizeChanger: false,
pageSize: 20,
total: nfcList?.data?.totalElements,
onChange: (page) => setCurrentPage(page - 1)
}}
rowKey="nfcRegistryId"
rowSelection={{
type: 'checkbox',
onChange: (selectedRowKeys) => {
setSelectedRowKeys(selectedRowKeys as string[]);
}
}}
/>
<CreateFestivalNfcModal
modalData={createModal}
closeModal={closeCreateModal}
festivalId={festivalId}
/>
<ModifyFestivalNfcModal
modalData={modifyModal}
closeModal={closeModifyModal}
festivalId={festivalId}
nfcRegistryId={currentNfcRegistryId}
/>
<ConfirmDeleteModal modalData={confirmModal} />
<ExcelModal modalData={excelModal} closeModal={closeExcelModal} festivalId={festivalId} />
</>
);
}
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;
gap: 8px;
`;
const CountContainer = styled.div`
margin-bottom: 16px;
color: #777;
font-size: 16px;
`;
const Count = styled.span`
color: #333;
font-weight: 500;
`;
|