diff --git a/index.html b/index.html new file mode 100644 index 00000000..8e80b03d --- /dev/null +++ b/index.html @@ -0,0 +1,47 @@ + + +
+ +${message}
${response.data.about}
` + ) + }) + + .catch((error) => { + reportStatus( + `Encountered an error while loading trips: ${tripID}: ${error.message}` + ); + console.log(error); + }); +}; + +// Make a reservation + +const readFormData = () => { + let parsedData = {}; + + parsedData.name = $("input[name='name']").val(); + parsedData.email = $("input[name='email']").val(); + + return parsedData; + }; + +const clearForm = () => { + $('#trip-form input[name="name"]').val(''); + $('#trip-form input[name="email"]').val(''); +} + +const reservation = (event) => { + + event.preventDefault(); + console.log('this works') + + + const tripID = event.target.className; + const createTripURL = `https://trektravel.herokuapp.com/trips/${tripID}/reservations`; + let tripData = readFormData(); + reportStatus('Sending trip data...'); + + console.log("About to post trip data", tripData) + // keep getting a 404 not found. The data isn't being read + axios.post(createTripURL, tripData) + .then((response) => { + console.log(response); + reportStatus(`Successfully added trip! ${response.data.id}`); + clearForm(); + }) + .catch((error) => { + console.log(error.response) + if(error.response.data && error.response.data.errors) { + reportStatus(`There was an error loading this trip: ${error.message}`, error.response.data.errors); + } else { + reportStatus(`There was an error loading this trip: ${error.message}`); + } + }); +}; + +$(document).on('click', 'li', detailsTrips); +$(document).on('submit', 'form', reservation); + +$(document).ready(() => { + $('#load-trips').click(loadTrips); + $('form').submit(readFormData); +}); diff --git a/style.css b/style.css new file mode 100644 index 00000000..f4161127 --- /dev/null +++ b/style.css @@ -0,0 +1,23 @@ +body { + background-color: #FFC2AD; +} + +main { + display: flex; +} + +h2 { + color: #CC6D4E; +} + +h3 { + color: #FF8960; +} + +li { + color: #CC6D4E +} + +ul { + list-style-type: none; +} \ No newline at end of file