delete users

This commit is contained in:
2024-08-26 14:10:18 +02:00
parent bced6d7036
commit 3f0ddf7138
5 changed files with 67 additions and 2 deletions

View File

@ -121,7 +121,7 @@ export function saveUser(api, event) {
.then(response => response.json())
.then(function (data) {
console.log(data);
if (data.ok === false) {
if (!data.ok) {
Swal.fire("Error" + data.message)
} else {
location.href = "/admin/all-users"
@ -129,3 +129,40 @@ export function saveUser(api, event) {
});
}
export function deleteUser(api) {
const token = localStorage.getItem("token");
let id = window.location.pathname.split("/").pop();
Swal.fire({
title: "Are you sure?",
text: "You won't be able to undo this!",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#3085d6",
cancelButtonColor: "#d33",
confirmButtonText: "Delete user"
}).then((result) => {
if (result.isConfirmed) {
const requestOptions = {
method: 'post',
headers: {
'Accept': `application/json`,
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + token,
},
};
fetch(api + `/api/admin/all-users/delete/${id}`, requestOptions)
.then(response => response.json())
.then(function (data) {
console.log(data);
if (!data.ok) {
Swal.fire("Error" + data.message)
} else {
location.href = "/admin/all-users"
}
});
}
});
}