-
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.
feat(fe): redesign contest table (#1930)
* feat(fe): redesign finished contest table * feat(fe): add registered tab * chore(fe): redesign tab button * chore(fe): change font weight * feat(fe): add search bar * feat(fe): add status badge * feat(fe): add search bar * chore(fe): delete unused import * feat(fe): add isRegistered column * chore(fe): delete unused tags, change props * chore(fe): delete unused tags
- Loading branch information
Showing
12 changed files
with
258 additions
and
46 deletions.
There are no files selected for viewing
51 changes: 29 additions & 22 deletions
51
apps/frontend/app/(main)/contest/_components/FinishedContestTable.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 |
---|---|---|
@@ -1,38 +1,45 @@ | ||
import DataTable from '@/components/DataTable' | ||
import { fetcher } from '@/lib/utils' | ||
import { fetcher, fetcherWithAuth } from '@/lib/utils' | ||
import type { Contest } from '@/types/type' | ||
import { columns } from './Columns' | ||
import type { Session } from 'next-auth' | ||
import { columns } from './FinishedTableColumns' | ||
|
||
interface ContestProps { | ||
data: Contest[] | ||
} | ||
|
||
export default async function FinishedContestTable() { | ||
const ContestData: ContestProps = await fetcher | ||
.get('contest/finished?take=51') | ||
export default async function FinishedContestTable({ | ||
search, | ||
session | ||
}: { | ||
search: string | ||
session: Session | null | ||
}) { | ||
const ContestData: ContestProps = await (session ? fetcherWithAuth : fetcher) | ||
.get('contest/finished', { | ||
searchParams: { | ||
search, | ||
take: '51' | ||
} | ||
}) | ||
.json() | ||
|
||
ContestData.data.forEach((contest) => { | ||
contest.status = 'finished' | ||
}) | ||
|
||
return ( | ||
<> | ||
<p className="text-xl font-bold md:text-2xl">Finished</p> | ||
{/* TODO: Add search bar */} | ||
<DataTable | ||
data={ContestData.data} | ||
columns={columns} | ||
headerStyle={{ | ||
title: 'text-left w-2/5 md:w-3/6', | ||
startTime: 'w-1/5 md:w-1/6', | ||
endTime: 'w-1/5 md:w-1/6', | ||
participants: 'w-1/5 md:w-1/6', | ||
status: 'w-1/4 md:w-1/6' | ||
}} | ||
linked | ||
emptyMessage="No finished contests found." | ||
/> | ||
</> | ||
<DataTable | ||
data={ContestData.data} | ||
columns={columns} | ||
headerStyle={{ | ||
title: 'text-left w-2/5 md:w-1/3', | ||
registered: 'w-1/5 md:w-1/6', | ||
participants: 'w-1/5 md:w-1/6', | ||
totalScore: 'w-1/5 md:w-1/6', | ||
period: 'w-1/5 md:w-1/4' | ||
}} | ||
linked | ||
/> | ||
) | ||
} |
47 changes: 47 additions & 0 deletions
47
apps/frontend/app/(main)/contest/_components/FinishedTableColumns.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,47 @@ | ||
'use client' | ||
|
||
import { dateFormatter } from '@/lib/utils' | ||
import CheckIcon from '@/public/check_blue.svg' | ||
import type { Contest } from '@/types/type' | ||
import type { ColumnDef } from '@tanstack/react-table' | ||
import Image from 'next/image' | ||
|
||
export const columns: ColumnDef<Contest>[] = [ | ||
{ | ||
header: 'Title', | ||
accessorKey: 'title', | ||
cell: ({ row }) => ( | ||
<p className="overflow-hidden text-ellipsis whitespace-nowrap text-left text-sm md:text-base"> | ||
{row.original.title} | ||
</p> | ||
) | ||
}, | ||
{ | ||
header: 'Registered', | ||
accessorKey: 'registered', | ||
cell: ({ row }) => | ||
row.original.isRegistered && ( | ||
<div className="flex items-center justify-center"> | ||
<Image src={CheckIcon} alt="check" height={24} /> | ||
</div> | ||
) | ||
}, | ||
{ | ||
header: 'Participants', | ||
accessorKey: 'participants', | ||
cell: ({ row }) => row.original.participants | ||
}, | ||
{ | ||
header: 'Total score', | ||
accessorKey: 'totalScore', | ||
cell: () => '000/000' | ||
}, | ||
{ | ||
header: 'Period', | ||
accessorKey: 'period', | ||
cell: ({ row }) => | ||
dateFormatter(row.original.startTime, 'YYYY-MM-DD') + | ||
' ~ ' + | ||
dateFormatter(row.original.endTime, 'YYYY-MM-DD') | ||
} | ||
] |
71 changes: 71 additions & 0 deletions
71
apps/frontend/app/(main)/contest/_components/RegisteredContestTable.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,71 @@ | ||
import DataTable from '@/components/DataTable' | ||
import { fetcherWithAuth } from '@/lib/utils' | ||
import type { Contest } from '@/types/type' | ||
import { columns } from './RegisteredTableColumns' | ||
|
||
interface FinishedContestProps { | ||
data: Contest[] | ||
} | ||
|
||
const getOngoingUpcomingContests = async (search: string) => { | ||
const data: { | ||
registeredOngoing: Contest[] | ||
registeredUpcoming: Contest[] | ||
} = await fetcherWithAuth | ||
.get('contest/registered-ongoing-upcoming', { | ||
searchParams: { | ||
search, | ||
take: '51' | ||
} | ||
}) | ||
.json() | ||
data.registeredOngoing.forEach((contest) => { | ||
contest.status = 'ongoing' | ||
}) | ||
data.registeredUpcoming.forEach((contest) => { | ||
contest.status = 'upcoming' | ||
}) | ||
return data.registeredOngoing.concat(data.registeredUpcoming) | ||
} | ||
|
||
const getFinishedContests = async (search: string) => { | ||
const data = await getOngoingUpcomingContests(search) | ||
|
||
const FinishedData: FinishedContestProps = await fetcherWithAuth | ||
.get('contest/registered-finished', { | ||
searchParams: { | ||
search, | ||
take: '51' | ||
} | ||
}) | ||
.json() | ||
FinishedData.data.forEach((contest) => { | ||
contest.status = 'finished' | ||
}) | ||
return data.concat(FinishedData.data) | ||
} | ||
|
||
export default async function RegisteredContestTable({ | ||
search | ||
}: { | ||
search: string | ||
}) { | ||
const data = await getFinishedContests(search) | ||
|
||
return ( | ||
<> | ||
<DataTable | ||
data={data} | ||
columns={columns} | ||
headerStyle={{ | ||
title: 'text-left w-2/5 md:w-1/3', | ||
status: 'w-1/5 md:w-1/6', | ||
participants: 'w-1/5 md:w-1/6', | ||
totalScore: 'w-1/5 md:w-1/6', | ||
period: 'w-1/5 md:w-1/4' | ||
}} | ||
linked | ||
/> | ||
</> | ||
) | ||
} |
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
37 changes: 37 additions & 0 deletions
37
apps/frontend/app/(main)/contest/_components/TableSwitchButton.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,37 @@ | ||
import { cn } from '@/lib/utils' | ||
import Link from 'next/link' | ||
|
||
export default function TableSwitchButton({ | ||
registered | ||
}: { | ||
registered: boolean | ||
}) { | ||
return ( | ||
<div className="flex items-center"> | ||
<Link | ||
href="/contest" | ||
className={cn( | ||
'w-fit p-6 text-xl font-medium text-[#333333]/30 hover:text-[#333333]/50 md:text-2xl', | ||
!registered | ||
? 'text-primary-light hover:text-primary-light border-primary-light border-b-2 font-bold' | ||
: '' | ||
)} | ||
scroll={false} | ||
> | ||
Finished | ||
</Link> | ||
<Link | ||
href="/contest?registered=true" | ||
className={cn( | ||
'w-fit p-6 text-xl font-medium text-[#333333]/30 hover:text-[#333333]/50 md:text-2xl', | ||
registered | ||
? 'text-primary-light hover:text-primary-light border-primary-light border-b-2 font-bold' | ||
: '' | ||
)} | ||
scroll={false} | ||
> | ||
Registered | ||
</Link> | ||
</div> | ||
) | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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