-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
"use client"; | ||
import { DataTableUsage } from "@/components/common/DataTable/DataTableUsage"; | ||
import { PageHeader } from "@/components/common/PageHeader"; | ||
import { AdminQuizListSection } from "@/components/pages/AdminQuizListSection/AdminQuizListSection"; | ||
|
||
export default function AdminQuizPage() { | ||
return ( | ||
<> | ||
<PageHeader title="퀴즈 제출 목록" /> | ||
<DataTableUsage></DataTableUsage> | ||
<AdminQuizListSection /> | ||
</> | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
src/components/pages/AdminQuizListSection/AdminQuizListSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { DataTable } from "@/components/common/DataTable"; | ||
import { DataTableData } from "@/components/common/DataTable/elements/DataTableData"; | ||
import { DataTableRow } from "@/components/common/DataTable/elements/DataTableRow"; | ||
import { QUIZ_TABLE_HEADERS } from "@/constants/DataTableHeaders"; | ||
import { PAGE_SIZES } from "@/constants/PageSize"; | ||
import { useQuizResults } from "@/hooks/swr/useQuizResults"; | ||
import { useTableSort } from "@/hooks/useTableSort"; | ||
import { Stack } from "@mantine/core"; | ||
import { useState } from "react"; | ||
|
||
export function AdminQuizListSection() { | ||
/* 페이지당 행 개수 */ | ||
const [pageSize, setPageSize] = useState<string | null>(String(PAGE_SIZES[0])); | ||
/* 페이지네이션 페이지 넘버*/ | ||
const [pageNumber, setPageNumber] = useState(1); | ||
/* 데이터 정렬 훅 */ | ||
const { sortBy, order, handleSortButton } = useTableSort(); | ||
|
||
/* SWR 훅을 사용하여 공지사항 목록 패칭 */ | ||
const { data, pageData } = useQuizResults({ | ||
params: { page: pageNumber - 1, size: Number(pageSize) }, | ||
}); | ||
|
||
return ( | ||
<> | ||
<Stack> | ||
<DataTable | ||
headers={QUIZ_TABLE_HEADERS} | ||
sortBy={sortBy} | ||
order={order} | ||
handleSortButton={handleSortButton} | ||
totalElements={String(pageData?.totalElements)} | ||
pageSize={pageSize} | ||
setPageSize={setPageSize} | ||
totalPages={pageData?.totalPages} | ||
pageNumber={pageNumber} | ||
setPageNumber={setPageNumber} | ||
> | ||
{data?.map((quiz, index) => ( | ||
<DataTableRow key={index}> | ||
<DataTableData>{index + 1 + (pageNumber - 1) * Number(pageSize)}</DataTableData> | ||
<DataTableData>{quiz.name}</DataTableData> | ||
<DataTableData>{quiz.email}</DataTableData> | ||
<DataTableData>{quiz.phone}</DataTableData> | ||
<DataTableData>{quiz.successCount}</DataTableData> | ||
</DataTableRow> | ||
))} | ||
</DataTable> | ||
</Stack> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"use client"; | ||
|
||
import { PagedQuizResultRequestParams, PagedQuizResultResponse } from "@/types/quiz"; | ||
import useSWR from "swr"; | ||
|
||
export function useQuizResults({ params }: { params: PagedQuizResultRequestParams }) { | ||
const result = useSWR<PagedQuizResultResponse>({ | ||
url: "/quizzes/result", | ||
query: params, | ||
}); | ||
|
||
return { | ||
data: result.data?.content, | ||
pageData: result.data && { | ||
pageSize: result.data.size, | ||
pageNumber: result.data.number, | ||
totalElements: result.data.totalElements, | ||
totalPages: result.data.totalPages, | ||
}, | ||
get isLoading() { | ||
return result.isLoading; | ||
}, | ||
get error() { | ||
return result.error; | ||
}, | ||
get mutate() { | ||
return result.mutate; | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { PagedApiResponse } from "./common"; | ||
|
||
export interface QuizResult { | ||
id: number; | ||
name: string; | ||
email: string; | ||
phone: string; | ||
successCount: number; | ||
} | ||
|
||
export interface PagedQuizResultRequestParams { | ||
year?: number; | ||
page: number; | ||
size: number; | ||
} | ||
|
||
export interface PagedQuizResultResponse extends PagedApiResponse<QuizResult> {} |