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 { redirect } from "next/navigation";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { createTicket } from "@/actions/help-tickets";
|
||||
import { ContentCard, EmptyState, StatBlock } from "@/components/public/ui";
|
||||
@@ -7,9 +8,6 @@ import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "";
|
||||
}
|
||||
|
||||
export default async function HelpTicketsPage() {
|
||||
const session = await auth();
|
||||
@@ -101,7 +99,7 @@ export default async function HelpTicketsPage() {
|
||||
{t2.open ? t("statusOpen") : t("statusClosed")}
|
||||
</span>
|
||||
</td>
|
||||
<td className="muted">{formatDate(t2.createdAt)}</td>
|
||||
<td className="muted">{formatDate(t2.createdAt, "datetime", "")}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
@@ -45,9 +46,6 @@ const REACTIONS: { key: string; emoji: string }[] = [
|
||||
{ key: "wow", emoji: "😮" },
|
||||
];
|
||||
|
||||
function formatDate(d: Date | null | undefined): string {
|
||||
return d ? d.toISOString().slice(0, 10) : "";
|
||||
}
|
||||
|
||||
export default async function ArticlePage({
|
||||
params,
|
||||
@@ -262,7 +260,7 @@ export default async function ArticlePage({
|
||||
<span>{t("userNumber", { id: c.userId })}</span>
|
||||
)}
|
||||
{c.createdAt ? (
|
||||
<span> · {formatDate(c.createdAt)}</span>
|
||||
<span> · {formatDate(c.createdAt, "date", "")}</span>
|
||||
) : null}
|
||||
</p>
|
||||
<p style={{ margin: 0, whiteSpace: "pre-wrap" }}>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Image from "next/image";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import Link from "next/link";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||
@@ -9,9 +10,6 @@ export const revalidate = 300;
|
||||
|
||||
export const metadata = { title: "News" };
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
return d ? d.toISOString().slice(0, 10) : "";
|
||||
}
|
||||
|
||||
export default async function NewsPage() {
|
||||
const t = await getTranslations("pages.news");
|
||||
@@ -99,7 +97,7 @@ export default async function NewsPage() {
|
||||
className="muted"
|
||||
style={{ margin: "0.35rem 0 0.6rem", fontSize: "0.78rem" }}
|
||||
>
|
||||
{formatDate(a.createdAt)}
|
||||
{formatDate(a.createdAt, "date", "")}
|
||||
</p>
|
||||
<p
|
||||
style={{
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Link from "next/link";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { ContentCard } from "@/components/public/ui";
|
||||
@@ -6,9 +7,6 @@ import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const revalidate = 300;
|
||||
|
||||
function formatDate(d: Date | null | undefined): string {
|
||||
return d ? d.toISOString().slice(0, 19).replace("T", " ") : "";
|
||||
}
|
||||
|
||||
export default async function RadioContestDetailPage({
|
||||
params,
|
||||
@@ -63,15 +61,15 @@ export default async function RadioContestDetailPage({
|
||||
<tr>
|
||||
<th>Period</th>
|
||||
<td>
|
||||
{contest.startDate ? formatDate(contest.startDate) : "—"}
|
||||
{contest.startDate ? formatDate(contest.startDate, "datetime-seconds", "") : "—"}
|
||||
{" — "}
|
||||
{contest.endDate ? formatDate(contest.endDate) : "ongoing"}
|
||||
{contest.endDate ? formatDate(contest.endDate, "datetime-seconds", "") : "ongoing"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Created</th>
|
||||
<td>
|
||||
{formatDate(contest.createdAt) || (
|
||||
{formatDate(contest.createdAt, "datetime-seconds", "") || (
|
||||
<span className="muted">—</span>
|
||||
)}
|
||||
</td>
|
||||
@@ -79,7 +77,7 @@ export default async function RadioContestDetailPage({
|
||||
<tr>
|
||||
<th>Updated</th>
|
||||
<td>
|
||||
{formatDate(contest.updatedAt) || (
|
||||
{formatDate(contest.updatedAt, "datetime-seconds", "") || (
|
||||
<span className="muted">—</span>
|
||||
)}
|
||||
</td>
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import Link from "next/link";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const revalidate = 300;
|
||||
|
||||
function formatDate(d: Date | null | undefined): string {
|
||||
return d ? d.toISOString().slice(0, 10) : "";
|
||||
}
|
||||
|
||||
export default async function RadioContestsPage() {
|
||||
const t = await getTranslations("pages.radioContests");
|
||||
@@ -67,7 +65,7 @@ export default async function RadioContestsPage() {
|
||||
style={{ margin: 0, fontSize: "0.85rem" }}
|
||||
>
|
||||
{c.startDate
|
||||
? `${formatDate(c.startDate)} — ${c.endDate ? formatDate(c.endDate) : "ongoing"}`
|
||||
? `${formatDate(c.startDate, "date", "")} — ${c.endDate ? formatDate(c.endDate, "date", "") : "ongoing"}`
|
||||
: t("dateUnknown")}
|
||||
</p>
|
||||
</Link>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Link from "next/link";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { ContentCard } from "@/components/public/ui";
|
||||
@@ -6,9 +7,6 @@ import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const revalidate = 300;
|
||||
|
||||
function formatDate(d: Date | null | undefined): string {
|
||||
return d ? d.toISOString().slice(0, 19).replace("T", " ") : "";
|
||||
}
|
||||
|
||||
export default async function RadioGiveawayDetailPage({
|
||||
params,
|
||||
@@ -68,15 +66,15 @@ export default async function RadioGiveawayDetailPage({
|
||||
<tr>
|
||||
<th>Period</th>
|
||||
<td>
|
||||
{giveaway.startDate ? formatDate(giveaway.startDate) : "—"}
|
||||
{giveaway.startDate ? formatDate(giveaway.startDate, "datetime-seconds", "") : "—"}
|
||||
{" — "}
|
||||
{giveaway.endDate ? formatDate(giveaway.endDate) : "ongoing"}
|
||||
{giveaway.endDate ? formatDate(giveaway.endDate, "datetime-seconds", "") : "ongoing"}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Created</th>
|
||||
<td>
|
||||
{formatDate(giveaway.createdAt) || (
|
||||
{formatDate(giveaway.createdAt, "datetime-seconds", "") || (
|
||||
<span className="muted">—</span>
|
||||
)}
|
||||
</td>
|
||||
@@ -84,7 +82,7 @@ export default async function RadioGiveawayDetailPage({
|
||||
<tr>
|
||||
<th>Updated</th>
|
||||
<td>
|
||||
{formatDate(giveaway.updatedAt) || (
|
||||
{formatDate(giveaway.updatedAt, "datetime-seconds", "") || (
|
||||
<span className="muted">—</span>
|
||||
)}
|
||||
</td>
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import Link from "next/link";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const revalidate = 300;
|
||||
|
||||
function formatDate(d: Date | null | undefined): string {
|
||||
return d ? d.toISOString().slice(0, 10) : "";
|
||||
}
|
||||
|
||||
export default async function RadioGiveawaysPage() {
|
||||
const t = await getTranslations("pages.radioGiveaways");
|
||||
@@ -74,7 +72,7 @@ export default async function RadioGiveawaysPage() {
|
||||
style={{ margin: 0, fontSize: "0.85rem" }}
|
||||
>
|
||||
{g.startDate
|
||||
? `${formatDate(g.startDate)} — ${g.endDate ? formatDate(g.endDate) : "ongoing"}`
|
||||
? `${formatDate(g.startDate, "date", "")} — ${g.endDate ? formatDate(g.endDate, "date", "") : "ongoing"}`
|
||||
: t("dateUnknown")}
|
||||
</p>
|
||||
</Link>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { submitRequest } from "@/actions/radio-requests";
|
||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||
import { auth } from "@/lib/auth";
|
||||
@@ -6,9 +7,6 @@ import { prisma } from "@/lib/prisma";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
function formatDate(d: Date | null | undefined): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "";
|
||||
}
|
||||
|
||||
export default async function RadioRequestsPage() {
|
||||
const t = await getTranslations("pages.radioRequests");
|
||||
@@ -136,7 +134,7 @@ export default async function RadioRequestsPage() {
|
||||
)}
|
||||
</td>
|
||||
<td className="muted">
|
||||
{r.submittedAt ? formatDate(r.submittedAt) : "—"}
|
||||
{r.submittedAt ? formatDate(r.submittedAt, "datetime", "") : "—"}
|
||||
</td>
|
||||
<td>{status}</td>
|
||||
</tr>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import { postShout } from "@/actions/radio-shouts";
|
||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||
import { auth } from "@/lib/auth";
|
||||
@@ -8,9 +9,6 @@ import { siteSettings } from "@/lib/services/site-settings";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
function formatDate(d: Date | null | undefined): string {
|
||||
return d ? d.toISOString().slice(0, 16).replace("T", " ") : "";
|
||||
}
|
||||
|
||||
export default async function RadioShoutsPage() {
|
||||
const t = await getTranslations("pages.radioShouts");
|
||||
@@ -124,7 +122,7 @@ export default async function RadioShoutsPage() {
|
||||
<div style={{ flex: 1, minWidth: 0 }}>
|
||||
<p style={{ margin: "0 0 0.25rem" }}>
|
||||
<strong>{author?.username ?? `User #${s.userId}`}</strong>{" "}
|
||||
<span className="muted">{formatDate(s.createdAt)}</span>
|
||||
<span className="muted">{formatDate(s.createdAt, "datetime", "")}</span>
|
||||
</p>
|
||||
<p style={{ margin: 0 }}>{s.message}</p>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import { formatDate } from "@/lib/format-date";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
@@ -47,9 +48,6 @@ function formatTimestamp(ts: number | null | undefined): string {
|
||||
return new Date(ts * 1000).toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function formatDate(d: Date | null | undefined): string {
|
||||
return d ? d.toISOString().slice(0, 10) : "";
|
||||
}
|
||||
|
||||
export default async function ProfilePage({
|
||||
params,
|
||||
@@ -565,7 +563,7 @@ export default async function ProfilePage({
|
||||
<strong>
|
||||
{author?.username ?? t("unknownUser", { id: g.userId })}
|
||||
</strong>{" "}
|
||||
<span className="muted">{formatDate(g.createdAt)}</span>
|
||||
<span className="muted">{formatDate(g.createdAt, "date", "")}</span>
|
||||
</p>
|
||||
<p style={{ margin: 0 }}>{g.message}</p>
|
||||
</div>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
export type DateFormatVariant = "date" | "datetime" | "datetime-seconds";
|
||||
|
||||
const FALLBACKS: Record<DateFormatVariant, string> = {
|
||||
date: "",
|
||||
datetime: "—",
|
||||
"datetime-seconds": "—",
|
||||
};
|
||||
|
||||
/**
|
||||
* Format a Date for display. Kept as a single shared helper so the various
|
||||
* admin/site pages no longer each redefine their own copy.
|
||||
*
|
||||
* - "date" → 2026-07-18
|
||||
* - "datetime" → 2026-07-18 18:30
|
||||
* - "datetime-seconds"→ 2026-07-18 18:30:45
|
||||
*
|
||||
* `fallback` overrides the default em-dash / empty string when the value is
|
||||
* null/undefined.
|
||||
*/
|
||||
export function formatDate(
|
||||
d: Date | null | undefined,
|
||||
variant: DateFormatVariant = "datetime",
|
||||
fallback?: string,
|
||||
): string {
|
||||
if (!d) return fallback ?? FALLBACKS[variant];
|
||||
const iso = d.toISOString();
|
||||
switch (variant) {
|
||||
case "date":
|
||||
return iso.slice(0, 10);
|
||||
case "datetime-seconds":
|
||||
return iso.slice(0, 19).replace("T", " ");
|
||||
case "datetime":
|
||||
default:
|
||||
return iso.slice(0, 16).replace("T", " ");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user