public/javascript/delete-post.js
// create js to enable user to delete post
create js to enable user to delete post
create js to enable user to delete post
async function deleteFormHandler(event) {
    event.preventDefault();
    const id = window.location.toString().split('/')[
        window.location.toString().split('/').length - 1
      ];
    const response = await fetch(`/api/posts/${id}`, {
        method: 'DELETE',
        body: JSON.stringify({
          post_id: id
        }),
        headers: {
          'Content-Type': 'application/json'
        }
      });
      if (response.ok) {
        document.location.replace('/dashboard/');
      } else {
        alert(response.statusText);
      }
  }
async function deleteFormHandler ( event ) { event . preventDefault ( ) ; const id = window . location . toString ( ) . split ( '/' ) [ window . location . toString ( ) . split ( '/' ) . length - 1 ] ; const response = await fetch ( ` ${ id } ` , { method : 'DELETE' , body : JSON . stringify ( { post_id : id } ) , headers : { 'Content-Type' : 'application/json' } } ) ; if ( response . ok ) { document . location . replace ( '/dashboard/' ) ; } else { alert ( response . statusText ) ; } }
create js to enable user to delete post
create js to enable user to delete post