From fe7a9f6dd4beae9c8b4856cc167c13703fbf6f52 Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Wed, 25 Mar 2026 17:40:57 -0500 Subject: [PATCH] edit date renewed --- public/js/views/invoice-view.js | 75 +++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 22 deletions(-) diff --git a/public/js/views/invoice-view.js b/public/js/views/invoice-view.js index d6cca3c..c4e505a 100644 --- a/public/js/views/invoice-view.js +++ b/public/js/views/invoice-view.js @@ -589,42 +589,73 @@ async function checkStripePayment(invoiceId) { } async function editSentDates(invoiceId) { - // Load current invoice data const res = await fetch(`/api/invoices/${invoiceId}`); const data = await res.json(); const invoice = data.invoice; - const sentDates = invoice.sent_dates || []; + const sentDates = (invoice.sent_dates || []).map(d => d.split('T')[0]); - // Build a simple prompt-based editor - let datesStr = sentDates.join('\n'); - const input = prompt( - 'Edit sent dates (one per line, YYYY-MM-DD format):\n\n' + - 'Add a new line to add a date.\nRemove a line to delete a date.\nLeave empty to clear all.', - datesStr - ); + // Build modal + let modal = document.getElementById('sent-dates-modal'); + if (!modal) { + modal = document.createElement('div'); + modal.id = 'sent-dates-modal'; + modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex justify-center items-center'; + document.body.appendChild(modal); + } - if (input === null) return; // Cancelled + modal.innerHTML = ` +
+

Edit Sent Dates

+
+ +
+ + +
+
`; - // Parse and validate - const newDates = input.trim() - ? input.trim().split('\n').map(d => d.trim()).filter(d => d) - : []; + const list = document.getElementById('sent-dates-list'); + if (sentDates.length === 0) { + _addSentDateRow(); + } else { + sentDates.forEach(d => _addSentDateRow(d)); + } - for (const d of newDates) { - if (!/^\d{4}-\d{2}-\d{2}$/.test(d)) { - alert(`Invalid date: "${d}"\nPlease use YYYY-MM-DD format.`); - return; - } + modal.classList.remove('hidden'); +} + +function _addSentDateRow(value = '') { + const list = document.getElementById('sent-dates-list'); + if (!list) return; + + const row = document.createElement('div'); + row.className = 'flex items-center gap-2'; + row.innerHTML = ` + + `; + list.appendChild(row); +} + +async function _saveSentDates(invoiceId) { + const inputs = document.querySelectorAll('#sent-dates-list .sent-date-input'); + const dates = []; + + for (const input of inputs) { + if (input.value) dates.push(input.value); } try { const response = await fetch(`/api/invoices/${invoiceId}/sent-dates`, { method: 'PATCH', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ sent_dates: newDates }) + body: JSON.stringify({ sent_dates: dates }) }); if (response.ok) { + document.getElementById('sent-dates-modal').classList.add('hidden'); loadInvoices(); } else { const err = await response.json(); @@ -632,7 +663,7 @@ async function editSentDates(invoiceId) { } } catch (e) { console.error('Error updating sent dates:', e); - alert('Network error updating sent dates.'); + alert('Network error.'); } } // ============================================================ @@ -641,5 +672,5 @@ async function editSentDates(invoiceId) { window.invoiceView = { viewPDF, viewHTML, syncFromQBO, resetQbo, markPaid, setEmailStatus, edit, remove, - loadInvoices, renderInvoiceView, setStatus, checkStripePayment, editSentDates + loadInvoices, renderInvoiceView, setStatus, checkStripePayment, editSentDates ,_addSentDateRow, _saveSentDates }; \ No newline at end of file