You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.1 KiB
75 lines
2.1 KiB
import moment from "moment";
|
|
import { capitalize } from "../../../common/util/Util";
|
|
import { AdminUserDTO } from "../../../common/dto/AdminUserDTO";
|
|
import log from "loglevel";
|
|
import { createApiHeaders } from "../../../common/ajax/util";
|
|
|
|
export async function viewUsers(authToken: string) {
|
|
// const users = await getOtherUsers(authToken);
|
|
|
|
const usersTable = $("#usersTable").DataTable({
|
|
ajax: {
|
|
url: "/api/admin/get/users",
|
|
headers: {
|
|
"X-AUTH-TOKEN": authToken,
|
|
},
|
|
dataSrc: "",
|
|
},
|
|
columns: [
|
|
{ data: "id" },
|
|
{ data: "userName" },
|
|
{
|
|
data: "role",
|
|
render: (data: string) => {
|
|
return capitalize(data.replace("_", " ").toLowerCase());
|
|
},
|
|
},
|
|
{
|
|
data: "joinDate",
|
|
render: (data: string, type) => {
|
|
return type === "sort"
|
|
? data
|
|
: moment.utc(data).format("DD/MM/YY").toString();
|
|
},
|
|
},
|
|
],
|
|
buttons: [
|
|
{
|
|
extend: "selectedSingle",
|
|
text: "User Profile",
|
|
action: (e, dt, button, config) => {
|
|
const username = (dt.row({ selected: true }).data() as AdminUserDTO)
|
|
.userName;
|
|
window.location.assign(`/admin/users/${username}`);
|
|
},
|
|
},
|
|
{
|
|
extend: "selectedSingle",
|
|
text: "Delete User",
|
|
action: (e, dt, button, config) => {
|
|
const selectedRow = dt.row({ selected: true });
|
|
const username = (selectedRow.data() as AdminUserDTO).userName;
|
|
fetch(`/api/admin/delete/users/${username}`, {
|
|
headers: createApiHeaders(authToken),
|
|
method: "DELETE",
|
|
}).then((resp) => {
|
|
if (resp.status === 200) {
|
|
selectedRow.remove();
|
|
log.info("User deleted successfully");
|
|
dt.draw();
|
|
}
|
|
});
|
|
},
|
|
},
|
|
{
|
|
text: "New User",
|
|
action: () => {
|
|
log.error("Not implemented yet");
|
|
},
|
|
},
|
|
],
|
|
dom: "Blfrtip",
|
|
lengthMenu: [2, 10, 25, 50, 75, 100],
|
|
select: true,
|
|
});
|
|
}
|