From 64bb9770456ab0da9db0b0f8de7fa7870354cac1 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 11 Sep 2023 18:08:35 -0300 Subject: [PATCH] Fixed isActive and isSuperuser not changing when creating user --- src/frontend/src/controllers/API/index.ts | 6 +++--- src/frontend/src/pages/AdminPage/index.tsx | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 945c77621..80e97a73e 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -421,14 +421,14 @@ export async function getLoggedUser(): Promise { export async function addUser(user: UserInputType): Promise> { try { const res = await api.post(`${BASE_URL_API}users/`, user); - if (res.status === 200) { - return res.data; + if (res.status !== 201) { + throw new Error(res.data.detail); } + return res.data; } catch (error) { console.log("Error:", error); throw error; } - return []; } export async function getUsersPage( diff --git a/src/frontend/src/pages/AdminPage/index.tsx b/src/frontend/src/pages/AdminPage/index.tsx index 4d29a9e1e..8c71c3b13 100644 --- a/src/frontend/src/pages/AdminPage/index.tsx +++ b/src/frontend/src/pages/AdminPage/index.tsx @@ -182,6 +182,10 @@ export default function AdminPage() { function handleNewUser(user: UserInputType) { addUser(user) .then((res) => { + updateUser(res["id"], { + is_active: user.is_active, + is_superuser: user.is_superuser, + }); resetFilter(); setSuccessData({ title: "Success! New user added!", @@ -189,8 +193,8 @@ export default function AdminPage() { }) .catch((error) => { setErrorData({ - title: "Error on add new user", - list: [error["response"]["data"]["detail"]], + title: "Error when adding new user", + list: [error.response.data.detail], }); }); }