feat: recurring transactions
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m36s
All checks were successful
Deploy / build-and-deploy (push) Successful in 1m36s
This commit is contained in:
parent
f0a309ea20
commit
448b6f6262
16 changed files with 1956 additions and 4 deletions
57
internal/ui/pages/recurring_event_helpers.go
Normal file
57
internal/ui/pages/recurring_event_helpers.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.juancwu.dev/juancwu/budgit/internal/model"
|
||||
)
|
||||
|
||||
func accountLabel(ev *model.RecurringEvent, accountByID map[string]string) string {
|
||||
src := accountByID[ev.SourceAccountID]
|
||||
if src == "" {
|
||||
src = ev.SourceAccountID
|
||||
}
|
||||
return src
|
||||
}
|
||||
|
||||
var weekdayLabels = []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
|
||||
|
||||
func recurrenceSummary(ev *model.RecurringEvent) string {
|
||||
timePart := fmt.Sprintf(" at %02d:%02d", ev.FireHour, ev.FireMinute)
|
||||
switch ev.Frequency {
|
||||
case model.RecurringFrequencyDaily:
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Daily" + timePart
|
||||
}
|
||||
return fmt.Sprintf("Every %d days%s", ev.IntervalCount, timePart)
|
||||
case model.RecurringFrequencyWeekly:
|
||||
dow := ""
|
||||
if ev.DayOfWeek != nil && *ev.DayOfWeek >= 0 && *ev.DayOfWeek < len(weekdayLabels) {
|
||||
dow = " on " + weekdayLabels[*ev.DayOfWeek]
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Weekly" + dow + timePart
|
||||
}
|
||||
return fmt.Sprintf("Every %d weeks%s%s", ev.IntervalCount, dow, timePart)
|
||||
case model.RecurringFrequencyMonthly:
|
||||
dom := ""
|
||||
if ev.DayOfMonth != nil {
|
||||
dom = fmt.Sprintf(" on day %d", *ev.DayOfMonth)
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Monthly" + dom + timePart
|
||||
}
|
||||
return fmt.Sprintf("Every %d months%s%s", ev.IntervalCount, dom, timePart)
|
||||
case model.RecurringFrequencyYearly:
|
||||
date := ""
|
||||
if ev.MonthOfYear != nil && ev.DayOfMonth != nil {
|
||||
date = fmt.Sprintf(" on %s %d", time.Month(*ev.MonthOfYear).String(), *ev.DayOfMonth)
|
||||
}
|
||||
if ev.IntervalCount == 1 {
|
||||
return "Yearly" + date + timePart
|
||||
}
|
||||
return fmt.Sprintf("Every %d years%s%s", ev.IntervalCount, date, timePart)
|
||||
}
|
||||
return string(ev.Frequency)
|
||||
}
|
||||
29
internal/ui/pages/space_create_recurring_event.templ
Normal file
29
internal/ui/pages/space_create_recurring_event.templ
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
package pages
|
||||
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/forms"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/layouts"
|
||||
|
||||
type SpaceCreateRecurringEventPageProps struct {
|
||||
SpaceID string
|
||||
SpaceName string
|
||||
Form forms.RecurringEventFormProps
|
||||
}
|
||||
|
||||
templ SpaceCreateRecurringEventPage(props SpaceCreateRecurringEventPageProps) {
|
||||
@layouts.AppWithBreadcrumb(
|
||||
"New Recurring",
|
||||
spaceChildBreadcrumb(props.SpaceID, props.SpaceName, "New Recurring"),
|
||||
spaceOverviewSidebarContent(),
|
||||
spaceSpecificSidebarContent(props.SpaceID),
|
||||
) {
|
||||
<div class="container max-w-3xl px-6 py-8 mx-auto space-y-6">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold">New Recurring Event</h1>
|
||||
<p class="text-muted-foreground mt-2">
|
||||
Schedule a bill, fund, or transfer to repeat automatically.
|
||||
</p>
|
||||
</div>
|
||||
@forms.RecurringEventForm(props.Form)
|
||||
</div>
|
||||
}
|
||||
}
|
||||
30
internal/ui/pages/space_edit_recurring_event.templ
Normal file
30
internal/ui/pages/space_edit_recurring_event.templ
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package pages
|
||||
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/forms"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/layouts"
|
||||
|
||||
type SpaceEditRecurringEventPageProps struct {
|
||||
SpaceID string
|
||||
SpaceName string
|
||||
EventID string
|
||||
Form forms.RecurringEventFormProps
|
||||
}
|
||||
|
||||
templ SpaceEditRecurringEventPage(props SpaceEditRecurringEventPageProps) {
|
||||
@layouts.AppWithBreadcrumb(
|
||||
"Edit Recurring",
|
||||
spaceChildBreadcrumb(props.SpaceID, props.SpaceName, "Edit Recurring"),
|
||||
spaceOverviewSidebarContent(),
|
||||
spaceSpecificSidebarContent(props.SpaceID),
|
||||
) {
|
||||
<div class="container max-w-3xl px-6 py-8 mx-auto space-y-6">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold">Edit Recurring Event</h1>
|
||||
<p class="text-muted-foreground mt-2">
|
||||
Changes apply going forward. Past transactions are not modified.
|
||||
</p>
|
||||
</div>
|
||||
@forms.RecurringEventForm(props.Form)
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
|
@ -74,6 +74,16 @@ templ spaceSpecificSidebarContent(spaceID string) {
|
|||
<span>Members</span>
|
||||
}
|
||||
}
|
||||
@sidebar.MenuItem() {
|
||||
@sidebar.MenuButton(sidebar.MenuButtonProps{
|
||||
Href: routeurl.URL("page.app.spaces.space.recurring", "spaceID", spaceID),
|
||||
IsActive: ctxkeys.URLPath(ctx) == routeurl.URL("page.app.spaces.space.recurring", "spaceID", spaceID),
|
||||
Tooltip: "Recurring",
|
||||
}) {
|
||||
@icon.CalendarSync()
|
||||
<span>Recurring</span>
|
||||
}
|
||||
}
|
||||
@sidebar.MenuItem() {
|
||||
@sidebar.MenuButton(sidebar.MenuButtonProps{
|
||||
Href: routeurl.URL("page.app.spaces.space.activity", "spaceID", spaceID),
|
||||
|
|
|
|||
132
internal/ui/pages/space_recurring_events.templ
Normal file
132
internal/ui/pages/space_recurring_events.templ
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
package pages
|
||||
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/model"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/routeurl"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/badge"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/button"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/card"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/components/icon"
|
||||
import "git.juancwu.dev/juancwu/budgit/internal/ui/layouts"
|
||||
|
||||
type SpaceRecurringEventsPageProps struct {
|
||||
SpaceID string
|
||||
SpaceName string
|
||||
Events []*model.RecurringEvent
|
||||
AccountByID map[string]string
|
||||
}
|
||||
|
||||
templ SpaceRecurringEventsPage(props SpaceRecurringEventsPageProps) {
|
||||
@layouts.AppWithBreadcrumb(
|
||||
"Recurring",
|
||||
spaceChildBreadcrumb(props.SpaceID, props.SpaceName, "Recurring"),
|
||||
spaceOverviewSidebarContent(),
|
||||
spaceSpecificSidebarContent(props.SpaceID),
|
||||
) {
|
||||
<div class="container max-w-5xl px-6 py-8 mx-auto space-y-6">
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<h1 class="text-3xl font-bold">Recurring</h1>
|
||||
<p class="text-muted-foreground mt-2">
|
||||
Bills, funds, and transfers that fire automatically on a schedule.
|
||||
</p>
|
||||
</div>
|
||||
@button.Button(button.Props{
|
||||
Href: routeurl.URL("page.app.spaces.space.recurring.create", "spaceID", props.SpaceID),
|
||||
Class: "flex gap-2 items-center",
|
||||
}) {
|
||||
@icon.Plus()
|
||||
New Recurring
|
||||
}
|
||||
</div>
|
||||
if len(props.Events) == 0 {
|
||||
@card.Card(card.Props{Class: "rounded-sm"}) {
|
||||
@card.Content(card.ContentProps{Class: "p-8 text-center text-muted-foreground"}) {
|
||||
No recurring events yet.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
<div class="space-y-3">
|
||||
for _, ev := range props.Events {
|
||||
@recurringEventRow(props.SpaceID, ev, props.AccountByID)
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
templ recurringEventRow(spaceID string, ev *model.RecurringEvent, accountByID map[string]string) {
|
||||
@card.Card(card.Props{Class: "rounded-sm"}) {
|
||||
@card.Content(card.ContentProps{Class: "p-4 flex flex-col md:flex-row md:items-center md:justify-between gap-3"}) {
|
||||
<div class="space-y-1 min-w-0">
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
<span class="font-semibold truncate">{ ev.Title }</span>
|
||||
@kindBadge(ev.Kind)
|
||||
if ev.Paused {
|
||||
@badge.Badge(badge.Props{Variant: badge.VariantSecondary}) {
|
||||
Paused
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div class="text-sm text-muted-foreground">
|
||||
{ accountLabel(ev, accountByID) } · ${ ev.Amount.StringFixedBank(2) } · { recurrenceSummary(ev) }
|
||||
</div>
|
||||
<div class="text-xs text-muted-foreground">
|
||||
Next: { ev.NextRunAt.Format("2006-01-02 15:04 MST") } ({ ev.Timezone })
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 shrink-0">
|
||||
if ev.Paused {
|
||||
<form hx-post={ routeurl.URL("action.app.spaces.space.recurring.event.resume", "spaceID", spaceID, "eventID", ev.ID) }>
|
||||
@button.Button(button.Props{
|
||||
Type: button.TypeSubmit,
|
||||
Variant: button.VariantOutline,
|
||||
Size: button.SizeSm,
|
||||
}) {
|
||||
Resume
|
||||
}
|
||||
</form>
|
||||
} else {
|
||||
<form hx-post={ routeurl.URL("action.app.spaces.space.recurring.event.pause", "spaceID", spaceID, "eventID", ev.ID) }>
|
||||
@button.Button(button.Props{
|
||||
Type: button.TypeSubmit,
|
||||
Variant: button.VariantOutline,
|
||||
Size: button.SizeSm,
|
||||
}) {
|
||||
Pause
|
||||
}
|
||||
</form>
|
||||
}
|
||||
@button.Button(button.Props{
|
||||
Variant: button.VariantOutline,
|
||||
Size: button.SizeSm,
|
||||
Href: routeurl.URL("page.app.spaces.space.recurring.event.edit", "spaceID", spaceID, "eventID", ev.ID),
|
||||
}) {
|
||||
Edit
|
||||
}
|
||||
<form hx-post={ routeurl.URL("action.app.spaces.space.recurring.event.delete", "spaceID", spaceID, "eventID", ev.ID) } hx-confirm="Delete this recurring event? This does not delete previously generated transactions.">
|
||||
@button.Button(button.Props{
|
||||
Type: button.TypeSubmit,
|
||||
Variant: button.VariantDestructive,
|
||||
Size: button.SizeSm,
|
||||
}) {
|
||||
@icon.Trash2()
|
||||
}
|
||||
</form>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
templ kindBadge(kind model.RecurringEventKind) {
|
||||
switch kind {
|
||||
case model.RecurringEventKindBill:
|
||||
@badge.Badge(badge.Props{Variant: badge.VariantDestructive}) {
|
||||
Bill
|
||||
}
|
||||
case model.RecurringEventKindFund:
|
||||
@badge.Badge(badge.Props{Variant: badge.VariantDefault}) {
|
||||
Fund
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue