auto email
This commit is contained in:
@@ -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,100 +180,108 @@ const ConsolidatedTable = () => {
|
||||
};
|
||||
|
||||
const handleSendEmail = async (teacher, teacherData) => {
|
||||
const workbook = XLSX.utils.book_new();
|
||||
|
||||
const headerInfo = [
|
||||
["Somaiya Vidyavihar University"],
|
||||
["K. J. SOMAIYA COLLEGE OF ENGINEERING"],
|
||||
[
|
||||
"Appointment of Internal Examiners for Paper Setting / OR/PR/Assessment/Reassessment",
|
||||
],
|
||||
["Class: B Tech/M Tech/Honour/Minor"],
|
||||
["Department - Computer Engineering"],
|
||||
[],
|
||||
];
|
||||
|
||||
const tableHeaders = [
|
||||
[
|
||||
"Sr No",
|
||||
"Semester",
|
||||
"Course Code",
|
||||
"Course Name",
|
||||
"Exam Type",
|
||||
"Year",
|
||||
"Marks",
|
||||
"Surname",
|
||||
"First Name",
|
||||
"Middle Name",
|
||||
"Affiliation/College",
|
||||
"Highest Qualification",
|
||||
"Career Experience",
|
||||
"Oral/Practical",
|
||||
"Assessment",
|
||||
"Reassessment",
|
||||
"Paper Setting",
|
||||
"Moderation",
|
||||
"PwD Paper Setting",
|
||||
],
|
||||
];
|
||||
|
||||
const dataRows = teacherData.map((row, index) => [
|
||||
index + 1,
|
||||
row.semester,
|
||||
row.courseCode,
|
||||
row.courseName,
|
||||
row.examType,
|
||||
row.year,
|
||||
row.marks,
|
||||
row.surname,
|
||||
row.firstName,
|
||||
row.middleName,
|
||||
row.affiliation,
|
||||
row.qualification,
|
||||
row.experience,
|
||||
row.oralPractical,
|
||||
row.assessment,
|
||||
row.reassessment,
|
||||
row.paperSetting,
|
||||
row.moderation,
|
||||
row.pwdPaperSetting,
|
||||
]);
|
||||
|
||||
const sheetData = [...headerInfo, ...tableHeaders, ...dataRows];
|
||||
const worksheet = XLSX.utils.aoa_to_sheet(sheetData);
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, teacher);
|
||||
|
||||
const fileName = `${teacher.replace(/\s+/g, "_")}_table.xlsx`;
|
||||
const excelBlob = XLSX.write(workbook, {
|
||||
bookType: "xlsx",
|
||||
type: "array",
|
||||
});
|
||||
|
||||
const file = new File([excelBlob], fileName, {
|
||||
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
});
|
||||
|
||||
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("file", file);
|
||||
const facultyId = teacherData[0].facultyId; // This assumes all rows for a teacher have the same facultyId
|
||||
|
||||
try {
|
||||
const response = await sendEmail(formData);
|
||||
alert(`Email sent successfully to ${recipientEmail}`);
|
||||
console.log("Response from server:", response);
|
||||
// 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 = [
|
||||
["Somaiya Vidyavihar University"],
|
||||
["K. J. SOMAIYA COLLEGE OF ENGINEERING"],
|
||||
[
|
||||
"Appointment of Internal Examiners for Paper Setting / OR/PR/Assessment/Reassessment",
|
||||
],
|
||||
["Class: B Tech/M Tech/Honour/Minor"],
|
||||
["Department - Computer Engineering"],
|
||||
[],
|
||||
];
|
||||
|
||||
const tableHeaders = [
|
||||
[
|
||||
"Sr No",
|
||||
"Semester",
|
||||
"Course Code",
|
||||
"Course Name",
|
||||
"Exam Type",
|
||||
"Year",
|
||||
"Marks",
|
||||
"Name",
|
||||
"Affiliation/College",
|
||||
"Highest Qualification",
|
||||
"Career Experience",
|
||||
"Oral/Practical",
|
||||
"Assessment",
|
||||
"Reassessment",
|
||||
"Paper Setting",
|
||||
"Moderation",
|
||||
"PwD Paper Setting",
|
||||
],
|
||||
];
|
||||
|
||||
const dataRows = teacherData.map((row, index) => [
|
||||
index + 1,
|
||||
row.semester,
|
||||
row.courseCode,
|
||||
row.courseName,
|
||||
row.examType,
|
||||
row.year,
|
||||
row.marks,
|
||||
row.Name,
|
||||
row.affiliation,
|
||||
row.qualification,
|
||||
row.experience,
|
||||
row.oralPractical,
|
||||
row.assessment,
|
||||
row.reassessment,
|
||||
row.paperSetting,
|
||||
row.moderation,
|
||||
row.pwdPaperSetting,
|
||||
]);
|
||||
|
||||
const sheetData = [...headerInfo, ...tableHeaders, ...dataRows];
|
||||
const worksheet = XLSX.utils.aoa_to_sheet(sheetData);
|
||||
XLSX.utils.book_append_sheet(workbook, worksheet, teacher);
|
||||
|
||||
const fileName = `${teacher.replace(/\s+/g, "_")}_table.xlsx`;
|
||||
const excelBlob = XLSX.write(workbook, {
|
||||
bookType: "xlsx",
|
||||
type: "array",
|
||||
});
|
||||
|
||||
const file = new File([excelBlob], fileName, {
|
||||
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
});
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("teacher", teacher);
|
||||
formData.append("fileName", fileName);
|
||||
formData.append("recipientEmail", facultyEmail);
|
||||
formData.append("file", file);
|
||||
|
||||
try {
|
||||
const response = await sendEmail(formData);
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user