diff --git a/pkg/invoices.go b/pkg/invoices.go index 7855a36..e9b4e7e 100644 --- a/pkg/invoices.go +++ b/pkg/invoices.go @@ -847,11 +847,15 @@ func HandleUpdateInvoice(w http.ResponseWriter, r *http.Request, params httprout if slug == "" { http.NotFound(w, r) } + indexUrl := companyURI(mustGetCompany(r), "/invoices") if IsHTMxRequest(r) { - w.Header().Set("HX-Refresh", "true") + w.Header().Set("HX-Location", MustMarshalHTMxLocation(&HTMxLocation{ + Path: indexUrl, + Target: "main", + })) w.WriteHeader(http.StatusNoContent) } else { - http.Redirect(w, r, companyURI(mustGetCompany(r), "/invoices"), http.StatusSeeOther) + http.Redirect(w, r, indexUrl, http.StatusSeeOther) } } else { slug := params[0].Value @@ -865,12 +869,21 @@ func HandleUpdateInvoice(w http.ResponseWriter, r *http.Request, params httprout http.NotFound(w, r) return } + viewUrl := companyURI(company, "/invoices/"+slug) if IsHTMxRequest(r) { w.Header().Set("HX-Trigger", "closeModal") - w.Header().Set("HX-Refresh", "true") + location := &HTMxLocation{ + Target: "main", + } + if form.Location.Val == "view" { + location.Path = viewUrl + } else { + location.Path = companyURI(company, "/invoices") + } + w.Header().Set("HX-Location", MustMarshalHTMxLocation(location)) w.WriteHeader(http.StatusNoContent) } else { - http.Redirect(w, r, companyURI(company, "/invoices/"+slug), http.StatusSeeOther) + http.Redirect(w, r, viewUrl, http.StatusSeeOther) } } } @@ -885,6 +898,7 @@ func ServeEditInvoice(w http.ResponseWriter, r *http.Request, params httprouter. http.NotFound(w, r) return } + form.Location.Val = r.URL.Query().Get("location") w.WriteHeader(http.StatusOK) mustRenderEditInvoiceForm(w, r, slug, form) } diff --git a/web/template/invoices/view.gohtml b/web/template/invoices/view.gohtml index 3ce8bad..d931a66 100644 --- a/web/template/invoices/view.gohtml +++ b/web/template/invoices/view.gohtml @@ -16,7 +16,7 @@ href="{{ companyURI "/invoices/new"}}?duplicate={{ .Slug }}&location=view">{{( pgettext "Duplicate" "action" )}} {{( pgettext "Edit" "action" )}} + href="{{ companyURI "/invoices/"}}{{ .Slug }}/edit?location=view">{{( pgettext "Edit" "action" )}} {{( pgettext "Download invoice" "action" )}}