import ChunkedUploaderInput from '@/components/chunked-uploader-input'; import InputError from '@/components/input-error'; import LoadingButton from '@/components/loading-button'; import { Button } from '@/components/ui/button'; 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 { useForm } from '@inertiajs/react'; import { useEffect, useState } from 'react'; interface Props { assignment: CourseAssignment; setDialogOpen: (open: boolean) => void; } const AssignmentSubmissionForm = ({ assignment, setDialogOpen }: Props) => { const [isSubmit, setIsSubmit] = useState(false); const [isFileUploaded, setIsFileUploaded] = useState(false); const { data, setData, post, processing, errors, reset, clearErrors } = useForm({ course_assignment_id: assignment.id, attachment_type: 'url', attachment_path: '', comment: '', }); // Handle submission const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (data.attachment_type === 'url') { submitForm(); return; } setIsSubmit(true); }; const submitForm = () => { clearErrors(); post(route('assignment.submission.store'), { preserveScroll: true, onSuccess: () => { reset(); setIsSubmit(false); setDialogOpen(false); }, onError: () => { setIsSubmit(false); }, }); }; useEffect(() => { if (data.attachment_path && isFileUploaded) { submitForm(); setIsFileUploaded(false); } }, [data.attachment_path]); return (
{/* Submission Type Selection */}
{/* URL Input */} {data.attachment_type === 'url' && (
setData('attachment_path', e.target.value)} required />

Share your GitHub repository, Google Drive, or any public URL

)} {/* File Upload */} {data.attachment_type === 'file' && (
{ setIsFileUploaded(true); setData('attachment_path', fileData.file_url); }} onError={(errors) => { setIsSubmit(false); }} onCancelUpload={() => { setIsSubmit(false); }} />

Formats: .JPEG, .PNG, .DOC, .PDF, .ZIP (Max: 10MB)

)} {/* Comment */}