diff --git a/frontend/src/pages/Home/components/JoinUsForm/Form.jsx b/frontend/src/pages/Home/components/JoinUsForm/Form.jsx index a254277a..05fa566c 100644 --- a/frontend/src/pages/Home/components/JoinUsForm/Form.jsx +++ b/frontend/src/pages/Home/components/JoinUsForm/Form.jsx @@ -1,6 +1,8 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import Joi from "joi-browser"; import MultiSelect from "react-multi-select-component"; +import { SimpleToast } from "../../../../components/util/Toast"; +import { postJoinUs, PostJoinUs } from '../../../../service/JoinUs'; import styles from "./form.module.scss"; import { Button2 } from "../../../../components/util/Button/index"; @@ -9,16 +11,18 @@ export const JoinUsForm = (props) => { const [formdata, setFormData] = useState({ name: "", - phone: "", + contact: "", email: "", - link: "", - desc: "", - other: "", - dept: "", + linkdin: "", + description: "", + otherDomain: "", + department: "", year: null, college: "", }); + const [isSubmitted, setIsSubmitted] = useState(false) + const options = [ { label: "Machine Learning", value: "ml" }, { label: "Artificial Intelligence", value: "ai" }, @@ -36,16 +40,21 @@ export const JoinUsForm = (props) => { const [domainError, setDomainError] = useState(); const [formerrors, setFormErrors] = useState({}); + const [toast, setToast] = useState({ + toastStatus: false, + toastType: "", + toastMessage: "", + }); const schema = { name: Joi.string().required(), - phone: Joi.number().allow(""), - email: Joi.string().email().required(), - link: Joi.string().uri().allow(""), - desc: Joi.string().allow(""), - other: Joi.string().allow(""), - dept: Joi.string().allow(""), - year: Joi.number().required(), + contact: Joi.number().required(), + email: Joi.string().email().required().required(), + linkdin: Joi.string().uri().required(), + description: Joi.string().required(), + otherDomain: Joi.string(), + department: Joi.string().required(), + year: Joi.number().required().required(), college: Joi.string().required(), }; @@ -80,7 +89,7 @@ export const JoinUsForm = (props) => { setFormErrors(errors); }; - const handleSubmit = (e) => { + const handleSubmit = async (e) => { e.preventDefault(); const errors = validate(); console.log(errors); @@ -91,375 +100,401 @@ export const JoinUsForm = (props) => { } if (errors === null || Object.keys(errors).length === 0) { setFormErrors({}); - console.log("Submitted", formdata); + let data = { ...formdata, interestedDomain: domains.map((value)=>value.label) } + let res = await postJoinUs(data, setToast) + if (res == true) + setIsSubmitted(true) } else { setFormErrors(errors); + setToast({ toastStatus: true, toastMessage: "Fill all the fields", toastType: "error" }) } }; - console.log("form error: ", formerrors); - console.log("form data: ", formdata, domains); - return ( -