diff --git a/frontend/src/components/ViewTrips/index.js b/frontend/src/components/ViewTrips/index.js index 07f14659..33f425ff 100644 --- a/frontend/src/components/ViewTrips/index.js +++ b/frontend/src/components/ViewTrips/index.js @@ -3,7 +3,7 @@ import React from 'react'; import Button from 'react-bootstrap/Button'; import Header from '../Header/'; -import AddTripModal from './add-trip-modal.js' +import SaveTripModal from './save-trip-modal.js' import TripsContainer from './trips-container.js'; @@ -17,13 +17,22 @@ class ViewTrips extends React.Component { super(); this.state = { showModal: false, refreshTripsContainer: false, - refreshAddTripModal: false, + refreshSaveTripModal: false, + tripId: null, + placeholderObj: { + name: null, + description: null, + destination: null, + startDate: null, + endDate: null, + collaborators: [] + } }; } /** - * Flips `refreshTripsContainer` property which causes that TripsContainer - * component to be reloaded. + * Handler that flips `refreshTripsContainer` property which causes that + * TripsContainer component to be reloaded. * * This allows a trip creator's view trips page to be updated in real time. * @@ -36,36 +45,84 @@ class ViewTrips extends React.Component { } /** - * Flips `refreshAddTripModal` property which causes that AddTripModal - * component to be reloaded. + * Handler that flips `refreshSaveTripModal` property which causes that + * save/edit trip component to be reloaded. * * This was done to prevent bugs where multiple component input fields would * persist from one instance of the modal to the next when view trips page * was not refreshed in between. */ - refreshAddTripModal = () => { - this.setState({ refreshAddTripModal: !this.state.refreshAddTripModal }); + refreshSaveTripModal = () => { + this.setState({ refreshSaveTripModal: !this.state.refreshSaveTripModal }); } - /** Property that refreshes and displays add trip page. */ - showAddTripModal = () => { - this.refreshAddTripModal() + /** Handler that hides the add/edit trip page. */ + hideSaveTripModal = () => { this.setState({ showModal: false }); } + + /** Handler that refreshes and displays the add/edit trip page. */ + showSaveTripModal = () => { + this.refreshSaveTripModal(); this.setState({ showModal: true }); } - /** Property that sets `showModal` to false --> hides add trip page. */ - hideAddTripModal = () => { this.setState({ showModal: false }); } + /** + * Handler that displays the add trip page. + * + * Sets state for the states `tripId` and `placeholderObj` in order + * to ensure the modal has the visual characteristics of an "add trip" modal + * and creates a new Trip document in the database. + */ + showAddTripModal = () => { + this.setState({ + tripId: null, + placeholderObj: { + name: 'Enter Trip Name', + description: 'Enter Trip Description', + destination: 'Enter Trip Destination', + startDate: '', + endDate: '', + collaborators: ['person@email.xyz'] + } + }); + this.showSaveTripModal(); + } + + /** + * Handler that displays the edit trip page. + * + * Sets state for the states `tripId` and `placeholderObj` in order + * to ensure the modal has the visual characteristics of an "edit trip" modal + * and overwrites and existing Trip document in the database. + * + * TODO(Issue #69): Get individual tripId and trip data for placeholderObj. + */ + showEditTripModal = () => { + this.setState({ + tripId: null, + placeholderObj: { + name: null, + description: null, + destination: null, + startDate: null, + endDate: null, + collaborators: [] + } + }); + this.showSaveTripModal(); + } /** @inheritdoc */ render() { return (
-
@@ -210,7 +271,7 @@ class AddTripModal extends React.Component { Cancel @@ -219,4 +280,4 @@ class AddTripModal extends React.Component { } }; -export default AddTripModal; +export default SaveTripModal;