From 5ca7dd765025b42421d72a2b5d6b7656216dd781 Mon Sep 17 00:00:00 2001 From: Madhawa Monarawila Date: Sat, 25 Nov 2023 16:59:03 +0530 Subject: [PATCH 1/7] Add mentor application --- src/App.tsx | 16 +- src/components/Layout/Navbar/Navbar.tsx | 6 + .../MentorRegistrationPage/index.tsx | 284 ++++++++++++++++++ 3 files changed, 303 insertions(+), 3 deletions(-) create mode 100644 src/components/MentorRegistrationPage/index.tsx diff --git a/src/App.tsx b/src/App.tsx index 4683b44b..d7d2a066 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,8 +1,10 @@ import React, { useContext, useEffect } from 'react'; +import { BrowserRouter, Route, Routes } from 'react-router-dom'; import Home from './components/Home/Home'; import MainLayout from './components/Layout/MainLayout'; import { UserContext, type UserContextType } from './contexts/UserContext'; +import MentorRegistrationPage from './components/MentorRegistrationPage'; const App: React.FC = () => { const { user, getUser } = useContext(UserContext) as UserContextType; @@ -15,9 +17,17 @@ const App: React.FC = () => { console.log(`user is authenticated as ${user.primary_email}`); return ( - - - + + + + } /> + } + /> + + + ); }; diff --git a/src/components/Layout/Navbar/Navbar.tsx b/src/components/Layout/Navbar/Navbar.tsx index 54605b49..efa5903a 100644 --- a/src/components/Layout/Navbar/Navbar.tsx +++ b/src/components/Layout/Navbar/Navbar.tsx @@ -18,6 +18,7 @@ import { type UserContextType, } from './../../../contexts/UserContext'; import LogoutModal from '../../LogoutModal'; +import { Link } from 'react-router-dom'; const { Text } = Typography; @@ -84,6 +85,11 @@ const Navbar: React.FC = () => { Join Us + {user !== null ? ( + + + + ) : null} diff --git a/src/components/MentorRegistrationPage/index.tsx b/src/components/MentorRegistrationPage/index.tsx new file mode 100644 index 00000000..cd5f203c --- /dev/null +++ b/src/components/MentorRegistrationPage/index.tsx @@ -0,0 +1,284 @@ +// MentorRegistrationPage.tsx +import React, { useState } from 'react'; +import axios from 'axios'; +import { API_URL } from '../../constants'; + +const MentorRegistrationPage: React.FC = () => { + const [currentStep, setCurrentStep] = useState(0); + const [error, setError] = useState(null); + const [formData, setFormData] = useState({ + firstName: '', + lastName: '', + linkedinUrl: '', + researchGateUrl: '', + googleScholarUrl: '', + categoryId: '', + country: '', + expertise: '', + mentoringStrategy: '', + }); + + const handleNext = (): void => { + setCurrentStep((prevStep) => prevStep + 1); + }; + + const handleInputChange = ( + e: React.ChangeEvent + ): void => { + const { name, value } = e.target; + setFormData((prevData) => ({ ...prevData, [name]: value })); + }; + + const handleSubmit = (event: React.FormEvent): void => { + event.preventDefault(); + setError(null); + axios + .post( + `${API_URL}/mentors`, + { + application: [ + { question: 'First Name', answer: formData.firstName }, + { question: 'Last Name', answer: formData.lastName }, + { question: 'Linkedin Url', answer: formData.linkedinUrl }, + { question: 'ResearchGate Url', answer: formData.researchGateUrl }, + { + question: 'GoogleScholar Url', + answer: formData.googleScholarUrl, + }, + { question: 'Country', answer: formData.country }, + { question: 'What is your expertise', answer: formData.expertise }, + { + question: 'What is your mentoring Strategy', + answer: formData.mentoringStrategy, + }, + ], + categoryId: formData.categoryId, + }, + { withCredentials: true } + ) + .then(() => { + window.location.href = '/'; + }) + .catch((error) => { + if (error.response.status !== 401) { + setError(error.response.data.message); + console.error({ + message: + 'Something went wrong with submitting the mentor application', + description: error, + }); + } else { + console.error('Error submitting mentor application:', error); + } + }); + }; + + return ( +
+
+
Become a Mentor
+
+
+
+
Step {currentStep + 1} of 3
+
+
+
+ {currentStep === 0 && ( + <> +
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+ + )} + {currentStep === 1 && ( + <> +
+ + +
+
+ + +
+ +
+ + +
+ + )} + {currentStep === 2 && ( + <> +
+ +