- Replace 'card' class with 'admin-card' (gradient cards, dark mode support) - Replace 'muted' class with consistent Tailwind muted states - Standardize page headers with gradient backgrounds and Lucide icons - Convert all inline styles to Tailwind classes - Add admin-page CSS helpers (admin-card, admin-filter-bar, admin-section-title) - Apply pattern to all 42 admin pages (was only 6 before) - Zero TypeScript errors, production builds successfully Co-authored-by: openhands <[email protected]>
183 lines
6.5 KiB
TypeScript
183 lines
6.5 KiB
TypeScript
import Link from 'next/link';
|
|
import {
|
|
createRadioRank,
|
|
deleteRadioRank,
|
|
updateRadioRank,
|
|
} from '@/actions/admin-radio-extra';
|
|
import { prisma } from '@/lib/prisma';
|
|
import { StatusCard } from '@/components/admin/dashboard';
|
|
import { Medal } from 'lucide-react';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
type Rank = {
|
|
id: bigint;
|
|
name: string;
|
|
description: string | null;
|
|
badgeCode: string | null;
|
|
isActive: boolean;
|
|
};
|
|
|
|
export default async function AdminRadioRanksPage() {
|
|
let ranks: Rank[] = [];
|
|
let dbError = false;
|
|
|
|
try {
|
|
ranks = await prisma.radioRanks.findMany({
|
|
select: {
|
|
id: true,
|
|
name: true,
|
|
description: true,
|
|
badgeCode: true,
|
|
isActive: true,
|
|
},
|
|
orderBy: { id: 'asc' },
|
|
});
|
|
} catch {
|
|
dbError = true;
|
|
ranks = [];
|
|
}
|
|
|
|
const activeCount = ranks.filter((r) => r.isActive).length;
|
|
|
|
return (
|
|
<main>
|
|
<nav className="text-xs text-gray-500 dark:text-gray-400 mb-2">
|
|
<Link href="/admin/radio">Radio</Link> ·{' '}
|
|
<Link href="/admin/radio/settings">Settings</Link> ·{' '}
|
|
<Link href="/admin/radio/banners">Banners</Link> ·{' '}
|
|
<Link href="/admin/radio/ranks">Ranks</Link> ·{' '}
|
|
<Link href="/admin/radio/history">History</Link>
|
|
</nav>
|
|
|
|
<div className="flex items-center gap-3 mb-6">
|
|
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-[var(--color-primary)]/20 to-[var(--color-primary)]/5 grid place-items-center">
|
|
<Medal size={20} className="text-[var(--color-primary)]" />
|
|
</div>
|
|
<div>
|
|
<h1 className="m-0 text-xl font-extrabold text-[var(--color-text)]">Radio Ranks</h1>
|
|
<p className="m-0 text-xs text-[var(--color-text-muted)] mt-0.5">DJ / staff ranks assignable on radio applications.</p>
|
|
</div>
|
|
</div>
|
|
|
|
{dbError ? (
|
|
<div className="admin-card mb-6">
|
|
<p className="text-xs text-gray-500 dark:text-gray-400 m-0">
|
|
Could not load ranks (database unavailable).
|
|
</p>
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-[repeat(auto-fit,minmax(180px,1fr))] gap-3.5 mb-6">
|
|
<StatusCard label="Ranks" value={ranks.length} icon="🎖️" />
|
|
<StatusCard
|
|
label="Active"
|
|
value={activeCount}
|
|
state={activeCount > 0 ? 'ok' : 'neutral'}
|
|
icon="✅"
|
|
/>
|
|
</div>
|
|
)}
|
|
|
|
<section className="mt-6">
|
|
<h2 className="admin-section-title">Add rank</h2>
|
|
<form action={createRadioRank} className="admin-card">
|
|
<div className="grid cols-3">
|
|
<div>
|
|
<label htmlFor="new_name" style={{ display: 'block', fontWeight: 700 }}>
|
|
Name
|
|
</label>
|
|
<input id="new_name" name="name" required style={{ width: '100%' }} />
|
|
</div>
|
|
<div>
|
|
<label htmlFor="new_badge" style={{ display: 'block', fontWeight: 700 }}>
|
|
Badge code
|
|
</label>
|
|
<input id="new_badge" name="badgeCode" style={{ width: '100%' }} />
|
|
</div>
|
|
<div style={{ display: 'flex', alignItems: 'flex-end' }}>
|
|
<label style={{ display: 'inline-flex', gap: '0.4rem', alignItems: 'center' }}>
|
|
<input type="checkbox" name="isActive" value="1" defaultChecked /> Active
|
|
</label>
|
|
</div>
|
|
<div style={{ gridColumn: '1 / -1' }}>
|
|
<label htmlFor="new_desc" style={{ display: 'block', fontWeight: 700 }}>
|
|
Description
|
|
</label>
|
|
<input id="new_desc" name="description" style={{ width: '100%' }} />
|
|
</div>
|
|
</div>
|
|
<div style={{ marginTop: '0.75rem' }}>
|
|
<button type="submit" className="btn btn-primary">
|
|
Create rank
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</section>
|
|
|
|
<section className="mt-6">
|
|
<h2 className="admin-section-title">Existing ranks ({ranks.length})</h2>
|
|
{ranks.length === 0 ? (
|
|
<div className="admin-empty">No ranks yet — add one above.</div>
|
|
) : (
|
|
<div className="grid">
|
|
{ranks.map((r) => (
|
|
<div key={String(r.id)} className="admin-card">
|
|
<div className="flex justify-between items-baseline gap-3 mb-2">
|
|
<strong>#{String(r.id)}</strong>
|
|
<span className={`inline-block text-[0.72rem] font-bold px-2 py-0.5 rounded-full ${r.isActive ? 'bg-green-600/20 text-[var(--color-text)]' : 'bg-red-500/22 text-[var(--color-text)]'}`}>
|
|
{r.isActive ? 'active' : 'inactive'}
|
|
</span>
|
|
</div>
|
|
|
|
<form action={updateRadioRank} className="flex items-center gap-2 flex-wrap">
|
|
<input type="hidden" name="id" value={String(r.id)} />
|
|
<input
|
|
name="name"
|
|
defaultValue={r.name}
|
|
required
|
|
placeholder="Name"
|
|
style={{ minWidth: 140 }}
|
|
/>
|
|
<input
|
|
name="badgeCode"
|
|
defaultValue={r.badgeCode ?? ''}
|
|
placeholder="Badge"
|
|
style={{ minWidth: 100 }}
|
|
/>
|
|
<input
|
|
name="description"
|
|
defaultValue={r.description ?? ''}
|
|
placeholder="Description"
|
|
className="flex-1 min-w-[160px]"
|
|
/>
|
|
<label
|
|
style={{ display: 'inline-flex', gap: '0.3rem', alignItems: 'center' }}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
name="isActive"
|
|
value="1"
|
|
defaultChecked={r.isActive}
|
|
/>{' '}
|
|
Active
|
|
</label>
|
|
<button type="submit" className="btn btn-primary">
|
|
Save
|
|
</button>
|
|
</form>
|
|
|
|
<form action={deleteRadioRank} style={{ marginTop: '0.5rem' }}>
|
|
<input type="hidden" name="id" value={String(r.id)} />
|
|
<button type="submit" className="btn btn-danger">
|
|
Delete rank #{String(r.id)}
|
|
</button>
|
|
</form>
|
|
</div>
|
|
))}
|
|
</div>
|
|
)}
|
|
</section>
|
|
</main>
|
|
);
|
|
}
|