refactor: centralize duplicated formatDate helper
Local Build and Deploy / deploy (push) Successful in 1m7s
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:
1 parent
3c9c1311ec
commit
b9c6001f08
20 files changed
+84
-86
No files matched your search
@@ -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}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import {
|
||||
addBlacklist,
|
||||
addWhitelist,
|
||||
@@ -19,9 +20,6 @@ type IpRow = {
|
||||
createdAt: Date | null;
|
||||
};
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "—";
|
||||
}
|
||||
|
||||
export default async function AdminIp() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
@@ -113,7 +111,7 @@ export default async function AdminIp() {
|
||||
{w.asn ?? "—"}
|
||||
</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
||||
{formatDate(w.createdAt)}
|
||||
{formatDate(w.createdAt, "datetime", "—")}
|
||||
</td>
|
||||
<td>
|
||||
<form action={deleteWhitelist}>
|
||||
@@ -175,7 +173,7 @@ export default async function AdminIp() {
|
||||
{b.asn ?? "—"}
|
||||
</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
||||
{formatDate(b.createdAt)}
|
||||
{formatDate(b.createdAt, "datetime", "—")}
|
||||
</td>
|
||||
<td>
|
||||
<form action={deleteBlacklist}>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import {
|
||||
createApiKey,
|
||||
deleteApiKey,
|
||||
@@ -23,9 +24,6 @@ type ApiKey = {
|
||||
createdAt: Date | null;
|
||||
};
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014";
|
||||
}
|
||||
|
||||
function maskKey(key: string): string {
|
||||
return key.length > 8 ? `${key.slice(0, 8)}\u2026` : key;
|
||||
@@ -204,10 +202,10 @@ export default async function AdminRadioApiKeysPage() {
|
||||
{k.rateLimit}/min
|
||||
</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
||||
{formatDate(k.lastUsedAt)}
|
||||
{formatDate(k.lastUsedAt, "datetime", "\u2014")}
|
||||
</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
||||
{formatDate(k.expiresAt)}
|
||||
{formatDate(k.expiresAt, "datetime", "\u2014")}
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Image from "next/image";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import {
|
||||
createTrack,
|
||||
@@ -32,9 +33,6 @@ function formatDuration(seconds: number | null): string {
|
||||
return `${m}:${String(s).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014";
|
||||
}
|
||||
|
||||
export default async function AdminRadioAutoDjPage() {
|
||||
const t = await getTranslations("pages.admin.radio");
|
||||
@@ -269,7 +267,7 @@ export default async function AdminRadioAutoDjPage() {
|
||||
{track.playCount}
|
||||
</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
||||
{formatDate(track.lastPlayedAt)}
|
||||
{formatDate(track.lastPlayedAt, "datetime", "\u2014")}
|
||||
</td>
|
||||
<td>
|
||||
<span
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import NextImage from "next/image";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import {
|
||||
createRadioBanner,
|
||||
@@ -21,9 +22,6 @@ type Banner = {
|
||||
createdAt: Date | null;
|
||||
};
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014";
|
||||
}
|
||||
|
||||
export default async function AdminRadioBannersPage() {
|
||||
const t = await getTranslations("pages.admin.radio");
|
||||
@@ -180,7 +178,7 @@ export default async function AdminRadioBannersPage() {
|
||||
<strong>#{String(b.id)}</strong>
|
||||
<span className="text-sm theme-text-muted dark:theme-text-muted inline-flex gap-2 items-center">
|
||||
{t("banners.byUser", { id: String(b.userId) })} ·{" "}
|
||||
{formatDate(b.createdAt)} ·{" "}
|
||||
{formatDate(b.createdAt, "datetime", "\u2014")} ·{" "}
|
||||
<span
|
||||
className={`inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full ${b.isActive ? "bg-[var(--admin-success-subtle)] text-[var(--admin-text)]" : "bg-[var(--admin-error-subtle)] text-[var(--admin-text)]"}`}
|
||||
>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { StatusCard } from "@/components/admin/dashboard";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
@@ -14,9 +15,6 @@ type History = {
|
||||
notes: string | null;
|
||||
};
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014";
|
||||
}
|
||||
|
||||
function formatDuration(start: Date, end: Date | null): string {
|
||||
if (!end) return "\u2014";
|
||||
@@ -137,12 +135,12 @@ export default async function AdminRadioHistoryPage() {
|
||||
</td>
|
||||
<td>{h.showName ?? "\u2014"}</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
||||
{formatDate(h.startedAt)}
|
||||
{formatDate(h.startedAt, "datetime", "\u2014")}
|
||||
</td>
|
||||
<td>
|
||||
{h.endedAt ? (
|
||||
<span className="text-sm theme-text-muted dark:theme-text-muted">
|
||||
{formatDate(h.endedAt)}
|
||||
{formatDate(h.endedAt, "datetime", "\u2014")}
|
||||
</span>
|
||||
) : (
|
||||
<span className="inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full bg-[var(--admin-success-subtle)] text-[var(--admin-text)]">
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { deleteShout } from "@/actions/admin-radio-moderation";
|
||||
import { StatusCard } from "@/components/admin/dashboard";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
@@ -13,9 +14,6 @@ type Shout = {
|
||||
updatedAt: Date | null;
|
||||
};
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014";
|
||||
}
|
||||
|
||||
export default async function AdminRadioModerationPage() {
|
||||
const t = await getTranslations("pages.admin.radio");
|
||||
@@ -72,7 +70,7 @@ export default async function AdminRadioModerationPage() {
|
||||
<td>{String(s.userId)}</td>
|
||||
<td>{s.message}</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
||||
{formatDate(s.createdAt)}
|
||||
{formatDate(s.createdAt, "datetime", "\u2014")}
|
||||
</td>
|
||||
<td>
|
||||
<form action={deleteShout}>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { deleteShout } from "@/actions/admin-radio-moderation";
|
||||
import { StatusCard } from "@/components/admin/dashboard";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
@@ -33,9 +34,6 @@ type Schedule = {
|
||||
isActive: boolean;
|
||||
};
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "\u2014";
|
||||
}
|
||||
|
||||
function formatTime(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(11, 16) : "\u2014";
|
||||
@@ -162,7 +160,7 @@ export default async function AdminRadioPage() {
|
||||
<td>{String(s.userId)}</td>
|
||||
<td>{s.message}</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted">
|
||||
{formatDate(s.createdAt)}
|
||||
{formatDate(s.createdAt, "datetime", "\u2014")}
|
||||
</td>
|
||||
<td>
|
||||
<form action={deleteShout}>
|
||||
@@ -218,7 +216,7 @@ export default async function AdminRadioPage() {
|
||||
</span>
|
||||
</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted">
|
||||
{formatDate(a.createdAt)}
|
||||
{formatDate(a.createdAt, "datetime", "\u2014")}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { createTag, deleteTag, updateTag } from "@/actions/admin-tags";
|
||||
import { StatusCard } from "@/components/admin/dashboard";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
@@ -14,9 +15,6 @@ type Tag = {
|
||||
createdAt: Date | null;
|
||||
};
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 10) : "—";
|
||||
}
|
||||
|
||||
export default async function AdminTagsPage() {
|
||||
const { session, permissions } = await getAdminContext();
|
||||
@@ -170,7 +168,7 @@ export default async function AdminTagsPage() {
|
||||
</span>
|
||||
</td>
|
||||
<td className="text-sm theme-text-muted dark:theme-text-muted whitespace-nowrap">
|
||||
{formatDate(tag.createdAt)}
|
||||
{formatDate(tag.createdAt, "date", "—")}
|
||||
</td>
|
||||
<td>
|
||||
<form
|
||||
|
||||
Reference in new issue
Block a user