|
1 | 1 | import { useState, useEffect, useMemo } from 'react'; |
2 | | -// import { getUserProfile } from '../../actions/userProfile' |
3 | 2 | import { ENDPOINTS } from 'utils/URL'; |
4 | 3 | import axios from 'axios'; |
5 | 4 | import { getWeeklySummaries } from 'actions/weeklySummaries'; |
@@ -62,6 +61,7 @@ import { |
62 | 61 | import NotificationCard from '../Notification/notificationCard'; |
63 | 62 | import DarkModeButton from './DarkModeButton'; |
64 | 63 | import BellNotification from './BellNotification'; |
| 64 | +import { getUserProfile } from '../../actions/userProfile'; |
65 | 65 |
|
66 | 66 | export function Header(props) { |
67 | 67 | const location = useLocation(); |
@@ -153,6 +153,7 @@ export function Header(props) { |
153 | 153 | const history = useHistory(); |
154 | 154 |
|
155 | 155 | const [showProjectDropdown, setShowProjectDropdown] = useState(false); |
| 156 | + const [isAckLoading, setIsAckLoading] = useState(false); |
156 | 157 |
|
157 | 158 | useEffect(() => { |
158 | 159 | const handleStorageEvent = () => { |
@@ -216,6 +217,28 @@ export function Header(props) { |
216 | 217 | const openModal = () => { |
217 | 218 | setLogoutPopup(true); |
218 | 219 | }; |
| 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 | + } |
219 | 242 |
|
220 | 243 | const removeViewingUser = () => { |
221 | 244 | setPopup(false); |
@@ -304,6 +327,7 @@ export function Header(props) { |
304 | 327 |
|
305 | 328 | if (location.pathname === '/login') return null; |
306 | 329 |
|
| 330 | + const viewingUser = JSON.parse(window.sessionStorage.getItem('viewingUser')) |
307 | 331 | return ( |
308 | 332 | <div className="header-wrapper"> |
309 | 333 | <Navbar className="py-3 navbar" color="dark" dark expand="md"> |
@@ -552,8 +576,16 @@ export function Header(props) { |
552 | 576 | </Navbar> |
553 | 577 | {!isAuthUser && ( |
554 | 578 | <PopUpBar |
| 579 | + message={`You are currently viewing the header for ${viewingUser.firstName} ${viewingUser.lastName}`} |
555 | 580 | 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} |
557 | 589 | /> |
558 | 590 | )} |
559 | 591 | <div> |
@@ -607,4 +639,5 @@ export default connect(mapStateToProps, { |
607 | 639 | getAllRoles, |
608 | 640 | hasPermission, |
609 | 641 | getWeeklySummaries, |
| 642 | + getUserProfile, |
610 | 643 | })(Header); |
0 commit comments