Skip to content

Commit

Permalink
added functionality to remove a user from the database
Browse files Browse the repository at this point in the history
  • Loading branch information
manuhdez committed Oct 15, 2018
1 parent 02c2ed7 commit edd6d73
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,8 @@ PROFILE PAGE CUSTOM STYLES
top: 10px;
left: 10px;
}

#remove {
bottom: 10px;
right: 10px;
}
1 change: 1 addition & 0 deletions html/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<i class="material-icons position-absolute" id="edit">edit</i>
<i class="material-icons position-absolute d-none" id="save">save</i>
<i class="material-icons position-absolute d-none" id="cancel">cancel</i>
<i class="material-icons position-absolute d-none text-danger" id="remove">delete</i>
<div class="jumbotron">
<div class="row">
<div class="container d-flex justify-content-center">
Expand Down
19 changes: 19 additions & 0 deletions js/user-profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ function changeEditModeStatus() {
edit.classList.add('d-none');
save.classList.remove('d-none');
cancel.classList.remove('d-none');
remove.classList.remove('d-none');
} else {
edit.classList.remove('d-none');
save.classList.add('d-none');
cancel.classList.add('d-none');
remove.classList.add('d-none');
}
}
// Edit profile functionality
Expand Down Expand Up @@ -95,8 +97,12 @@ function openEditMode() {
cancel.addEventListener('click', closeEditMode);
// Save profile changes functionality
save.addEventListener('click', saveProfileChanges);
// Remove user profile functionality
remove.addEventListener('click', removeUser);

// Replace experience and languages for inputs of type select
changeForSelect('experience', ["- 1 year", "1 - 3 years", "3 - 5 years", "+ 5 years"], false);

// Get all available languages from the api to create the select input dynamically
fetch(`https://cv-mobile-api.herokuapp.com/api/langs`)
.then( res => res.json() ).then(langs => {
Expand Down Expand Up @@ -175,6 +181,19 @@ function saveProfileChanges() {
}
}

function removeUser() {
if (editModeStatus) {
fetch(`https://cv-mobile-api.herokuapp.com/api/users/${userID}`, {
method: 'DELETE'
})
.then(data => data.json())
.then(response => {
console.log(response);
window.location.pathname = '/index.html';
});
}
}

// Handle user's info content changes
function handleTextChange(e) {

Expand Down

0 comments on commit edd6d73

Please sign in to comment.