auto email

This commit is contained in:
amNobodyyy
2025-01-24 01:11:21 +05:30
parent 2841638ba5
commit add7192ccf
2 changed files with 115 additions and 105 deletions

View File

@@ -55,9 +55,7 @@ const ConsolidatedTable = () => {
"Exam Type",
"Year",
"Marks",
"Surname",
"First Name",
"Middle Name",
"Name",
"Affiliation/College",
"Highest Qualification",
"Career Experience",
@@ -78,9 +76,7 @@ const ConsolidatedTable = () => {
row.examType,
row.year,
row.marks,
row.surname,
row.firstName,
row.middleName,
row.Name,
row.affiliation,
row.qualification,
row.experience,
@@ -111,7 +107,12 @@ const ConsolidatedTable = () => {
};
const redStyle = {
font: { bold: true, color: { rgb: "FF0000" }, name: "Times New Roman", sz: 14 },
font: {
bold: true,
color: { rgb: "FF0000" },
name: "Times New Roman",
sz: 14,
},
alignment: { horizontal: "center", vertical: "center" },
};
@@ -179,6 +180,14 @@ const ConsolidatedTable = () => {
};
const handleSendEmail = async (teacher, teacherData) => {
const facultyId = teacherData[0].facultyId; // This assumes all rows for a teacher have the same facultyId
try {
// Fetch email from the backend
const response = await axios.get(
`http://localhost:8080/api/faculty/email/${facultyId}`
);
const facultyEmail = response.data.email;
const workbook = XLSX.utils.book_new();
const headerInfo = [
@@ -201,9 +210,7 @@ const ConsolidatedTable = () => {
"Exam Type",
"Year",
"Marks",
"Surname",
"First Name",
"Middle Name",
"Name",
"Affiliation/College",
"Highest Qualification",
"Career Experience",
@@ -224,9 +231,7 @@ const ConsolidatedTable = () => {
row.examType,
row.year,
row.marks,
row.surname,
row.firstName,
row.middleName,
row.Name,
row.affiliation,
row.qualification,
row.experience,
@@ -255,24 +260,28 @@ const ConsolidatedTable = () => {
const formData = new FormData();
formData.append("teacher", teacher);
formData.append("fileName", fileName);
const recipientEmail = prompt(`Enter recipient email for ${teacher}:`);
formData.append("recipientEmail", recipientEmail);
formData.append("recipientEmail", facultyEmail);
formData.append("file", file);
try {
const response = await sendEmail(formData);
alert(`Email sent successfully to ${recipientEmail}`);
alert(`Email sent successfully to ${facultyEmail}`);
console.log("Response from server:", response);
} catch (error) {
console.error("Error sending email:", error);
alert("Failed to send email.");
}
} catch (error) {
console.error("Error sending email:", error);
alert("Failed to send email.");
}
};
return (
<div>
<h1 style={{ textAlign: "center" }}>Faculty Tables with Download Options</h1>
<h1 style={{ textAlign: "center" }}>
Faculty Tables with Download Options
</h1>
<div style={{ marginBottom: "20px", textAlign: "center" }}>
<button

View File

@@ -63,6 +63,7 @@ router.get("/consolidated-table", async (req, res) => {
paperSetting: data.tasks.has("paperSetting") ? "✔" : "",
moderation: data.tasks.has("moderation") ? "✔" : "",
pwdPaperSetting: data.tasks.has("pwdPaperSetter") ? "✔" : "",
key: `${data.facultyId}`
}));
res.status(200).json(tableData);