import { Form, Head, Link } from '@inertiajs/react'; import { ArrowLeft, XCircle } from 'lucide-react'; import { useState } from 'react'; import InputError from '@/components/input-error'; import { PageHeader } from '@/components/page-header'; import { SignaturePad } from '@/components/signature-pad'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from '@/components/ui/card'; import { Checkbox } from '@/components/ui/checkbox'; import { index, store } from '@/routes/student/course-registrations'; import type { AcademicTerm } from '@/types/academic-term'; import { formatAcademicTermLabel } from '@/types/academic-term'; type Lecturer = { user: { profile: { full_name: string } | null } | null; }; type Course = { id: number; code: string; name: string; credits: number; }; type CourseClass = { id: number; lecturer: Lecturer | null; }; type Student = { student_number: string; current_semester: number; department: { name: string } | null; user: { profile: { full_name: string } | null } | null; academic_advisor: { user: { profile: { full_name: string } | null } | null; } | null; }; type AvailableCourse = { course: Course; course_class: CourseClass | null; }; type Registration = { id: number; course_class: { id: number }; }; type Submission = { status: 'submitted' | 'approved' | 'rejected'; rejection_reason: string | null; course_registrations: Registration[]; }; type Props = { student: Student; academicTerm: AcademicTerm; submission: Submission | null; availableCourses: AvailableCourse[]; }; export default function CourseRegistrationCreate({ student, academicTerm, submission, availableCourses, }: Props) { const [selected, setSelected] = useState(() => { if (submission && submission.course_registrations.length > 0) { return submission.course_registrations.map( (registration) => registration.course_class.id, ); } return availableCourses .filter((item) => item.course_class) .map((item) => item.course_class!.id); }); function toggle(courseClassId: number, checked: boolean) { setSelected((prev) => checked ? [...prev, courseClassId] : prev.filter((id) => id !== courseClassId), ); } const totalCredits = availableCourses .filter( (item) => item.course_class && selected.includes(item.course_class.id), ) .reduce((sum, item) => sum + item.course.credits, 0); return ( <>
Kembali } /> {student.user?.profile?.full_name ?? '-'} {student.student_number} ·{' '} {student.department?.name ?? '-'} · Semester{' '} {student.current_semester}

Periode Akademik:{' '} {formatAcademicTermLabel(academicTerm)}

Dosen Pembimbing Akademik:{' '} {student.academic_advisor?.user?.profile ?.full_name ?? '-'}

{submission?.status === 'rejected' && (

KRS Anda ditolak

{submission.rejection_reason ?? 'Tidak ada alasan yang diberikan.'}

Silakan perbaiki pilihan mata kuliah Anda dan ajukan kembali di bawah ini.

)}
{({ errors, processing }) => ( Pilih Mata Kuliah Semester{' '} {student.current_semester} Total {totalCredits} SKS dipilih {availableCourses.length === 0 && (

Belum ada mata kuliah/kelas untuk semester ini pada periode aktif.

)} {availableCourses.map( ({ course, course_class }) => ( ), )} {selected.map((courseClassId) => ( ))}
)}
); }