-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(fe): replace data table admin component to new components (1) (
#2176) * refactor(fe): refactor admin user table * refactor(fe): refactor admin problem table * refactor(fe): refactor admin contest table * refactor(fe): refactor contest problem table and import problem table * chore(fe): fix admin page layout * fix(fe): reset page index when the filter is changed * chore(fe): add error toast message * chore(fe): separate component file * fix(fe): force to trigger sorting fn when the row selection is changed
- Loading branch information
Showing
23 changed files
with
739 additions
and
420 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
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
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
33 changes: 33 additions & 0 deletions
33
apps/frontend/app/admin/contest/_components/ContestProblemTable.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,33 @@ | ||
import { useMemo, type Dispatch, type SetStateAction } from 'react' | ||
import DataTable from '../../_components/table/DataTable' | ||
import DataTableRoot from '../../_components/table/DataTableRoot' | ||
import type { ContestProblem } from '../utils' | ||
import { createColumns } from './ContestProblemColumns' | ||
|
||
interface ContestProblemTableProps { | ||
problems: ContestProblem[] | ||
setProblems: Dispatch<SetStateAction<ContestProblem[]>> | ||
disableInput: boolean | ||
} | ||
|
||
export default function ContestProblemTable({ | ||
problems, | ||
setProblems, | ||
disableInput | ||
}: ContestProblemTableProps) { | ||
const columns = useMemo( | ||
() => createColumns(setProblems, disableInput), | ||
[setProblems, disableInput] | ||
) | ||
|
||
return ( | ||
<DataTableRoot | ||
columns={columns} | ||
data={problems} | ||
defaultPageSize={20} | ||
defaultSortState={[{ id: 'order', desc: false }]} | ||
> | ||
<DataTable showFooter={true} /> | ||
</DataTableRoot> | ||
) | ||
} |
86 changes: 86 additions & 0 deletions
86
apps/frontend/app/admin/contest/_components/ContestTable.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,86 @@ | ||
'use client' | ||
|
||
import { DELETE_CONTEST } from '@/graphql/contest/mutations' | ||
import { GET_CONTESTS } from '@/graphql/contest/queries' | ||
import { useApolloClient, useMutation, useSuspenseQuery } from '@apollo/client' | ||
import DataTable from '../../_components/table/DataTable' | ||
import DataTableDeleteButton from '../../_components/table/DataTableDeleteButton' | ||
import DataTableFallback from '../../_components/table/DataTableFallback' | ||
import DataTablePagination from '../../_components/table/DataTablePagination' | ||
import DataTableRoot from '../../_components/table/DataTableRoot' | ||
import DataTableSearchBar from '../../_components/table/DataTableSearchBar' | ||
import { columns } from './ContestTableColumns' | ||
import DuplicateContestButton from './DuplicateContestButton' | ||
|
||
const headerStyle = { | ||
select: '', | ||
title: 'w-3/5', | ||
startTime: 'px-0 w-1/5', | ||
participants: 'px-0 w-1/12', | ||
isVisible: 'px-0 w-1/12' | ||
} | ||
|
||
export function ContestTable() { | ||
const { data } = useSuspenseQuery(GET_CONTESTS, { | ||
variables: { | ||
groupId: 1, | ||
take: 300 | ||
} | ||
}) | ||
|
||
const contests = data.getContests.map((contest) => ({ | ||
...contest, | ||
id: Number(contest.id) | ||
})) | ||
|
||
return ( | ||
<DataTableRoot | ||
data={contests} | ||
columns={columns} | ||
defaultSortState={[{ id: 'startTime', desc: true }]} | ||
> | ||
<div className="flex gap-2"> | ||
<DataTableSearchBar columndId="title" /> | ||
<DuplicateContestButton /> | ||
<ContestsDeleteButton /> | ||
</div> | ||
<DataTable | ||
headerStyle={headerStyle} | ||
getHref={(data) => `/admin/contest/${data.id}`} | ||
/> | ||
<DataTablePagination showSelection /> | ||
</DataTableRoot> | ||
) | ||
} | ||
|
||
function ContestsDeleteButton() { | ||
const client = useApolloClient() | ||
const [deleteContest] = useMutation(DELETE_CONTEST) | ||
|
||
const deleteTarget = (id: number) => { | ||
return deleteContest({ | ||
variables: { | ||
groupId: 1, | ||
contestId: id | ||
} | ||
}) | ||
} | ||
|
||
const onSuccess = () => { | ||
client.refetchQueries({ | ||
include: [GET_CONTESTS] | ||
}) | ||
} | ||
|
||
return ( | ||
<DataTableDeleteButton | ||
target="contest" | ||
deleteTarget={deleteTarget} | ||
onSuccess={onSuccess} | ||
/> | ||
) | ||
} | ||
|
||
export function ContestTableFallback() { | ||
return <DataTableFallback columns={columns} headerStyle={headerStyle} /> | ||
} |
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
Oops, something went wrong.