deckhearth/pages/admin/card-submissions.js

146 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

import { useState, useEffect } from 'react';
import Layout from '../../components/Layout';
import AdminProtected from '../../components/AdminProtected';
function CardSubmissionsAdmin() {
const [submissions, setSubmissions] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [processingId, setProcessingId] = useState(null);
const loadSubmissions = async () => {
setLoading(true);
setError(null);
try {
const response = await fetch('/api/admin/card-submissions?status=pending', {
headers: {
Authorization: `Bearer ${localStorage.getItem('auth_token')}`,
},
});
if (!response.ok) {
throw new Error('Failed to load submissions');
}
const data = await response.json();
setSubmissions(data.submissions || []);
} catch (err) {
setError(err.message);
} finally {
setLoading(false);
}
};
useEffect(() => {
// eslint-disable-next-line react-hooks/set-state-in-effect -- mount fetch; setLoading runs inside async loader
loadSubmissions();
}, []);
const reviewSubmission = async (submissionId, action) => {
setProcessingId(submissionId);
try {
const response = await fetch('/api/admin/card-submissions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${localStorage.getItem('auth_token')}`,
},
body: JSON.stringify({ submissionId, action }),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || 'Review failed');
}
await loadSubmissions();
} catch (err) {
setError(err.message);
} finally {
setProcessingId(null);
}
};
return (
<div className="max-w-4xl mx-auto px-6 py-8">
<h1 className="text-2xl font-bold mb-2" style={{ color: 'var(--text-primary)' }}>
Card Scan Submissions
</h1>
<p className="text-sm mb-6" style={{ color: 'var(--text-secondary)' }}>
Review cards identified by the scanner that are not yet in the global catalog.
</p>
{error && (
<div className="mb-4 p-3 rounded-lg border border-red-500 text-sm text-red-600">
{error}
</div>
)}
{loading ? (
<p style={{ color: 'var(--text-secondary)' }}>Loading</p>
) : submissions.length === 0 ? (
<p style={{ color: 'var(--text-secondary)' }}>No pending submissions.</p>
) : (
<ul className="space-y-4">
{submissions.map((sub) => {
const payload = sub.ocr_payload || {};
return (
<li
key={sub.id}
feat(design-system): sweep authenticated body-content panels to glass (#97) PR #95/#96 shipped the Liquid Glass foundation (tokens, primitives, gates) plus Layout shell, modals, landing, auth pages, and form CTAs — but body- content panels on authenticated pages (admin Card Editor, admin Card Import, admin Submissions, dashboard, my-cards, settings, scanner panels, card detail price cards, popovers) were still rendering as flat var(--bg-secondary) cards. Result: the admin Tools screen and several core pages looked unchanged after the redesign. This sweep adds a `.glass-panel` / `.glass-panel-strong` utility (<GlassSurface tint=mid/high rim=subtle elevation=ambient/pronounced blur=mid/high> in class form) and applies it across 18 surfaces: * Admin Card Editor view, search panel, form (5 sections), preview * Admin Card Import navigation + 3 body cards + sync panel * Admin Card Submissions list items * Dashboard stat cards + empty-state + grid items (5 surfaces) * My-cards empty-state CTA card * Settings panels (3) * Scanner page settings + grid + queue + bulk toolbar + dialog * Scanner destination picker + camera status banner + disambiguation * Card detail price cards (Current / TCGPlayer / CardKingdom) * Permission indicator tooltips * Collections page header card * Card detail view price cards Also migrates the lingering admin Card Editor "Card Editor / Card Import" nav buttons and the "Save Changes" / "Import Cards" / "Run catalog sync" CTAs to the <Button> primitive (consistent loading + disabled states). Page header bands (full-bleed strips with border-bottom on dashboard, my-cards, cards, collections, community/collections, collection/[id]) are intentionally left solid — they're not card-shaped surfaces and stacking glass-on-glass directly below the already-glass topbar would muddy the hierarchy. Tests: lint clean, vitest 104/104, build green. The visual diff baseline will need refresh because the homepage spec is unaffected (it targets the unauthenticated landing page) but the dashboard/ admin/scanner surfaces will diff if/when we add baselines for them. Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-03 22:28:52 -04:00
className="glass-panel p-4 rounded-xl"
>
<div className="flex justify-between gap-4 mb-2">
<div>
<div className="font-semibold" style={{ color: 'var(--text-primary)' }}>
{payload.name || sub.ocr_text || 'Unknown card'}
</div>
<div className="text-sm" style={{ color: 'var(--text-secondary)' }}>
{payload.game} · confidence {sub.ocr_confidence ?? '—'}% · by {sub.submitter_email}
</div>
</div>
<div className="text-xs" style={{ color: 'var(--text-secondary)' }}>
#{sub.id}
</div>
</div>
{sub.ocr_text && (
<p className="text-xs mb-3 line-clamp-2" style={{ color: 'var(--text-secondary)' }}>
{sub.ocr_text}
</p>
)}
<div className="flex gap-2">
<button
type="button"
disabled={processingId === sub.id}
onClick={() => reviewSubmission(sub.id, 'approve')}
className="px-3 py-1.5 rounded-lg text-sm font-medium disabled:opacity-50"
style={{ backgroundColor: 'var(--accent-gold)', color: 'white' }}
>
Approve
</button>
<button
type="button"
disabled={processingId === sub.id}
onClick={() => reviewSubmission(sub.id, 'reject')}
className="px-3 py-1.5 rounded-lg text-sm border disabled:opacity-50"
style={{ borderColor: 'var(--border)', color: 'var(--text-secondary)' }}
>
Reject
</button>
</div>
</li>
);
})}
</ul>
)}
</div>
);
}
export default function CardSubmissionsPage() {
return (
<AdminProtected>
{(user) => (
<Layout user={user}>
<CardSubmissionsAdmin />
</Layout>
)}
</AdminProtected>
);
}