import TableFilter from '@/components/table/table-filter'; import TableFooter from '@/components/table/table-footer'; import TableHeader from '@/components/table/table-header'; import { Card } from '@/components/ui/card'; import { Table, TableBody, TableCell, TableRow } from '@/components/ui/table'; import { usePage } from '@inertiajs/react'; import { SortingState, flexRender, getCoreRowModel, getFilteredRowModel, getSortedRowModel, useReactTable } from '@tanstack/react-table'; import * as React from 'react'; import { ExamUpdateProps } from '../../update'; import ExamAttemptReview from '../exam-attempt-review'; import ExamAttemptTableColumn from '../exam-attempt-table-columns'; const Attempts = () => { const { attempts, exam, attempt } = usePage().props; const [sorting, setSorting] = React.useState([]); const table = useReactTable({ data: attempts.data, columns: ExamAttemptTableColumn(), onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), state: { sorting }, }); return (
{/* Exam Attempts Summary */}

Total Attempts

{attempts.total}

Completed

{attempts.data.filter((a) => a.status === 'completed').length}

In Progress

{attempts.data.filter((a) => a.status === 'in_progress').length}

Pass Rate

{attempts.data.length > 0 ? ( (attempts.data.filter((a) => a.is_passed && a.status === 'completed').length / attempts.data.filter((a) => a.status === 'completed').length) * 100 || 0 ).toFixed(1) : 0} %

{/* Attempts Table */} {attempt ? ( ) : ( {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( No exam attempts found. )}
)}
); }; export default Attempts;