-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from akhilome/gh-pages
Update Frontend to consume delete /menu/:id endpoint
- Loading branch information
Showing
3 changed files
with
41 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
function deleteFoodItem(e) { | ||
if (!e.target.matches('.food-details__action > button')) return; | ||
flashMessage('deleting selected item ...'); | ||
|
||
const foodCard = e.target.parentNode.parentNode.parentNode; | ||
const foodId = Number(e.target.parentNode.previousElementSibling.dataset.foodid); | ||
|
||
fetch(`https://kiakiafood.herokuapp.com/api/v1/menu/${foodId}`, { | ||
method: 'DELETE', | ||
headers: { 'x-auth': token }, | ||
}).then(data => data.json()) | ||
.then((response) => { | ||
if (response.status !== 'success') { | ||
flashMessage(response.message, 'error'); | ||
return; | ||
} | ||
foodCard.remove(); | ||
flashMessage('food item removed', 'success'); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
flashMessage('an error occured while removing that food item', 'error'); | ||
}); | ||
} | ||
|
||
document.querySelector('.admin-menu').addEventListener('click', deleteFoodItem); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters