Skip to content

Commit f3f816b

Browse files
Add some error handling for booking form and update minor css
1 parent 98e258e commit f3f816b

File tree

6 files changed

+23
-9
lines changed

6 files changed

+23
-9
lines changed

dist/index.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
<header>
1313
<h1>The Overlook Hotel</h1>
1414
<nav>
15-
<!-- <button>view availability</button> -->
16-
<button class="nav-btn" id="changeUserBtn">logout</buttons>
15+
<button class="nav-btn" id="changeUserBtn">Logout</buttons>
1716
</nav>
1817
</header>
1918
<section class="log-in-view" id="logInView">

src/apiCalls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const postData = (user, dateSelected, roomNum) => {
4444
})
4545
.then(checkForError)
4646
.then(() => loadPageInfo())
47-
.catch(err => console.error(err))
47+
.catch(domUpdates.displayCatchE)
4848
}
4949

5050
const checkForError = (response) => {

src/css/_login.scss

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
width: 30vw;
2020
height: 6vw;
2121
margin: 0.7rem;
22+
font-size: 2vw;
2223
}
2324

2425
.log-in-form{

src/css/_roomCards.scss

+2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ img {
4040
}
4141

4242
.go-home{
43+
width: 20vw;
4344
margin-left: 3vw;
45+
font: 2vw;
4446
}
4547

4648
.select-room{

src/domUpdates.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ const domUpdates = {
8888
},
8989

9090
renderAvailableRooms(guest, bookings, rooms, hotel) {
91+
const noRooms = document.getElementById('noRoomsError');
92+
noRooms.innerText = ''
93+
9194
availableCards.innerHTML = ''
9295
let date = dayjs(arrivalDate.value).format('YYYY/MM/DD');
9396
if(searchOptions.value === 'empty') {
@@ -148,7 +151,6 @@ const domUpdates = {
148151

149152
displayNoRoomsError(){
150153
const noRooms = document.getElementById('noRoomsError');
151-
console.log(noRooms)
152154
noRooms.innerText = 'Sorry there are no rooms available for your search requirements, please try again!'
153155

154156
},
@@ -161,6 +163,16 @@ const domUpdates = {
161163
displaySuccess(){
162164
const successMsg = document.getElementById('successMsg');
163165
successMsg.innerText = 'Your booking was added successfully!'
166+
},
167+
168+
displayBookingError(){
169+
const successMsg = document.getElementById('successMsg');
170+
successMsg.innerText = 'Something went wrong. Please try again later!'
171+
},
172+
173+
displayLoginCatchError(){
174+
const signInError = document.getElementById('signInError');
175+
signInError.innerText = 'Sorry, something went wrong with the server. Please try again later!'
164176
}
165177

166178
}

src/scripts.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ export function loadPageInfo(){
5656
bookingsData = response[2].bookings;
5757
instantiateRooms(roomsData);
5858
instantiateBookings(bookingsData)
59-
// guest = new Guest(guestData[5]);
6059
hotel = new Hotel(rooms, bookings)
6160
domUpdates.displayGuestDashboard(guest, rooms, bookings, hotel)
6261
})
63-
console.log(bookings, 'outside')
64-
62+
console.log(bookings)
6563
}
6664

6765
function getUser(customerID){
@@ -71,6 +69,7 @@ function getUser(customerID){
7169
guest = new Guest(currentUser);
7270
loadPageInfo();
7371
})
72+
7473
}
7574

7675
function instantiateRooms(roomsData) {
@@ -99,7 +98,6 @@ function displayAvailableRooms() {
9998
event.preventDefault();
10099
domUpdates.renderAvailableRooms(guest, bookings, rooms, hotel);
101100
form.reset();
102-
103101
}
104102

105103
function displaySelectedRoom(event) {
@@ -122,7 +120,7 @@ function addNewBooking(event) {
122120

123121
apiCalls.postData(user, dateSelected, roomNum)
124122
}
125-
// setTimeout()
123+
setTimeout(returnHome, 2000);
126124

127125
}
128126

@@ -153,6 +151,7 @@ function logIn(customerID){
153151
logInView.classList.add('hidden');
154152
mainPage.classList.remove('hidden');
155153
getUser(customerID)
154+
156155
}
157156

158157
function changeUser(){
@@ -161,5 +160,6 @@ function changeUser(){
161160

162161
function returnHome(){
163162
domUpdates.goHome();
163+
selectedRoom.classList.add('hide');
164164
loadPageInfo();
165165
}

0 commit comments

Comments
 (0)