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)
|
newTag, err := h.tagService.CreateTag(spaceID, tagName, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("failed to create new tag from expense form", "error", err, "tag_name", tagName)
|
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
|
continue
|
||||||
}
|
}
|
||||||
finalTagIDs = append(finalTagIDs, newTag.ID)
|
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
|
processedTags[tagName] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- DTO Creation & Service Call ---
|
|
||||||
dto := service.CreateExpenseDTO{
|
dto := service.CreateExpenseDTO{
|
||||||
SpaceID: spaceID,
|
SpaceID: spaceID,
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
|
|
@ -434,8 +430,6 @@ func (h *SpaceHandler) CreateExpense(w http.ResponseWriter, r *http.Request) {
|
||||||
balance, err := h.expenseService.GetBalanceForSpace(spaceID)
|
balance, err := h.expenseService.GetBalanceForSpace(spaceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("failed to get balance", "error", err, "space_id", spaceID)
|
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))
|
ui.Render(w, r, pages.ExpenseCreatedResponse(newExpense, balance))
|
||||||
|
|
|
||||||
|
|
@ -86,10 +86,12 @@ templ BalanceCard(spaceID string, balance int, oob bool) {
|
||||||
<div
|
<div
|
||||||
id="balance-card"
|
id="balance-card"
|
||||||
class="border rounded-lg p-4 bg-card text-card-foreground"
|
class="border rounded-lg p-4 bg-card text-card-foreground"
|
||||||
hx-swap-oob?={ oob }
|
|
||||||
hx-get={ "/app/spaces/" + spaceID + "/components/balance" }
|
hx-get={ "/app/spaces/" + spaceID + "/components/balance" }
|
||||||
hx-trigger="sse:balance_changed"
|
hx-trigger="sse:balance_changed"
|
||||||
hx-swap="outerHTML"
|
hx-swap="outerHTML"
|
||||||
|
if oob {
|
||||||
|
hx-swap-oob="true"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<h2 class="text-lg font-semibold">Current Balance</h2>
|
<h2 class="text-lg font-semibold">Current Balance</h2>
|
||||||
<p class={ "text-3xl font-bold", templ.KV("text-destructive", balance < 0) }>
|
<p class={ "text-3xl font-bold", templ.KV("text-destructive", balance < 0) }>
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ templ SpaceExpensesPage(space *model.Space, expenses []*model.Expense, balance i
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<h1 class="text-2xl font-bold">Expenses</h1>
|
<h1 class="text-2xl font-bold">Expenses</h1>
|
||||||
@dialog.Dialog(dialog.Props{ ID: "add-expense-dialog" }) {
|
@dialog.Dialog(dialog.Props{ID: "add-expense-dialog"}) {
|
||||||
@dialog.Trigger() {
|
@dialog.Trigger() {
|
||||||
@button.Button() {
|
@button.Button() {
|
||||||
Add Expense
|
Add Expense
|
||||||
|
|
@ -22,7 +22,9 @@ templ SpaceExpensesPage(space *model.Space, expenses []*model.Expense, balance i
|
||||||
}
|
}
|
||||||
@dialog.Content() {
|
@dialog.Content() {
|
||||||
@dialog.Header() {
|
@dialog.Header() {
|
||||||
@dialog.Title() { Add Transaction }
|
@dialog.Title() {
|
||||||
|
Add Transaction
|
||||||
|
}
|
||||||
@dialog.Description() {
|
@dialog.Description() {
|
||||||
Add a new expense or top-up to your space.
|
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>
|
</div>
|
||||||
|
|
||||||
// Balance Card
|
// Balance Card
|
||||||
@expense.BalanceCard(space.ID, balance, false)
|
@expense.BalanceCard(space.ID, balance, false)
|
||||||
|
|
||||||
// List of expenses
|
// List of expenses
|
||||||
<div
|
<div
|
||||||
id="expenses-list"
|
id="expenses-list"
|
||||||
|
|
@ -84,4 +84,4 @@ templ ExpenseListItem(expense *model.Expense) {
|
||||||
templ ExpenseCreatedResponse(newExpense *model.Expense, balance int) {
|
templ ExpenseCreatedResponse(newExpense *model.Expense, balance int) {
|
||||||
@ExpenseListItem(newExpense)
|
@ExpenseListItem(newExpense)
|
||||||
@expense.BalanceCard(newExpense.SpaceID, balance, true)
|
@expense.BalanceCard(newExpense.SpaceID, balance, true)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue