-
+
+
diff --git a/src/components/PermissionsManagement/PermissionsManagement.test.js b/src/components/PermissionsManagement/PermissionsManagement.test.js
index 01c39ff89e..85fb8beca7 100644
--- a/src/components/PermissionsManagement/PermissionsManagement.test.js
+++ b/src/components/PermissionsManagement/PermissionsManagement.test.js
@@ -7,6 +7,7 @@ import { screen } from '@testing-library/react';
import { renderWithRouterMatch } from '../../__tests__/utils';
import configureMockStore from 'redux-mock-store';
import userEvent from '@testing-library/user-event';
+import { ModalProvider } from 'context/ModalContext';
jest.mock('actions/role.js');
@@ -32,7 +33,9 @@ describe('permissions management page structure', () => {
store.dispatch = jest.fn();
renderWithRouterMatch(
- {props => },
+
+ {props => }
+ ,
{
route: `/permissionsmanagement`,
store,
diff --git a/src/components/PermissionsManagement/ReminderModal.jsx b/src/components/PermissionsManagement/ReminderModal.jsx
new file mode 100644
index 0000000000..756e9dbad3
--- /dev/null
+++ b/src/components/PermissionsManagement/ReminderModal.jsx
@@ -0,0 +1,42 @@
+/* eslint-disable react/button-has-type */
+import './PermissionsManagement.css';
+import { ModalContext } from 'context/ModalContext';
+import { useContext } from 'react';
+
+function ReminderModal({
+ setReminderModal,
+ reminderModal,
+ updateProfileOnSubmit,
+ changedAccount,
+ darkMode,
+}) {
+ const { modalStatus, updateModalStatus } = useContext(ModalContext);
+
+ return (
+
+
+
Remember to Save Your Changes!
+
+
+
+ Please log out and log back in to your account, {changedAccount} to apply the changes.
+
+
+
+
+
+
+
+
+ );
+}
+
+export default ReminderModal;
diff --git a/src/components/PermissionsManagement/UserPermissionsPopUp.jsx b/src/components/PermissionsManagement/UserPermissionsPopUp.jsx
index e8510e218f..6f556b381e 100644
--- a/src/components/PermissionsManagement/UserPermissionsPopUp.jsx
+++ b/src/components/PermissionsManagement/UserPermissionsPopUp.jsx
@@ -6,6 +6,7 @@ import { getAllUserProfile } from 'actions/userManagement';
import './PermissionsManagement.css';
import axios from 'axios';
import { ENDPOINTS } from 'utils/URL';
+// eslint-disable-next-line no-unused-vars
import { boxStyle, boxStyleDark } from 'styles';
import {
DEV_ADMIN_ACCOUNT_EMAIL_DEV_ENV_ONLY,
@@ -15,14 +16,28 @@ import {
import PermissionList from './PermissionList';
import { addNewRole, getAllRoles } from '../../actions/role';
import { cantUpdateDevAdminDetails } from '../../utils/permissions';
+import ReminderModal from './ReminderModal';
-function UserPermissionsPopUp({ toggle, allUserProfiles, getAllUsers, roles, authUser, darkMode }) {
+function UserPermissionsPopUp({
+ allUserProfiles,
+ // eslint-disable-next-line no-unused-vars
+ toggle,
+ getAllUsers,
+ roles,
+ authUser,
+ setReminderModal,
+ reminderModal,
+ modalStatus,
+ darkMode,
+}) {
const [searchText, onInputChange] = useState('');
const [actualUserProfile, setActualUserProfile] = useState();
const [userPermissions, setUserPermissions] = useState();
const [isOpen, setIsOpen] = useState(false);
const [isInputFocus, setIsInputFocus] = useState(false);
const [actualUserRolePermission, setActualUserRolePermission] = useState();
+ const [selectedAccount, setSelectedAccount] = useState('');
+ const [toastShown, setToastShown] = useState(false);
const setToDefault = () => {
setUserPermissions([]);
@@ -37,6 +52,7 @@ function UserPermissionsPopUp({ toggle, allUserProfiles, getAllUsers, roles, aut
const url = ENDPOINTS.USER_PROFILE(userId);
const allUserInfo = await axios.get(url).then(res => res.data);
setActualUserProfile(allUserInfo);
+ setSelectedAccount(`${allUserInfo.firstName} ${allUserInfo.lastName}`);
};
useEffect(() => {
@@ -70,13 +86,15 @@ function UserPermissionsPopUp({ toggle, allUserProfiles, getAllUsers, roles, aut
await axios
.put(url, newUserInfo)
.then(() => {
- const SUCCESS_MESSAGE = `
- Permission has been updated successfully. Be sure to tell them that you are changing these
- permissions and for that they need to log out and log back in for their new permissions to take
- place.`;
- toast.success(SUCCESS_MESSAGE, {
- autoClose: 10000,
- });
+ if (!toastShown) {
+ const SUCCESS_MESSAGE = `
+ Permissions have been updated successfully.
+ Please inform the user to log out and log back in for the new permissions to take effect.`;
+ toast.success(SUCCESS_MESSAGE, {
+ autoClose: 10000,
+ });
+ setToastShown(true);
+ }
toggle();
})
.catch(err => {
@@ -92,113 +110,136 @@ function UserPermissionsPopUp({ toggle, allUserProfiles, getAllUsers, roles, aut
useEffect(() => {
refInput.current.focus();
}, []);
+ useEffect(() => {
+ if (!modalStatus) {
+ setToastShown(false);
+ }
+ }, [modalStatus]);
return (
-
+ {isInputFocus || (searchText !== '' && allUserProfiles && allUserProfiles.length > 0) ? (
+
+ {allUserProfiles
+ // eslint-disable-next-line array-callback-return, consistent-return
+ .filter(user => {
+ if (
+ user.firstName.toLowerCase().includes(searchText.toLowerCase()) ||
+ user.lastName.toLowerCase().includes(searchText.toLowerCase()) ||
+ `${user.firstName} ${user.lastName}`
+ .toLowerCase()
+ .includes(searchText.toLowerCase())
+ ) {
+ if (user.isActive) {
+ return user;
+ }
+ }
+ })
+ .map(user => (
+
{
+ onInputChange(`${user.firstName} ${user.lastName}`);
+ setIsOpen(false);
+ setActualUserProfile(user);
+ getUserData(user._id);
+ }}
+ >
+ {`${user.firstName} ${user.lastName}`}
+
+ ))}
+
+ ) : (
+ // eslint-disable-next-line react/jsx-no-useless-fragment
+ <>>
+ )}
+
+
+
+
+ >
);
}
diff --git a/src/components/PermissionsManagement/__tests__/NewRolePopUp.test.js b/src/components/PermissionsManagement/__tests__/NewRolePopUp.test.js
index c165ddd432..6a8874641a 100644
--- a/src/components/PermissionsManagement/__tests__/NewRolePopUp.test.js
+++ b/src/components/PermissionsManagement/__tests__/NewRolePopUp.test.js
@@ -4,7 +4,11 @@ import thunk from 'redux-thunk';
import { Provider } from 'react-redux';
import configureStore from 'redux-mock-store';
import CreateNewRolePopup from '../NewRolePopUp'
-import { themeMock } from '__tests__/mockStates';
+import { ModalProvider } from 'context/ModalContext';
+import axios from 'axios';
+
+jest.mock('axios');
+
const mockTogglePopUpNewRole = jest.fn()
@@ -21,6 +25,10 @@ const mockAuth = {
},
firstName: 'Jerry'
}
+
+const themeMock = {
+ primaryColor: '#000000',
+};
const middlewares = [thunk]
const mockStore = configureStore(middlewares)
const store = mockStore({
@@ -29,6 +37,14 @@ const store = mockStore({
theme: themeMock,
})
+const renderComponent = () => {
+ const { container } = render(
+
+
+
+
+
+ )
const renderComponent = () => {
const { container } = render(
@@ -43,7 +59,8 @@ const renderComponent = () => {
beforeEach(() => {
- store.clearActions();
+ store.clearActions();
+ axios.get.mockResolvedValue({ data: {} });
});
@@ -89,4 +106,4 @@ describe('Render NewRolePopUp component', () => {
})
});
})
-
+}
\ No newline at end of file
diff --git a/src/components/PermissionsManagement/__tests__/RolePermissions.test.js b/src/components/PermissionsManagement/__tests__/RolePermissions.test.js
index d3a41a3512..74dae6de53 100644
--- a/src/components/PermissionsManagement/__tests__/RolePermissions.test.js
+++ b/src/components/PermissionsManagement/__tests__/RolePermissions.test.js
@@ -10,6 +10,12 @@ import axios from 'axios';
import { toast } from 'react-toastify';
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
+import { ModalContext } from 'context/ModalContext';
+
+const mockModalContext = {
+ modalStatus: false,
+ updateModalStatus: jest.fn(),
+};
const mockStore = configureStore([thunk]);
let store;
@@ -64,17 +70,19 @@ const flushAllPromises = () => new Promise(setImmediate);
const renderComponent = (newStore, history, newRoleName, newRoleId) => {
return render(
-
-
-
-
- ,
+
+
+
+
+
+
+
);
};
diff --git a/src/components/PermissionsManagement/__tests__/UserPermissionsPopup.test.js b/src/components/PermissionsManagement/__tests__/UserPermissionsPopup.test.js
index a36edaa002..0458d67420 100644
--- a/src/components/PermissionsManagement/__tests__/UserPermissionsPopup.test.js
+++ b/src/components/PermissionsManagement/__tests__/UserPermissionsPopup.test.js
@@ -9,9 +9,16 @@ import { Provider } from 'react-redux';
import { toast } from 'react-toastify';
import axios from 'axios';
import { themeMock } from '__tests__/mockStates';
+import { ModalContext } from 'context/ModalContext';
const mockStore = configureStore([thunk]);
let store;
+
+const mockModalContext = {
+ modalStatus: false,
+ updateModalStatus: jest.fn(),
+};
+
beforeEach(() => {
store = mockStore({
auth: {
@@ -85,7 +92,9 @@ describe('UserPermissionsPopup component', () => {
});
render(
-
+
+
+
,
);
await flushAllPromises();
@@ -98,7 +107,9 @@ describe('UserPermissionsPopup component', () => {
});
render(
-
+
+
+
,
);
await flushAllPromises();
@@ -117,7 +128,9 @@ describe('UserPermissionsPopup component', () => {
});
render(
-
+
+
+
,
);
await flushAllPromises();
@@ -138,7 +151,9 @@ describe('UserPermissionsPopup component', () => {
render(
-
+
+
+
,
);
const nameElement = screen.getByText('Test1 Volunteer');
@@ -148,9 +163,8 @@ describe('UserPermissionsPopup component', () => {
});
expect(toast.success).toHaveBeenCalledWith(
`
- Permission has been updated successfully. Be sure to tell them that you are changing these
- permissions and for that they need to log out and log back in for their new permissions to take
- place.`,
+ Permissions have been updated successfully.
+ Please inform the user to log out and log back in for the new permissions to take effect.`,
{
autoClose: 10000,
},
@@ -171,7 +185,9 @@ describe('UserPermissionsPopup component', () => {
render(
-
+
+
+
,
);
const nameElement = screen.getByText('Test1 Volunteer');
@@ -179,9 +195,8 @@ describe('UserPermissionsPopup component', () => {
await waitFor(() => {
expect(toast.success).not.toHaveBeenCalledWith(
`
- Permission has been updated successfully. Be sure to tell them that you are changing these
- permissions and for that they need to log out and log back in for their new permissions to take
- place.`,
+ Permissions have been updated successfully.
+ Please inform the user to log out and log back in for the new permissions to take effect.`,
{
autoClose: 10000,
},
@@ -202,7 +217,9 @@ describe('UserPermissionsPopup component', () => {
axios.put.mockRejectedValue({ err: 'server error' });
render(
-
+
+
+
,
);
const mockObject = {};
@@ -238,7 +255,9 @@ describe('UserPermissionsPopup component', () => {
render(
-
+
+
+
,
);
const userElement = screen.getByText('Test2 Manager');
diff --git a/src/components/PermissionsManagement/__tests__/UserRoleTab.test.js b/src/components/PermissionsManagement/__tests__/UserRoleTab.test.js
index 74161c10e7..94f4b4398c 100644
--- a/src/components/PermissionsManagement/__tests__/UserRoleTab.test.js
+++ b/src/components/PermissionsManagement/__tests__/UserRoleTab.test.js
@@ -10,6 +10,7 @@ import axios from 'axios';
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import { themeMock } from '__tests__/mockStates';
+import { ModalProvider } from 'context/ModalContext';
const mockStore = configureStore([thunk]);
let store;
@@ -46,7 +47,9 @@ describe('UserRoleTab component when the role does not exist', () => {
});
render(
+
+
,
);
});
@@ -57,7 +60,9 @@ describe('UserRoleTab component when the role does not exist', () => {
});
render(
+
+
,
);
expect(screen.queryByText('Error')).toBeInTheDocument();
@@ -69,7 +74,9 @@ describe('UserRoleTab component when the role does not exist', () => {
});
render(
+
+
,
);
expect(screen.queryByText('User Role not existent')).toBeInTheDocument();
@@ -81,7 +88,9 @@ describe('UserRoleTab component when the role does not exist', () => {
});
render(
+
+
,
);
const linkElement = screen.getByText('Back to permissions management');
@@ -115,7 +124,9 @@ describe('UserRoleTab component when the role does exist', () => {
render(
+
+
,
);
diff --git a/src/context/ModalContext.jsx b/src/context/ModalContext.jsx
new file mode 100644
index 0000000000..ff72956856
--- /dev/null
+++ b/src/context/ModalContext.jsx
@@ -0,0 +1,17 @@
+import { createContext, useState, useMemo } from 'react';
+
+export const ModalContext = createContext();
+
+export function ModalProvider({ children }) {
+ const [modalStatus, setModalStatus] = useState(false);
+
+ const updateModalStatus = newStatus => {
+ setModalStatus(newStatus);
+ };
+
+ const contextValue = useMemo(() => {
+ return { modalStatus, updateModalStatus };
+ }, [modalStatus]);
+
+ return {children};
+}