From 25d04f231e8066a7118f135c1afe2d8226b2da43 Mon Sep 17 00:00:00 2001 From: VinayJangotra <109384165+VinayJangotra@users.noreply.github.com> Date: Sat, 27 Apr 2024 23:26:25 +0530 Subject: [PATCH] Application Completed --- .../components/Application/Application.jsx | 123 ++++++++++- .../components/Application/MyApplications.jsx | 195 +++++++++++++++++- .../components/Application/ResumeModal.jsx | 19 +- frontend/src/components/Job/Job.jsx | 2 +- frontend/src/components/Job/PostJob.jsx | 2 +- 5 files changed, 317 insertions(+), 24 deletions(-) diff --git a/frontend/src/components/Application/Application.jsx b/frontend/src/components/Application/Application.jsx index fa58527..260d869 100644 --- a/frontend/src/components/Application/Application.jsx +++ b/frontend/src/components/Application/Application.jsx @@ -1,11 +1,118 @@ -import React from 'react' - +import axios from "axios"; +import { useContext, useState } from "react"; +import toast from "react-hot-toast"; +import { useNavigate, useParams } from "react-router-dom"; +import { Context } from "../../main"; const Application = () => { + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [coverLetter, setCoverLetter] = useState(""); + const [phone, setPhone] = useState(""); + const [address, setAddress] = useState(""); + const [resume, setResume] = useState(null); + + const { isAuthorized, user } = useContext(Context); + + const navigateTo = useNavigate(); + + // Function to handle file input changes + const handleFileChange = (event) => { + const resume = event.target.files[0]; + setResume(resume); + }; + + const { id } = useParams(); + const handleApplication = async (e) => { + e.preventDefault(); + const formData = new FormData(); + formData.append("name", name); + formData.append("email", email); + formData.append("phone", phone); + formData.append("address", address); + formData.append("coverLetter", coverLetter); + formData.append("resume", resume); + formData.append("jobId", id); + + try { + const { data } = await axios.post( + "http://localhost:4000/api/v1/application/post", + formData, + { + withCredentials: true, + headers: { + "Content-Type": "multipart/form-data", + }, + } + ); + setName(""); + setEmail(""); + setCoverLetter(""); + setPhone(""); + setAddress(""); + setResume(""); + toast.success(data.message); + navigateTo("/job/getall"); + } catch (error) { + toast.error(error.response.data.message); + } + }; + + if (!isAuthorized || (user && user.role === "Employer")) { + navigateTo("/"); + } + return ( -
- -
- ) -} +
+
+

Application Form

+
+ setName(e.target.value)} + /> + setEmail(e.target.value)} + /> + setPhone(e.target.value)} + /> + setAddress(e.target.value)} + /> +