import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { usePage } from '@inertiajs/react'; import { Download, Eye, Pencil, Plus } from 'lucide-react'; import { useState } from 'react'; import { ExamUpdateProps } from '../../update'; import ResourceForm from '../forms/resource-form'; const Resources = () => { const [editId, setEditId] = useState(''); const { exam } = usePage().props; // Helper to handle file download const handleDownload = async (resource: ExamResource, e: React.MouseEvent) => { e.preventDefault(); try { // For non-link resources, use the download endpoint const url = route('exam-resources.download', resource.id); window.open(url, '_blank'); } catch (error) { // Fallback to direct download if the endpoint fails window.open(resource.resource, '_blank'); } }; return (

Exam Resources

Exam Resources List

Add Resource } />
{exam.resources.length > 0 ? ( exam.resources.map((resource: ExamResource) => (
{resource.type === 'link' ? ( {resource.title.slice(0, 50) + (resource.title.length > 50 ? '...' : '')} ) : ( handleDownload(resource, e)}> {resource.title.slice(0, 50) + (resource.title.length > 50 ? '...' : '')} )}
} /> {resource.type !== 'link' ? ( ) : ( )}
)) ) : (

No resources available

)}
); }; export default Resources;