From 26bbd378a36b38a76434a45ddfdafb1a52999c66 Mon Sep 17 00:00:00 2001 From: Kwon Seo Jin <97675977+B0XERCAT@users.noreply.github.com> Date: Mon, 26 Aug 2024 15:33:16 +0900 Subject: [PATCH] feat(fe): add toggles in contest create (#1991) * feat(fe): add enable copy and hide result toggle in create contest * feat(fe): add switchfield to edit contest page * feat(fe): add error message in zod schema * feat(fe): change popover to tooltip --------- Co-authored-by: YooJin Lee <113789141+youznn@users.noreply.github.com> --- .../app/admin/_components/SwitchField.tsx | 23 ++++---- .../app/admin/contest/[id]/edit/page.tsx | 31 +++++++++- .../_components/ContestProblemListLabel.tsx | 57 +++++++++---------- .../_components/ImportProblemButton.tsx | 2 + .../app/admin/contest/create/page.tsx | 27 ++++++++- apps/frontend/app/admin/contest/utils.ts | 17 +++++- .../app/admin/problem/[id]/edit/page.tsx | 3 +- .../app/admin/problem/create/page.tsx | 8 ++- apps/frontend/graphql/contest/mutations.ts | 4 ++ apps/frontend/graphql/contest/queries.ts | 2 + 10 files changed, 126 insertions(+), 48 deletions(-) diff --git a/apps/frontend/app/admin/_components/SwitchField.tsx b/apps/frontend/app/admin/_components/SwitchField.tsx index 1d0b265d55..a8113653db 100644 --- a/apps/frontend/app/admin/_components/SwitchField.tsx +++ b/apps/frontend/app/admin/_components/SwitchField.tsx @@ -12,7 +12,7 @@ interface SwitchFieldProps { name: string title?: string placeholder?: string - isInput?: boolean + formElement?: 'input' | 'textarea' type?: string hasValue?: boolean } @@ -21,15 +21,16 @@ export default function SwitchField({ name, title, placeholder, - isInput = false, + formElement, type = 'text', hasValue = false }: SwitchFieldProps) { - const [isEnabled, setIsEnabled] = useState(false) + const [isEnabled, setIsEnabled] = useState(false) const { register, setValue, trigger, + getValues, formState: { errors } } = useFormContext() @@ -43,15 +44,17 @@ export default function SwitchField({ { + if (name == 'invitationCode') setValue(name, null) + else if (name == 'hint' || name == 'source') setValue(name, '') + else setValue(name, !getValues(name)) setIsEnabled(!isEnabled) - setValue(name, name === 'invitationCode' ? null : '') }} checked={isEnabled} - className="data-[state=checked]:bg-black data-[state=unchecked]:bg-gray-300" + className="data-[state=checked]:bg-primary data-[state=unchecked]:bg-gray-300" /> {isEnabled && - (isInput ? ( + (formElement == 'input' ? ( trigger(name) })} /> - ) : ( + ) : formElement == 'textarea' ? (