import { Head, router } from '@inertiajs/react'; import type { ColumnDef } from '@tanstack/react-table'; import { format } from 'date-fns'; import { ArrowLeft, Pencil, Plus, Trash2 } from 'lucide-react'; import { useState } from 'react'; import { DataTable } from '@/components/data-table'; import { DateTimeField } from '@/components/datetime-field'; import { DeleteConfirmDialog } from '@/components/delete-confirm-dialog'; import { FileUploadField } from '@/components/file-upload-field'; import { FormDialog } from '@/components/form-dialog'; import InputError from '@/components/input-error'; import { PageHeader } from '@/components/page-header'; import { RowActions } from '@/components/row-actions'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import { Textarea } from '@/components/ui/textarea'; import { index as assignmentIndex } from '@/routes/admin/academic-classes/assignments'; import { destroy, store, update, } from '@/routes/admin/academic-classes/assignments/submissions'; import type { Assignment } from '@/types/assignment'; import type { Submission, SubmissionStudent } from '@/types/submission'; import { SubmissionStatusLabels, SubmissionStatuses } from '@/types/submission'; type Props = { assignment: Assignment; submissions: Submission[]; availableStudents: SubmissionStudent[]; }; export default function SubmissionIndex({ assignment, submissions, availableStudents, }: Props) { const [createOpen, setCreateOpen] = useState(false); const [editing, setEditing] = useState(null); const [deleting, setDeleting] = useState(null); function handleDelete() { if (!deleting) { return; } router.delete(destroy([assignment.id, deleting.id]), { onSuccess: () => setDeleting(null), }); } const columns: ColumnDef[] = [ { accessorKey: 'student.student_number', header: () => NIM, cell: ({ row }) => row.original.student?.student_number ?? '-', }, { accessorKey: 'student.user.profile.full_name', header: () => Nama Mahasiswa, cell: ({ row }) => row.original.student?.user?.profile?.full_name ?? '-', }, { accessorKey: 'status', header: () => Status, meta: { className: 'w-[160px] text-center', headerClassName: 'w-[160px] text-center', }, cell: ({ row }) => { const status = row.getValue('status') as keyof typeof SubmissionStatusLabels | null; return (
{status ? ( {SubmissionStatusLabels[status]} ) : ( - )}
); }, }, { accessorKey: 'submitted_at', header: () => Waktu Kumpul, cell: ({ row }) => { const submittedAt = row.getValue('submitted_at') as string | null; return submittedAt ? format(new Date(submittedAt), 'd MMM yyyy, HH:mm') : '-'; }, }, { accessorKey: 'score', header: () => Nilai, meta: { className: 'w-[90px] text-center', headerClassName: 'w-[90px] text-center', }, cell: ({ row }) => (
{row.original.score ?? '-'}
), }, { id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => ( , onClick: () => setEditing(row.original), }, { label: 'Hapus', icon: ( ), onClick: () => setDeleting(row.original), }, ]} /> ), }, ]; return ( <>
Kembali } /> {assignment.title}

Kelas: {assignment.course_class?.course?.code}{' '} {assignment.course_class?.course?.name}

Batas Waktu:{' '} {format( new Date(assignment.deadline), 'd MMM yyyy, HH:mm', )}

Jumlah Pengumpulan: {submissions.length}

Daftar Pengumpulan

{ if (!open) { setEditing(null); } }} assignmentId={assignment.id} editing={editing} /> { if (!open) { setDeleting(null); } }} title="Hapus Pengumpulan" description={(submission) => `Apakah Anda yakin ingin menghapus pengumpulan "${submission.student?.user?.profile?.full_name ?? 'mahasiswa ini'}"? Tindakan ini tidak dapat dibatalkan.` } onConfirm={handleDelete} />
); } function CreateForm({ open, onOpenChange, assignmentId, availableStudents, }: { open: boolean; onOpenChange: (open: boolean) => void; assignmentId: number; availableStudents: SubmissionStudent[]; }) { return ( onOpenChange(false)} > {({ errors }) => (
)}
); } function EditForm({ open, onOpenChange, assignmentId, editing, }: { open: boolean; onOpenChange: (open: boolean) => void; assignmentId: number; editing: Submission | null; }) { return ( onOpenChange(false)} > {({ errors }) => editing && (

{editing.student?.user?.profile?.full_name ?? 'N/A'}{' '} - {editing.student?.student_number}

) }
); } function SubmissionFields({ errors, editing, resetKey, }: { errors: Record; editing?: Submission; resetKey?: string; }) { return ( <>