delete users
This commit is contained in:
@ -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"
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user