From 886e2446c706f93b9538a03258e3f66c759e6537 Mon Sep 17 00:00:00 2001 From: Balaharisankar Lakshmanaperumal <114602603+BHS-Harish@users.noreply.github.com> Date: Thu, 8 Aug 2024 00:07:34 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=83=20Integration=20Join=20Us=20Form?= =?UTF-8?q?=20with=20backend=20(#1117)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Upvote and Downvotes fixed * JoinUs functionality fixed --- .../pages/Home/components/JoinUsForm/Form.jsx | 697 +++++++++--------- .../components/JoinUsForm/form.module.scss | 69 +- frontend/src/service/JoinUs.jsx | 32 + 3 files changed, 447 insertions(+), 351 deletions(-) create mode 100644 frontend/src/service/JoinUs.jsx 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 ( -