This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
-
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.
feat(page:user): display user submissions on
/users/[username]
page
## what - display user submissions on `/users/[username]` page ## how - using DataTable to display a table ## why ## where - ./src/app/users/[username]/page.tsx ## usage
- Loading branch information
1 parent
511df75
commit 49816a8
Showing
1 changed file
with
69 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"use client"; | ||
|
||
import { AxiosError } from "axios"; | ||
import { z } from "zod"; | ||
|
||
import Error from "@/components/error"; | ||
import { userSchema } from "@/schema"; | ||
import { useFetchUserSubmissions } from "@/hooks"; | ||
import { processUserSubmissionsVerdictBarChart } from "@/utils/dataProcessing"; | ||
import { UserSubmission } from "@/types"; | ||
import { DataTable } from "@/components/ui/data-table"; | ||
import { columns } from "@/app/users/[username]/components/data-table/submissionColumns"; | ||
|
||
type Props = { | ||
params: z.infer<typeof userSchema>; | ||
}; | ||
|
||
const UserPage = ({ params }: Props) => { | ||
const { | ||
isLoading: userSubmissionIsLoading, | ||
isSuccess: userSubmissionIsSuccess, | ||
isError: userSubmissionIsError, | ||
data: userSubmissionData, | ||
error: userSubmissionError, | ||
} = useFetchUserSubmissions(params.username); | ||
|
||
if (userSubmissionIsLoading) { | ||
return <div>Loading {params.username}</div>; | ||
} | ||
|
||
if(userSubmissionIsError) { | ||
type ErrorMessage = { | ||
message: string; | ||
} | ||
|
||
const status = (userSubmissionError as AxiosError<ErrorMessage>).response?.status | ||
const message = (userSubmissionError as AxiosError<ErrorMessage>).response?.data.message | ||
|
||
return ( | ||
<Error | ||
status={status as number} | ||
message={ message } | ||
/> | ||
); | ||
} | ||
|
||
// process data | ||
// const userSubmissionVerdicts = processUserSubmissionsVerdictBarChart((userSubmissionData as UserSubmission).subs) | ||
// console.log(userSubmissionVerdicts) | ||
|
||
return ( | ||
<section> | ||
<div> | ||
<h1 className="text-3xl">{userSubmissionData?.name} ({params.username})</h1> | ||
</div> | ||
<div> | ||
<div></div> | ||
<div> | ||
<div> | ||
<h1 className="text-3xl mb-4 mt-6">Submissions</h1> | ||
<DataTable columns={columns} data={( userSubmissionData as UserSubmission ).subs} height={400} /> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
) | ||
}; | ||
|
||
export default UserPage; |