caelum0x 2299eb1ba5 feat(mail): customer dashboard (no-build HTML + vanilla JS)
Login via our own magic links, 3-step onboarding (domain, DNS records, first send),
emails with status timeline, domains, API keys (live/test), webhooks, suppressions,
team, usage + plan. Live/Test switch everywhere. Dev mock server + MOUNT.md listing
the one-line axum mount and missing API pieces. Verified in a headless browser
against the mock (24 screenshots).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-13 04:24:04 +03:00

95 lines
5.0 KiB
JavaScript

// Domains: list, add, detail with DNS records (one-click copy) and live verify.
import * as api from "../api.js";
import { badge, button, confirmAction, copyButton, el, errorBox, fullTime, label, loading, pageHead, table, toast } from "../ui.js";
/** One DNS record as registrar-friendly host / type / value with copy buttons. */
function recordCard(r) {
const host = r.name || "@";
const value = r.priority !== undefined && r.priority !== null && r.type === "MX" ? `${r.priority} ${r.value}` : r.value;
return el(
"div.rec",
el("div.head", el("b", r.record), el("span.badge", r.type), badge(r.status), r.purpose ? el("span.muted.small", r.purpose) : null),
el("div.lab", "Host"), el("div.val.mono", host), copyButton(host),
el("div.lab", "Value"), el("div.val.mono", value), copyButton(value),
r.ttl ? [el("div.lab", "TTL"), el("div.val.muted", r.ttl), el("div")] : null
);
}
export const recordsList = (records) =>
records.length ? el("div", records.map(recordCard)) : el("p.help", "No records yet.");
export async function domainsView() {
const list = el("div.card.tight");
const msg = el("div");
const name = el("input.input", { placeholder: "yourdomain.com", required: true, autocomplete: "off" });
async function load() {
list.replaceChildren(loading());
try {
const page = await api.listDomains();
list.replaceChildren(
table(
["Domain", "Status", "Region", "Tracking", "Added"],
(page.data || []).map((d) =>
el("tr.click", { onclick: () => (location.hash = `#/domains/${d.id}`) },
el("td", d.name), el("td", badge(d.status)), el("td.muted", d.region),
el("td.muted", [d.open_tracking ? "opens" : null, d.click_tracking ? "clicks" : null].filter(Boolean).join(", ") || "off"),
el("td.muted", fullTime(d.created_at)))
),
"No domains yet. Add the one your emails will come from."
)
);
} catch (e) {
list.replaceChildren(errorBox(e));
}
}
await load();
const form = el(
"form.inline-form",
{ onsubmit: async (e) => { e.preventDefault(); msg.replaceChildren(); try { const d = await api.createDomain({ name: name.value.trim().toLowerCase() }); location.hash = `#/domains/${d.id}`; } catch (err) { msg.append(errorBox(err)); } } },
el("div.field", el("label", "Add a domain"), name),
el("button.btn", { type: "submit" }, "Add")
);
return el("div", pageHead("Domains", "Domains you send from. Each needs DNS records published once."), el("div.card", form, msg), list);
}
export async function domainDetailView(ctx) {
let d = await api.getDomain(ctx.id);
const status = el("span", badge(d.status));
const recs = el("div", recordsList(d.records || []));
const msg = el("div");
const verify = button("Check now", async () => {
msg.replaceChildren();
try {
d = await api.verifyDomain(d.id);
status.replaceChildren(badge(d.status));
recs.replaceChildren(recordsList(d.records || []));
toast(d.status === "verified" ? "Verified" : `Status: ${label(d.status)}`);
if (d.status !== "verified") msg.append(el("p.help", "Some records do not resolve yet. Publish them at your DNS provider and check again; propagation can take minutes."));
if (d.relay && d.relay.dkim_state && d.relay.dkim_state !== "ACTIVE") msg.append(el("p.help", `Relay DKIM state: ${d.relay.dkim_state}.`));
} catch (err) {
msg.append(errorBox(err));
}
});
const track = (key, text) => {
const cb = el("input", { type: "checkbox", checked: Boolean(d[key]) });
cb.onchange = async () => { try { await api.updateDomain(d.id, { [key]: cb.checked }); d[key] = cb.checked; toast("Saved"); } catch (err) { cb.checked = !cb.checked; alert(err.message); } };
return el("label.check", cb, text);
};
const remove = button("Delete domain", async () => {
if (!confirmAction(`Delete ${d.name}? Sends from it will be refused.`)) return;
try { await api.deleteDomain(d.id); location.hash = "#/domains"; } catch (err) { msg.append(errorBox(err)); }
}, "btn danger");
return el(
"div",
pageHead(d.name, `Added ${fullTime(d.created_at)}. Region ${d.region}.`, status, verify, el("a.btn.secondary", { href: "#/domains" }, "Back")),
el("div.card", el("h2", "DNS records"), el("p.muted", "Add each record at your DNS provider. Host is relative to the domain; most providers accept it as shown."), recs, msg),
el("div.grid2",
el("div.card", el("h2", "Tracking"), track("open_tracking", "Track opens (adds a pixel)"), track("click_tracking", "Track clicks (rewrites links)"), el("p.help", "Off by default. Transactional mail usually does not need it.")),
el("div.card", el("h2", "Details"),
el("dl.kv", el("dt", "Domain ID"), el("dd.mono", d.id), el("dt", "DKIM selector"), el("dd.mono", d.dkim_selector || ""), el("dt", "Return path"), el("dd.mono", d.return_path ? `${d.return_path}.${d.name}` : ""), el("dt", "Capabilities"), el("dd", `sending ${d.capabilities?.sending || ""}`)),
el("div", { style: "margin-top:14px" }, remove)))
);
}