Skip to content

Commit f25e247

Browse files
Merge pull request #3396 from OneCommunityGlobal/vinay/notify-user-new-permission
Vinay - Let a user know through a popup that Permissions have been changed for them
2 parents 66d33ca + 9ff52a3 commit f25e247

5 files changed

Lines changed: 68 additions & 20 deletions

File tree

src/components/Header/Header.jsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useState, useEffect, useMemo } from 'react';
2-
// import { getUserProfile } from '../../actions/userProfile'
32
import { ENDPOINTS } from 'utils/URL';
43
import axios from 'axios';
54
import { getWeeklySummaries } from 'actions/weeklySummaries';
@@ -62,6 +61,7 @@ import {
6261
import NotificationCard from '../Notification/notificationCard';
6362
import DarkModeButton from './DarkModeButton';
6463
import BellNotification from './BellNotification';
64+
import { getUserProfile } from '../../actions/userProfile';
6565

6666
export function Header(props) {
6767
const location = useLocation();
@@ -153,6 +153,7 @@ export function Header(props) {
153153
const history = useHistory();
154154

155155
const [showProjectDropdown, setShowProjectDropdown] = useState(false);
156+
const [isAckLoading, setIsAckLoading] = useState(false);
156157

157158
useEffect(() => {
158159
const handleStorageEvent = () => {
@@ -216,6 +217,28 @@ export function Header(props) {
216217
const openModal = () => {
217218
setLogoutPopup(true);
218219
};
220+
221+
const handlePermissionChangeAck = async () => {
222+
// handle setting the ack true
223+
try {
224+
setIsAckLoading(true)
225+
const {firstName: name, lastName, personalLinks, adminLinks, _id} = props.userProfile
226+
axios.put(ENDPOINTS.USER_PROFILE(_id), {
227+
// req fields for updation
228+
firstName: name,
229+
lastName,
230+
personalLinks,
231+
adminLinks,
232+
233+
isAcknowledged: true,
234+
}).then(()=>{
235+
setIsAckLoading(false);
236+
dispatch(getUserProfile(_id));
237+
});
238+
} catch (e) {
239+
// console.log('update ack', e);
240+
}
241+
}
219242

220243
const removeViewingUser = () => {
221244
setPopup(false);
@@ -304,6 +327,7 @@ export function Header(props) {
304327

305328
if (location.pathname === '/login') return null;
306329

330+
const viewingUser = JSON.parse(window.sessionStorage.getItem('viewingUser'))
307331
return (
308332
<div className="header-wrapper">
309333
<Navbar className="py-3 navbar" color="dark" dark expand="md">
@@ -552,8 +576,16 @@ export function Header(props) {
552576
</Navbar>
553577
{!isAuthUser && (
554578
<PopUpBar
579+
message={`You are currently viewing the header for ${viewingUser.firstName} ${viewingUser.lastName}`}
555580
onClickClose={() => setPopup(prevPopup => !prevPopup)}
556-
viewingUser={JSON.parse(window.sessionStorage.getItem('viewingUser'))}
581+
/>
582+
)}
583+
{props.auth.isAuthenticated && props.userProfile?.permissions?.isAcknowledged===false && (
584+
<PopUpBar
585+
message="Heads Up, there were permission changes made to this account"
586+
onClickClose={handlePermissionChangeAck}
587+
textColor="black_text"
588+
isLoading={isAckLoading}
557589
/>
558590
)}
559591
<div>
@@ -607,4 +639,5 @@ export default connect(mapStateToProps, {
607639
getAllRoles,
608640
hasPermission,
609641
getWeeklySummaries,
642+
getUserProfile,
610643
})(Header);

src/components/PopUpBar/PopUpBar.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
z-index: 2;
1111
opacity: 0.8;
1212
}
13+
.popup_container.black_text{
14+
color: #000000
15+
}
1316

1417
.close_button {
1518
background: none;
@@ -21,4 +24,15 @@
2124
top: 50%;
2225
right: 30px;
2326
transform: translateY(-50%);
24-
}
27+
}
28+
29+
.close_button.btn_padding{
30+
@media (max-width: 768px) {
31+
top: 70%;
32+
}
33+
}
34+
35+
.close_button > .container-fluid {
36+
padding: 0px;
37+
}
38+

src/components/PopUpBar/PopUpBar.jsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
// import React from 'react';
2+
import Loading from 'components/common/Loading';
23
import './PopUpBar.css';
34

45
function PopUpBar(props) {
5-
const { viewingUser, onClickClose } = props;
6-
const { firstName, lastName } = viewingUser;
6+
const { message, onClickClose, textColor, isLoading = false } = props;
77
return (
8-
<div className="popup_container" data-testid="test-popup">
9-
{`You are currently viewing the header for ${firstName} ${lastName}`}
10-
<button type="button" className="close_button" onClick={onClickClose}>
11-
X
12-
</button>
8+
<div className={`popup_container ${textColor}`} data-testid="test-popup">
9+
{message}
10+
{isLoading ? (
11+
<span className="close_button">
12+
<Loading className="fa-sm" />
13+
</span>
14+
) : (
15+
<button type="button" className="close_button btn_padding" onClick={onClickClose}>
16+
X
17+
</button>
18+
)}
1319
</div>
1420
);
1521
}

src/components/PopUpBar/__tests__/PopUpBar.test.jsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1+
/* eslint-disable react/jsx-props-no-spreading */
12
import { render, screen, fireEvent } from '@testing-library/react';
23
import PopUpBar from '../PopUpBar';
34

4-
const viewingUser = {
5-
firstName: 'TestUser',
6-
lastName: 'LastName',
7-
};
8-
95
// render Component
106
const renderComponent = (props = {}) => {
11-
// eslint-disable-next-line react/jsx-props-no-spreading
12-
render(<PopUpBar viewingUser={viewingUser} {...props} />);
7+
render(<PopUpBar message="PopUpBar text message" {...props} />);
138
};
149

1510
// Test Cases
@@ -22,7 +17,7 @@ describe('Test Suite for PopUpBar', () => {
2217

2318
it('Test Case 2: Renders with correct text', () => {
2419
renderComponent();
25-
const expectedText = `You are currently viewing the header for ${viewingUser.firstName} ${viewingUser.lastName}`;
20+
const expectedText = `PopUpBar text message`;
2621
const actualText = screen.getByText(expectedText);
2722
expect(actualText).toBeInTheDocument();
2823
});

src/components/common/Loading/Loading.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line react/function-component-definition
2-
const Loading = ({ align, darkMode }) => {
2+
const Loading = ({ align, darkMode, className }) => {
33
let alignClassName = '';
44
if (align === 'center') {
55
alignClassName = 'd-flex justify-content-center align-items-center';
@@ -10,7 +10,7 @@ const Loading = ({ align, darkMode }) => {
1010
}
1111
return (
1212
<div className={`container-fluid ${alignClassName}`} data-testid="loading">
13-
<div className="fa-5x">
13+
<div className={className || 'fa-5x'}>
1414
<i
1515
className={`fa fa-spinner fa-pulse ${darkMode ? 'text-azure' : ''}`}
1616
data-testid="loading-spinner"

0 commit comments

Comments
 (0)