From deac54853cd0a0ba1747b50e5320a7fb65893189 Mon Sep 17 00:00:00 2001 From: Kohminchae Date: Wed, 11 Sep 2024 23:27:41 +0900 Subject: [PATCH 1/3] chore(fe): block testcase and limit edit when submission exist --- .../app/admin/problem/[id]/edit/page.tsx | 33 +++++++++++++++---- .../problem/_components/ExampleTextarea.tsx | 6 +++- .../admin/problem/_components/LimitForm.tsx | 4 ++- .../problem/_components/TestcaseField.tsx | 4 ++- .../problem/_components/TestcaseItem.tsx | 4 +++ 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/apps/frontend/app/admin/problem/[id]/edit/page.tsx b/apps/frontend/app/admin/problem/[id]/edit/page.tsx index a0e95da22c..3a072ae1a5 100644 --- a/apps/frontend/app/admin/problem/[id]/edit/page.tsx +++ b/apps/frontend/app/admin/problem/[id]/edit/page.tsx @@ -4,8 +4,9 @@ import { useConfirmNavigation } from '@/app/admin/_components/ConfirmNavigation' import { Button } from '@/components/ui/button' import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area' import { UPDATE_PROBLEM } from '@/graphql/problem/mutations' -import { GET_PROBLEM } from '@/graphql/problem/queries' +import { GET_PROBLEM, GET_PROBLEMS } from '@/graphql/problem/queries' import { useMutation, useQuery } from '@apollo/client' +import { Language, Level } from '@generated/graphql' import type { Template, Testcase, UpdateProblemInput } from '@generated/graphql' import { zodResolver } from '@hookform/resolvers/zod' import Link from 'next/link' @@ -38,9 +39,7 @@ export default function Page({ params }: { params: { id: string } }) { const methods = useForm({ resolver: zodResolver(editSchema), - defaultValues: { - template: [] - } + defaultValues: { template: [] } }) const { handleSubmit, setValue, getValues } = methods @@ -134,6 +133,28 @@ export default function Page({ params }: { params: { id: string } }) { router.refresh() } + const [blockEdit, setBlockEdit] = useState(false) + + useQuery(GET_PROBLEMS, { + variables: { + groupId: 1, + take: 500, + input: { + difficulty: [ + Level.Level1, + Level.Level2, + Level.Level3, + Level.Level4, + Level.Level5 + ], + languages: [Language.C, Language.Cpp, Language.Java, Language.Python3] + } + }, + onCompleted: (data) => { + if (data.getProblems[0].submissionCount > 0) setBlockEdit(true) + } + }) + return (
@@ -187,10 +208,10 @@ export default function Page({ params }: { params: { id: string } }) { - {getValues('testcases') && } + {getValues('testcases') && } - + onRemove()} />