From 5d9c5a7d0948ba4fc4fd7da63befcbef08146652 Mon Sep 17 00:00:00 2001 From: jimin9038 Date: Tue, 26 Mar 2024 10:38:04 +0900 Subject: [PATCH] fix(fe): unpack contest config (#1614) * fix(fe): unpack contest config * fix(deps): revert cmdk to v0.2.1 * fix(fe): add default value --- apps/frontend/app/admin/contest/[id]/page.tsx | 19 +- .../app/admin/contest/_components/Columns.tsx | 33 +-- .../app/admin/contest/create/page.tsx | 15 +- apps/frontend/app/admin/contest/page.tsx | 3 +- apps/frontend/package.json | 2 +- pnpm-lock.yaml | 216 +++++++++++++++++- 6 files changed, 238 insertions(+), 50 deletions(-) diff --git a/apps/frontend/app/admin/contest/[id]/page.tsx b/apps/frontend/app/admin/contest/[id]/page.tsx index 6ac33b6b10..9366d8d4b4 100644 --- a/apps/frontend/app/admin/contest/[id]/page.tsx +++ b/apps/frontend/app/admin/contest/[id]/page.tsx @@ -40,7 +40,8 @@ const UPDATE_CONTEST = gql(` mutation UpdateContest($groupId: Int!, $input: UpdateContestInput!) { updateContest(groupId: $groupId, input: $input) { id - config + isRankVisible + isVisible description endTime startTime @@ -121,10 +122,8 @@ const inputStyle = const schema = z.object({ id: z.number(), title: z.string().min(1).max(100), - config: z.object({ - isRankVisible: z.boolean(), - isVisible: z.boolean() - }), + isRankVisible: z.boolean(), + isVisible: z.boolean(), description: z.string().min(1), startTime: z.date(), endTime: z.date() @@ -155,10 +154,8 @@ export default function Page({ params }: { params: { id: string } }) { } = useForm({ resolver: zodResolver(schema), defaultValues: { - config: { - isRankVisible: true, - isVisible: true - } + isRankVisible: true, + isVisible: true } }) @@ -349,7 +346,7 @@ export default function Page({ params }: { params: { id: string } }) { {errors.title && (
- {getValues('title').length === 0 + {getValues('title')?.length === 0 ? 'required' : errors.title?.message}
@@ -405,7 +402,7 @@ export default function Page({ params }: { params: { id: string } }) { )} name="description" diff --git a/apps/frontend/app/admin/contest/_components/Columns.tsx b/apps/frontend/app/admin/contest/_components/Columns.tsx index eafcbedce3..5933ccf02f 100644 --- a/apps/frontend/app/admin/contest/_components/Columns.tsx +++ b/apps/frontend/app/admin/contest/_components/Columns.tsx @@ -24,17 +24,16 @@ interface DataTableContest { endTime: string description: string participants: number - config: { - isVisible: boolean - isRankVisible: boolean - } + isVisible: boolean + isRankVisible: boolean } const EDIT_VISIBLE = gql(` mutation UpdateContestVisible($groupId: Int!, $input: UpdateContestInput!) { updateContest(groupId: $groupId, input: $input) { id - config + isVisible + isRankVisible } } `) @@ -46,7 +45,7 @@ function VisibleCell({ row }: { row: Row }) {
{ const currentTime = dateFormatter(new Date(), 'YYYY-MM-DD HH:mm:ss') const startTime = dateFormatter( @@ -61,10 +60,6 @@ function VisibleCell({ row }: { row: Row }) { toast.error('Cannot change visibility of ongoing contest') return } - row.original.config = { - ...row.original.config, - isVisible: !row.original.config.isVisible - } // TODO: contest update API 수정되면 고치기 updateVisible({ variables: { @@ -75,10 +70,8 @@ function VisibleCell({ row }: { row: Row }) { startTime: row.original.startTime, endTime: row.original.endTime, description: row.original.description, - config: { - isVisible: row.original.config.isVisible, - isRankVisible: row.original.config.isRankVisible - } + isVisible: !row.original.isVisible, + isRankVisible: row.original.isRankVisible } } }) @@ -90,7 +83,7 @@ function VisibleCell({ row }: { row: Row }) {