| @@ -4,17 +4,19 @@ import { useState, useEffect } from 'react'; | |||||
| import { Card, Portal } from '@/types'; | import { Card, Portal } from '@/types'; | ||||
| export default function AdminDashboard() { | export default function AdminDashboard() { | ||||
| console.log('[ADMIN] Component rendering'); | |||||
| const [activeTab, setActiveTab] = useState<'cards' | 'settings'>('cards'); | const [activeTab, setActiveTab] = useState<'cards' | 'settings'>('cards'); | ||||
| // Card State | // Card State | ||||
| const [cards, setCards] = useState<Card[]>([]); | const [cards, setCards] = useState<Card[]>([]); | ||||
| const [isEditing, setIsEditing] = useState<Partial<Card> | null>(null); | const [isEditing, setIsEditing] = useState<Partial<Card> | null>(null); | ||||
| // Portal State | // Portal State | ||||
| const [portal, setPortal] = useState<Partial<Portal>>({}); | const [portal, setPortal] = useState<Partial<Portal>>({}); | ||||
| const [savingPortal, setSavingPortal] = useState(false); | const [savingPortal, setSavingPortal] = useState(false); | ||||
| const [uploading, setUploading] = useState<{ [key: string]: boolean }>({}); | const [uploading, setUploading] = useState<{ [key: string]: boolean }>({}); | ||||
| // NEW UI STATES: Toast and Confirm Dialog | // NEW UI STATES: Toast and Confirm Dialog | ||||
| const [toast, setToast] = useState<string | null>(null); | const [toast, setToast] = useState<string | null>(null); | ||||
| const [confirmDialog, setConfirmDialog] = useState<{ message: string, onConfirm: () => void } | null>(null); | const [confirmDialog, setConfirmDialog] = useState<{ message: string, onConfirm: () => void } | null>(null); | ||||
| @@ -24,10 +26,17 @@ export default function AdminDashboard() { | |||||
| setToast(message); | setToast(message); | ||||
| setTimeout(() => setToast(null), 3000); | setTimeout(() => setToast(null), 3000); | ||||
| }; | }; | ||||
| useEffect(() => { | useEffect(() => { | ||||
| fetch('/api/cards').then(res => res.json()).then(setCards); | |||||
| fetch('/api/portals').then(res => res.json()).then(data => data && setPortal(data)); | |||||
| console.log('[ADMIN] useEffect fired - fetching data'); | |||||
| fetch('/api/cards') | |||||
| .then(res => { console.log('[ADMIN] /api/cards status:', res.status); return res.json(); }) | |||||
| .then(data => { console.log('[ADMIN] cards received:', data); setCards(data); }) | |||||
| .catch(err => console.error('[ADMIN] cards fetch error:', err)); | |||||
| fetch('/api/portals') | |||||
| .then(res => { console.log('[ADMIN] /api/portals status:', res.status); return res.json(); }) | |||||
| .then(data => { console.log('[ADMIN] portal received:', data); if (data) setPortal(data); }) | |||||
| .catch(err => console.error('[ADMIN] portal fetch error:', err)); | |||||
| }, []); | }, []); | ||||
| const handleUpload = async (e: React.ChangeEvent<HTMLInputElement>, field: string, isPortal = false) => { | const handleUpload = async (e: React.ChangeEvent<HTMLInputElement>, field: string, isPortal = false) => { | ||||
| @@ -163,10 +172,10 @@ export default function AdminDashboard() { | |||||
| <div className="max-w-5xl mx-auto mt-8 px-4"> | <div className="max-w-5xl mx-auto mt-8 px-4"> | ||||
| {/* Tab Navigation */} | {/* Tab Navigation */} | ||||
| <div className="flex space-x-2 mb-6"> | <div className="flex space-x-2 mb-6"> | ||||
| <button onClick={() => setActiveTab('cards')} className={`px-6 py-3 rounded-t-lg font-bold transition-colors ${activeTab === 'cards' ? 'bg-white text-blue-700 border-t-4 border-blue-600 shadow-sm' : 'bg-gray-200 text-gray-600 hover:bg-gray-300'}`}> | |||||
| <button onClick={() => { console.log('[ADMIN] click: cards tab'); setActiveTab('cards'); }} className={`px-6 py-3 rounded-t-lg font-bold transition-colors ${activeTab === 'cards' ? 'bg-white text-blue-700 border-t-4 border-blue-600 shadow-sm' : 'bg-gray-200 text-gray-600 hover:bg-gray-300'}`}> | |||||
| Manage Cards | Manage Cards | ||||
| </button> | </button> | ||||
| <button onClick={() => setActiveTab('settings')} className={`px-6 py-3 rounded-t-lg font-bold transition-colors ${activeTab === 'settings' ? 'bg-white text-blue-700 border-t-4 border-blue-600 shadow-sm' : 'bg-gray-200 text-gray-600 hover:bg-gray-300'}`}> | |||||
| <button onClick={() => { console.log('[ADMIN] click: settings tab'); setActiveTab('settings'); }} className={`px-6 py-3 rounded-t-lg font-bold transition-colors ${activeTab === 'settings' ? 'bg-white text-blue-700 border-t-4 border-blue-600 shadow-sm' : 'bg-gray-200 text-gray-600 hover:bg-gray-300'}`}> | |||||
| Portal Settings | Portal Settings | ||||
| </button> | </button> | ||||
| </div> | </div> | ||||