import DeleteModal from '@/components/inertia/delete-modal'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; import { useAuth } from '@/hooks/use-auth'; import { getQueryParams } from '@/lib/route'; import { cn, systemCurrency } from '@/lib/utils'; import { SharedData } from '@/types/global'; import { Link, router, usePage } from '@inertiajs/react'; import { ColumnDef } from '@tanstack/react-table'; import { ArrowUpDown, ChevronsUpDown, Eye, Pencil, Trash2 } from 'lucide-react'; const ExamTableColumn = (): ColumnDef[] => { const { isAdmin } = useAuth(); const { props, url } = usePage(); const { system, translate } = props; const { table, common } = translate; const currency = systemCurrency(system.fields['selling_currency']); const urlParams = getQueryParams(url); const statuses = ['all', 'draft', 'published', 'archived']; return [ { accessorKey: 'instructor', header: ({ column }) => { return (
); }, cell: ({ row }) => (

{row.original.instructor.user.name}

{row.original.instructor.user.email}

), }, { accessorKey: 'title', header: 'Exam Title', cell: ({ row }) => (
{row.getValue('title')}

{row.original.exam_category.title}

), }, { accessorKey: 'status', header: ({ column }) => (
{statuses.map((status) => ( router.get( route('exams.index', { ...urlParams, status: status, }), ) } className={cn('cursor-pointer text-center capitalize', urlParams['status'] === status && 'bg-gray-100')} > {status} ))}
), cell: ({ row }) => (
{row.getValue('status')}
), }, { accessorKey: 'level', header: () =>
Level
, cell: ({ row }) => (
{row.getValue('level') ? ( {row.getValue('level')} ) : ( '--' )}
), }, { accessorKey: 'total_questions', header: () =>
Questions
, cell: ({ row }) =>
{row.getValue('total_questions')}
, }, { accessorKey: 'total_marks', header: () =>
Total Marks
, cell: ({ row }) =>
{row.getValue('total_marks')}
, }, { accessorKey: 'enrollments_count', header: ({ column }) => (
), cell: ({ row }) =>
{row.getValue('enrollments_count') || 0}
, }, { accessorKey: 'pricing_type', header: () =>
Price
, cell: ({ row }) => { const discountPrice = row.original.discount_price ? Number(row.original.discount_price) : null; const price = row.original.price ? Number(row.original.price) : 0; const displayPrice = discountPrice || price; return (
{row.original.pricing_type === 'paid' ? ( {currency?.symbol} {displayPrice.toFixed(2)} ) : ( Free )}
); }, }, { id: 'actions', header: () =>
Actions
, cell: ({ row }) => { const exam = row.original; return (
{isAdmin && ( } /> )}
); }, }, ]; }; export default ExamTableColumn;