Skip to content

Commit

Permalink
fix(fe): block testcase and limit edit when submission exist (#2084)
Browse files Browse the repository at this point in the history
* chore(fe): block testcase and limit edit when submission exist

* chore(fe): change blockEdit as optional property
  • Loading branch information
Kohminchae authored and mnseok committed Nov 12, 2024
1 parent c196b16 commit 921e9cf
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
12 changes: 7 additions & 5 deletions apps/frontend/app/admin/problem/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,12 @@ export default function Page({ params }: { params: { id: string } }) {

const methods = useForm<UpdateProblemInput>({
resolver: zodResolver(editSchema),
defaultValues: {
template: []
}
defaultValues: { template: [] }
})

const { handleSubmit, setValue, getValues } = methods

const [blockEdit, setBlockEdit] = useState<boolean>(false)
const [showHint, setShowHint] = useState<boolean>(false)
const [showSource, setShowSource] = useState<boolean>(false)
const [isDialogOpen, setDialogOpen] = useState<boolean>(false)
Expand All @@ -57,6 +56,9 @@ export default function Page({ params }: { params: { id: string } }) {
},
onCompleted: (problemData) => {
const data = problemData.getProblem

if (data.submissionCount > 0) setBlockEdit(true)

setValue('id', +id)
setValue('title', data.title)
setValue('isVisible', data.isVisible)
Expand Down Expand Up @@ -193,10 +195,10 @@ export default function Page({ params }: { params: { id: string } }) {
</div>
</div>

{getValues('testcases') && <TestcaseField />}
{getValues('testcases') && <TestcaseField blockEdit={blockEdit} />}

<FormSection title="Limit">
<LimitForm />
<LimitForm blockEdit={blockEdit} />
</FormSection>
<TemplateField />
<SwitchField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ interface ExampleTextareaProps {
// TODO: any를 다른 type으로 대체
// eslint-disable-next-line @typescript-eslint/no-explicit-any
register: any
blockEdit?: boolean
}
export default function ExampleTextarea({
onRemove,
inputName,
outputName,
className,
register
register,
blockEdit
}: ExampleTextareaProps) {
return (
<div
Expand All @@ -30,11 +32,13 @@ export default function ExampleTextarea({
onClick={() => onRemove()}
/>
<Textarea
disabled={blockEdit}
placeholder="Input"
className="resize-none border-0 px-4 py-0 shadow-none focus-visible:ring-0"
{...register(inputName)}
/>
<Textarea
disabled={blockEdit}
placeholder="Output"
className="min-h-[120px] rounded-none border-l border-transparent border-l-gray-200 px-4 py-0 shadow-none focus-visible:ring-0"
{...register(outputName)}
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/app/admin/problem/_components/LimitForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useFormContext } from 'react-hook-form'
import ErrorMessage from '../../_components/ErrorMessage'
import { inputStyle } from '../../utils'

export default function LimitForm() {
export default function LimitForm({ blockEdit }: { blockEdit?: boolean }) {
const {
formState: { errors },
register
Expand All @@ -17,6 +17,7 @@ export default function LimitForm() {
<div className="flex flex-col gap-1">
<div className="flex items-center gap-2">
<Input
disabled={blockEdit}
id="time"
type="number"
min={0}
Expand All @@ -34,6 +35,7 @@ export default function LimitForm() {
<div className="flex flex-col gap-1">
<div className="flex items-center gap-2">
<Input
disabled={blockEdit}
id="memory"
type="number"
min={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import AddBadge from './AddBadge'
import { CautionDialog } from './CautionDialog'
import TestcaseItem from './TestcaseItem'

export default function TestcaseField() {
export default function TestcaseField({ blockEdit }: { blockEdit?: boolean }) {
const {
formState: { errors },
getValues,
Expand Down Expand Up @@ -119,6 +119,7 @@ export default function TestcaseField() {
(item, index) =>
!item.isHidden && (
<TestcaseItem
blockEdit={blockEdit}
key={index}
index={index}
itemError={itemErrors}
Expand All @@ -134,6 +135,7 @@ export default function TestcaseField() {
(item, index) =>
item.isHidden && (
<TestcaseItem
blockEdit={blockEdit}
key={index}
index={index}
itemError={itemErrors}
Expand Down
4 changes: 4 additions & 0 deletions apps/frontend/app/admin/problem/_components/TestcaseItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { isInvalid } from '../_libs/utils'
import ExampleTextarea from './ExampleTextarea'

interface TestcaseItemProps {
blockEdit?: boolean
index: number
itemError: FieldErrorsImpl | undefined
onRemove: () => void
}

export default function TestcaseItem({
blockEdit,
index,
itemError,
onRemove
Expand Down Expand Up @@ -77,6 +79,7 @@ export default function TestcaseItem({

<div>
<input
disabled={blockEdit}
{...register(`testcases.${index}.scoreWeight`, {
setValueAs: (value) => (isInvalid(value) ? null : Number(value))
})}
Expand All @@ -94,6 +97,7 @@ export default function TestcaseItem({
</div>
</div>
<ExampleTextarea
blockEdit={blockEdit}
onRemove={onRemove}
inputName={`testcases.${index}.input`}
outputName={`testcases.${index}.output`}
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/app/admin/problem/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export default function Page({
enableFilter={true}
enableDelete={true}
enablePagination={true}
defaultSortColumn={{ id: 'createTime', desc: true }}
defaultSortColumn={{ id: 'updateTime', desc: true }}
/>
)}
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/graphql/problem/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const GET_PROBLEM = gql(`
description
inputDescription
outputDescription
submissionCount
testcase {
id
input
Expand Down

0 comments on commit 921e9cf

Please sign in to comment.