From ae69c4ed087acef3bc325512c9ca4011708c2090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o?= <43091603+glazk0@users.noreply.github.com> Date: Sat, 22 Apr 2023 10:34:40 +0200 Subject: [PATCH] Added mutate on groupCreate/groupJoin --- ui/Puzzles.tsx | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ui/Puzzles.tsx b/ui/Puzzles.tsx index 9e3267e..a3d1781 100644 --- a/ui/Puzzles.tsx +++ b/ui/Puzzles.tsx @@ -357,22 +357,22 @@ function GroupForm({ chapter, token }: { chapter: Chapter; token: string }) { }); async function onSubmit(data: GroupData) { - await fetch(`${process.env.NEXT_PUBLIC_API_URL}/${isJoining ? 'groupJoin' : 'groupCreate'}`, { - method: 'POST', - body: JSON.stringify(data), - headers: { - Authorization: `Bearer ${token}` + const res = await fetch( + `${process.env.NEXT_PUBLIC_API_URL}/${isJoining ? 'groupJoin' : 'groupCreate'}`, + { + method: 'POST', + body: JSON.stringify(data), + headers: { + Authorization: `Bearer ${token}` + } } - }); - // TODO: handle errors - // if (res.ok) { - // if (!isJoining) { - // mutate('groups'); - // } else { - // mutate('me'); - // } - // router.refresh(); - // } + ); + + if (res.ok) { + mutate('me'); + // TODO REFACTOR + router.refresh(); + } } return (