feat(frontend): Enhance user management UI and error handling in users.html
- Added default values for "Traffic Limit" and "Expiration Days" in the "Add User" modal.
This commit is contained in:
@ -389,10 +389,11 @@
|
|||||||
// Add User Form Submit
|
// Add User Form Submit
|
||||||
$("#addUserForm").on("submit", function (e) {
|
$("#addUserForm").on("submit", function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// Additional check before submitting (in case JS is disabled briefly)
|
|
||||||
if (!validateUsername($("#addUsername").val(), "addUsernameError")) {
|
if (!validateUsername($("#addUsername").val(), "addUsernameError")) {
|
||||||
|
$("#addSubmitButton").prop("disabled", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$("#addSubmitButton").prop("disabled", true);
|
||||||
|
|
||||||
const formData = $(this).serializeArray();
|
const formData = $(this).serializeArray();
|
||||||
const jsonData = {};
|
const jsonData = {};
|
||||||
@ -406,31 +407,32 @@
|
|||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
data: JSON.stringify(jsonData),
|
data: JSON.stringify(jsonData),
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
if (response.detail) {
|
Swal.fire({
|
||||||
Swal.fire({
|
title: "Success!",
|
||||||
title: "Success!",
|
text: response.detail || "User added successfully!",
|
||||||
text: response.detail,
|
icon: "success",
|
||||||
icon: "success",
|
confirmButtonText: "OK",
|
||||||
confirmButtonText: "OK",
|
}).then(() => {
|
||||||
}).then(() => {
|
location.reload();
|
||||||
location.reload();
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
Swal.fire({
|
|
||||||
title: "Error!",
|
|
||||||
text: response.error || "Failed to add user",
|
|
||||||
icon: "error",
|
|
||||||
confirmButtonText: "OK",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
let errorMessage = "An error occurred while adding user.";
|
||||||
|
if (jqXHR.responseJSON && jqXHR.responseJSON.detail) {
|
||||||
|
errorMessage = jqXHR.responseJSON.detail;
|
||||||
|
} else if (jqXHR.status === 409) {
|
||||||
|
errorMessage = "User '" + jsonData.username + "' already exists.";
|
||||||
|
$("#addUsernameError").text(errorMessage);
|
||||||
|
} else if (jqXHR.status === 422) {
|
||||||
|
errorMessage = jqXHR.responseJSON.detail || "Invalid input provided.";
|
||||||
|
}
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
title: "Error!",
|
title: "Error!",
|
||||||
text: "An error occurred while adding user",
|
text: errorMessage,
|
||||||
icon: "error",
|
icon: "error",
|
||||||
confirmButtonText: "OK",
|
confirmButtonText: "OK",
|
||||||
});
|
});
|
||||||
|
$("#addSubmitButton").prop("disabled", false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -761,6 +763,14 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$('#addUserModal').on('show.bs.modal', function (event) {
|
||||||
|
$('#addUsername').val('');
|
||||||
|
$('#addTrafficLimit').val('30');
|
||||||
|
$('#addExpirationDays').val('30');
|
||||||
|
$('#addUsernameError').text('');
|
||||||
|
$('#addSubmitButton').prop('disabled', true);
|
||||||
|
});
|
||||||
|
|
||||||
$("#searchButton").on("click", filterUsers);
|
$("#searchButton").on("click", filterUsers);
|
||||||
$("#searchInput").on("keyup", filterUsers);
|
$("#searchInput").on("keyup", filterUsers);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user