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 { 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
|
||||
|
||||
Reference in new issue
Block a user