Skip to content

Commit 2ad6f87

Browse files
Merge pull request #4953 from OneCommunityGlobal/Diya_Fix_TotalOrg_WeeklySummaryEmail
Diya fix (orgSummaryEmail): Fixed Total Org Weekly Summary Email Flow
2 parents f5c2a56 + 09560bd commit 2ad6f87

7 files changed

Lines changed: 206 additions & 1 deletion

File tree

src/components/Header/Header.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
PERMISSIONS_MANAGEMENT,
4848
SEND_EMAILS,
4949
TOTAL_ORG_SUMMARY,
50+
TOTAL_ORG_SUMMARY_EMAIL,
5051
TOTAL_CONSTRUCTION_SUMMARY,
5152
PR_PROMOTIONS,
5253
ACTUAL_COST_BREAKDOWN,
@@ -628,6 +629,11 @@ export function Header(props) {
628629
>
629630
{ACTUAL_COST_BREAKDOWN}
630631
</DropdownItem>
632+
{canGetWeeklyVolunteerSummary && (
633+
<DropdownItem tag={Link} to="/TotalOrgSummaryEmail" className={fontColor}>
634+
{TOTAL_ORG_SUMMARY_EMAIL}
635+
</DropdownItem>
636+
)}
631637
{canGetJobAnalytics && (
632638
<DropdownItem
633639
tag={Link}

src/components/Login/Login.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ export class Login extends Form {
8080
darkMode,
8181
})}
8282
<div>
83-
{this.renderButton({ label: 'Submit', darkMode })}
83+
{this.renderButton({
84+
name: 'submit',
85+
id: 'submit',
86+
label: 'Submit',
87+
type: 'submit',
88+
darkMode,
89+
})}
8490
<Link to="forgotpassword">
8591
<span
8692
style={{

src/components/TotalOrgSummary/AccordianWrapper/AccordianWrapper.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export default function AccordianWrapper({ children, title }) {
1111
className={darkMode ? 'bg-space-cadet text-light' : ''}
1212
openedClassName={darkMode ? 'bg-space-cadet text-light' : ''}
1313
trigger={title}
14+
triggerClassName={`accordian-trigger ${darkMode ? 'text-light' : ''}`}
15+
triggerOpenedClassName={`accordian-trigger ${darkMode ? 'text-light' : ''}`}
1416
>
1517
{children}
1618
</Collapsible>
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import { useState, useEffect } from 'react';
2+
import axios from 'axios';
3+
import { useSelector } from 'react-redux';
4+
5+
import { v4 as uuid } from 'uuid';
6+
import { ToastContainer, toast } from 'react-toastify';
7+
import { ENDPOINTS } from '../../../utils/URL';
8+
9+
function TotalOrgSummaryEmail() {
10+
// State for managing email recipients
11+
const [recipients, setRecipients] = useState('');
12+
const [recipientList, setRecipientList] = useState([]);
13+
const [emailSubject, setSubject] = useState('');
14+
const [body, setBody] = useState('');
15+
16+
// Fetch admin list from the backend
17+
useEffect(() => {
18+
const fetchAdminList = async () => {
19+
try {
20+
// console.log('Endpoint:', ENDPOINTS.ADMIN_LIST()); // Log the endpoint for debugging
21+
const response = await axios.get(ENDPOINTS.ADMIN_LIST());
22+
23+
// Extract the emailList from the response
24+
setRecipientList(response.data.emailList); // Use response.data.emailList
25+
} catch (error) {
26+
// console.error('Error fetching admin list:', error);
27+
}
28+
};
29+
fetchAdminList();
30+
}, []);
31+
32+
// Handle adding new recipients
33+
const handleAddRecipient = () => {
34+
if (recipients.trim() !== '') {
35+
setRecipientList([...recipientList, recipients.trim()]);
36+
setRecipients('');
37+
}
38+
};
39+
40+
const handlRemoveAllRecipients = () => {
41+
setRecipientList([]);
42+
};
43+
44+
// Handle removing a recipient
45+
const handleRemoveRecipient = email => {
46+
const updatedList = recipientList.filter(recipient => recipient !== email);
47+
setRecipientList(updatedList);
48+
};
49+
function notify(type) {
50+
switch (type) {
51+
case 'info':
52+
toast.info('Sending email...');
53+
break;
54+
case 'error':
55+
toast.error('Failed to send email.');
56+
break;
57+
case 'success':
58+
toast.success('Email sent successfully!');
59+
break;
60+
default:
61+
break;
62+
}
63+
}
64+
// Handle sending the email
65+
const handleSendEmail = async () => {
66+
try {
67+
notify('info');
68+
69+
const emailData = {
70+
recipients: recipientList,
71+
subject: emailSubject,
72+
message: body,
73+
};
74+
75+
const response = await axios.post(ENDPOINTS.SEND_EMAIL_REPORT(), emailData);
76+
77+
if (response.status === 200) {
78+
notify('success');
79+
} else {
80+
notify('error');
81+
}
82+
} catch (error) {
83+
notify('error');
84+
}
85+
};
86+
87+
// Darkmode
88+
const darkMode = useSelector(state => state.theme.darkMode);
89+
useEffect(() => {
90+
const rootDiv = document.getElementById('root');
91+
if (darkMode) {
92+
rootDiv.classList.add('bg-dark', 'text-light');
93+
} else {
94+
rootDiv.classList.remove('bg-dark', 'text-light');
95+
}
96+
}, [darkMode]);
97+
98+
return (
99+
<div>
100+
<h1 className={`h1 ${darkMode ? 'text-light' : ''}`}>Total Org Summary Email</h1>
101+
{/* Recipient Management */}
102+
<div className={`container ${darkMode ? 'bg-dark text-light' : ''}`}>
103+
<h2 className={`h2 ${darkMode ? 'text-light' : ''}`}>Recipients</h2>
104+
<div className={`container-fluid ${darkMode ? 'bg-dark text-light' : ''}`}>
105+
{recipientList.map((email, index) => (
106+
<div
107+
key={uuid() + String(index)}
108+
className={`row ${darkMode ? 'bg-dark text-light' : ''}`}
109+
>
110+
<span className="col">{email}</span>
111+
<span className="col">
112+
<button
113+
type="button"
114+
onClick={() => handleRemoveRecipient(email)}
115+
className="btn btn-danger"
116+
>
117+
Remove
118+
</button>
119+
</span>
120+
</div>
121+
))}
122+
</div>
123+
<div className={`row ${darkMode ? 'bg-dark text-light' : ''}`}>
124+
<span className="col">
125+
<input
126+
type="email"
127+
placeholder="Enter email address"
128+
value={recipients}
129+
className={`form-control ${darkMode ? 'bg-dark text-light' : ''}`}
130+
onChange={e => setRecipients(e.target.value)}
131+
/>
132+
</span>
133+
<span className="col">
134+
<button type="button" onClick={handleAddRecipient} className="btn btn-primary">
135+
Add Recipient
136+
</button>
137+
<button type="button" onClick={handlRemoveAllRecipients} className="btn btn-danger">
138+
Remove all
139+
</button>
140+
</span>
141+
</div>
142+
143+
<div className="row m-3">
144+
<input
145+
type="subject"
146+
placeholder="Enter Subject"
147+
value={emailSubject}
148+
className={`form-control ${darkMode ? 'bg-dark text-light' : ''}`}
149+
onChange={e => setSubject(e.target.value)}
150+
/>
151+
</div>
152+
<div className="row m-3">
153+
<textarea
154+
type="body"
155+
placeholder="Enter Body"
156+
value={body}
157+
className={`form-control ${darkMode ? 'bg-dark text-light' : ''}`}
158+
onChange={e => setBody(e.target.value)}
159+
/>
160+
</div>
161+
<div className="row ml-3">
162+
<button type="button" onClick={handleSendEmail} className="btn btn-success">
163+
Send Email
164+
</button>
165+
<ToastContainer />
166+
</div>
167+
</div>
168+
</div>
169+
);
170+
}
171+
172+
export default TotalOrgSummaryEmail;

src/languages/en/ui.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const INVENTORY = 'Inventory';
3333
export const REPORTS = 'Reports';
3434
export const WEEKLY_SUMMARIES_REPORT = 'Weekly Summaries Report';
3535
export const TOTAL_ORG_SUMMARY = 'Total Org Summary';
36+
export const TOTAL_ORG_SUMMARY_EMAIL = 'Total Org Summary Email'
3637
export const ACTUAL_COST_BREAKDOWN = 'Actual Cost Breakdown';
3738
export const TEAM_LOCATIONS = 'Team Locations';
3839
export const TOTAL_CONSTRUCTION_SUMMARY = 'Total Construction Summary';

src/routes.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import HeaderRenderer from './components/Header/HeaderRenderer';
3535
import Announcements from './components/Announcements';
3636
import JobCCDashboard from './components/JobCCDashboard/JobCCDashboard';
3737
import WeeklyProjectSummary from './components/BMDashboard/WeeklyProjectSummary/WeeklyProjectSummary';
38+
import TotalOrgSummaryEmail from './components/TotalOrgSummary/WeeklySummaryEmail/TotalOrgSummaryEmail';
3839
import LessonForm from './components/BMDashboard/Lesson/LessonForm';
3940
import LessonList from './components/BMDashboard/LessonList/LessonListForm';
4041
import AddEquipmentType from './components/BMDashboard/Equipment/Add/AddEquipmentType';
@@ -557,6 +558,21 @@ export default (
557558
// setting permission as Weeklysummariesreport for now. Later it will be changed to weeklyVolunteerSummary. - H
558559
routePermissions={RoutePermissions.weeklySummariesReport}
559560
/>
561+
<ProtectedRoute
562+
path="/TotalOrgSummaryEmail"
563+
exact
564+
component={TotalOrgSummaryEmail}
565+
fallback
566+
allowedRoles={[
567+
UserRole.Administrator,
568+
UserRole.Manager,
569+
UserRole.CoreTeam,
570+
UserRole.Owner,
571+
UserRole.Mentor,
572+
]}
573+
// setting permission as Weeklysummariesreport for now. Later it will be changed to weeklyVolunteerSummary. - H
574+
routePermissions={RoutePermissions.weeklySummariesReport}
575+
/>
560576
<ProtectedRoute
561577
path="/job-notification-dashboard"
562578
exact

src/utils/URL.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ export const ENDPOINTS = {
162162
BADGE_ASSIGN_MULTIPLE: `${APIEndpoint}/badge/assign`,
163163
BADGE_ASSIGN: userId => `${APIEndpoint}/badge/assign/${userId}`,
164164
BADGE_BY_ID: badgeId => `${APIEndpoint}/badge/${badgeId}`,
165+
ADMIN_LIST: () => `${APIEndpoint}/reports/getAdminList`,
166+
SEND_EMAIL_REPORT: () => `${APIEndpoint}/reports/sendEmailReport`,
165167

166168
TEAM_MEMBER_TASKS: userId => `${ENDPOINTS.APIEndpoint()}/user/${userId}/teams/tasks`,
167169
CREATE_OR_UPDATE_TASK_NOTIFICATION: taskId =>

0 commit comments

Comments
 (0)