Skip to content

Commit

Permalink
ReservationSummary
Browse files Browse the repository at this point in the history
  • Loading branch information
Pomog committed Nov 16, 2023
1 parent 2e64f3f commit e8a5d1c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,13 @@ func (m *Repository) ReservationSummary(w http.ResponseWriter, r *http.Request)
reservation, ok := m.App.Session.Get(r.Context(), "reservation").(models.Reservation)
if !ok {
log.Println("cannot get item from session")
m.App.Session.Put(r.Context(), "error", "cannot get item from session")
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
return
}

m.App.Session.Remove(r.Context(), "reservation")

data := make(map[string]interface{})
data["reservation"] = reservation

Expand Down
3 changes: 3 additions & 0 deletions internal/render/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func NewTemplates(a *config.AppConfig) {
}

func AddDefaultData(td *models.TemplateData, r *http.Request) *models.TemplateData {
td.Flash = app.Session.PopString(r.Context(), "flash")
td.Warning = app.Session.PopString(r.Context(), "warning")
td.Error = app.Session.PopString(r.Context(), "error")
td.CSRFToken = nosurf.Token(r)
return td
}
Expand Down
12 changes: 12 additions & 0 deletions templates/base.layout.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@
})
}

{{with .Error}}
notify("{{.}}", "error")
{{end}}

{{with .Flash}}
notify("{{.}}", "success")
{{end}}

{{with .Warning}}
notify("{{.}}", "warning")
{{end}}

function Prompt() {
let toast = function (c) {
const{
Expand Down
6 changes: 3 additions & 3 deletions templates/reservation-summary.page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<tbody>
<tr>
<td>Name:</td>
<td>{{$res.FirstName}} {{res.LastName}}</td>
<td>{{$res.FirstName}} {$res.LastName}}</td>
</tr>

<tr>
Expand All @@ -32,12 +32,12 @@

<tr>
<td>Email:</td>
<td>{{res.Email}}</td>
<td>{{$res.Email}}</td>
</tr>

<tr>
<td>Phone:</td>
<td>{{res.Phone}}</td>
<td>{{$res.Phone}}</td>
</tr>

</tbody>
Expand Down

0 comments on commit e8a5d1c

Please sign in to comment.