Skip to content

Commit

Permalink
fix(fe): fix contestdenied message (#2155)
Browse files Browse the repository at this point in the history
* fix(fe): fix contestdenied message

* fix(fe): fix contestdenied message delete message

* fix(fe): fix contestdenied message ifelse
  • Loading branch information
Kimhyojung0810 authored Oct 13, 2024
1 parent b7f5f0b commit 446abd7
Showing 1 changed file with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import DataTable from '@/components/DataTable'
import { fetcherWithAuth } from '@/lib/utils'
import { getStatusWithStartEnd } from '@/lib/utils'
import { dateFormatter } from '@/lib/utils'
import type { ContestProblem } from '@/types/type'
import type { Contest } from '@/types/type'
import { columns } from './_components/Columns'

interface ContestProblemProps {
Expand All @@ -21,17 +24,42 @@ export default async function ContestProblem({ params }: ContestProblemProps) {
})

if (!res.ok) {
const { statusCode, message }: { statusCode: number; message: string } =
await res.json()
const { statusCode }: { statusCode: number } = await res.json()

const contest: Contest = await fetcherWithAuth
.get(`contest/${contestId}`)
.then((res) => res.json())

const formattedStartTime = dateFormatter(
contest.startTime,
'YYYY-MM-DD HH:mm:ss'
)
const formattedEndTime = dateFormatter(
contest.endTime,
'YYYY-MM-DD HH:mm:ss'
)
const contestStatus = getStatusWithStartEnd(
formattedStartTime,
formattedEndTime
)

let displayMessage = ''

if (statusCode === 401) {
displayMessage = 'Log in first to check the problems.'
} else {
if (contestStatus === 'ongoing') {
displayMessage = 'Please register first to view the problem list'
} else {
displayMessage = 'You can access after the contest started'
}
}

return (
<div className="flex h-44 translate-y-[22px] items-center justify-center gap-4">
<div className="flex flex-col items-center gap-1 font-mono">
<p className="text-xl font-semibold">Access Denied</p>
<p className="text-gray-500">
{statusCode === 401
? 'Log in first to check the problems.'
: message}
</p>
<p className="text-gray-500">{displayMessage}</p>
</div>
</div>
)
Expand Down

0 comments on commit 446abd7

Please sign in to comment.