title: Add a delete function when viewing events (React-Redux-Firebase)
body: <p>Here I let user to view the details of the event. There will be a button at the end of the event details for them to delete the event. However, how should I go about doing this?</p>
  
  <p>Should I implement the delete function here in the viewing event details file? Or should I create another .jsx file that handles the delete? The delete.jsx file below contains the handleDelete method that will delete the event from the redux store, which then updates the delete to the firestore</p>
  
  <pre><code>VIEWING EVENT DETAILS FILE
  import React from "react";
  import { connect } from "react-redux";
  import { firestoreConnect } from "react-redux-firebase";
  import { compose } from "redux";
  import { Redirect } from "react-router-dom";
  import moment from "moment";
  import DeleteEvent from "./DeleteEvent";
  
  const EventDetails = props =&gt; {
    const { event, auth } = props;
    if (!auth.uid) return &lt;Redirect to="/signin" /&gt;;
  
    if (event) {
      return (
        &lt;div className="container section project-details"&gt;
          &lt;div className="card z-depth-0"&gt;
            &lt;div className="card-content"&gt;
              &lt;span className="card-title"&gt;Subject: {event.subject}&lt;/span&gt;
              &lt;p&gt;Venue: {event.venue}&lt;/p&gt;
              &lt;p&gt;Time: {event.time}&lt;/p&gt;
              &lt;p&gt;Description: {event.description}&lt;/p&gt;
              &lt;p&gt;Class Size: {event.size}&lt;/p&gt;
            &lt;/div&gt;
            &lt;div className="card-action grey lighten-4 grey-text"&gt;
              &lt;div&gt;
                Tutor: {event.authorFirstName} {event.authorLastName}
              &lt;/div&gt;
              &lt;div&gt;
                Time of class created:
                {moment(event.createdAt.toDate()).calendar()}
              &lt;/div&gt;
              &lt;DeleteEvent event={event} /&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      );
    } else {
      return (
        &lt;div className="container centre"&gt;
          &lt;p&gt;Loading event....&lt;/p&gt;
        &lt;/div&gt;
      );
    }
  };
  
  const mapStateToProps = (state, ownProps) =&gt; {
    const id = ownProps.match.params.id;
    const events = state.firestore.data.events;
    const event = events ? events[id] : null;
    return {
      event: event,
      auth: state.firebase.auth
    };
  };
  
  export default compose(
    connect(mapStateToProps),
    firestoreConnect([
      {
        collection: "events"
      }
    ])
  )(EventDetails);
  </code></pre>
  
  
  
  <pre><code>DELETE.JSX FILE
  import React, { Component } from "react";
  import { connect } from "react-redux";
  import { Redirect } from "react-router-dom";
  import { deleteEvent } from "../../store/actions/eventActions";
  
  const DeleteEvent = ({ event }) =&gt; {
    const handleDelete = e =&gt; {
      e.preventDefault();
      this.props.deleteEvent(event);
      //this.props.history.push("/"); // redirect to homepage after deletion
    };
  
    return (
      &lt;div&gt;
        &lt;button onClick={this.handleDelete} className="btn green z-depth-0"&gt;
          Delete
        &lt;/button&gt;
      &lt;/div&gt;
    );
  };
  
  const mapDispatchToProps = dispatch =&gt; {
    return {
      deleteEvent: event =&gt; dispatch(deleteEvent(event))
    };
  };
  
  export default connect(null, mapDispatchToProps)(DeleteEvent);
  </code></pre>