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 (
-
-
-
- )
-}
+
+ );
+};
-export default Application
+export default Application;
diff --git a/frontend/src/components/Application/MyApplications.jsx b/frontend/src/components/Application/MyApplications.jsx
index 3732ea8..497a7e6 100644
--- a/frontend/src/components/Application/MyApplications.jsx
+++ b/frontend/src/components/Application/MyApplications.jsx
@@ -1,11 +1,192 @@
-import React from 'react'
+import React, { useContext, useEffect, useState } from "react";
+import { Context } from "../../main";
+import axios from "axios";
+import toast from "react-hot-toast";
+import { useNavigate } from "react-router-dom";
+import ResumeModal from "./ResumeModal";
const MyApplications = () => {
+ const { user } = useContext(Context);
+ const [applications, setApplications] = useState([]);
+ const [modalOpen, setModalOpen] = useState(false);
+ const [resumeImageUrl, setResumeImageUrl] = useState("");
+
+ const { isAuthorized } = useContext(Context);
+ const navigateTo = useNavigate();
+
+ useEffect(() => {
+ try {
+ if (user && user.role === "Employer") {
+ axios
+ .get("http://localhost:4000/api/v1/application/employer/getall", {
+ withCredentials: true,
+ })
+ .then((res) => {
+ setApplications(res.data.applications);
+ });
+ } else {
+ axios
+ .get("http://localhost:4000/api/v1/application/jobseeker/getall", {
+ withCredentials: true,
+ })
+ .then((res) => {
+ setApplications(res.data.applications);
+ });
+ }
+ } catch (error) {
+ toast.error(error.response.data.message);
+ }
+ }, [isAuthorized]);
+
+ if (!isAuthorized) {
+ navigateTo("/");
+ }
+
+ const deleteApplication = (id) => {
+ try {
+ axios
+ .delete(`http://localhost:4000/api/v1/application/delete/${id}`, {
+ withCredentials: true,
+ })
+ .then((res) => {
+ toast.success(res.data.message);
+ setApplications((prevApplication) =>
+ prevApplication.filter((application) => application._id !== id)
+ );
+ });
+ } catch (error) {
+ toast.error(error.response.data.message);
+ }
+ };
+
+ const openModal = (imageUrl) => {
+ setResumeImageUrl(imageUrl);
+ setModalOpen(true);
+ };
+
+ const closeModal = () => {
+ setModalOpen(false);
+ };
+
return (
-
-
-
- )
-}
+
+ {user && user.role === "Job Seeker" ? (
+
+
My Applications
+ {applications.length <= 0 ? (
+ <>
+ {" "}
+ No Applications Found
{" "}
+ >
+ ) : (
+ applications.map((element) => {
+ return (
+
+ );
+ })
+ )}
+
+ ) : (
+
+
Applications From Job Seekers
+ {applications.length <= 0 ? (
+ <>
+ No Applications Found
+ >
+ ) : (
+ applications.map((element) => {
+ return (
+
+ );
+ })
+ )}
+
+ )}
+ {modalOpen && (
+
+ )}
+
+ );
+};
+
+export default MyApplications;
-export default MyApplications
+const JobSeekerCard = ({ element, deleteApplication, openModal }) => {
+ return (
+ <>
+
+
+
+ Name: {element.name}
+
+
+ Email: {element.email}
+
+
+ Phone: {element.phone}
+
+
+ Address: {element.address}
+
+
+ CoverLetter: {element.coverLetter}
+
+
+
+
openModal(element.resume.url)}
+ />
+
+
+
+
+
+ >
+ );
+};
+
+const EmployerCard = ({ element, openModal }) => {
+ return (
+ <>
+
+
+
+ Name: {element.name}
+
+
+ Email: {element.email}
+
+
+ Phone: {element.phone}
+
+
+ Address: {element.address}
+
+
+ CoverLetter: {element.coverLetter}
+
+
+
+
openModal(element.resume.url)}
+ />
+
+
+ >
+ );
+};
diff --git a/frontend/src/components/Application/ResumeModal.jsx b/frontend/src/components/Application/ResumeModal.jsx
index 8317d43..14d2a02 100644
--- a/frontend/src/components/Application/ResumeModal.jsx
+++ b/frontend/src/components/Application/ResumeModal.jsx
@@ -1,11 +1,16 @@
-import React from 'react'
-const ResumeModal = () => {
+
+const ResumeModal = ({ imageUrl, onClose }) => {
return (
-
-
+
+
+
+ ×
+
+
+
- )
-}
+ );
+};
-export default ResumeModal
+export default ResumeModal;
diff --git a/frontend/src/components/Job/Job.jsx b/frontend/src/components/Job/Job.jsx
index e5071ac..7d0932b 100644
--- a/frontend/src/components/Job/Job.jsx
+++ b/frontend/src/components/Job/Job.jsx
@@ -1,4 +1,4 @@
-import React, { useContext, useEffect, useState } from "react";
+import { useContext, useEffect, useState } from "react";
import axios from "axios";
import { Link, useNavigate } from "react-router-dom";
import { Context } from "../../main";
diff --git a/frontend/src/components/Job/PostJob.jsx b/frontend/src/components/Job/PostJob.jsx
index aadcc8e..fcdf1e2 100644
--- a/frontend/src/components/Job/PostJob.jsx
+++ b/frontend/src/components/Job/PostJob.jsx
@@ -1,4 +1,4 @@
-import { useContext, useEffect, useState } from "react";
+import { useContext, useState } from "react";
import axios from "axios";
import toast from "react-hot-toast";
import { useNavigate } from "react-router-dom";