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

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

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

File diff suppressed because one or more lines are too long