feat: show allocated amount in expenses
This commit is contained in:
parent
c82c7865b6
commit
6bc00a08c7
3 changed files with 23 additions and 18 deletions
|
|
@ -426,7 +426,7 @@ func (h *SpaceHandler) ExpensesPage(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Render(w, r, pages.SpaceExpensesPage(space, expenses, balance, tags, listsWithItems, page, totalPages))
|
ui.Render(w, r, pages.SpaceExpensesPage(space, expenses, balance, totalAllocated, tags, listsWithItems, page, totalPages))
|
||||||
|
|
||||||
if r.URL.Query().Get("created") == "true" {
|
if r.URL.Query().Get("created") == "true" {
|
||||||
ui.Render(w, r, toast.Toast(toast.Props{
|
ui.Render(w, r, toast.Toast(toast.Props{
|
||||||
|
|
@ -587,7 +587,7 @@ func (h *SpaceHandler) CreateExpense(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Render(w, r, pages.ExpenseCreatedResponse(spaceID, expenses, balance, 1, totalPages))
|
ui.Render(w, r, pages.ExpenseCreatedResponse(spaceID, expenses, balance, totalAllocated, 1, totalPages))
|
||||||
|
|
||||||
// OOB-swap the item selector with fresh data (items may have been deleted/checked)
|
// OOB-swap the item selector with fresh data (items may have been deleted/checked)
|
||||||
listsWithItems, err := h.listService.GetListsWithUncheckedItems(spaceID)
|
listsWithItems, err := h.listService.GetListsWithUncheckedItems(spaceID)
|
||||||
|
|
@ -712,7 +712,7 @@ func (h *SpaceHandler) UpdateExpense(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
balance -= totalAllocated
|
balance -= totalAllocated
|
||||||
|
|
||||||
ui.Render(w, r, pages.ExpenseUpdatedResponse(spaceID, expWithTags, balance))
|
ui.Render(w, r, pages.ExpenseUpdatedResponse(spaceID, expWithTags, balance, totalAllocated))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpaceHandler) DeleteExpense(w http.ResponseWriter, r *http.Request) {
|
func (h *SpaceHandler) DeleteExpense(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -741,7 +741,7 @@ func (h *SpaceHandler) DeleteExpense(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
balance -= totalAllocated
|
balance -= totalAllocated
|
||||||
|
|
||||||
ui.Render(w, r, expense.BalanceCard(spaceID, balance, true))
|
ui.Render(w, r, expense.BalanceCard(spaceID, balance, totalAllocated, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpaceHandler) CreateInvite(w http.ResponseWriter, r *http.Request) {
|
func (h *SpaceHandler) CreateInvite(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -821,7 +821,7 @@ func (h *SpaceHandler) GetBalanceCard(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
balance -= totalAllocated
|
balance -= totalAllocated
|
||||||
|
|
||||||
ui.Render(w, r, expense.BalanceCard(spaceID, balance, false))
|
ui.Render(w, r, expense.BalanceCard(spaceID, balance, totalAllocated, false))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *SpaceHandler) GetExpensesList(w http.ResponseWriter, r *http.Request) {
|
func (h *SpaceHandler) GetExpensesList(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,14 @@ func (p AddExpenseFormProps) formAttrs() templ.Attributes {
|
||||||
closeScript := "on htmx:afterOnLoad if event.detail.xhr.status == 200 then call window.tui.dialog.close('" + p.DialogID + "') then reset() me then show #item-selector-section end"
|
closeScript := "on htmx:afterOnLoad if event.detail.xhr.status == 200 then call window.tui.dialog.close('" + p.DialogID + "') then reset() me then show #item-selector-section end"
|
||||||
if p.FromOverview {
|
if p.FromOverview {
|
||||||
return templ.Attributes{
|
return templ.Attributes{
|
||||||
"hx-post": "/app/spaces/" + p.Space.ID + "/expenses?from=overview",
|
"hx-post": "/app/spaces/" + p.Space.ID + "/expenses?from=overview",
|
||||||
"hx-target": "body",
|
"hx-target": "body",
|
||||||
"hx-swap": "beforeend",
|
"hx-swap": "beforeend",
|
||||||
"_": closeScript,
|
"_": closeScript,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return templ.Attributes{
|
return templ.Attributes{
|
||||||
"hx-post": "/app/spaces/" + p.Space.ID + "/expenses",
|
"hx-post": "/app/spaces/" + p.Space.ID + "/expenses",
|
||||||
"hx-target": "#expenses-list-wrapper",
|
"hx-target": "#expenses-list-wrapper",
|
||||||
"hx-swap": "innerHTML",
|
"hx-swap": "innerHTML",
|
||||||
"_": closeScript,
|
"_": closeScript,
|
||||||
|
|
@ -229,10 +229,10 @@ templ EditExpenseForm(spaceID string, exp *model.ExpenseWithTags) {
|
||||||
Amount
|
Amount
|
||||||
}
|
}
|
||||||
@input.Input(input.Props{
|
@input.Input(input.Props{
|
||||||
Name: "amount",
|
Name: "amount",
|
||||||
ID: "edit-amount-" + exp.ID,
|
ID: "edit-amount-" + exp.ID,
|
||||||
Type: "number",
|
Type: "number",
|
||||||
Value: fmt.Sprintf("%.2f", float64(exp.AmountCents)/100.0),
|
Value: fmt.Sprintf("%.2f", float64(exp.AmountCents)/100.0),
|
||||||
Attributes: templ.Attributes{"step": "0.01", "required": "true"},
|
Attributes: templ.Attributes{"step": "0.01", "required": "true"},
|
||||||
})
|
})
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -357,7 +357,7 @@ templ ItemSelectorSection(listsWithItems []model.ListWithUncheckedItems, oob boo
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
templ BalanceCard(spaceID string, balance int, oob bool) {
|
templ BalanceCard(spaceID string, balance int, allocated 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"
|
||||||
|
|
@ -368,6 +368,11 @@ templ BalanceCard(spaceID string, balance int, oob bool) {
|
||||||
<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) }>
|
||||||
{ fmt.Sprintf("$%.2f", float64(balance)/100.0) }
|
{ fmt.Sprintf("$%.2f", float64(balance)/100.0) }
|
||||||
|
if allocated > 0 {
|
||||||
|
<span class="text-base font-normal text-muted-foreground">
|
||||||
|
({ fmt.Sprintf("$%.2f", float64(allocated)/100.0) } in accounts)
|
||||||
|
</span>
|
||||||
|
}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"git.juancwu.dev/juancwu/budgit/internal/ui/layouts"
|
"git.juancwu.dev/juancwu/budgit/internal/ui/layouts"
|
||||||
)
|
)
|
||||||
|
|
||||||
templ SpaceExpensesPage(space *model.Space, expenses []*model.ExpenseWithTags, balance int, tags []*model.Tag, listsWithItems []model.ListWithUncheckedItems, currentPage, totalPages int) {
|
templ SpaceExpensesPage(space *model.Space, expenses []*model.ExpenseWithTags, balance int, allocated int, tags []*model.Tag, listsWithItems []model.ListWithUncheckedItems, currentPage, totalPages int) {
|
||||||
@layouts.Space("Expenses", space) {
|
@layouts.Space("Expenses", space) {
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
|
|
@ -43,7 +43,7 @@ templ SpaceExpensesPage(space *model.Space, expenses []*model.ExpenseWithTags, b
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
// Balance Card
|
// Balance Card
|
||||||
@expense.BalanceCard(space.ID, balance, false)
|
@expense.BalanceCard(space.ID, balance, allocated, false)
|
||||||
// List of expenses
|
// List of expenses
|
||||||
<div class="border rounded-lg">
|
<div class="border rounded-lg">
|
||||||
<div id="expenses-list-wrapper">
|
<div id="expenses-list-wrapper">
|
||||||
|
|
@ -191,12 +191,12 @@ templ ExpenseListItem(spaceID string, exp *model.ExpenseWithTags) {
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
templ ExpenseCreatedResponse(spaceID string, expenses []*model.ExpenseWithTags, balance int, currentPage, totalPages int) {
|
templ ExpenseCreatedResponse(spaceID string, expenses []*model.ExpenseWithTags, balance int, allocated int, currentPage, totalPages int) {
|
||||||
@ExpensesListContent(spaceID, expenses, currentPage, totalPages)
|
@ExpensesListContent(spaceID, expenses, currentPage, totalPages)
|
||||||
@expense.BalanceCard(spaceID, balance, true)
|
@expense.BalanceCard(spaceID, balance, allocated, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
templ ExpenseUpdatedResponse(spaceID string, exp *model.ExpenseWithTags, balance int) {
|
templ ExpenseUpdatedResponse(spaceID string, exp *model.ExpenseWithTags, balance int, allocated int) {
|
||||||
@ExpenseListItem(spaceID, exp)
|
@ExpenseListItem(spaceID, exp)
|
||||||
@expense.BalanceCard(exp.SpaceID, balance, true)
|
@expense.BalanceCard(exp.SpaceID, balance, allocated, true)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue