From fed901ce25ff92d689fbb6e143963394b77c2c9b Mon Sep 17 00:00:00 2001 From: vinchent Date: Wed, 10 Jul 2024 23:32:49 +0200 Subject: [PATCH] Providing feedback when searching by room, and connecting to the reservation page --- internal/handlers/handlers.go | 18 ++++++++++++------ templates/base.layout.tmpl | 4 ++++ templates/generals.page.tmpl | 20 +++++++++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index a721c33..107c07a 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -245,9 +245,12 @@ func (m *Repository) PostAvailability(w http.ResponseWriter, r *http.Request) { }) } -type responseJSON struct { - OK bool `json:"ok"` - Message string `json:"message"` +type jsonResponse struct { + OK bool `json:"ok"` + Message string `json:"message"` + RoomID string `json:"room_id"` + StartDate string `json:"start_date"` + EndDate string `json:"end_date"` } // AvailabilityJSON is the search for availability page handler @@ -279,9 +282,12 @@ func (m *Repository) AvailabilityJSON(w http.ResponseWriter, r *http.Request) { return } - resp := responseJSON{ - OK: available, - Message: "", + resp := jsonResponse{ + OK: available, + Message: "", + StartDate: sd, + EndDate: ed, + RoomID: strconv.Itoa(roomID), } out, err := json.MarshalIndent(resp, "", " ") diff --git a/templates/base.layout.tmpl b/templates/base.layout.tmpl index e53bccd..43e0be0 100644 --- a/templates/base.layout.tmpl +++ b/templates/base.layout.tmpl @@ -183,16 +183,20 @@ async function custom(c) { const { + icon = "", msg = "", title = "", + showConfirmButton = true, } = c; const {value: result} = await Swal.fire({ + icon: icon, title: title, html: msg, backdrop: false, focusConfirm: false, showCancelButton: true, + showConfirmButton: showConfirmButton, willOpen: () => { if (c.willOpen !== undefined) { c.willOpen(); diff --git a/templates/generals.page.tmpl b/templates/generals.page.tmpl index 877b0c4..3d2644e 100644 --- a/templates/generals.page.tmpl +++ b/templates/generals.page.tmpl @@ -43,7 +43,8 @@ `; - Prompt().custom({ + let attention = Prompt() + attention.custom({ title: "Choose your dates", msg: html, willOpen: () => { @@ -74,8 +75,25 @@ .then(data => { if (data.ok) { console.log("room is available") + attention.custom({ + icon: "success", + // TODO: use the default ok button instead + msg: '

Room is available

' + + '

' + + 'Book now!

', + showConfirmButton: false, + }); } else { console.log("room is not available") + attention.error({ + msg: "No availability" + }); } }) },