blocked dates page and warning for special-cake orders
Add blocked_date table (migration 5), model, and store CRUD methods. Add management page at /blocked with add/delete functionality. Add nav link 'Terminy zablokowane' with event_busy icon. Pass blocked dates to order form as JSON data attribute. On form submit, if the order has special cakes and the date is blocked, show a confirm() dialog warning the user.
This commit is contained in:
parent
5a5372b831
commit
5f156ab6a0
13 changed files with 175 additions and 16 deletions
|
|
@ -141,6 +141,27 @@ func (h *Server) cake(r *http.Request) (templ.Component, int, error) {
|
|||
return templates.CakePage(data, tags), http.StatusOK, nil
|
||||
}
|
||||
|
||||
func (h *Server) blocked(r *http.Request) (templ.Component, int, error) {
|
||||
dates, err := h.s.GetBlockedDates()
|
||||
if err != nil {
|
||||
return nil, http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
if r.Header.Get("HX-Request") == "true" {
|
||||
return templates.MainContent("Terminy zablokowane", templ.NopComponent, templates.BlockedMain(dates)), http.StatusOK, nil
|
||||
}
|
||||
|
||||
return templates.BlockedPage(dates), http.StatusOK, nil
|
||||
}
|
||||
|
||||
func loadBlockedDates(h *Server) []models.BlockedDate {
|
||||
dates, err := h.s.GetBlockedDates()
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return dates
|
||||
}
|
||||
|
||||
func (h *Server) order(r *http.Request) (templ.Component, int, error) {
|
||||
catalogue, err := h.s.GetCakes()
|
||||
if err != nil {
|
||||
|
|
@ -150,13 +171,14 @@ func (h *Server) order(r *http.Request) (templ.Component, int, error) {
|
|||
if err != nil {
|
||||
return nil, http.StatusInternalServerError, err
|
||||
}
|
||||
blockedDates := loadBlockedDates(h)
|
||||
|
||||
url := strings.Split(r.URL.Path, "/")
|
||||
if len(url) < 3 || url[2] == "" {
|
||||
if r.Header.Get("HX-Request") == "true" {
|
||||
return templates.MainContent("Nowe zamówienie", templ.NopComponent, templates.OrderForm(models.Order{Date: time.Now()}, catalogue, tags)), http.StatusOK, nil
|
||||
return templates.MainContent("Nowe zamówienie", templ.NopComponent, templates.OrderForm(models.Order{Date: time.Now()}, catalogue, tags, blockedDates)), http.StatusOK, nil
|
||||
}
|
||||
return templates.OrderPage(models.Order{Date: time.Now()}, catalogue, tags), http.StatusOK, nil
|
||||
return templates.OrderPage(models.Order{Date: time.Now()}, catalogue, tags, blockedDates), http.StatusOK, nil
|
||||
}
|
||||
|
||||
id, err := strconv.Atoi(url[2])
|
||||
|
|
@ -170,8 +192,8 @@ func (h *Server) order(r *http.Request) (templ.Component, int, error) {
|
|||
}
|
||||
|
||||
if r.Header.Get("HX-Request") == "true" {
|
||||
return templates.MainContent(templates.OrderTitle(order), templ.NopComponent, templates.OrderForm(order, catalogue, tags)), http.StatusOK, nil
|
||||
return templates.MainContent(templates.OrderTitle(order), templ.NopComponent, templates.OrderForm(order, catalogue, tags, blockedDates)), http.StatusOK, nil
|
||||
}
|
||||
|
||||
return templates.OrderPage(order, catalogue, tags), http.StatusOK, nil
|
||||
return templates.OrderPage(order, catalogue, tags, blockedDates), http.StatusOK, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue