Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 36 additions & 33 deletions service-manager/src/components/apply-list/ApplyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,30 @@ export const ApplyList = ({ eventId }: ApplyListProps) => {
const { sectorSettingData } = useSectorQueryById(eventId);
const { onEmailTransmit } = useTransmitEmail(eventId);

const sectorFilteredRegistrations = registrations.filter(
(registration) => registration.sectorNum === selectedSector,
);

const exportXLSX = async () => {
const data = sectorSettingData
.map((sector) =>
registrations
.filter(
(registration) => registration.sectorNum === sector.sectorNumber,
)
.map((registration) =>
EXCEL_HEADERS.reduce(
(acc, header) => ({
...acc,
...getExcelCellValue(header, registration, registrations),
}),
{},
),
.map((sector) => {
const currentSectorRegistrations = registrations.filter(
(registration) => registration.sectorNum === sector.sectorNumber,
);
return currentSectorRegistrations.map((registration) =>
EXCEL_HEADERS.reduce(
(acc, header) => ({
...acc,
...getExcelCellValue(
header,
registration,
currentSectorRegistrations,
),
}),
{},
),
)
);
})
.flat();

const XLSX = await import('xlsx');
Expand Down Expand Up @@ -97,25 +104,21 @@ export const ApplyList = ({ eventId }: ApplyListProps) => {
</tr>
</thead>
<tbody className="text-center">
{registrations
.filter(
(registration) => registration.sectorNum === selectedSector,
)
.map((registration) => {
return (
<tr key={registration.id}>
{TABLE_HEADERS.map((header) => (
<td key={header.key}>
{getTableCellValue(
header.key,
registration,
registrations,
)}
</td>
))}
</tr>
);
})}
{sectorFilteredRegistrations.map((registration) => {
return (
<tr key={registration.id}>
{TABLE_HEADERS.map((header) => (
<td key={header.key}>
{getTableCellValue(
header.key,
registration,
sectorFilteredRegistrations,
)}
</td>
))}
</tr>
);
})}
</tbody>
</table>
</div>
Expand Down
20 changes: 14 additions & 6 deletions service-manager/src/functions/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import { EXCEL_HEADERS, TABLE_HEADERS } from '../constants/apply';
const getCellValue = (
headerKey: (typeof EXCEL_HEADERS)[number]['key'],
userInfo: RegistrationResponse,
registrations: RegistrationResponse[],
sectorFilteredRegistrations: RegistrationResponse[],
) => {
switch (headerKey) {
case 'sector':
return userInfo.sectorNum;
case 'order':
return registrations.findIndex((data) => data.id === userInfo.id) + 1;
return (
sectorFilteredRegistrations.findIndex(
(data) => data.id === userInfo.id,
) + 1
);
case 'name':
return userInfo.name;
case 'affiliation':
Expand Down Expand Up @@ -38,17 +42,21 @@ const getCellValue = (
export const getTableCellValue = (
headerKey: (typeof TABLE_HEADERS)[number]['key'],
userInfo: RegistrationResponse,
registrations: RegistrationResponse[],
sectorFilteredRegistrations: RegistrationResponse[],
) => {
return getCellValue(headerKey, userInfo, registrations);
return getCellValue(headerKey, userInfo, sectorFilteredRegistrations);
};

export const getExcelCellValue = (
headerKey: (typeof EXCEL_HEADERS)[number],
userInfo: RegistrationResponse,
registrations: RegistrationResponse[],
sectorFilteredRegistrations: RegistrationResponse[],
) => {
const value = getCellValue(headerKey.key, userInfo, registrations);
const value = getCellValue(
headerKey.key,
userInfo,
sectorFilteredRegistrations,
);
return {
[headerKey.label]: value,
};
Expand Down