diff --git a/packages/esm-admin-app/src/components/users/manage-users/user-management.workspace.tsx b/packages/esm-admin-app/src/components/users/manage-users/user-management.workspace.tsx index 9a88fd7a..98de44a6 100644 --- a/packages/esm-admin-app/src/components/users/manage-users/user-management.workspace.tsx +++ b/packages/esm-admin-app/src/components/users/manage-users/user-management.workspace.tsx @@ -49,10 +49,11 @@ import { } from '../../../user-management.resources'; import UserManagementFormSchema from '../userManagementFormSchema'; import { CardHeader } from '@openmrs/esm-patient-common-lib/src'; -import { ChevronSortUp } from '@carbon/react/icons'; +import { ChevronSortUp, ChevronRight } from '@carbon/react/icons'; import { useSystemUserRoleConfigSetting } from '../../hook/useSystemRoleSetting'; import { Provider, User, UserRoleScope } from '../../../config-schema'; import { DATE_PICKER_CONTROL_FORMAT, DATE_PICKER_FORMAT, formatForDatePicker, today } from '../../../constants'; +import { ResourceRepresentation } from '../../../api'; type ManageUserWorkspaceProps = DefaultWorkspaceProps & { initialUserValue?: User; @@ -73,7 +74,10 @@ const ManageUserWorkspace: React.FC = ({ const { provider = [], loadingProvider, providerError } = useProvider(initialUserValue.systemId); const { location, loadingLocation } = useLocation(); - const { items, loadingRoleScope, userRoleScopeError } = useUserRoleScopes(); + const { items, loadingRoleScope, userRoleScopeError } = useUserRoleScopes({ + v: ResourceRepresentation.Default, + totalCount: true, + }); const { userManagementFormSchema } = UserManagementFormSchema(); const { @@ -88,6 +92,9 @@ const ManageUserWorkspace: React.FC = ({ const { roles = [], isLoading } = useRoles(); const { rolesConfig, error } = useSystemUserRoleConfigSetting(); const { attributeTypes = [] } = usePersonAttribute(); + + const userRoleScope = items.results.find((user) => user.userUuid === initialUserValue.uuid); + // Memoize provider attribute mappings const attributeTypeMapping = useMemo(() => { return { @@ -143,6 +150,20 @@ const ManageUserWorkspace: React.FC = ({ providerLicense: providerLicenseNumber, licenseExpiryDate: licenseExpiryDate, primaryFacility: primaryFacility, + stockOperations: + userRoleScope.operationTypes?.map((op) => ({ + operationTypeName: op.operationTypeName, + operationTypeUuid: op.operationTypeUuid, + })) || [], + operationLocation: + userRoleScope.locations?.map((loc) => ({ + locationName: loc.locationName, + locationUuid: loc.locationUuid, + })) || [], + permanent: userRoleScope.permanent, + enabled: userRoleScope.enabled, + activeTo: userRoleScope.activeTo, + activeFrom: userRoleScope.activeFrom, }; }, [isInitialValuesEmpty, initialUserValue, providerLicenseNumber, licenseExpiryDate, primaryFacility]); @@ -263,7 +284,9 @@ const ManageUserWorkspace: React.FC = ({ if (userRoleScopePayload && Object.keys(userRoleScopePayload).length > 0) { try { - const userRoleScopeUrl = `${restBaseUrl}/stockmanagement/userrolescope`; + const userRoleScopeUrl = data.isEditUseRoleScope + ? `${restBaseUrl}/stockmanagement/userrolescope/${userRoleScope.uuid}` + : `${restBaseUrl}/stockmanagement/userrolescope`; const userUuid = response.uuid; const userRoleScopeResponse = await createOrUpdateUserRoleScope( @@ -273,6 +296,7 @@ const ManageUserWorkspace: React.FC = ({ ); if (userRoleScopeResponse.ok) { + handleMutation(`${restBaseUrl}/stockmanagement/userrolescope`); showSnackbarMessage(t('userRoleScopeSaved', 'User role scope saved successfully'), '', 'success'); } } catch (error) { @@ -487,6 +511,20 @@ const ManageUserWorkspace: React.FC = ({ )} /> + + +