{"size": 1049, "ext": "js", "max_stars_repo_path": "public/js/deleteEvent.js", "max_stars_repo_name": "damienluzzo33/Grouper-App", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/js/deleteEvent.js", "max_issues_repo_name": "damienluzzo33/Grouper-App", "max_issues_repo_issues_event_min_datetime": "2021-11-01T16:09:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-02T16:32:12.000Z", "max_forks_repo_path": "public/js/deleteEvent.js", "max_forks_repo_name": "damienluzzo33/Grouper-App", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 49.9523809524, "max_line_length": 107, "alphanum_fraction": 0.6816015253}
//*  create a function that allows the user to delete an event that they have created
const deleteEventHandler = async (event) => {
    //* if the data-id attribute exists for the event, then get it and use it to delete corresponding event
    if (event.target.hasAttribute('data-delete')) {
        const eventId = event.target.getAttribute('data-delete');
        const response = await fetch(`/api/events/${eventId}`, {
            method: 'DELETE',
            headers: { 'Content-Type': "application/json" }
        });
        //* if the response comes back okay, then send the user back to the dashboard
        if (response.ok) document.location.replace('/dashboard');
        //*  otherwise alert them with failure message
        else alert('Failed to delete event. Try again!')
    }
};

//* get the button with the id of delete-event-btn
const deleteButton = document.querySelector('#delete-event-btn');
//* add event listener to the button and run above function when clicked
deleteButton.addEventListener('click', deleteEventHandler);
