Populating the user form
This commit is contained in:
		@ -34,10 +34,18 @@ export function showUsers(api) {
 | 
			
		||||
        });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function showUser(api) {
 | 
			
		||||
export function showUser(api, userID) {
 | 
			
		||||
    const token = localStorage.getItem("token");
 | 
			
		||||
    let id = window.location.pathname.split("/").pop();
 | 
			
		||||
    let delBtn = document.getElementById("deleteBtn");
 | 
			
		||||
 | 
			
		||||
    if (id === "0") {
 | 
			
		||||
        return
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (userID !== parseInt(id, 10)) {
 | 
			
		||||
        delBtn.classList.remove("d-none")
 | 
			
		||||
    }
 | 
			
		||||
    const requestOptions = {
 | 
			
		||||
        method: 'post',
 | 
			
		||||
        headers: {
 | 
			
		||||
@ -51,6 +59,23 @@ export function showUser(api) {
 | 
			
		||||
        .then(response => response.json())
 | 
			
		||||
        .then(function (data) {
 | 
			
		||||
            console.log(data);
 | 
			
		||||
            document.getElementById("first_name").value = data.first_name;
 | 
			
		||||
            document.getElementById("last_name").value = data.last_name;
 | 
			
		||||
            document.getElementById("email").value = data.email;
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
    delBtn.addEventListener("click", function () {
 | 
			
		||||
        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) => {
 | 
			
		||||
            console.log("would delete user id", id);
 | 
			
		||||
        });
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user