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:
Whispering Wind
2025-05-09 00:12:42 +03:30
committed by GitHub
parent 69e9605414
commit 5b04b47e60

View File

@ -389,10 +389,11 @@
// Add User Form Submit
$("#addUserForm").on("submit", function (e) {
e.preventDefault();
// Additional check before submitting (in case JS is disabled briefly)
if (!validateUsername($("#addUsername").val(), "addUsernameError")) {
$("#addSubmitButton").prop("disabled", true);
return;
}
$("#addSubmitButton").prop("disabled", true);
const formData = $(this).serializeArray();
const jsonData = {};
@ -406,31 +407,32 @@
contentType: "application/json",
data: JSON.stringify(jsonData),
success: function (response) {
if (response.detail) {
Swal.fire({
title: "Success!",
text: response.detail,
text: response.detail || "User added successfully!",
icon: "success",
confirmButtonText: "OK",
}).then(() => {
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({
title: "Error!",
text: "An error occurred while adding user",
text: errorMessage,
icon: "error",
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);
$("#searchInput").on("keyup", filterUsers);