refactor and order template

This commit is contained in:
bronku 2026-06-16 16:15:40 +02:00
parent 922478bdeb
commit 2465956fc2
5 changed files with 126 additions and 99 deletions

View file

@ -5,15 +5,12 @@ import (
"strconv"
"git.bronku.xyz/bronku/cake-order-tracker/models"
"git.bronku.xyz/bronku/cake-order-tracker/server/dto"
)
templ OrderPage(order models.Order, catalogue []models.Cake, allTags []models.Tag, blockedDates []models.BlockedDate) {
@Layout(OrderTitle(order), OrderForm(order, catalogue, allTags, blockedDates))
}
templ OrderForm(order models.Order, catalogue []models.Cake, allTags []models.Tag, blockedDates []models.BlockedDate) {
<form method="post" class="split-pane order-form" onsubmit="return confirmBlockedDate(this)" data-blocked-dates={ blockedDatesJSON(blockedDates) } data-state={ orderStateJSON(order) }>
<input type="hidden" name="id" value={ strconv.Itoa(order.ID) }/>
templ OrderForm(dto dto.OrderPage) {
<form method="post" class="split-pane order-form" onsubmit="return confirmBlockedDate(this)" data-blocked-dates={ blockedDatesJSON(dto.BlockedDates) } data-state={ orderStateJSON(dto.Order) }>
<input type="hidden" name="id" value={ dto.Order.ID }/>
<div class="order-left">
<section class="card">
<header>
@ -26,33 +23,32 @@ templ OrderForm(order models.Order, catalogue []models.Cake, allTags []models.Ta
<div class="form-grid">
<div>
<label>Imię *</label>
<input type="text" name="name" value={ order.Name } placeholder="Jan"/>
<input type="text" name="name" value={ dto.Order.Name } placeholder="Jan"/>
</div>
<div>
<label>Nazwisko *</label>
<input type="text" name="surname" value={ order.Surname } placeholder="Kowalski"/>
<input type="text" name="surname" value={ dto.Order.Surname } placeholder="Kowalski"/>
</div>
<div>
<label>Telefon</label>
<input type="tel" name="phone" value={ order.Phone } placeholder="+48 123 456 789"/>
<input type="tel" name="phone" value={ dto.Order.Phone } placeholder="+48 123 456 789"/>
</div>
<div>
<label>Lokalizacja</label>
<div class="toggle-group">
<input type="hidden" name="location" value={ order.Location }/>
<button type="button" class={ "toggle-btn", templ.KV("active", order.Location == "Kartuzy") } onclick="setLocation(this, 'Kartuzy')">Kartuzy</button>
<button type="button" class={ "toggle-btn", templ.KV("active", order.Location == "Somonino") } onclick="setLocation(this, 'Somonino')">Somonino</button>
<input type="hidden" name="location" value={ dto.Order.Location }/>
<button type="button" class={ "toggle-btn", templ.KV("active", dto.Order.Location == "Kartuzy") } onclick="setLocation(this, 'Kartuzy')">Kartuzy</button>
<button type="button" class={ "toggle-btn", templ.KV("active", dto.Order.Location == "Somonino") } onclick="setLocation(this, 'Somonino')">Somonino</button>
</div>
</div>
<div>
<label>Data dostawy *</label>
<input type="date" name="date" value={ order.Date.Format("2006-01-02") }/>
<input type="date" name="date" value={ dto.Order.Date.Format("2006-01-02") }/>
</div>
<div>
<label>Zaliczka</label>
<input type="number" name="paid" min="0" step="0.01" value={ order.Paid.String() } oninput={ templ.JSFuncCall("updatePrepaid") }/>
<input type="number" name="paid" min="0" step="0.01" value={ dto.Order.Paid.String() } oninput={ templ.JSFuncCall("updatePrepaid") }/>
</div>
</div>
</div>
</section>
@ -81,16 +77,16 @@ templ OrderForm(order models.Order, catalogue []models.Cake, allTags []models.Ta
<input type="text" placeholder="Filtruj produkty..." oninput="filterCatalogue(this)"/>
</div>
</header>
if len(allTags) > 0 {
if len(dto.Tags) > 0 {
<div class="tag-row">
for _, t := range allTags {
for _, t := range dto.Tags {
<button type="button" class="tag-chip" data-tag={ t.Name } onclick="toggleCatalogueTagFilter(this)">{ t.Name }</button>
}
</div>
}
<div class="catalogue-scroll">
<ul id="catalogue-grid">
for _, c := range catalogue {
for _, c := range dto.Catalogue {
<li data-name={ c.Name } data-tags={ tagNames(c.Tags) }>
<div>
<div class="icon cake">
@ -125,7 +121,7 @@ templ OrderForm(order models.Order, catalogue []models.Cake, allTags []models.Ta
</h2>
</header>
<ul id="basket-items">
for _, c := range order.Cakes {
for _, c := range dto.Order.Cakes {
<li data-cake-id={ strconv.Itoa(c.ID) }>
<div class="basket-item-body">
<div class="name">{ c.Name }</div>
@ -138,7 +134,7 @@ templ OrderForm(order models.Order, catalogue []models.Cake, allTags []models.Ta
<input type="hidden" name={ "cake[" + strconv.Itoa(c.ID) + "]" } value={ strconv.Itoa(c.Amount) }/>
</li>
}
for _, s := range order.SpecialCakes {
for _, s := range dto.Order.SpecialCakes {
<li data-special-id={ strconv.Itoa(s.ID) }>
<div class="basket-item-body">
<div class="name">{ s.Name }</div>
@ -173,15 +169,15 @@ templ OrderForm(order models.Order, catalogue []models.Cake, allTags []models.Ta
<div class="summary-totals">
<div class="total-row">
<span>Subtotal</span>
<span id="subtotal-price">{ order.Subtotal().String() } PLN</span>
<span id="subtotal-price">{ dto.Order.Subtotal().String() } PLN</span>
</div>
<div class="total-row">
<span>Zaliczka</span>
<span id="paid-amount">{ order.Paid.String() } PLN</span>
<span id="paid-amount">{ dto.Order.Paid.String() } PLN</span>
</div>
<div class="total-row grand">
<span>Do zapłaty</span>
<span id="total-price">{ order.Total().String() } PLN</span>
<span id="total-price">{ dto.Order.Total().String() } PLN</span>
</div>
<button type="submit" class="btn-finalize">
<span class="material-symbols-outlined">check_circle</span>
@ -191,8 +187,7 @@ templ OrderForm(order models.Order, catalogue []models.Cake, allTags []models.Ta
</section>
</aside>
</form>
@SpecialCakeOverlay(allTags)
@SpecialCakeOverlay(dto.Tags)
}
func orderStateJSON(order models.Order) string {