import React, { useState } from 'react'; import { Head, Link, useForm } from '@inertiajs/react'; import { CheckCircle, AlertCircle, RefreshCcw } from 'lucide-react'; import CourseLayout from '@/Layouts/CourseLayout'; import { Button } from '@/Components/ui/button'; import { RadioGroup, RadioGroupItem } from "@/Components/ui/radio-group"; import { Label } from "@/Components/ui/label"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/Components/ui/card"; import { cn } from '@/lib/utils'; export default function Exam({ course, modules, lesson, previousResult, flash }: any) { const [answers, setAnswers] = useState>({}); const { post, processing, wasSuccessful } = useForm(); // We can use flash messages or page props to show result state const result = flash?.score !== undefined ? flash : (previousResult ? { score: previousResult, passed: previousResult >= 70 } : null); const handleSelect = (questionId: string, value: string) => { setAnswers(prev => ({ ...prev, [questionId]: value })); }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); post(route('exams.store', { course: course.slug, lesson: lesson.slug, answers }), { preserveScroll: true, }); }; return (

{lesson.title}

Jawab semua pertanyaan untuk menyelesaikan kursus ini.

{result && (
{result.passed ? (
) : (
)}

{result.passed ? "Lulus!" : "Belum Lulus"}

Skor Anda: {result.score}%

{result.passed ? ( ) : ( )}
)} {!result?.passed && (
{lesson.questions.map((q: any, i: number) => ( {i + 1}. {q.question} handleSelect(q.id, val)}> {q.options.map((opt: string, idx: number) => (
))}
))}
)}
); }