Skip to content

Commit

Permalink
fix(fe): problem cannot be null (#1968)
Browse files Browse the repository at this point in the history
* fix(fe): visible can be null

* fix(fe): fix isvisible to be null if undefined
  • Loading branch information
jimin9038 authored Aug 18, 2024
1 parent 91b4e0a commit 71ebc00
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions apps/frontend/app/admin/problem/_components/Columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface DataTableProblem {
difficulty: string
submissionCount: number
acceptedRate: number
isVisible: boolean
isVisible: boolean | null
languages: string[]
tag: { id: number; tag: Tag }[]
}
Expand All @@ -33,7 +33,8 @@ function VisibleCell({ row }: { row: Row<DataTableProblem> }) {
<Switch
id="hidden-mode"
onClick={(e) => e.stopPropagation()}
checked={row.original.isVisible}
disabled={!row.original.isVisible}
checked={row.original.isVisible === true}
onCheckedChange={() => {
row.original.isVisible = !row.original.isVisible
updateVisible({
Expand All @@ -48,6 +49,7 @@ function VisibleCell({ row }: { row: Row<DataTableProblem> }) {
}}
/>
{!row.original.isVisible && (
// TODO: Add contest info modal
<button
className="justify-centert flex items-center"
onClick={(e) => e.stopPropagation()}
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/app/admin/problem/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default function Page({
data?.getProblems.map((problem) => ({
...problem,
id: Number(problem.id),
isVisible: problem.isVisible !== undefined ? problem.isVisible : null,
languages: problem.languages ?? [],
tag: problem.tag.map(({ id, tag }) => ({
id: +id,
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/app/admin/problem/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from 'zod'

const commonSchema = z.object({
title: z.string().min(1, { message: 'required' }).max(200),
isVisible: z.boolean(),
isVisible: z.boolean().optional(),
difficulty: z.enum(levels),
languages: z.array(z.enum(languages)).min(1),
description: z
Expand Down

0 comments on commit 71ebc00

Please sign in to comment.