refactor: centralize duplicated formatDate helper
Local Build and Deploy / deploy (push) Successful in 1m7s

21 files defined their own local formatDate (with three different output
formats: date, datetime, datetime-seconds, and varying null fallbacks).
Replace them with a single shared helper at src/lib/format-date.ts that
takes a variant + optional fallback, preserving the exact previous output
per call site (verified identical string results).

Removes ~21 copies of the same logic. photos.tsx and media-grid.tsx keep
their epoch-ms based formatters since those are a different input shape.

Verified: tsc --noEmit clean, full test suite green (301/301).
This commit is contained in:
openhands committed 2026-07-18 19:17:17 +02:00
1 parent 3c9c1311ec
commit b9c6001f08
20 files changed
+84 -86

No files matched your search

+2 -4
View File
@@ -1,4 +1,5 @@
import { ClipboardList } from "lucide-react";
import { formatDate } from "@/lib/format-date";
import Link from "next/link";
import { getTranslations } from "next-intl/server";
import { dismissApplication } from "@/actions/admin-applications";
@@ -17,9 +18,6 @@ type ApplicationRow = {
createdAt: Date | null;
};
function formatDate(d: Date | null): string {
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "—";
}
export default async function AdminApplications() {
const { session, permissions } = await getAdminContext();
@@ -105,7 +103,7 @@ export default async function AdminApplications() {
</span>
</div>
<p className="text-xs theme-text-muted dark:theme-text-muted m-0 mb-2">
{formatDate(a.createdAt)}
{formatDate(a.createdAt, "datetime", "—")}
</p>
<p className="text-sm text-[var(--admin-text)] whitespace-pre-wrap m-0 mb-3">
{a.content}