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

@@ -33,7 +33,7 @@ const ConsolidatedTable = () => {
const createExcelFile = (teacherData, teacherName) => {
const workbook = XLSX.utils.book_new();
// Define header information
const headerInfo = [
["Somaiya Vidyavihar University"],
@@ -45,7 +45,7 @@ const ConsolidatedTable = () => {
["Department - Computer Engineering"],
[],
];
const tableHeaders = [
[
"Sr No",
@@ -55,9 +55,7 @@ const ConsolidatedTable = () => {
"Exam Type",
"Year",
"Marks",
"Surname",
"First Name",
"Middle Name",
"Name",
"Affiliation/College",
"Highest Qualification",
"Career Experience",
@@ -69,7 +67,7 @@ const ConsolidatedTable = () => {
"PwD Paper Setting",
],
];
const dataRows = teacherData.map((row, index) => [
index + 1,
row.semester,
@@ -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,
@@ -91,10 +87,10 @@ const ConsolidatedTable = () => {
row.moderation,
row.pwdPaperSetting,
]);
const sheetData = [...headerInfo, ...tableHeaders, ...dataRows];
const worksheet = XLSX.utils.aoa_to_sheet(sheetData);
// Add merged cells
worksheet["!merges"] = [
{ s: { r: 0, c: 0 }, e: { r: 0, c: 18 } },
@@ -103,22 +99,27 @@ const ConsolidatedTable = () => {
{ s: { r: 3, c: 0 }, e: { r: 3, c: 18 } },
{ s: { r: 4, c: 0 }, e: { r: 4, c: 18 } },
];
// Define styles
const boldStyle = {
font: { bold: true, name: "Times New Roman", sz: 14 },
alignment: { horizontal: "center", vertical: "center" },
};
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" },
};
const normalStyle = {
font: { name: "Times New Roman", sz: 12 },
};
// Apply styles to headers
const headerRanges = [
{ row: 0, style: boldStyle },
@@ -127,7 +128,7 @@ const ConsolidatedTable = () => {
{ row: 3, style: boldStyle },
{ row: 4, style: redStyle },
];
headerRanges.forEach(({ row, style }) => {
for (let col = 0; col <= 18; col++) {
const cellAddress = XLSX.utils.encode_cell({ r: row, c: col });
@@ -135,7 +136,7 @@ const ConsolidatedTable = () => {
worksheet[cellAddress].s = style;
}
});
// Set column widths for better readability
worksheet["!cols"] = [
{ wch: 10 }, // Sr No
@@ -158,14 +159,14 @@ const ConsolidatedTable = () => {
{ wch: 15 }, // Moderation
{ wch: 15 }, // PwD Paper Setting
];
// Apply normal font style to all cells
Object.keys(worksheet).forEach((key) => {
if (worksheet[key] && key[0] !== "!") {
worksheet[key].s = worksheet[key].s || normalStyle;
}
});
// Add worksheet to workbook and save file
XLSX.utils.book_append_sheet(workbook, worksheet, teacherName);
XLSX.writeFile(workbook, `${teacherName.replace(/\s+/g, "_")}_Table.xlsx`);
@@ -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