Skip to content

Commit

Permalink
fixed people screen filter
Browse files Browse the repository at this point in the history
  • Loading branch information
kanhaiya04 committed Apr 14, 2024
1 parent 2da9090 commit c0db9f4
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 50 deletions.
6 changes: 0 additions & 6 deletions src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/GraphQl/Queries/Queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export const ORGANIZATIONS_LIST = gql`
firstName
lastName
email
createdAt
}
membershipRequests {
_id
Expand Down
2 changes: 2 additions & 0 deletions src/components/LeftDrawerOrg/LeftDrawerOrg.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const MOCKS = [
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
createdAt: '12-03-2024',
},
],
membershipRequests: [],
Expand Down Expand Up @@ -189,6 +190,7 @@ const MOCKS_WITH_IMAGE = [
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
createdAt: '12-03-2024',
},
],
membershipRequests: [],
Expand Down
36 changes: 8 additions & 28 deletions src/components/OrgAdminListCard/OrgAdminListCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -23,40 +19,24 @@ 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',
});

const removeAdmin = async (): Promise<void> => {
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 */
Expand Down
2 changes: 2 additions & 0 deletions src/components/OrgUpdate/OrgUpdateMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const MOCKS = [
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
createdAt: '12-03-2024',
},
],
membershipRequests: {
Expand Down Expand Up @@ -159,6 +160,7 @@ export const MOCKS_ERROR_UPDATE_ORGLIST = [
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
createdAt: '12-03-2024',
},
],
membershipRequests: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const MOCKS = [
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
createdAt: '12-03-2024',
},
],
membershipRequests: [
Expand Down Expand Up @@ -274,6 +275,7 @@ export const EMPTY_MOCKS = [
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
createdAt: '12-03-2024',
},
],
membershipRequests: [],
Expand Down
1 change: 1 addition & 0 deletions src/screens/OrganizationPeople/OrganizationPeople.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ const MOCKS: TestMock[] = [
firstName: 'firstName',
lastName: 'lastName',
email: 'email',
createdAt: '12-03-2024',
},
],
membershipRequests: [
Expand Down
38 changes: 22 additions & 16 deletions src/screens/OrganizationPeople/OrganizationPeople.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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];

Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -348,7 +354,7 @@ function organizationPeople(): JSX.Element {
</div>
</Row>
{((state == 0 && memberData) ||
(state == 1 && adminData) ||
(state == 1 && adminFilteredData) ||
(state == 2 && usersData)) && (
<div className="datatable">
<DataGrid
Expand Down Expand Up @@ -389,7 +395,7 @@ function organizationPeople(): JSX.Element {
state === 0
? memberData.organizationsMemberConnection.edges
: state === 1
? adminData.organizationsMemberConnection.edges
? adminFilteredData
: convertObject(usersData)
}
columns={columns}
Expand Down
1 change: 1 addition & 0 deletions src/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface InterfaceQueryOrganizationsListObject {
firstName: string;
lastName: string;
email: string;
createdAt: string;
}[];
membershipRequests: {
_id: string;
Expand Down

0 comments on commit c0db9f4

Please sign in to comment.