forked from CSI-KJSCE/appointment_to_examiner
Send email to all faculties
This commit is contained in:
@@ -35,7 +35,7 @@ const ConsolidatedTable = () => {
|
||||
// Extract unique faculty names
|
||||
const uniqueTeachers = [...new Set(data.map((row) => row.Name))];
|
||||
|
||||
// Pagination
|
||||
// Pagination
|
||||
const indexOfLastTable = currentPage * tablesPerPage;
|
||||
const indexOfFirstTable = indexOfLastTable - tablesPerPage;
|
||||
const currentTeachers = uniqueTeachers.slice(indexOfFirstTable, indexOfLastTable);
|
||||
@@ -65,7 +65,6 @@ 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/${facultyId}`
|
||||
);
|
||||
@@ -101,6 +100,15 @@ const ConsolidatedTable = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// Send emails to all teachers
|
||||
const sendEmailsToAllTeachers = async () => {
|
||||
for (let teacher of uniqueTeachers) {
|
||||
const teacherData = data.filter((row) => row.Name === teacher);
|
||||
await handleSendEmail(teacher, teacherData); // Wait for each email to be sent before proceeding to the next
|
||||
}
|
||||
alert("Emails sent to all teachers.");
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 style={{ textAlign: "center" }}>
|
||||
@@ -135,6 +143,21 @@ const ConsolidatedTable = () => {
|
||||
>
|
||||
Download Consolidated Table
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={sendEmailsToAllTeachers}
|
||||
className="btn btn-danger"
|
||||
style={{
|
||||
padding: "10px 15px",
|
||||
backgroundColor: "#dc3545",
|
||||
color: "white",
|
||||
textDecoration: "none",
|
||||
borderRadius: "5px",
|
||||
marginLeft: "10px",
|
||||
}}
|
||||
>
|
||||
Send Emails to All Teachers
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user