diff --git a/client/src/actions/interviews.js b/client/src/actions/interviews.js index 2bc0c93..08c55f1 100644 --- a/client/src/actions/interviews.js +++ b/client/src/actions/interviews.js @@ -63,6 +63,16 @@ export const changeMeetingStatus = (id, status, penalty) => async (dispatch) => } } +export const changeInterviewHiringStatus = (id, status) => async (dispatch) => { + try { + const statusJson = { hiringStatus: status}; + const {data} = await api.changeInterviewHiringStatus(id, statusJson); + dispatch({ type: UPDATE_MEETING, payload: data }); + } catch (error) { + console.log(error); + } +} + export const getEvaluation = (id) => async (dispatch) => { try { const { data } = await api.getEvaluation(id); diff --git a/client/src/api/index.js b/client/src/api/index.js index 7b7ecab..7254063 100644 --- a/client/src/api/index.js +++ b/client/src/api/index.js @@ -54,6 +54,7 @@ export const getMeeting = (id) => API.get(`/interviews/${id}`); // export const scheduleMeeting = (meetingData) => API.post('/schedule', meetingData); export const scheduleMeeting = (formData) => API.post(`/interviews/schedule`, formData); export const changeMeetingStatus = (id, status) => API.patch(`/interviews/update/${id}`, status); +export const changeInterviewHiringStatus = (id, status) => API.patch(`/interviews/hiring/${id}`, status); export const processCandidateAnswer = (formData) => AI_APP_API.post('/post_audio/', formData); export const saveUserDetails = (userDetails) => AI_APP_API.post('/user/', userDetails); diff --git a/client/src/components/SeeScheduledInterviews/EvaluationPopup.js b/client/src/components/SeeScheduledInterviews/EvaluationPopup.js index 93a38ef..97420b1 100644 --- a/client/src/components/SeeScheduledInterviews/EvaluationPopup.js +++ b/client/src/components/SeeScheduledInterviews/EvaluationPopup.js @@ -1,5 +1,8 @@ -import React from "react"; -import "./EvaluationPopup.css"; // Import the CSS file for styling +import React, { useState } from "react"; +import "./EvaluationPopup.css"; +import { useDispatch } from "react-redux"; +import { changeInterviewHiringStatus } from "../../actions/interviews"; +import { AI_URL } from "../../api/index"; // Function to parse the evaluation text const parseEvaluationText = (text) => { @@ -16,16 +19,22 @@ const parseEvaluationText = (text) => { const EvaluationPopup = ({ evaluationData, onClose, interviewDetails }) => { let parsedEvaluationData = {}; + const dispatch = useDispatch(); + const [currentHiringStatus, setCurrentHiringStatus] = + useState("Decision Pending"); + const [buttonsDisabled, setButtonsDisabled] = useState(false); const sendHiringStatusEmail = (hiringDecision) => { const mail_type = hiringDecision === "Select" ? "select_candidate" : "reject_candidate"; interviewDetails.mail_type = mail_type; + // Disable the buttons immediately + setButtonsDisabled(true); + // send email to the candidate - console.log("mail status"); - fetch("http://localhost:8000/mail/", { + fetch(AI_URL + "/mail/", { method: "POST", - header: { + headers: { "Content-Type": "application/json", }, body: JSON.stringify(interviewDetails), @@ -36,12 +45,33 @@ const EvaluationPopup = ({ evaluationData, onClose, interviewDetails }) => { .catch((err) => { console.log(err); }); + + updateHiringStatusForInterview(hiringDecision); + }; + + const updateHiringStatusForInterview = (hiringDecision) => { + if (hiringDecision === "Select") { + hiringDecision = "Selected"; + } else { + hiringDecision = "Rejected"; + } + interviewDetails.hiring_status = hiringDecision; + const response = dispatch( + changeInterviewHiringStatus(interviewDetails._id, hiringDecision) + ); + + if (response.status === 200) { + setCurrentHiringStatus(hiringDecision); + } }; if (evaluationData) { // Replace double backslashes with single backslashes and split by new lines evaluationData = evaluationData.replace(/\\n/g, "\n"); parsedEvaluationData = parseEvaluationText(evaluationData); + if (interviewDetails.hiringStatus !== currentHiringStatus) { + setCurrentHiringStatus(interviewDetails.hiringStatus); + } } // Extract the final evaluation score and details to display at the top @@ -111,19 +141,46 @@ const EvaluationPopup = ({ evaluationData, onClose, interviewDetails }) => { ) : (
No evaluation data available.
)} - {" "} - {" "} - + {currentHiringStatus === "Decision Pending" ? ( + <> + + + > + ) : ( + <> + + + > + )} + )}