import React, { useEffect, useState } from 'react'; import { supabase } from '../../supabaseClient'; export default function RecentApplications({ onNavigate }) { const [applications, setApplications] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const fetchApps = async () => { try { // ✅ FIX: Using the EXACT constraint name from your error log const { data, error } = await supabase .from('applications') .select(` id, created_at, status, experience, jobs:jobs!applications_job_id_fkey ( title ), profiles:profiles!fk_applications_profiles ( full_name, avatar_url ) `) .order('created_at', { ascending: false }) .limit(4); if (error) throw error; console.log('Fetched Data:', data); setApplications(data || []); } catch (error) { console.error('Error fetching applications:', error); } finally { setLoading(false); } }; fetchApps(); }, []); // Helper for Status Badges const getStatusBadge = (status) => { const s = status ? status.toLowerCase() : ''; let bg = 'rgba(255,255,255,0.1)'; let text = '#D1D5DB'; if (s === 'accepted' || s === 'hired') { bg = 'rgba(16, 185, 129, 0.2)'; text = '#34D399'; } else if (s === 'rejected') { bg = 'rgba(239, 68, 68, 0.2)'; text = '#F87171'; } else if (s === 'pending') { bg = 'rgba(245, 158, 11, 0.2)'; text = '#FBBF24'; } return ( {status || 'Pending'} ); }; return (

Recent Applications

{loading ? (

Loading...

) : applications.length === 0 ? (

No applications yet.

) : ( applications.map((app) => { // Safe access const profile = app.profiles || {}; const job = app.jobs || {}; const name = profile.full_name || 'Unknown User'; const jobTitle = job.title || 'Unknown Role'; const exp = app.experience ? `• ${app.experience} years` : ''; const initial = name.charAt(0).toUpperCase(); return (
{profile.avatar_url ? ( {name} ) : (
{initial}
)}
{name}
{jobTitle} {exp}
{new Date(app.created_at).toLocaleDateString()} {getStatusBadge(app.status)}
); }) )}
); }