-
Notifications
You must be signed in to change notification settings - Fork 0
/
book.js
27 lines (26 loc) · 1023 Bytes
/
book.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
document.getElementById('bookForm').addEventListener('submit', async (e) => {
e.preventDefault();
const token = localStorage.getItem('token');
const computerId = document.getElementById('computerId').value;
const startTime = document.getElementById('startTime').value;
const endTime = document.getElementById('endTime').value;
try {
const response = await fetch('http://192.168.81.91:5000/api/computers/book', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`,
},
body: JSON.stringify({ computerId, startTime, endTime }),
});
const data = await response.json();
if (response.ok) {
alert('Booking successful');
window.location.href = 'dashboard.html';
} else {
alert(data.error);
}
} catch (error) {
console.error('Error:', error);
}
});