import React from 'react'; import { updateAssignment } from '@services/courses/assignments'; import { mutate } from 'swr'; import { getAPIUrl } from '@services/config/config'; import toast from 'react-hot-toast'; import FormLayout, { FormField, FormLabelAndMessage, Input, Textarea, Flex, FormLabel, FormMessage } from '@components/Objects/StyledElements/Form/Form'; import * as Form from '@radix-ui/react-form'; import { useFormik } from 'formik'; import Modal from '@components/Objects/StyledElements/Modal/Modal'; interface Assignment { assignment_uuid: string; title: string; description: string; due_date?: string; grading_type?: 'ALPHABET' | 'NUMERIC' | 'PERCENTAGE'; } interface EditAssignmentFormProps { onClose: () => void; assignment: Assignment; accessToken: string; } interface EditAssignmentModalProps { isOpen: boolean; onClose: () => void; assignment: Assignment; accessToken: string; } const EditAssignmentForm: React.FC = ({ onClose, assignment, accessToken }) => { const formik = useFormik({ initialValues: { title: assignment.title || '', description: assignment.description || '', due_date: assignment.due_date || '', grading_type: assignment.grading_type || 'ALPHABET' }, enableReinitialize: true, onSubmit: async (values, { setSubmitting }) => { const toast_loading = toast.loading('Updating assignment...'); try { const res = await updateAssignment(values, assignment.assignment_uuid, accessToken); if (res.success) { mutate(`${getAPIUrl()}assignments/${assignment.assignment_uuid}`); toast.success('Assignment updated successfully'); onClose(); } else { toast.error('Failed to update assignment'); } } catch (error) { toast.error('An error occurred while updating the assignment'); } finally { toast.dismiss(toast_loading); setSubmitting(false); } } }); return ( Assignment Title Please provide a name for your assignment Assignment Description Please provide a description for your assignment