diff --git a/client/src/components/pages/add-course/add-course-form.tsx b/client/src/components/pages/add-course/add-course-form.tsx index 3278517..771c963 100644 --- a/client/src/components/pages/add-course/add-course-form.tsx +++ b/client/src/components/pages/add-course/add-course-form.tsx @@ -20,16 +20,15 @@ interface CourseFormValues { [key: string]: string; } - const initialValues = { title: "", duration: "", category: "", - level:"", - tags: "", - about:"", + level: "", + tags: "", + about: "", description: "", - syllabus:"", + syllabus: "", requirements: "", price: "", }; @@ -38,21 +37,29 @@ const CombinedForm: React.FC = () => { const [paid, setPaid] = useState(false); const [thumbnail, setThumbnail] = useState(null); const [guidelines, setGuidelines] = useState(null); + const [introduction,setIntroduction] = useState(null) const [categories, setCategories] = useState( null ); - const handleFormSubmit = async (values: CourseFormValues, { resetForm }: FormikHelpers) => { + const handleFormSubmit = async ( + values: CourseFormValues, + { resetForm }: FormikHelpers + ) => { try { const formData = new FormData(); guidelines && formData.append("files", guidelines); thumbnail && formData.append("files", thumbnail); + introduction && formData.append("files",introduction) Object.keys(values).forEach((key) => formData.append(key, values[key])); const response = await addCourse(formData); - toast.success(response.data.message, { + toast.success(response.data.message, { position: toast.POSITION.BOTTOM_RIGHT, }); - resetForm() + resetForm(); + setGuidelines(null) + setThumbnail(null) + setIntroduction(null) } catch (error: any) { toast.error(error.data.message, { position: toast.POSITION.BOTTOM_RIGHT, @@ -65,7 +72,7 @@ const CombinedForm: React.FC = () => { const response = await getAllCategories(); setCategories(response.data); } catch (error) { - toast.error("something went wrong") + toast.error("something went wrong"); } }; @@ -144,9 +151,11 @@ const CombinedForm: React.FC = () => { name='category' className='pl-2 block w-80 rounded-md border-0 py-2.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-700 focus-visible:outline-none focus-visible:ring-blue-600 sm:text-sm sm:leading-6' > - {categories?.map(({ _id, name },index) => ( - - ))} + {categories?.map(({ _id, name }, index) => ( + + ))} { name='level' className='pl-2 block w-80 rounded-md border-0 py-2.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-700 focus-visible:outline-none focus-visible:ring-blue-600 sm:text-sm sm:leading-6' > - + @@ -208,7 +219,7 @@ const CombinedForm: React.FC = () => { {paid && ( -
+
)} + +
+ + { + const file = event.target.files?.[0] || null; + setIntroduction(file); + }} + required + className='pl-2 block w-80 rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-inset focus:ring-indigo-700 focus-visible:outline-none focus-visible:ring-blue-600 sm:text-sm sm:leading-6' + /> + +
@@ -341,7 +378,6 @@ const CombinedForm: React.FC = () => { />
-