Skip to content
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

Aruna(ampers) #21

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
45 changes: 45 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Trips</title>
<!-- <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/foundation/6.2.3/foundation.min.css"> -->

<link rel="stylesheet" href="style.css">
</head>
<body>

<header>
<div id="header">TREK</div>

</header>

<main class="tripcontainer">
<div class="buttoncontainer">
<section id="status-message"></section>
<section class="button">
<button id="load" class="button">Get trips!</button>
</section>
</div>
<div class="triplist">
<ul id="trip-list"></ul>

</div>
<div class="tripdetail">
<h4>Trip Details</h4>
<section id="trip"></section>
</div>
<div class="tripreservation">
<h4>Reserve Trip</h4>
<section id="reservation">


</div>
</main>

<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>

</body>
</html>
100 changes: 100 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const URL = 'https://ada-backtrek-api.herokuapp.com/trips/';

const reportStatus = (message) => {
$('#status-message').html(message);
}

const loadTrips = () => {

const tripList = $('#trip-list');
tripList.empty();

reportStatus('Loading Trips! Please Wait...');

axios.get(URL)
.then((response) => {
response.data.forEach((trip) => {
tripList.append(`<li id="${trip.id}">${trip.name}</li>`);
});
reportStatus('Trips Loaded!');
})
.catch((error) => {
reportStatus(`Error: ${error.message}`);
})
}
const loadTrip = (id) => {

const tripInfo = $('#trip');
tripInfo.empty();
const reservationInfo = $('#reservation');
reservationInfo.empty();

reportStatus('Loading Trip Details! Please Wait...')

axios.get(URL + `${id}`)
.then((response) => {

let data = response.data;
console.log(data.name);


tripInfo.append(`<li><strong>Name: </strong>${data.name}</li>`);
tripInfo.append(`<li>Continent: ${data.continent}</li>`);
tripInfo.append(`<li>Category:${data.category}</li>`);
tripInfo.append(`<li>Weeks: ${data.weeks}</li>`);
tripInfo.append(`<li>Cost: ${data.cost}</li>`);
tripInfo.append(`<li>About:${data.about}</li>`);
console.log(tripInfo);

reservationInfo.append(
`<label class="user"> Name:</label>
<input type="text" name="name" class="form"/><br>`

);
reservationInfo.append(
`<label class="user">Email:</label>
<input type="text" name="email" class="form"/><br>`
);
reservationInfo.append(`<label>Trip: ${data.name}</label><br>`);
reservationInfo.append(
`<input type="submit" name="reserve-trip" class="reserve" id="reserve${data.id}"/>`
);
reportStatus('Trip Details Loaded!');
})
.catch((error) => {
reportStatus(`Error: ${error.message}`);
})
}
const reservationData = (id) => {
let tripData = {name: $(`input[name="name"]`).val(),
email:$(`input[name="email"]`).val()
}
console.log(reservationData);

reportStatus('Reserving a trip...');

axios.post(URL + `${id}/reservations`, tripData)
.then((response) => {
console.log('The post req was succesful')
reportStatus(`Successfully reserved this trip ${response.data.name}!`);

})
.catch((error) => {
console.log(error.response);

reportStatus(`Encountered an error: ${error.message}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should loop through the validation errors (if any) here as well as the error message.

});

};
$(document).ready(() => {
$('#load').click(loadTrips);
$('#trip-list').on('click', 'li', function() {
let id = $(this).attr('id');
loadTrip(id);
});
$('#reservation').on('click', '.reserve', function(){
let id = $(this).attr('id').substr(7);
console.log(id);
reservationData(id);
});
})
50 changes: 50 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

body{

/* background-color: lightblue; */
background-image: url("trips.jpeg");
height: 100%;
padding: 2rem;

background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}



header{


}
*{
list-style-type: none;
}
.tripcontainer{
display: grid;
grid-template-columns: auto auto;
align-content: space-around;
/* border: 1px solid black; */
font-size: 12px;


}
.buttoncontainer{
grid-column: 1/3;
border: 1px solid black;
}
.triplist{
grid-row: 2/5;
border: 1px solid black;
text-decoration: underline;

}
.tripdetail{
border: 1px solid black;
padding:5px;
}
.tripreservation{
border: 1px solid black;
padding:5px;
}
83 changes: 83 additions & 0 deletions travel.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added trek.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added trips.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.