diff --git a/src/App.test.tsx b/src/App.test.tsx index 0beea1d719..b20f75e1ce 100644 --- a/src/App.test.tsx +++ b/src/App.test.tsx @@ -48,7 +48,6 @@ const MOCKS = [ phone: { mobile: '+8912313112', }, - userType: 'SUPERADMIN', }, }, }, diff --git a/src/components/DeleteOrg/DeleteOrg.test.tsx b/src/components/DeleteOrg/DeleteOrg.test.tsx index cf32700a22..d9ac99f3ad 100644 --- a/src/components/DeleteOrg/DeleteOrg.test.tsx +++ b/src/components/DeleteOrg/DeleteOrg.test.tsx @@ -116,7 +116,7 @@ afterEach(() => { describe('Delete Organization Component', () => { test('should be able to Toggle Delete Organization Modal', async () => { mockURL = '456'; - setItem('UserType', 'SUPERADMIN'); + setItem('SuperAdmin', true); render( @@ -140,7 +140,7 @@ describe('Delete Organization Component', () => { test('should be able to Toggle Delete Organization Modal When Organization is Sample Organization', async () => { mockURL = '123'; - setItem('UserType', 'SUPERADMIN'); + setItem('SuperAdmin', true); render( @@ -164,7 +164,7 @@ describe('Delete Organization Component', () => { test('Delete organization functionality should work properly', async () => { mockURL = '456'; - setItem('UserType', 'SUPERADMIN'); + setItem('SuperAdmin', true); render( @@ -183,7 +183,7 @@ describe('Delete Organization Component', () => { test('Delete organization functionality should work properly for sample org', async () => { mockURL = '123'; - setItem('UserType', 'SUPERADMIN'); + setItem('SuperAdmin', true); render( @@ -204,7 +204,7 @@ describe('Delete Organization Component', () => { test('Error handling for IS_SAMPLE_ORGANIZATION_QUERY mock', async () => { mockURL = '123'; - setItem('UserType', 'SUPERADMIN'); + setItem('SuperAdmin', true); jest.spyOn(toast, 'error'); render( @@ -228,7 +228,7 @@ describe('Delete Organization Component', () => { test('Error handling for DELETE_ORGANIZATION_MUTATION mock', async () => { mockURL = '456'; - setItem('UserType', 'SUPERADMIN'); + setItem('SuperAdmin', true); render( diff --git a/src/components/DeleteOrg/DeleteOrg.tsx b/src/components/DeleteOrg/DeleteOrg.tsx index 02c4427c99..947aa023f6 100644 --- a/src/components/DeleteOrg/DeleteOrg.tsx +++ b/src/components/DeleteOrg/DeleteOrg.tsx @@ -21,7 +21,7 @@ function deleteOrg(): JSX.Element { const navigate = useNavigate(); const [showDeleteModal, setShowDeleteModal] = useState(false); const { getItem } = useLocalStorage(); - const canDelete = getItem('UserType') === 'SUPERADMIN'; + const canDelete = getItem('SuperAdmin'); const toggleDeleteModal = (): void => setShowDeleteModal(!showDeleteModal); const [del] = useMutation(DELETE_ORGANIZATION_MUTATION); @@ -55,7 +55,7 @@ function deleteOrg(): JSX.Element { }, }); navigate('/orglist'); - } catch (error: any) { + } catch (error) { errorHandler(t, error); } } diff --git a/src/components/LeftDrawer/LeftDrawer.test.tsx b/src/components/LeftDrawer/LeftDrawer.test.tsx index 6cef74e73e..faecc6de8f 100644 --- a/src/components/LeftDrawer/LeftDrawer.test.tsx +++ b/src/components/LeftDrawer/LeftDrawer.test.tsx @@ -62,9 +62,6 @@ afterEach(() => { }); describe('Testing Left Drawer component for SUPERADMIN', () => { - beforeEach(() => { - setItem('UserType', 'SUPERADMIN'); - }); test('Component should be rendered properly', () => { setItem('UserImage', ''); setItem('UserImage', ''); @@ -134,9 +131,6 @@ describe('Testing Left Drawer component for SUPERADMIN', () => { }); describe('Testing Left Drawer component for ADMIN', () => { - beforeEach(() => { - setItem('UserType', 'ADMIN'); - }); test('Components should be rendered properly', () => { render( diff --git a/src/components/LeftDrawer/LeftDrawer.tsx b/src/components/LeftDrawer/LeftDrawer.tsx index 4fce2fb847..5954874b5e 100644 --- a/src/components/LeftDrawer/LeftDrawer.tsx +++ b/src/components/LeftDrawer/LeftDrawer.tsx @@ -19,7 +19,6 @@ const leftDrawer = ({ hideDrawer }: InterfaceLeftDrawerProps): JSX.Element => { const { t } = useTranslation('translation', { keyPrefix: 'leftDrawer' }); const { getItem } = useLocalStorage(); - const userType = getItem('UserType'); const superAdmin = getItem('SuperAdmin'); const role = superAdmin ? 'SuperAdmin' : 'Admin'; diff --git a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx index 38cde616ba..5a4de2470a 100644 --- a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx +++ b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx @@ -259,10 +259,6 @@ const linkImage = new StaticMockLink(MOCKS_WITH_IMAGE, true); const linkEmpty = new StaticMockLink(MOCKS_EMPTY, true); describe('Testing LeftDrawerOrg component for SUPERADMIN', () => { - beforeEach(() => { - setItem('UserType', 'SUPERADMIN'); - }); - test('Component should be rendered properly', async () => { setItem('UserImage', ''); setItem('SuperAdmin', true); diff --git a/src/components/OrganizationScreen/OrganizationScreen.tsx b/src/components/OrganizationScreen/OrganizationScreen.tsx index 8989a7beb5..f4434a2cdb 100644 --- a/src/components/OrganizationScreen/OrganizationScreen.tsx +++ b/src/components/OrganizationScreen/OrganizationScreen.tsx @@ -7,7 +7,7 @@ import { updateTargets } from 'state/action-creators'; import type { RootState } from 'state/reducers'; import type { TargetsType } from 'state/reducers/routesReducer'; import styles from './OrganizationScreen.module.css'; -import ProfileDropdown from 'components/ProfileDropdown/profileDropdown'; +import ProfileDropdown from 'components/ProfileDropdown/ProfileDropdown'; const OrganizationScreen = (): JSX.Element => { const location = useLocation(); diff --git a/src/components/ProfileDropdown/profileDropdown.module.css b/src/components/ProfileDropdown/ProfileDropdown.module.css similarity index 100% rename from src/components/ProfileDropdown/profileDropdown.module.css rename to src/components/ProfileDropdown/ProfileDropdown.module.css diff --git a/src/components/ProfileDropdown/profileDropdown.test.tsx b/src/components/ProfileDropdown/ProfileDropdown.test.tsx similarity index 98% rename from src/components/ProfileDropdown/profileDropdown.test.tsx rename to src/components/ProfileDropdown/ProfileDropdown.test.tsx index b9bcc336b3..d62b7b4520 100644 --- a/src/components/ProfileDropdown/profileDropdown.test.tsx +++ b/src/components/ProfileDropdown/ProfileDropdown.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { act, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { BrowserRouter } from 'react-router-dom'; -import ProfileDropdown from './profileDropdown'; +import ProfileDropdown from './ProfileDropdown'; import 'jest-localstorage-mock'; import { MockedProvider } from '@apollo/react-testing'; import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations'; diff --git a/src/components/ProfileDropdown/profileDropdown.tsx b/src/components/ProfileDropdown/ProfileDropdown.tsx similarity index 94% rename from src/components/ProfileDropdown/profileDropdown.tsx rename to src/components/ProfileDropdown/ProfileDropdown.tsx index fdf65d0333..1bf177d500 100644 --- a/src/components/ProfileDropdown/profileDropdown.tsx +++ b/src/components/ProfileDropdown/ProfileDropdown.tsx @@ -1,9 +1,9 @@ import Avatar from 'components/Avatar/Avatar'; import React from 'react'; import { ButtonGroup, Dropdown } from 'react-bootstrap'; -import { useNavigate, useParams } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; import useLocalStorage from 'utils/useLocalstorage'; -import styles from './profileDropdown.module.css'; +import styles from './ProfileDropdown.module.css'; import { REVOKE_REFRESH_TOKEN } from 'GraphQl/Mutations/mutations'; import { useMutation } from '@apollo/client'; @@ -12,7 +12,7 @@ const profileDropdown = (): JSX.Element => { const { getItem } = useLocalStorage(); const superAdmin = getItem('SuperAdmin'); const adminFor = getItem('AdminFor'); - const userType = superAdmin + const userRole = superAdmin ? 'SuperAdmin' : adminFor?.length > 0 ? 'Admin' @@ -67,7 +67,7 @@ const profileDropdown = (): JSX.Element => { {displayedName} - {`${userType}`} + {`${userRole}`} diff --git a/src/components/RequestsTableItem/RequestsTableItem.test.tsx b/src/components/RequestsTableItem/RequestsTableItem.test.tsx index 278e4982e6..866abc7f68 100644 --- a/src/components/RequestsTableItem/RequestsTableItem.test.tsx +++ b/src/components/RequestsTableItem/RequestsTableItem.test.tsx @@ -32,7 +32,6 @@ jest.mock('react-toastify', () => ({ })); beforeEach(() => { - setItem('UserType', 'ADMIN'); setItem('id', '123'); }); diff --git a/src/components/SuperAdminScreen/SuperAdminScreen.test.tsx b/src/components/SuperAdminScreen/SuperAdminScreen.test.tsx index 6d06f0da0e..f048766f7a 100644 --- a/src/components/SuperAdminScreen/SuperAdminScreen.test.tsx +++ b/src/components/SuperAdminScreen/SuperAdminScreen.test.tsx @@ -23,8 +23,6 @@ const clickToggleMenuBtn = (toggleButton: HTMLElement): void => { describe('Testing LeftDrawer in SuperAdminScreen', () => { test('Testing LeftDrawer in page functionality', async () => { - setItem('UserType', 'SUPERADMIN'); - render( diff --git a/src/components/SuperAdminScreen/SuperAdminScreen.tsx b/src/components/SuperAdminScreen/SuperAdminScreen.tsx index be28184651..93e012e2a1 100644 --- a/src/components/SuperAdminScreen/SuperAdminScreen.tsx +++ b/src/components/SuperAdminScreen/SuperAdminScreen.tsx @@ -4,7 +4,7 @@ import Button from 'react-bootstrap/Button'; import { useTranslation } from 'react-i18next'; import { Outlet, useLocation } from 'react-router-dom'; import styles from './SuperAdminScreen.module.css'; -import ProfileDropdown from 'components/ProfileDropdown/profileDropdown'; +import ProfileDropdown from 'components/ProfileDropdown/ProfileDropdown'; const superAdminScreen = (): JSX.Element => { const location = useLocation(); @@ -71,7 +71,10 @@ const superAdminScreen = (): JSX.Element => { export default superAdminScreen; -const map: any = { +const map: Record< + string, + 'orgList' | 'requests' | 'users' | 'memberDetail' | 'communityProfile' +> = { orglist: 'orgList', requests: 'requests', users: 'users', diff --git a/src/components/UserPortal/Login/Login.test.tsx b/src/components/UserPortal/Login/Login.test.tsx index f23399013c..9f2e30f9ee 100644 --- a/src/components/UserPortal/Login/Login.test.tsx +++ b/src/components/UserPortal/Login/Login.test.tsx @@ -61,13 +61,15 @@ const MOCKS = [ login: { user: { _id: '1', - userType: 'ADMIN', - adminApproved: false, firstName: 'firstname', lastName: 'secondname', email: 'tempemail@example.com', image: 'image', }, + appUserProfile: { + adminFor: {}, + isSuperAdmin: false, + }, accessToken: 'accessToken', refreshToken: 'refreshToken', }, diff --git a/src/components/UserPortal/StartPostModal/StartPostModal.test.tsx b/src/components/UserPortal/StartPostModal/StartPostModal.test.tsx index 4a8aa798f6..2b6ce6933d 100644 --- a/src/components/UserPortal/StartPostModal/StartPostModal.test.tsx +++ b/src/components/UserPortal/StartPostModal/StartPostModal.test.tsx @@ -72,7 +72,6 @@ const renderStartPostModal = ( lastName: 'dsza', email: 'glen@dsza.com', appLanguageCode: 'en', - userType: 'USER', pluginCreationAllowed: true, adminApproved: true, createdAt: '2023-02-18T09:22:27.969Z', diff --git a/src/screens/MemberDetail/MemberDetail.test.tsx b/src/screens/MemberDetail/MemberDetail.test.tsx index 3ac84a928c..3f56a20592 100644 --- a/src/screens/MemberDetail/MemberDetail.test.tsx +++ b/src/screens/MemberDetail/MemberDetail.test.tsx @@ -12,11 +12,6 @@ import { BrowserRouter } from 'react-router-dom'; import { Provider } from 'react-redux'; import { store } from 'state/store'; import { I18nextProvider } from 'react-i18next'; -import { - ADD_ADMIN_MUTATION, - UPDATE_USERTYPE_MUTATION, - UPDATE_USER_MUTATION, -} from 'GraphQl/Mutations/mutations'; import { USER_DETAILS } from 'GraphQl/Queries/Queries'; import i18nForTest from 'utils/i18nForTest'; import { StaticMockLink } from 'utils/StaticMockLink'; @@ -120,20 +115,6 @@ const MOCKS1 = [ }, }, }, - { - request: { - query: ADD_ADMIN_MUTATION, - variables: { - userid: '123', - orgid: '456', - }, - }, - result: { - data: { - success: true, - }, - }, - }, ]; const MOCKS2 = [ @@ -224,20 +205,6 @@ const MOCKS2 = [ }, }, }, - { - request: { - query: ADD_ADMIN_MUTATION, - variables: { - userid: '123', - orgid: '456', - }, - }, - result: { - data: { - success: true, - }, - }, - }, ]; const MOCKS3 = [ { @@ -327,20 +294,6 @@ const MOCKS3 = [ }, }, }, - { - request: { - query: ADD_ADMIN_MUTATION, - variables: { - userid: '123', - orgid: '456', - }, - }, - result: { - data: { - success: true, - }, - }, - }, ]; const link1 = new StaticMockLink(MOCKS1, true); diff --git a/src/screens/MemberDetail/MemberDetail.tsx b/src/screens/MemberDetail/MemberDetail.tsx index 520a965e65..cc12279438 100644 --- a/src/screens/MemberDetail/MemberDetail.tsx +++ b/src/screens/MemberDetail/MemberDetail.tsx @@ -28,7 +28,7 @@ import { maritalStatusEnum, genderEnum, employmentStatusEnum, -} from 'utils/memberFields'; +} from 'utils/formEnumFields'; import DynamicDropDown from 'components/DynamicDropDown/DynamicDropDown'; type MemberDetailProps = { diff --git a/src/screens/OrgSettings/OrgSettings.test.tsx b/src/screens/OrgSettings/OrgSettings.test.tsx index 445f85e248..f411bd68e1 100644 --- a/src/screens/OrgSettings/OrgSettings.test.tsx +++ b/src/screens/OrgSettings/OrgSettings.test.tsx @@ -112,7 +112,7 @@ describe('Organisation Settings Page', () => { test('should render props and text elements test for the screen', async () => { window.location.assign('/orgsetting/id=123'); - setItem('UserType', 'SUPERADMIN'); + setItem('SuperAdmin', true); render( @@ -140,7 +140,7 @@ describe('Organisation Settings Page', () => { test('should render appropriate settings based on the orgSetting state', async () => { window.location.assign('/orgsetting/id=123'); - setItem('UserType', 'SUPERADMIN'); + setItem('SuperAdmin', true); const { queryByText } = render( diff --git a/src/screens/OrganizationEvents/OrganizationEvents.tsx b/src/screens/OrganizationEvents/OrganizationEvents.tsx index ca24e10553..d87eef53e8 100644 --- a/src/screens/OrganizationEvents/OrganizationEvents.tsx +++ b/src/screens/OrganizationEvents/OrganizationEvents.tsx @@ -114,7 +114,13 @@ function organizationEvents(): JSX.Element { }); const userId = getItem('id') as string; - const userRole = getItem('UserType') as string; + const superAdmin = getItem('SuperAdmin'); + const adminFor = getItem('AdminFor'); + const userRole = superAdmin + ? 'SUPERADMIN' + : adminFor?.length > 0 + ? 'ADMIN' + : 'USER'; const [create, { loading: loading2 }] = useMutation(CREATE_EVENT_MUTATION); diff --git a/src/screens/Requests/Requests.test.tsx b/src/screens/Requests/Requests.test.tsx index ec34b98714..eb08beca82 100644 --- a/src/screens/Requests/Requests.test.tsx +++ b/src/screens/Requests/Requests.test.tsx @@ -69,7 +69,6 @@ describe('Testing Requests screen', () => { test(`Component should be rendered properly when user is not Admin and or userId does not exists in localstorage`, async () => { - setItem('UserType', 'SUPERADMIN'); setItem('id', ''); render( diff --git a/src/screens/UserPortal/Settings/Settings.test.tsx b/src/screens/UserPortal/Settings/Settings.test.tsx index c80c826d38..bc0487120a 100644 --- a/src/screens/UserPortal/Settings/Settings.test.tsx +++ b/src/screens/UserPortal/Settings/Settings.test.tsx @@ -65,7 +65,6 @@ const Mocks1 = [ mobile: '+174567890', }, image: 'https://api.dicebear.com/5.x/initials/svg?seed=John%20Doe', - userType: 'user', _id: '65ba1621b7b00c20e5f1d8d2', }, }, @@ -98,7 +97,6 @@ const Mocks2 = [ mobile: '', }, image: '', - userType: 'user', _id: '65ba1621b7b00c20e5f1d8d2', }, }, diff --git a/src/utils/formEnumFields.ts b/src/utils/formEnumFields.ts index 2620e7ad58..928537aaab 100644 --- a/src/utils/formEnumFields.ts +++ b/src/utils/formEnumFields.ts @@ -323,10 +323,30 @@ const employmentStatusEnum = [ }, ]; +const userRoleEnum = [ + { + value: 'USER', + label: 'User', + }, + { + value: 'ADMIN', + label: 'Admin', + }, + { + value: 'SUPERADMIN', + label: 'Super Admin', + }, + { + value: 'NON_USER', + label: 'Non-User', + }, +]; + export { countryOptions, educationGradeEnum, maritalStatusEnum, genderEnum, employmentStatusEnum, + userRoleEnum, }; diff --git a/src/utils/interfaces.ts b/src/utils/interfaces.ts index f753b48fc4..fa7b1b523f 100644 --- a/src/utils/interfaces.ts +++ b/src/utils/interfaces.ts @@ -324,16 +324,6 @@ export interface InterfaceQueryVenueListItem { capacity: string; } -export interface InterfaceQueryRequestListItem { - _id: string; - firstName: string; - lastName: string; - image: string | null; - email: string; - userType: string; - createdAt: string; -} - export interface InterfaceAddress { city: string; countryCode: string; diff --git a/src/utils/memberFields.ts b/src/utils/memberFields.ts deleted file mode 100644 index 440dbfcf4c..0000000000 --- a/src/utils/memberFields.ts +++ /dev/null @@ -1,149 +0,0 @@ -const educationGradeEnum = [ - { - value: 'NO_GRADE', - label: 'No Grade', - }, - { - value: 'PRE_KG', - label: 'Pre-KG', - }, - { - value: 'KG', - label: 'KG', - }, - { - value: 'GRADE_1', - label: 'Grade 1', - }, - { - value: 'GRADE_2', - label: 'Grade 2', - }, - { - value: 'GRADE_3', - label: 'Grade 3', - }, - { - value: 'GRADE_4', - label: 'Grade 4', - }, - { - value: 'GRADE_5', - label: 'Grade 5', - }, - { - value: 'GRADE_6', - label: 'Grade 6', - }, - { - value: 'GRADE_7', - label: 'Grade 7', - }, - { - value: 'GRADE_8', - label: 'Grade 8', - }, - { - value: 'GRADE_9', - label: 'Grade 9', - }, - { - value: 'GRADE_10', - label: 'Grade 10', - }, - { - value: 'GRADE_11', - label: 'Grade 11', - }, - { - value: 'GRADE_12', - label: 'Grade 12', - }, - { - value: 'GRADUATE', - label: 'Graduate', - }, -]; - -const maritalStatusEnum = [ - { - value: 'SINGLE', - label: 'Single', - }, - { - value: 'ENGAGED', - label: 'Engaged', - }, - { - value: 'MARRIED', - label: 'Married', - }, - { - value: 'DIVORCED', - label: 'Divorced', - }, - { - value: 'WIDOWED', - label: 'Widowed', - }, - { - value: 'SEPARATED', - label: 'Separated', - }, -]; - -const genderEnum = [ - { - value: 'MALE', - label: 'Male', - }, - { - value: 'FEMALE', - label: 'Female', - }, - { - value: 'OTHER', - label: 'Other', - }, -]; - -const employmentStatusEnum = [ - { - value: 'FULL_TIME', - label: 'Full Time', - }, - { - value: 'PART_TIME', - label: 'Part Time', - }, - { - value: 'UNEMPLOYED', - label: 'Unemployed', - }, -]; -const userTypeEnum = [ - { - value: 'USER', - label: 'User', - }, - { - value: 'ADMIN', - label: 'Admin', - }, - { - value: 'SUPERADMIN', - label: 'Super Admin', - }, - { - value: 'NON_USER', - label: 'Non-User', - }, -]; - -export { - educationGradeEnum, - maritalStatusEnum, - genderEnum, - employmentStatusEnum, - userTypeEnum, -};