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>> {
|
export async function addUser(user: UserInputType): Promise<Array<Users>> {
|
||||||
try {
|
try {
|
||||||
const res = await api.post(`${BASE_URL_API}users/`, user);
|
const res = await api.post(`${BASE_URL_API}users/`, user);
|
||||||
if (res.status === 200) {
|
if (res.status !== 201) {
|
||||||
return res.data;
|
throw new Error(res.data.detail);
|
||||||
}
|
}
|
||||||
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error:", error);
|
console.log("Error:", error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
return [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUsersPage(
|
export async function getUsersPage(
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,10 @@ export default function AdminPage() {
|
||||||
function handleNewUser(user: UserInputType) {
|
function handleNewUser(user: UserInputType) {
|
||||||
addUser(user)
|
addUser(user)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
|
updateUser(res["id"], {
|
||||||
|
is_active: user.is_active,
|
||||||
|
is_superuser: user.is_superuser,
|
||||||
|
});
|
||||||
resetFilter();
|
resetFilter();
|
||||||
setSuccessData({
|
setSuccessData({
|
||||||
title: "Success! New user added!",
|
title: "Success! New user added!",
|
||||||
|
|
@ -189,8 +193,8 @@ export default function AdminPage() {
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setErrorData({
|
setErrorData({
|
||||||
title: "Error on add new user",
|
title: "Error when adding new user",
|
||||||
list: [error["response"]["data"]["detail"]],
|
list: [error.response.data.detail],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue