-
Notifications
You must be signed in to change notification settings - Fork 42
Victoria Garcia - Ampers - Trek #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0d3ab7e
163e5ce
1feda0a
e3ae4ea
65cb878
24a5e2b
5781f34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
|
|
||
| body { | ||
| font-family: sans-serif; | ||
| } | ||
|
|
||
| main { | ||
| display: grid; | ||
| grid-template-columns: 1fr 1fr; | ||
| } | ||
|
|
||
| .all_trips { | ||
| display: inline-block; | ||
| } | ||
|
|
||
| .trip_specifics { | ||
| display: inline-block; | ||
| } | ||
|
|
||
| .single-trip-detail { | ||
| display: block; | ||
| } | ||
|
|
||
| .reservation-opt-in { | ||
| display: block; | ||
| } | ||
|
|
||
| .make_reservation { | ||
| display: block; | ||
| } | ||
|
|
||
| .reservation-result { | ||
| display: block; | ||
| } | ||
|
|
||
| ul { | ||
| list-style-type: none; | ||
| } | ||
|
|
||
| #every-trip li { | ||
| padding-top: 5px; | ||
| } | ||
|
|
||
| .details_box { | ||
| padding-left: 15px; | ||
| } | ||
|
|
||
| .success_message { | ||
| color: fuchsia; | ||
| background-color: khaki; | ||
| padding-left: 20px; | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>All Trekked Up</title> | ||
| <script | ||
| src="https://code.jquery.com/jquery-3.3.1.js"></script> | ||
| <script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
| <script type="text/javascript" src="index.js"></script> | ||
| <link rel="stylesheet" href="index.css"> | ||
| </head> | ||
| <body> | ||
| <section id="status-message"></section> | ||
|
|
||
| <main> | ||
| <section class="all-trips"> | ||
| <h1>DO YOU WANT TO TREK UP YOUR LIFE?</h1> | ||
| <button id="load">LIST EVERY SINGLE WAY TO GET TREKKED UP!!!</button> | ||
| <ul id="every-trip"></ul> | ||
| </section> | ||
| <section class="trip-specifics"> | ||
| <section class = "single-trip-detail"> | ||
| <article id="trip-deets"></article> | ||
| </section> | ||
| <section class = "reservation-opt-in"> | ||
| <article id="reserve-button"></article> | ||
| </section> | ||
| <section class="make-reservation"> | ||
| <article id="reservation-box"></article> | ||
| </section> | ||
| <section class="reservation-result"> | ||
| <article id="result-box"></article> | ||
| </section> | ||
| </section> | ||
|
|
||
| </main> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
|
|
||
|
|
||
| let targetTripId = null | ||
| let targetTripName = null | ||
|
|
||
| const BASE_URL = 'https://ada-backtrek-api.herokuapp.com/trips'; | ||
|
|
||
| // | ||
| // Status Management | ||
| // | ||
| const reportStatus = (message) => { | ||
| $('#status-message').html(message); | ||
| }; | ||
|
|
||
| const reportError = (message, errors) => { | ||
| let content = `<p>${message}</p><ul>`; | ||
| for (const field in errors) { | ||
| for (const problem of errors[field]) { | ||
| content += `<li>${field}: ${problem}</li>`; | ||
| } | ||
| } | ||
| content += "</ul>"; | ||
| reportStatus(content); | ||
| }; | ||
|
|
||
|
|
||
| const loadTrips = () => { | ||
| reportStatus('Loading trips...'); | ||
|
|
||
| const allTrips = $('#every-trip'); | ||
| allTrips.empty(); | ||
|
|
||
| let allTripsUrl = BASE_URL | ||
|
|
||
| axios.get(allTripsUrl) | ||
| .then((response) => { | ||
| reportStatus(`Successfully loaded ${response.data.length} trips`); | ||
| response.data.forEach((trip) => { | ||
| allTrips.append(`<li id="${trip.id}">${trip.name}</li>`); | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading trips: ${error.message}`); | ||
| console.log(error); | ||
| }); | ||
| }; | ||
|
|
||
| const getTripDetail = function getTripDetail(tripID) { | ||
|
|
||
| reportStatus('Getting trip details.'); | ||
|
|
||
| targetTripId = tripID | ||
|
|
||
| const singleTripDetail = $('#trip-deets'); | ||
| singleTripDetail.empty(); | ||
|
|
||
| let tripDetailUrl = BASE_URL.concat("/").concat(tripID) | ||
|
|
||
| const reserveButton = $('#reserve-button'); | ||
| reserveButton.empty(); | ||
|
|
||
| console.log(`${tripDetailUrl}`); | ||
|
|
||
| axios.get(tripDetailUrl) | ||
| .then((response) => { | ||
| reportStatus(`Trip details loaded!`); | ||
| targetTripName = response.data.name; | ||
| singleTripDetail.append( | ||
| `<h1>HERE'S ONE GOOD WAY TO GET TREKKED UP:</h1> | ||
| <section class="details_box" > | ||
| <h3>Name: ${targetTripName}</h3> | ||
| <h4>Continent: ${response.data.continent}</h4> | ||
| <h4>Category: ${response.data.category}</h4> | ||
| <h5>Weeks: ${response.data.weeks}</h5> | ||
| <h5>Cost: ${response.data.cost}</h5> | ||
| <h5>About: </h5> | ||
| <p>${response.data.about}</p> | ||
| <h6>Trip ID: ${targetTripId}</h6> | ||
| </section>`); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading trip details: ${error.message}`); | ||
| console.log(error); | ||
| }); | ||
| if (singleTripDetail.length > 0 ) { | ||
| reserveButton.append(`<button id="reservation">I Would Like To Trek Up in This Manner</button>` ) | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| const callReservationScreen = function callReservationScreen() { | ||
|
|
||
| reportStatus('Pulling up reservation screen'); | ||
|
|
||
| const reservationScreen = $('#reservation-box'); | ||
| reservationScreen.empty(); | ||
|
|
||
| reservationScreen.append( | ||
| ` <h1> SECURE YOUR OPPORTUNITY TO TREK UP ROYALLY: </h1> | ||
| <h3 class="details_box"> The Trip You Want To Go On Is: ${targetTripName}</h3> | ||
| <form class="details_box" id='reservation-form' name='reservation-form'> | ||
| <label for='name'>Name:</label> | ||
| <input type='text' id='name' name='name'><br> | ||
| <label for='email'>Email:</label> | ||
| <input type='email' id='email' name='email'><br> | ||
| <label> </label> | ||
| <input type='submit' id='submit-reservation-info' | ||
| value='I hereby commit to unapologetically trekking up my life'><br> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You use |
||
| </form>` | ||
| ) | ||
| }; | ||
|
|
||
| const createReservation = (e) => { | ||
|
|
||
| e.preventDefault() | ||
|
|
||
| console.log('in the Create Reservation method!') | ||
|
|
||
| console.log(`Here is the targetTripId: ${targetTripId}`) | ||
| console.log(`Here is the targetTripName: ${targetTripName}`) | ||
|
|
||
| const reserveTripUrl = BASE_URL.concat("/").concat(targetTripId).concat("/reservations") | ||
|
|
||
| console.log(`Here is the reservation-posting URL: ${reserveTripUrl}`) | ||
|
|
||
| const reservationResult = $('#result-box'); | ||
| reservationResult.empty(); | ||
|
|
||
| const reservationData = { | ||
| // name: 'Mona VanDerWaal', | ||
| // email: 'scarysmart@happycrazy.ru' | ||
| name: $('#name').val(), | ||
| email: $('#email').val() | ||
| } | ||
|
|
||
| console.log(`Here is the name for the reservation ${reservationData.name}`) | ||
| console.log(`Here is the email for the reservation ${reservationData.email}`) | ||
|
|
||
| reportStatus(`Submitting a request to reserve a slot in ${targetTripName}.`); | ||
|
|
||
| axios.post(reserveTripUrl, reservationData) | ||
| .then((response) => { | ||
| console.log(response); | ||
| reservationScreen.empty(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I fill out the reservation form correctly to make a reservation, I actually get an unexpected error... that's because I fixed it by adding |
||
| reservationResult.append(`<section class="success_message"><h2>YOUR RESERVATION HAS BEEN CREATED!</h2><h3>Now nothing can stop you from trekking up everything!</h3></section>`) | ||
| reportStatus(`Successfully reservered a slot in Trip Number | ||
| ${response.data.trip_id} for | ||
| ${response.data.name}!` | ||
| ); | ||
| // clearForm(); | ||
| }) | ||
| .catch((error) => { | ||
| console.log(error.response); | ||
| if (error.response.data && error.response.data.errors) { | ||
| reportError( | ||
| `Encountered an error: ${error.message}`, | ||
| error.response.data.errors | ||
| ); | ||
| } else { | ||
| reportStatus(`Encountered an error: ${error.message}`); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| $(document).ready(() => { | ||
| $('#load').click(loadTrips); | ||
| $('#every-trip').on('click', 'li', function(event) { | ||
| getTripDetail(this.id) | ||
| }); | ||
| $('#reserve-button').on('click', 'button', function(event) { | ||
| callReservationScreen() | ||
| }); | ||
| $('#reservation-box').on('submit', 'form', function(event) { | ||
| createReservation(event) | ||
| }); | ||
| }) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beautiful color combination. also, i had no idea
fuchsiawas spelled like that