From 26886d9b31a0dd2ae1a17e6b3ab512788922d6ec Mon Sep 17 00:00:00 2001 From: nic Date: Thu, 24 Apr 2025 16:12:12 -0400 Subject: [PATCH] fix: oob swap didn't work with the response structure; used hx-target and hx-swap outerHTML instead and it seems to work --- internal/handlers/web/invoices.go | 28 ++++++++++++++++++++++++---- templates/partials/invoice_card.html | 7 ++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/internal/handlers/web/invoices.go b/internal/handlers/web/invoices.go index ff1d4cc..4e88f30 100644 --- a/internal/handlers/web/invoices.go +++ b/internal/handlers/web/invoices.go @@ -386,6 +386,8 @@ func renderSingleInvoiceUpdate(w http.ResponseWriter, invoiceID string, session originalSearch = r.URL.Query().Get("original_search") } + log.Printf("Original search term: %s", originalSearch) + // Fetch just the updated invoice invoice, err := session.GetInvoice(invoiceID) if err != nil { @@ -400,24 +402,42 @@ func renderSingleInvoiceUpdate(w http.ResponseWriter, invoiceID string, session return } + // Log invoice data for debugging + invoiceNumberRaw, hasInvoiceNumber := invoice["invoiceNumber"] + if !hasInvoiceNumber { + log.Printf("WARNING: Invoice does not have invoiceNumber field") + } else { + log.Printf("Invoice number: %v", invoiceNumberRaw) + } + // Format the invoice ID if needed if id, ok := invoice["id"].(float64); ok { invoice["id"] = fmt.Sprintf("%.0f", id) + log.Printf("Formatted invoice ID: %s", invoice["id"]) } // Add status buttons invoice["buttons"] = getInvoiceStatusButtons(invoice["id"].(string), invoice["status"].(string)) - // Add search term and set flag for partial update + // Add search term and set flags for rendering invoice["SearchTerm"] = originalSearch - invoice["PartialUpdate"] = true - invoice["InvoiceID"] = invoiceID + invoice["MultipleInvoices"] = true // Ensure it renders in the multiple invoice style + + // Debug output the structure of the template data + keyCount := 0 + for key := range invoice { + keyCount++ + log.Printf("Template data key: %s", key) + } + log.Printf("Total template data keys: %d", keyCount) - // Render only the specific invoice card with hx-swap-oob + // Render just the specific invoice card for direct replacement tmpl := root.WebTemplates + w.Header().Set("Content-Type", "text/html") err = tmpl.ExecuteTemplate(w, "invoice_card", invoice) if err != nil { log.Printf("Error executing template for partial update: %v", err) http.Error(w, "Internal Server Error", http.StatusInternalServerError) } + log.Printf("Successfully rendered updated invoice card for %s", invoiceID) } diff --git a/templates/partials/invoice_card.html b/templates/partials/invoice_card.html index 0001ac4..dbc86ed 100644 --- a/templates/partials/invoice_card.html +++ b/templates/partials/invoice_card.html @@ -1,5 +1,6 @@ {{define "invoice_card"}} -
+{{$cardID := or .invoiceNumber .id}} +

Invoice #{{.invoiceNumber}}

{{.status}}
@@ -34,8 +35,8 @@
{{range .buttons}}