diff --git a/app/package.json b/app/package.json
index 5163622b0..76abec9d3 100644
--- a/app/package.json
+++ b/app/package.json
@@ -5,6 +5,7 @@
"dependencies": {
"@2fd/ant-design-icons": "^2.6.0",
"@ant-design/icons": "^4.7.0",
+ "@ant-design/pro-components": "^2.6.32",
"@onaio/connected-private-route": "^0.0.11",
"@onaio/connected-reducer-registry": "^0.0.3",
"@onaio/gatekeeper": "1.0.0",
diff --git a/app/src/App/fhir-apps.tsx b/app/src/App/fhir-apps.tsx
index 7e05e1926..3df5289a7 100644
--- a/app/src/App/fhir-apps.tsx
+++ b/app/src/App/fhir-apps.tsx
@@ -63,6 +63,8 @@ import {
import {
CreateEditUser as FHIRConnectedCreateEditUser,
UserList as FhirUserList,
+ USER_DETAILS_URL,
+ UserDetailsV2,
} from '@opensrp/fhir-user-management';
import { Home } from '../containers/pages/Home/Home';
import {
@@ -224,6 +226,14 @@ const FHIRApps = () => {
permissions={['iam_user.read']}
component={FhirUserList}
/>
+
void;
+ keycloakBaseUrl: string;
+ fhirBaseUrl: string;
+ resourceId: string;
+}
+
+export const UserDeleteBtn = (props: UserDeleteBtnProp) => {
+ const { afterActions, keycloakBaseUrl, fhirBaseUrl, resourceId } = props;
+ const { t } = useTranslation();
+ const queryClient = useQueryClient();
+
+ return (
+ {
+ await deleteUser(keycloakBaseUrl, fhirBaseUrl, resourceId, t);
+ try {
+ return await queryClient.invalidateQueries({
+ queryKey: [KEYCLOAK_URL_USERS],
+ exact: true,
+ });
+ } catch {
+ return sendErrorNotification(
+ t('Failed to update data, please refresh the page to see the most recent changes')
+ );
+ } finally {
+ afterActions?.();
+ }
+ }}
+ >
+
+ {t('Delete')}
+
+
+ );
+};
diff --git a/packages/fhir-keycloak-user-management/src/components/UserList/ListView/index.tsx b/packages/fhir-keycloak-user-management/src/components/UserList/ListView/index.tsx
index e9aee11be..da7450196 100644
--- a/packages/fhir-keycloak-user-management/src/components/UserList/ListView/index.tsx
+++ b/packages/fhir-keycloak-user-management/src/components/UserList/ListView/index.tsx
@@ -6,8 +6,6 @@ import {
TableLayout,
BrokenPage,
searchQuery,
- useSearchParams,
- viewDetailsQuery,
} from '@opensrp/react-utils';
import { PlusOutlined } from '@ant-design/icons';
import { URL_USER_CREATE, KEYCLOAK_URL_USERS } from '@opensrp/user-management';
@@ -20,8 +18,6 @@ import { PageHeader } from '@opensrp/react-utils';
import { getExtraData } from '@onaio/session-reducer';
import { KeycloakUser } from '@opensrp/user-management';
import { useSelector } from 'react-redux';
-import { ViewDetailsWrapper } from '../ViewDetails';
-import { useQueryClient } from 'react-query';
import { useTranslation } from '@opensrp/i18n';
import { RbacCheck, useUserRole } from '@opensrp/rbac';
@@ -41,13 +37,9 @@ export const UserList = (props: OrganizationListProps) => {
const history = useHistory();
const match = useRouteMatch();
const extraData = useSelector(getExtraData);
- const queryClient = useQueryClient();
const { t } = useTranslation();
const userRole = useUserRole();
- const { sParams, addParam } = useSearchParams();
- const resourceId = sParams.get(viewDetailsQuery) ?? undefined;
-
const { isLoading, data, error, isFetching } = useQuery([KEYCLOAK_URL_USERS], () =>
loadKeycloakResources(keycloakBaseURL, KEYCLOAK_URL_USERS)
);
@@ -77,17 +69,7 @@ export const UserList = (props: OrganizationListProps) => {
};
});
- const onViewDetails = (resourceId: string) => addParam(viewDetailsQuery, resourceId);
- const columns = getTableColumns(
- keycloakBaseURL,
- fhirBaseURL,
- extraData,
- queryClient,
- t,
- onViewDetails,
- userRole,
- history
- );
+ const columns = getTableColumns(keycloakBaseURL, fhirBaseURL, extraData, t, userRole, history);
const searchFormProps = {
defaultValue: getQueryParams(location)[searchQuery],
@@ -134,11 +116,6 @@ export const UserList = (props: OrganizationListProps) => {
-
);
diff --git a/packages/fhir-keycloak-user-management/src/components/UserList/ListView/tableColumns.tsx b/packages/fhir-keycloak-user-management/src/components/UserList/ListView/tableColumns.tsx
index ea57d13ae..613c67f1d 100644
--- a/packages/fhir-keycloak-user-management/src/components/UserList/ListView/tableColumns.tsx
+++ b/packages/fhir-keycloak-user-management/src/components/UserList/ListView/tableColumns.tsx
@@ -1,22 +1,16 @@
import * as React from 'react';
-import { Popconfirm, Divider, Dropdown, Button } from 'antd';
+import { Divider, Dropdown, Button } from 'antd';
import type { MenuProps } from 'antd';
import { MoreOutlined } from '@ant-design/icons';
-import { deleteUser } from './utils';
import { Link } from 'react-router-dom';
-import {
- KeycloakUser,
- URL_USER_EDIT,
- KEYCLOAK_URL_USERS,
- URL_USER_CREDENTIALS,
-} from '@opensrp/user-management';
+import { KeycloakUser, URL_USER_EDIT, URL_USER_CREDENTIALS } from '@opensrp/user-management';
import { Dictionary } from '@onaio/utils';
import { Column } from '@opensrp/react-utils';
-import { sendErrorNotification } from '@opensrp/notifications';
-import { QueryClient } from 'react-query';
import type { TFunction } from '@opensrp/i18n';
import { RbacCheck, UserRole } from '@opensrp/rbac';
import { History } from 'history';
+import { UserDeleteBtn } from '../../UserDeleteBtn';
+import { USER_DETAILS_URL } from '../../../constants';
/**
* Get table columns for user list
@@ -24,9 +18,7 @@ import { History } from 'history';
* @param keycloakBaseUrl - keycloak base url
* @param baseUrl - server base url
* @param extraData - session data about logged in user
- * @param queryClient - react query client
* @param t - translator function
- * @param onViewDetails - callback when view details is clicked.
* @param userRole - role of logged in user.
* @param history - history object for managing navigation
*/
@@ -34,9 +26,7 @@ export const getTableColumns = (
keycloakBaseUrl: string,
baseUrl: string,
extraData: Dictionary,
- queryClient: QueryClient,
t: TFunction,
- onViewDetails: (recordId: string) => void,
userRole: UserRole,
history: History
): Column[] => {
@@ -61,44 +51,16 @@ export const getTableColumns = (
});
const getItems = (record: KeycloakUser): MenuProps['items'] => {
- return [
+ const items = [
{
key: '1',
- permissions: [],
+ permissions: ['iam_user.read'],
label: (
- onViewDetails(record.id)} type="link">
+ history.push(`${USER_DETAILS_URL}/${record.id}`)} type="link">
{t('View Details')}
),
},
- {
- key: '2',
- permissions: ['iam_user.delete'],
- label: (
- {
- await deleteUser(keycloakBaseUrl, baseUrl, record.id, t);
- try {
- return await queryClient.invalidateQueries([KEYCLOAK_URL_USERS]);
- } catch {
- return sendErrorNotification(
- t('Failed to update data, please refresh the page to see the most recent changes')
- );
- }
- }}
- >
- {user_id &&
- (record.id === user_id ? null : (
-
- {t('Delete')}
-
- ))}
-
- ),
- },
{
key: '3',
permissions: ['iam_user.update'],
@@ -114,7 +76,22 @@ export const getTableColumns = (
),
},
- ]
+ ];
+ // don't show delete for the current logged in user - back compatibility reasons.
+ if (user_id && record.id !== user_id) {
+ items.push({
+ key: '2',
+ permissions: ['iam_user.delete'],
+ label: (
+
+ ),
+ });
+ }
+ return items
.filter((item) => userRole.hasPermissions(item.permissions))
.map((item) => {
const { permissions, ...rest } = item;
diff --git a/packages/fhir-keycloak-user-management/src/components/UserList/ListView/tests/__snapshots__/index.test.tsx.snap b/packages/fhir-keycloak-user-management/src/components/UserList/ListView/tests/__snapshots__/index.test.tsx.snap
index e94011a45..683c4ba37 100644
--- a/packages/fhir-keycloak-user-management/src/components/UserList/ListView/tests/__snapshots__/index.test.tsx.snap
+++ b/packages/fhir-keycloak-user-management/src/components/UserList/ListView/tests/__snapshots__/index.test.tsx.snap
@@ -1,5 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`View details navigates correctly: Header title 1`] = `
+
+`;
+
exports[`renders correctly when listing resources: Header title 1`] = `