Send email to all faculties
This commit is contained in:
@@ -65,7 +65,6 @@ const ConsolidatedTable = () => {
|
|||||||
const handleSendEmail = async (teacher, teacherData) => {
|
const handleSendEmail = async (teacher, teacherData) => {
|
||||||
const facultyId = teacherData[0].facultyId; // This assumes all rows for a teacher have the same facultyId
|
const facultyId = teacherData[0].facultyId; // This assumes all rows for a teacher have the same facultyId
|
||||||
try {
|
try {
|
||||||
// Fetch email from the backend
|
|
||||||
const response = await axios.get(
|
const response = await axios.get(
|
||||||
`http://localhost:8080/api/faculty/${facultyId}`
|
`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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h1 style={{ textAlign: "center" }}>
|
<h1 style={{ textAlign: "center" }}>
|
||||||
@@ -135,6 +143,21 @@ const ConsolidatedTable = () => {
|
|||||||
>
|
>
|
||||||
Download Consolidated Table
|
Download Consolidated Table
|
||||||
</button>
|
</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>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|||||||
Reference in New Issue
Block a user