fix: balance card wrong oob swap
This commit is contained in:
parent
78047c7ee8
commit
91679c3aee
3 changed files with 9 additions and 13 deletions
|
|
@ -401,18 +401,14 @@ func (h *SpaceHandler) CreateExpense(w http.ResponseWriter, r *http.Request) {
|
|||
newTag, err := h.tagService.CreateTag(spaceID, tagName, nil)
|
||||
if err != nil {
|
||||
slog.Error("failed to create new tag from expense form", "error", err, "tag_name", tagName)
|
||||
// Continue processing other tags? Or fail?
|
||||
// Let's continue, maybe the tag was invalid or duplicate race condition.
|
||||
// If duplicate race condition, we could try fetching it again, but for now simple log.
|
||||
continue
|
||||
}
|
||||
finalTagIDs = append(finalTagIDs, newTag.ID)
|
||||
existingTagsMap[tagName] = newTag.ID // Update map in case repeated in this request (though processedTags handles that)
|
||||
existingTagsMap[tagName] = newTag.ID
|
||||
}
|
||||
processedTags[tagName] = true
|
||||
}
|
||||
|
||||
// --- DTO Creation & Service Call ---
|
||||
dto := service.CreateExpenseDTO{
|
||||
SpaceID: spaceID,
|
||||
UserID: user.ID,
|
||||
|
|
@ -434,8 +430,6 @@ func (h *SpaceHandler) CreateExpense(w http.ResponseWriter, r *http.Request) {
|
|||
balance, err := h.expenseService.GetBalanceForSpace(spaceID)
|
||||
if err != nil {
|
||||
slog.Error("failed to get balance", "error", err, "space_id", spaceID)
|
||||
// Fallback: return just the item if balance fails, but ideally we want both.
|
||||
// For now we will just log and continue, potentially showing stale balance.
|
||||
}
|
||||
|
||||
ui.Render(w, r, pages.ExpenseCreatedResponse(newExpense, balance))
|
||||
|
|
|
|||
|
|
@ -86,10 +86,12 @@ templ BalanceCard(spaceID string, balance int, oob bool) {
|
|||
<div
|
||||
id="balance-card"
|
||||
class="border rounded-lg p-4 bg-card text-card-foreground"
|
||||
hx-swap-oob?={ oob }
|
||||
hx-get={ "/app/spaces/" + spaceID + "/components/balance" }
|
||||
hx-trigger="sse:balance_changed"
|
||||
hx-swap="outerHTML"
|
||||
if oob {
|
||||
hx-swap-oob="true"
|
||||
}
|
||||
>
|
||||
<h2 class="text-lg font-semibold">Current Balance</h2>
|
||||
<p class={ "text-3xl font-bold", templ.KV("text-destructive", balance < 0) }>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,9 @@ templ SpaceExpensesPage(space *model.Space, expenses []*model.Expense, balance i
|
|||
}
|
||||
@dialog.Content() {
|
||||
@dialog.Header() {
|
||||
@dialog.Title() { Add Transaction }
|
||||
@dialog.Title() {
|
||||
Add Transaction
|
||||
}
|
||||
@dialog.Description() {
|
||||
Add a new expense or top-up to your space.
|
||||
}
|
||||
|
|
@ -31,10 +33,8 @@ templ SpaceExpensesPage(space *model.Space, expenses []*model.Expense, balance i
|
|||
}
|
||||
}
|
||||
</div>
|
||||
|
||||
// Balance Card
|
||||
@expense.BalanceCard(space.ID, balance, false)
|
||||
|
||||
// List of expenses
|
||||
<div
|
||||
id="expenses-list"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue