|
|
@@ -12,7 +12,12 @@ const placeInput = document.getElementById('place');
|
|
|
|
|
|
window.addEventListener("load", async function() {
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
- appointment = urlParams.get('appointment');
|
|
|
+ const appointment = urlParams.get('appointment');
|
|
|
+
|
|
|
+ if (appointment) {
|
|
|
+ // load appointment data
|
|
|
+ await loadAppointment(appointment);
|
|
|
+ }
|
|
|
|
|
|
document.getElementById("appointment-btn").addEventListener('click', async () => {
|
|
|
if (!appointment) {
|
|
|
@@ -32,6 +37,31 @@ async function fetchWithToken(url, options) {
|
|
|
}});
|
|
|
}
|
|
|
|
|
|
+async function displayAppointment(data) {
|
|
|
+ titleInput.value = data.title;
|
|
|
+ descriptionInput.value = data.description;
|
|
|
+ dueDateInput.value = data.dueDate;
|
|
|
+ startDateInput.value = data.startDate;
|
|
|
+ endDateInput.value = data.endDate;
|
|
|
+ placeInput.value = data.place;
|
|
|
+ console.log(data.dueDate);
|
|
|
+ console.log(data.startDate);
|
|
|
+ console.log(data.endDate);
|
|
|
+}
|
|
|
+
|
|
|
+async function loadAppointment(appointment) {
|
|
|
+ let options = {method: 'GET', headers: {'User-Agent': 'insomnia/10.0.0'}};
|
|
|
+
|
|
|
+ const response = await fetch(`/api/schedule?appointmentId=${appointment}`, options)
|
|
|
+ .catch(err => console.error('error:' + err));
|
|
|
+
|
|
|
+ if (response.status === 404) {
|
|
|
+ window.location.replace("/html/404.html");
|
|
|
+ }
|
|
|
+ const js = await response.json();
|
|
|
+ await displayAppointment(js);
|
|
|
+}
|
|
|
+
|
|
|
async function createAppointment() {
|
|
|
const title = titleInput.value;
|
|
|
const description = descriptionInput.value;
|