-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 3 commits
a9d738a
b2608cd
6cd7b80
9762a55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) => { | ||
|
@@ -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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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), | ||
|
@@ -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 }) => { | |
) : ( | ||
<p>No evaluation data available.</p> | ||
)} | ||
<button | ||
onClick={() => sendHiringStatusEmail("Select")} | ||
className="btn btn-success" | ||
> | ||
Select Candidate | ||
</button>{" "} | ||
{" "} | ||
<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={{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why new - true? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.