/** * The Inbox: saved copies of inquiries and order requests sent through the * site, unhandled first and newest first. Each one shows whether its email * reached Greg, so a failed email is never a lost request. */ import type { Submission, SubmissionCounts } from "./client.ts"; import { html, qs, when, type Html } from "./html.ts"; export const inboxHref = (id: number) => `/inbox/${id}`; const kindLabel = (s: Submission) => (s.kind === "order" ? "Order" : "Inquiry"); const typeLabels: Record = { job: "Job or role", freelance: "Freelance web work", patiun: "Patiun custom order" }; const typeLabel = (s: Submission) => (s.kind === "inquiry" ? (typeLabels[s.type] ?? s.type) : s.type); export function deliveryPill(s: Pick): Html { switch (s.delivery) { case "sent": return html`Emailed`; case "failed": return html`Email failed`; case "skipped": return html`Not emailed`; default: return html`Email unknown`; } } const handledPill = (s: Submission) => (s.handled ? html`Handled` : html`New`); const size = (n: number) => (n >= 1024 * 1024 ? `${(n / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(n / 1024))} KB`); /** The first line of the longest field, as a hint of what it is about. */ function gist(s: Submission): string { const d = s.fields.find((f) => /^(details|notes)$/i.test(f.label))?.value ?? s.fields[0]?.value ?? ""; const line = d.split("\n").find((l) => l.trim()) ?? ""; return line.length > 90 ? `${line.slice(0, 89)}…` : line; } export function inboxList(items: Submission[], counts: SubmissionCounts, show: string): Html { const filters: [string, string][] = [ ["open", "Not handled"], ["all", "All"], ["handled", "Handled"], ]; return html`

Inbox

Inquiries and order requests sent through the site. Each one is emailed to you and saved here, so nothing is lost if the email is.

${counts.unhandled}
not handled yet
${counts.failed}
not handled and the email failed
${counts.total}
saved in all

${filters.map(([v, l]) => (v === show ? html`${l}` : html`${l}`))}

${items.length ? html`
${items.map( (s) => html``, )}
FromWhatAboutReceivedEmail
${s.name}
${s.email}
${kindLabel(s)}
${typeLabel(s)}
${gist(s)}${s.attachment ? html` File` : ""} ${when(s.createdAt)} ${deliveryPill(s)} ${handledPill(s)}
` : html`

${show === "open" ? "Nothing waiting. Every request is handled." : "None yet."}

`}`; } export function inboxOne(s: Submission): Html { const reply = `mailto:${s.email}?subject=${encodeURIComponent(s.kind === "order" ? "Your order request" : "Your inquiry")}`; return html`

${kindLabel(s)} from ${s.name}

Back to the inbox · Received ${when(s.createdAt)} · ${handledPill(s)} ${s.handled ? when(s.handledAt) : ""}

${s.delivery === "failed" ? html`` : s.delivery === "skipped" ? html`
No email was sent (SMTP is not set up on the site). This saved copy is the only one.
` : s.delivery === "pending" ? html`
The site did not report whether the email went out. Check your mail before relying on it.
` : ""}
Kind
${kindLabel(s)}: ${typeLabel(s)}
Name
${s.name}
Email
${s.email}
${s.fields.map((f) => html`
${f.label}
${f.value.includes("\n") ? html`
${f.value}
` : f.value}
`)} ${s.attachment ? html`
Attachment
${s.attachment.name} ${size(s.attachment.size)}, downloads as a file
` : ""}
Email to you
${deliveryPill(s)} ${s.deliveryAt ? when(s.deliveryAt) : ""}
Reply by email
`; }