set invoice mail

This commit is contained in:
oliver
2026-06-09 14:09:45 -03:00
parent b86a3293da
commit fbd620074b
+16 -3
View File
@@ -22,7 +22,7 @@ const REFERRAL_URL = `${API_BASE}/etc/referral`; // POST {referrer,friend_name,f
// WIZZARD=false is written via AGENT_INFO_URL (POST { uuid, key, value })
const CREDITS_URL = `${API_BASE}/payment/credits`; // hidden form POST → 302 Stripe redirect
const INVOICES_URL = `${API_BASE}/invoices`; // GET ?email=
const INVOICE_EMAIL_URL = `${API_BASE}/account/invoice-email`; // POST {email, invoice_email}
const INVOICE_EMAIL_URL = `${API_BASE}/user`; // POST {email, invoice_email}
const CONTRACT_EXTEND_URL = "https://derez.ai"; // ← replace with Stripe payment link
const CONTRACT_CANCEL_URL = "https://derez.ai"; // ← replace with Stripe cancellation link
@@ -1122,15 +1122,28 @@ async function saveInvoiceEmail() {
async function loadInvoices() {
const body = document.getElementById("invoices-body");
if (!body) return;
body.innerHTML = '<div class="loading-row"><div class="spinner"></div></div>';
try {
const res = await apiFetch(
`${INVOICES_URL}?email=${encodeURIComponent(currentEmail || "")}`,
);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
renderInvoices(Array.isArray(data) ? data : []);
let data = await res.json();
dbg("\u2190 Invoices", data);
// unwrap n8n envelope: [{json:{...}}] → [{...}]
if (Array.isArray(data)) {
data = data.map((item) =>
item && typeof item === "object" && "json" in item ? item.json : item,
);
} else if (data && typeof data === "object" && "json" in data) {
data = [data.json];
} else {
data = [];
}
renderInvoices(data);
} catch (err) {
dbg("\u2190 Invoices error", err.message);
body.innerHTML =
'<p class="text-muted" style="font-size:13px;padding:4px 0;">Could not load invoices.</p>';
}