diff --git a/src/GraphQl/Mutations/mutations.ts b/src/GraphQl/Mutations/mutations.ts index 2c685bc85a..37f8489597 100644 --- a/src/GraphQl/Mutations/mutations.ts +++ b/src/GraphQl/Mutations/mutations.ts @@ -411,12 +411,6 @@ export const FORGOT_PASSWORD_MUTATION = gql` } `; -export const UPDATE_USERTYPE_MUTATION = gql` - mutation UpdateUserType($id: ID!, $userType: String!) { - updateUserType(data: { id: $id, userType: $userType }) - } -`; - /** * {@label UPDATE_INSTALL_STATUS_PLUGIN_MUTATION} * @remarks diff --git a/src/GraphQl/Queries/Queries.ts b/src/GraphQl/Queries/Queries.ts index 740e153a7f..00424d38b5 100644 --- a/src/GraphQl/Queries/Queries.ts +++ b/src/GraphQl/Queries/Queries.ts @@ -368,6 +368,7 @@ export const ORGANIZATIONS_LIST = gql` firstName lastName email + createdAt } membershipRequests { _id diff --git a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx index 5a4de2470a..2810048678 100644 --- a/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx +++ b/src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx @@ -126,6 +126,7 @@ const MOCKS = [ firstName: 'John', lastName: 'Doe', email: 'JohnDoe@example.com', + createdAt: '12-03-2024', }, ], membershipRequests: [], @@ -189,6 +190,7 @@ const MOCKS_WITH_IMAGE = [ firstName: 'John', lastName: 'Doe', email: 'JohnDoe@example.com', + createdAt: '12-03-2024', }, ], membershipRequests: [], diff --git a/src/components/OrgAdminListCard/OrgAdminListCard.tsx b/src/components/OrgAdminListCard/OrgAdminListCard.tsx index 251bbc12da..6d60af9338 100644 --- a/src/components/OrgAdminListCard/OrgAdminListCard.tsx +++ b/src/components/OrgAdminListCard/OrgAdminListCard.tsx @@ -3,11 +3,7 @@ import Button from 'react-bootstrap/Button'; import Modal from 'react-bootstrap/Modal'; import { useMutation } from '@apollo/client'; import { toast } from 'react-toastify'; - -import { - REMOVE_ADMIN_MUTATION, - UPDATE_USERTYPE_MUTATION, -} from 'GraphQl/Mutations/mutations'; +import { REMOVE_ADMIN_MUTATION } from 'GraphQl/Mutations/mutations'; import { useTranslation } from 'react-i18next'; import { Navigate, useParams } from 'react-router-dom'; import { errorHandler } from 'utils/errorHandler'; @@ -23,7 +19,6 @@ function orgAdminListCard(props: InterfaceOrgPeopleListCardProps): JSX.Element { } const { orgId: currentUrl } = useParams(); const [remove] = useMutation(REMOVE_ADMIN_MUTATION); - const [updateUserType] = useMutation(UPDATE_USERTYPE_MUTATION); const { t } = useTranslation('translation', { keyPrefix: 'orgAdminListCard', @@ -31,32 +26,17 @@ function orgAdminListCard(props: InterfaceOrgPeopleListCardProps): JSX.Element { const removeAdmin = async (): Promise => { try { - const { data } = await updateUserType({ + const { data } = await remove({ variables: { - id: props.id, - userType: 'USER', + userid: props.id, + orgid: currentUrl, }, }); - - /* istanbul ignore next */ if (data) { - try { - const { data } = await remove({ - variables: { - userid: props.id, - orgid: currentUrl, - }, - }); - if (data) { - toast.success(t('adminRemoved')); - setTimeout(() => { - window.location.reload(); - }, 2000); - } - } catch (error: unknown) { - /* istanbul ignore next */ - errorHandler(t, error); - } + toast.success(t('adminRemoved')); + setTimeout(() => { + window.location.reload(); + }, 2000); } } catch (error: unknown) { /* istanbul ignore next */ diff --git a/src/components/OrgUpdate/OrgUpdateMocks.ts b/src/components/OrgUpdate/OrgUpdateMocks.ts index 76cef50710..4c7f704719 100644 --- a/src/components/OrgUpdate/OrgUpdateMocks.ts +++ b/src/components/OrgUpdate/OrgUpdateMocks.ts @@ -44,6 +44,7 @@ export const MOCKS = [ firstName: 'John', lastName: 'Doe', email: 'johndoe@gmail.com', + createdAt: '12-03-2024', }, ], membershipRequests: { @@ -159,6 +160,7 @@ export const MOCKS_ERROR_UPDATE_ORGLIST = [ firstName: 'John', lastName: 'Doe', email: 'johndoe@gmail.com', + createdAt: '12-03-2024', }, ], membershipRequests: { diff --git a/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts b/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts index 146391e74d..d3a686653c 100644 --- a/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts +++ b/src/screens/OrganizationDashboard/OrganizationDashboardMocks.ts @@ -48,6 +48,7 @@ export const MOCKS = [ firstName: 'John', lastName: 'Doe', email: 'johndoe@gmail.com', + createdAt: '12-03-2024', }, ], membershipRequests: [ @@ -274,6 +275,7 @@ export const EMPTY_MOCKS = [ firstName: 'John', lastName: 'Doe', email: 'johndoe@gmail.com', + createdAt: '12-03-2024', }, ], membershipRequests: [], diff --git a/src/screens/OrganizationPeople/OrganizationPeople.test.tsx b/src/screens/OrganizationPeople/OrganizationPeople.test.tsx index e458766666..545cddcb74 100644 --- a/src/screens/OrganizationPeople/OrganizationPeople.test.tsx +++ b/src/screens/OrganizationPeople/OrganizationPeople.test.tsx @@ -226,6 +226,7 @@ const MOCKS: TestMock[] = [ firstName: 'firstName', lastName: 'lastName', email: 'email', + createdAt: '12-03-2024', }, ], membershipRequests: [ diff --git a/src/screens/OrganizationPeople/OrganizationPeople.tsx b/src/screens/OrganizationPeople/OrganizationPeople.tsx index 9a3cee8b06..62be3becaf 100644 --- a/src/screens/OrganizationPeople/OrganizationPeople.tsx +++ b/src/screens/OrganizationPeople/OrganizationPeople.tsx @@ -1,6 +1,7 @@ import { useLazyQuery } from '@apollo/client'; import { Search, Sort } from '@mui/icons-material'; import { + ORGANIZATIONS_LIST, ORGANIZATIONS_MEMBER_CONNECTION_LIST, USER_LIST_FOR_TABLE, } from 'GraphQl/Queries/Queries'; @@ -39,6 +40,7 @@ function organizationPeople(): JSX.Element { firstName_contains: '', lastName_contains: '', }); + const [adminFilteredData, setAdminFilteredData] = useState(); const [userName, setUserName] = useState(''); const [showRemoveModal, setShowRemoveModal] = React.useState(false); @@ -80,12 +82,9 @@ function organizationPeople(): JSX.Element { loading: adminLoading, error: adminError, refetch: adminRefetch, - } = useLazyQuery(ORGANIZATIONS_MEMBER_CONNECTION_LIST, { + } = useLazyQuery(ORGANIZATIONS_LIST, { variables: { - firstName_contains: '', - lastName_contains: '', - orgId: currentUrl, - admin_for: currentUrl, + id: currentUrl, }, })[1]; @@ -109,16 +108,15 @@ function organizationPeople(): JSX.Element { }); } else if (state === 1) { adminRefetch({ - ...filterData, - orgId: currentUrl, - admin_for: currentUrl, + id: currentUrl, }); + setAdminFilteredData(adminData?.organizations[0].admins); } else { usersRefetch({ ...filterData, }); } - }, [state]); + }, [state, adminData]); /* istanbul ignore next */ if (memberError || usersError || adminError) { @@ -150,11 +148,19 @@ function organizationPeople(): JSX.Element { orgId: currentUrl, }); } else if (state === 1) { - adminRefetch({ - ...newFilterData, - orgId: currentUrl, - admin_for: currentUrl, - }); + const filterData = adminData.organizations[0].admins.filter( + (value: { + _id: string; + firstName: string; + lastName: string; + createdAt: string; + }) => { + return (value.firstName + value.lastName) + .toLowerCase() + .includes(userName.toLowerCase()); + }, + ); + setAdminFilteredData(filterData); } else { usersRefetch({ ...newFilterData, @@ -348,7 +354,7 @@ function organizationPeople(): JSX.Element { {((state == 0 && memberData) || - (state == 1 && adminData) || + (state == 1 && adminFilteredData) || (state == 2 && usersData)) && (