mirror of
https://github.com/R0m1k3/Menu.git
synced 2026-10-11 17:28:28 +02:00
feat: initialize Prisma schema with Config and Button models
This commit is contained in:
1 parent
ca99378348
commit
485aba96fd
10 files changed
+408
-241
No files matched your search
+55
-102
@@ -1,162 +1,118 @@
|
||||
import { prisma } from '@/lib/db';
|
||||
import { isAuthenticated, logoutAdmin, addButton, deleteButton } from '@/app/actions/admin';
|
||||
import { isAuthenticated, logoutAdmin, deleteButton } from '@/app/actions/admin';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { GlassCard } from '@/components/GlassCard';
|
||||
import { ThemeToggle } from '@/components/ThemeToggle';
|
||||
import { Trash2, LogOut, PlusCircle, Globe, ArrowLeft } from 'lucide-react';
|
||||
import { LogOut, ArrowLeft, Trash2, Globe } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
import Link from 'next/link';
|
||||
import { AddButtonForm } from '@/components/AddButtonForm';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
function getDomainFromUrl(url: string): string {
|
||||
try {
|
||||
return new URL(url).hostname;
|
||||
} catch {
|
||||
return url;
|
||||
}
|
||||
function getDomain(url: string): string {
|
||||
try { return new URL(url).hostname; } catch { return url; }
|
||||
}
|
||||
|
||||
export default async function AdminPage() {
|
||||
const auth = await isAuthenticated();
|
||||
|
||||
if (!auth) {
|
||||
redirect('/admin/login');
|
||||
}
|
||||
if (!auth) redirect('/admin/login');
|
||||
|
||||
const buttons = await prisma.button.findMany({
|
||||
orderBy: { order: 'asc' },
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="page-container" style={{ maxWidth: '900px' }}>
|
||||
<div style={{ minHeight: '100vh', padding: '1.5rem 2rem', maxWidth: '860px', margin: '0 auto' }}>
|
||||
|
||||
{/* Header */}
|
||||
<header style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'center',
|
||||
marginBottom: '2.5rem',
|
||||
}}>
|
||||
<header style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: '2.5rem' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
|
||||
<Link href="/" aria-label="Retour" style={{
|
||||
background: 'var(--glass-bg)',
|
||||
backdropFilter: 'blur(20px)',
|
||||
WebkitBackdropFilter: 'blur(20px)',
|
||||
border: '1px solid var(--glass-border)',
|
||||
<Link href="/" style={{
|
||||
background: 'rgba(255,255,255,0.1)',
|
||||
backdropFilter: 'blur(16px)',
|
||||
border: '1px solid rgba(255,255,255,0.15)',
|
||||
borderRadius: '50%',
|
||||
width: '38px',
|
||||
height: '38px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
width: '36px', height: '36px',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
}}>
|
||||
<ArrowLeft size={16} color="var(--fg-secondary)" />
|
||||
<ArrowLeft size={15} color="rgba(255,255,255,0.8)" />
|
||||
</Link>
|
||||
<div>
|
||||
<h1 style={{ fontSize: '1.6rem', fontWeight: 700, letterSpacing: '-0.03em' }}>
|
||||
<h1 style={{ fontSize: '1.4rem', fontWeight: 700, letterSpacing: '-0.02em', color: '#fff' }}>
|
||||
Administration
|
||||
</h1>
|
||||
<p style={{ fontSize: '0.85rem', color: 'var(--fg-secondary)', marginTop: '0.1rem' }}>
|
||||
Gérez vos raccourcis d'applications
|
||||
<p style={{ fontSize: '0.8rem', color: 'rgba(255,255,255,0.45)', marginTop: '0.1rem' }}>
|
||||
{buttons.length} application{buttons.length !== 1 ? 's' : ''} configurée{buttons.length !== 1 ? 's' : ''}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '0.75rem' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '0.6rem' }}>
|
||||
<ThemeToggle />
|
||||
<form action={logoutAdmin}>
|
||||
<button type="submit" style={{
|
||||
background: 'var(--glass-bg)',
|
||||
backdropFilter: 'blur(20px)',
|
||||
WebkitBackdropFilter: 'blur(20px)',
|
||||
border: '1px solid var(--glass-border)',
|
||||
background: 'rgba(255,255,255,0.08)',
|
||||
backdropFilter: 'blur(12px)',
|
||||
border: '1px solid rgba(255,255,255,0.12)',
|
||||
borderRadius: '50px',
|
||||
padding: '0.5rem 1rem',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: '0.4rem',
|
||||
fontSize: '0.85rem',
|
||||
padding: '0.45rem 0.9rem',
|
||||
color: 'rgba(255,255,255,0.7)',
|
||||
fontSize: '0.82rem',
|
||||
fontWeight: 500,
|
||||
color: 'var(--fg-secondary)',
|
||||
display: 'flex', alignItems: 'center', gap: '0.4rem',
|
||||
}}>
|
||||
<LogOut size={15} /> Déconnexion
|
||||
<LogOut size={13} /> Déconnexion
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* Add form */}
|
||||
<GlassCard style={{ padding: '1.75rem', marginBottom: '2rem' }}>
|
||||
<h2 style={{
|
||||
fontSize: '1rem',
|
||||
fontWeight: 600,
|
||||
marginBottom: '1.25rem',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: '0.5rem',
|
||||
}}>
|
||||
<PlusCircle size={18} color="var(--accent)" />
|
||||
Ajouter une application
|
||||
</h2>
|
||||
|
||||
<form action={addButton} style={{ display: 'flex', gap: '0.75rem', flexWrap: 'wrap' }}>
|
||||
<div style={{ flex: '1 1 180px' }}>
|
||||
<label style={{ display: 'block', fontSize: '0.8rem', fontWeight: 600, color: 'var(--fg-secondary)', marginBottom: '0.4rem' }}>Nom</label>
|
||||
<input name="name" type="text" placeholder="Ex: Slack, Notion..." required />
|
||||
</div>
|
||||
<div style={{ flex: '2 1 280px' }}>
|
||||
<label style={{ display: 'block', fontSize: '0.8rem', fontWeight: 600, color: 'var(--fg-secondary)', marginBottom: '0.4rem' }}>URL</label>
|
||||
<input name="url" type="url" placeholder="https://..." required />
|
||||
</div>
|
||||
<div style={{ alignSelf: 'flex-end' }}>
|
||||
<button type="submit" className="btn-primary" style={{ whiteSpace: 'nowrap' }}>
|
||||
Ajouter →
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</GlassCard>
|
||||
<AddButtonForm />
|
||||
|
||||
{/* Button list */}
|
||||
{buttons.length === 0 ? (
|
||||
<div style={{ textAlign: 'center', padding: '4rem', color: 'var(--fg-secondary)', fontSize: '0.9rem' }}>
|
||||
Aucun bouton configuré. Ajoutez-en un ci-dessus.
|
||||
<div style={{ textAlign: 'center', padding: '4rem', color: 'rgba(255,255,255,0.35)', fontSize: '0.9rem' }}>
|
||||
Aucun bouton configuré.
|
||||
</div>
|
||||
) : (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.6rem' }}>
|
||||
{buttons.map((btn: any) => {
|
||||
const domain = getDomainFromUrl(btn.url);
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
|
||||
{(buttons as any[]).map((btn) => {
|
||||
const domain = getDomain(btn.url);
|
||||
const faviconUrl = `https://www.google.com/s2/favicons?domain=${domain}&sz=32`;
|
||||
|
||||
return (
|
||||
<GlassCard key={btn.id} style={{
|
||||
padding: '0.9rem 1.25rem',
|
||||
<div key={btn.id} style={{
|
||||
background: 'rgba(255,255,255,0.06)',
|
||||
backdropFilter: 'blur(16px)',
|
||||
border: '1px solid rgba(255,255,255,0.10)',
|
||||
borderRadius: '14px',
|
||||
padding: '0.85rem 1.2rem',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
gap: '1rem',
|
||||
borderRadius: '14px',
|
||||
}}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '0.85rem', minWidth: 0 }}>
|
||||
{/* Icon: emoji or favicon */}
|
||||
<div style={{
|
||||
width: '36px',
|
||||
height: '36px',
|
||||
width: '40px', height: '40px',
|
||||
borderRadius: '10px',
|
||||
background: 'var(--bg-base)',
|
||||
border: '1px solid var(--glass-border)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
background: 'rgba(255,255,255,0.08)',
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
flexShrink: 0,
|
||||
overflow: 'hidden',
|
||||
fontSize: '1.3rem',
|
||||
}}>
|
||||
<Image src={faviconUrl} alt={btn.name} width={20} height={20} unoptimized />
|
||||
{btn.icon ? btn.icon : (
|
||||
<Image src={faviconUrl} alt={btn.name} width={20} height={20} unoptimized />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div style={{ minWidth: 0 }}>
|
||||
<div style={{ fontWeight: 600, fontSize: '0.9rem', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
<div style={{ fontWeight: 600, fontSize: '0.9rem', color: '#fff', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
{btn.name}
|
||||
</div>
|
||||
<div style={{ fontSize: '0.78rem', color: 'var(--fg-secondary)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>
|
||||
<div style={{ fontSize: '0.76rem', color: 'rgba(255,255,255,0.4)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', maxWidth: '360px' }}>
|
||||
{btn.url}
|
||||
</div>
|
||||
</div>
|
||||
@@ -168,21 +124,18 @@ export default async function AdminPage() {
|
||||
}}>
|
||||
<button type="submit" style={{
|
||||
background: 'transparent',
|
||||
color: 'var(--fg-secondary)',
|
||||
color: 'rgba(255,255,255,0.3)',
|
||||
padding: '0.4rem',
|
||||
borderRadius: '8px',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
flexShrink: 0,
|
||||
transition: 'color 200ms',
|
||||
}}
|
||||
onMouseEnter={(e) => (e.currentTarget.style.color = 'var(--error)')}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.color = 'var(--fg-secondary)')}
|
||||
onMouseEnter={(e) => (e.currentTarget.style.color = '#ff6b7a')}
|
||||
onMouseLeave={(e) => (e.currentTarget.style.color = 'rgba(255,255,255,0.3)')}
|
||||
>
|
||||
<Trash2 size={17} />
|
||||
<Trash2 size={16} />
|
||||
</button>
|
||||
</form>
|
||||
</GlassCard>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user