Fixed isActive and isSuperuser not changing when creating user
This commit is contained in:
parent
967483e59c
commit
64bb977045
2 changed files with 9 additions and 5 deletions
|
|
@ -421,14 +421,14 @@ export async function getLoggedUser(): Promise<Users | null> {
|
|||
export async function addUser(user: UserInputType): Promise<Array<Users>> {
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -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],
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue