Fix EditUser submit bug

This commit is contained in:
Nathan Barber
2021-04-07 12:37:36 -04:00
parent 7e132f22e6
commit 405d78a9d4
5 changed files with 33 additions and 32 deletions

View File

@@ -36,14 +36,7 @@ const AddUser = (props) => {
type="checkbox"
value=""
id="admin-check"
onChange={(e) =>
// this.setState(
// Object.assign({}, this.state, {
// admin: e.target.checked,
// })
// )
setAdmin(e.target.checked)
}
onChange={(e) => setAdmin(e.target.checked)}
/>
<span> </span>
<label className="form-check-label">Admin</label>

View File

@@ -12,9 +12,7 @@ const withUserAPI = withProps((props) => ({
deleteUser: (username) => jhapiRequest("/users/" + username, "DELETE"),
failRegexEvent: () =>
alert(
"Removed " +
JSON.stringify(removed_users) +
" for either containing special characters or being too short."
"Cannot change username - either contains special characters or is too short."
),
refreshUserData: () =>
jhapiRequest("/users", "GET")

View File

@@ -79,24 +79,34 @@ const EditUser = (props) => {
id="submit"
className="btn btn-primary"
onClick={() => {
if (updatedUsername == "" && admin == has_admin) return;
if (
updatedUsername.length > 2 &&
/[!@#$%^&*(),.?":{}|<>]/g.test(updatedUsername) == false
) {
editUser(
username,
updatedUsername != "" ? updatedUsername : username,
admin
)
if (updatedUsername == "" && admin == has_admin) {
return;
} else if (updatedUsername != "") {
if (
updatedUsername.length > 2 &&
/[!@#$%^&*(),.?":{}|<>]/g.test(updatedUsername) == false
) {
editUser(
username,
updatedUsername != "" ? updatedUsername : username,
admin
)
.then((data) => {
history.push("/");
refreshUserData();
})
.catch((err) => {});
} else {
setUpdatedUsername("");
failRegexEvent();
}
} else {
editUser(username, username, admin)
.then((data) => {
history.push("/");
refreshUserData();
})
.catch((err) => {});
} else {
setUpdatedUsername(null);
failRegexEvent();
}
}}
>