Skip to content

Commit 4c3dc1f

Browse files
authored
refactor: 신청 목록 페이지의 테이블과 엑셀 파일 리팩토링 (#284)
2 parents 43729e5 + c075c3c commit 4c3dc1f

File tree

3 files changed

+96
-33
lines changed

3 files changed

+96
-33
lines changed

service-manager/src/components/apply-list/ApplyList.tsx

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {
77
} from '../../hooks/react-query/useRegistration';
88
import { useSectorQueryById } from '../../hooks/react-query/useSetting';
99
import { ApplyCount } from './ApplyCount';
10+
import { EXCEL_HEADERS, TABLE_HEADERS } from '../../constants/apply';
11+
import { getExcelCellValue, getTableCellValue } from '../../functions/apply';
1012
import ErrorBoundary from '../common/ErrorBoundary';
1113

1214
interface ApplyListProps {
@@ -30,17 +32,15 @@ export const ApplyList = ({ eventId }: ApplyListProps) => {
3032
.filter(
3133
(registration) => registration.sectorNum === sector.sectorNumber,
3234
)
33-
.map((registration, index) => ({
34-
구간: registration.sectorNum,
35-
순서: index + 1,
36-
이름: registration.name,
37-
학과: registration.department,
38-
차량번호: registration.carNumber,
39-
학생번호: registration.studentNumber,
40-
경차여부: registration.isCompact ? '경차' : '경차 아님',
41-
휴대폰번호: registration.phoneNumber,
42-
이메일: registration.email,
43-
})),
35+
.map((registration) =>
36+
EXCEL_HEADERS.reduce(
37+
(acc, header) => ({
38+
...acc,
39+
...getExcelCellValue(header, registration, registrations),
40+
}),
41+
{},
42+
),
43+
),
4444
)
4545
.flat();
4646

@@ -91,15 +91,9 @@ export const ApplyList = ({ eventId }: ApplyListProps) => {
9191
<table className="w-full min-w-[50rem]">
9292
<thead>
9393
<tr>
94-
<th>순서</th>
95-
<th>이름</th>
96-
<th>단과 대학</th>
97-
<th>학과</th>
98-
<th>차량 번호</th>
99-
<th>학생 번호</th>
100-
<th>경차 여부</th>
101-
<th>휴대폰 번호</th>
102-
<th>이메일</th>
94+
{TABLE_HEADERS.map((header) => (
95+
<th key={header.key}>{header.label}</th>
96+
))}
10397
</tr>
10498
</thead>
10599
<tbody className="text-center">
@@ -110,19 +104,15 @@ export const ApplyList = ({ eventId }: ApplyListProps) => {
110104
.map((registration) => {
111105
return (
112106
<tr key={registration.id}>
113-
<td>
114-
{registrations.findIndex(
115-
(data) => data.id === registration.id,
116-
) + 1}
117-
</td>
118-
<td>{registration.name}</td>
119-
<td>{registration.affiliation}</td>
120-
<td> {registration.department} </td>
121-
<td>{registration.carNumber}</td>
122-
<td>{registration.studentNumber}</td>
123-
<td>{registration.isCompact ? '경차' : '경차 아님'}</td>
124-
<td>{registration.phoneNumber}</td>
125-
<td>{registration.email}</td>
107+
{TABLE_HEADERS.map((header) => (
108+
<td key={header.key}>
109+
{getTableCellValue(
110+
header.key,
111+
registration,
112+
registrations,
113+
)}
114+
</td>
115+
))}
126116
</tr>
127117
);
128118
})}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { RegistrationResponse } from '../apis/dtos/registration.dto';
2+
3+
export const TABLE_HEADERS = [
4+
{ key: 'order', label: '순서' },
5+
{ key: 'name', label: '이름' },
6+
{ key: 'affiliation', label: '단과 대학' },
7+
{ key: 'department', label: '학과' },
8+
{ key: 'carNumber', label: '차량 번호' },
9+
{ key: 'studentNumber', label: '학생 번호' },
10+
{ key: 'isCompact', label: '경차 여부' },
11+
{ key: 'phoneNumber', label: '휴대폰 번호' },
12+
{ key: 'email', label: '이메일' },
13+
] as const;
14+
15+
export const EXCEL_HEADERS = [
16+
{ key: 'sector', label: '구간' },
17+
...TABLE_HEADERS,
18+
] as const;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { RegistrationResponse } from '../apis/dtos/registration.dto';
2+
import { EXCEL_HEADERS, TABLE_HEADERS } from '../constants/apply';
3+
4+
const getCellValue = (
5+
headerKey: (typeof EXCEL_HEADERS)[number]['key'],
6+
userInfo: RegistrationResponse,
7+
registrations: RegistrationResponse[],
8+
) => {
9+
switch (headerKey) {
10+
case 'sector':
11+
return userInfo.sectorNum;
12+
case 'order':
13+
return registrations.findIndex((data) => data.id === userInfo.id) + 1;
14+
case 'name':
15+
return userInfo.name;
16+
case 'affiliation':
17+
return userInfo.affiliation;
18+
case 'department':
19+
return userInfo.department;
20+
case 'carNumber':
21+
return userInfo.carNumber;
22+
case 'studentNumber':
23+
return userInfo.studentNumber;
24+
case 'isCompact':
25+
return userInfo.isCompact ? '경차' : '경차 아님';
26+
case 'phoneNumber':
27+
return userInfo.phoneNumber;
28+
case 'email':
29+
return userInfo.email;
30+
default:
31+
if (process.env.NODE_ENV === 'development') {
32+
console.warn(`${headerKey}는 정의되지 않은 헤더입니다.`);
33+
}
34+
return '';
35+
}
36+
};
37+
38+
export const getTableCellValue = (
39+
headerKey: (typeof TABLE_HEADERS)[number]['key'],
40+
userInfo: RegistrationResponse,
41+
registrations: RegistrationResponse[],
42+
) => {
43+
return getCellValue(headerKey, userInfo, registrations);
44+
};
45+
46+
export const getExcelCellValue = (
47+
headerKey: (typeof EXCEL_HEADERS)[number],
48+
userInfo: RegistrationResponse,
49+
registrations: RegistrationResponse[],
50+
) => {
51+
const value = getCellValue(headerKey.key, userInfo, registrations);
52+
return {
53+
[headerKey.label]: value,
54+
};
55+
};

0 commit comments

Comments
 (0)