Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update hiring status in mongodb db and change button behaviour #194

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/src/actions/interviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions client/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we will need another route. can try with /update/{id} route and check if it is working or not?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will work, but require changes in the update controller. So i don think we should do it now

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. You can merge it.


export const processCandidateAnswer = (formData) => AI_APP_API.post('/post_audio/', formData);
export const saveUserDetails = (userDetails) => AI_APP_API.post('/user/', userDetails);
Expand Down
89 changes: 73 additions & 16 deletions client/src/components/SeeScheduledInterviews/EvaluationPopup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
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";

// Function to parse the evaluation text
const parseEvaluationText = (text) => {
Expand All @@ -16,16 +18,23 @@ 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 =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please update this function. get url from .env instead of hardcode.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting from env is not working in my machine, i am hardcoding in client/src/api/index.js

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/", {
method: "POST",
header: {
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(interviewDetails),
Expand All @@ -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
Expand Down Expand Up @@ -111,19 +141,46 @@ const EvaluationPopup = ({ evaluationData, onClose, interviewDetails }) => {
) : (
<p>No evaluation data available.</p>
)}
<button
onClick={() => sendHiringStatusEmail("Select")}
className="btn btn-success"
>
Select Candidate
</button>{" "}
&nbsp;{" "}
<button
onClick={() => sendHiringStatusEmail("Reject")}
className="btn btn-danger"
>
Reject Candidate
</button>
{currentHiringStatus === "Decision Pending" ? (
<>
<button
onClick={() => sendHiringStatusEmail("Select")}
id="select-candidate-button"
className="btn btn-success"
disabled={buttonsDisabled}
>
Select Candidate
</button>
<button
onClick={() => sendHiringStatusEmail("Reject")}
id="reject-candidate-button"
className="btn btn-danger"
disabled={buttonsDisabled}
>
Reject Candidate
</button>
</>
) : (
<>
<button
disabled
onClick={() => sendHiringStatusEmail("Select")}
id="select-candidate-button"
className="btn btn-success"
>
Select Candidate
</button>
<button
disabled
onClick={() => sendHiringStatusEmail("Reject")}
id="reject-candidate-button"
className="btn btn-danger"
>
Reject Candidate
</button>
</>
)}

<button
onClick={onClose}
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ const SeeScheduledInterviews = () => {
</button>
)}
<td>
{interview.hiringStatus ? "Decision Pending" : interview.hiringStatus}
{interview.hiringStatus ? interview.hiringStatus : "Decision Pending"}
</td>
</tr>
))}
Expand Down
18 changes: 0 additions & 18 deletions client/src/components/UpdateProfile/UpdateProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,24 +315,6 @@ const UpdateProfile = () => {
</>
)}

{userRole === "candidate" && (
<>
<label htmlFor="experience" className={styles.label}>
Years of experience:
</label>
<input
type="number"
id="experience"
name="experience"
placeholder="Years of experience"
value={formData.experience}
onChange={handleChange}
className={styles.input_feild}
required
/>
</>
)}

{userRole === "candidate" && initialData.experience > 0 && (
<>
<label
Expand Down
16 changes: 16 additions & 0 deletions server/src/controllers/interviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,22 @@ export const updateMeeting = async (req: any, res: any) => {
}
};

export const updateHiringStatus = async (req: any, res: any) => {
const meetingId = req.params.id;
const { hiringStatus } = req.body;
const updatedMeeting = { hiringStatus };
try {
const updatedMeetingResponse = await Interview.findByIdAndUpdate(
meetingId,
updatedMeeting,
{ new: true }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why new - true?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new: This is a boolean-type option. If true, return the modified document rather than the original.

)
res.status(200).json(updatedMeetingResponse);
} catch (error: any) {
res.status(404).json({ message: error.message });
}
}

export const getInterviewEndTime = async (req: any, res: any) => {
try {
const interviewId = req.params.id;
Expand Down
3 changes: 2 additions & 1 deletion server/src/routes/interviews.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import express from "express";
import { getCandidateInterviewScore, getInterviewEndTime, getMeeting, listInterviewsCandidate, listInterviewsHR, scheduleMeeting, updateAllInterviews, updateMeeting } from "../controllers/interviews.js";
import { getCandidateInterviewScore, getInterviewEndTime, getMeeting, listInterviewsCandidate, listInterviewsHR, scheduleMeeting, updateAllInterviews, updateMeeting, updateHiringStatus } from "../controllers/interviews.js";
import { auth, hrAuth } from "../middleware/auth.js";


Expand All @@ -14,6 +14,7 @@ router.patch("/update/:id", auth, updateMeeting);

// TODO: add super admin middleware
router.patch("/update", updateAllInterviews);
router.patch("/hiring/:id", hrAuth, updateHiringStatus);
router.get("/:id/endtime", auth, getInterviewEndTime);
router.get("/score/:id", hrAuth, getCandidateInterviewScore);

Expand Down
Loading