34 lines
902 B
TypeScript
34 lines
902 B
TypeScript
import { notFound, redirect } from 'next/navigation'
|
|
import ResultsClient from './ResultsClient'
|
|
|
|
export default async function ResultsPage({
|
|
params,
|
|
searchParams,
|
|
}: {
|
|
params: Promise<{ code: string }>
|
|
searchParams: Promise<{ pid?: string }>
|
|
}) {
|
|
const { code } = await params
|
|
const { pid: participationId } = await searchParams
|
|
|
|
if (!participationId) redirect(`/quiz/${code}`)
|
|
|
|
const baseUrl = process.env.NEXT_PUBLIC_APP_URL ?? 'http://localhost:3000'
|
|
const res = await fetch(
|
|
`${baseUrl}/api/student/results?participation_id=${participationId}`,
|
|
{ cache: 'no-store' }
|
|
)
|
|
|
|
if (!res.ok) {
|
|
const data = await res.json()
|
|
if (data.error?.includes('terminé')) {
|
|
redirect(`/quiz/${code}/exam?pid=${participationId}`)
|
|
}
|
|
notFound()
|
|
}
|
|
|
|
const data = await res.json()
|
|
|
|
return <ResultsClient results={data.results} sessionCode={code.toUpperCase()} />
|
|
}
|