Skip to content

Commit

Permalink
UIU-2967 Don't display affiliations of users with types 'patron' or '…
Browse files Browse the repository at this point in the history
…dbc'
  • Loading branch information
usavkov-epam committed Oct 16, 2023
1 parent 5ba9643 commit d7b7313
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [11.0.0] IN PROGRESS

* Don't display affiliations of users with types `patron` or `dbc`. Refs UIU-2967.

## [10.0.0](https://github.com/folio-org/ui-users/tree/v10.0.0) (2023-10-13)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v9.0.3...v10.0.0)

Expand Down
4 changes: 3 additions & 1 deletion src/components/PermissionsAccordion/PermissionsAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import EnableUnassignAll from './EnableUnassignAll';
import AffiliationsSelect from '../AffiliationsSelect';
import IfConsortium from '../IfConsortium';
import IfConsortiumPermission from '../IfConsortiumPermission';
import { isAffiliationsEnabled } from '../util';

const PermissionsAccordion = (props) => {
const {
Expand Down Expand Up @@ -57,6 +58,7 @@ const PermissionsAccordion = (props) => {

const isAllowedPermissions = !!getAssignedPermissions().length;
const isActionsDisabled = disabled || isLoading;
const isAffiliationsVisible = isAffiliationsEnabled(props.initialValues) && affiliations?.length > 1;

const [permissionModalOpen, setPermissionModalOpen] = useState(false);
const [unassignModalOpen, setUnassignModalOpen] = useState(false);
Expand Down Expand Up @@ -186,7 +188,7 @@ const PermissionsAccordion = (props) => {
>
<IfConsortium>
<IfConsortiumPermission perm="consortia.user-tenants.collection.get">
{affiliations?.length > 1 && (
{isAffiliationsVisible && (
<AffiliationsSelect
affiliations={affiliations}
onChange={onChangeAffiliation}
Expand Down
8 changes: 8 additions & 0 deletions src/components/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import queryString from 'query-string';
import { NoValue } from '@folio/stripes/components';

import {
USER_TYPES,
requestStatuses,
sortTypes,
} from '../../constants';
Expand Down Expand Up @@ -199,3 +200,10 @@ export const getRequestUrl = (barcode, userId) => {
userId,
})}`;
};

export const isPatronUser = (user) => user?.type === USER_TYPES.PATRON;
export const isDcbUser = (user) => user?.type === USER_TYPES.DCB;

export const isAffiliationsEnabled = (user) => {
return !isPatronUser(user) && !isDcbUser(user);
};
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,5 @@ export const USER_TYPES = {
SHADOW: 'shadow',
STAFF: 'staff',
SYSTEM: 'system',
DCB: 'dcb',
};
9 changes: 7 additions & 2 deletions src/hooks/useUserAffiliations/useUserAffiliations.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const useUserAffiliations = ({ userId } = {}, options = {}) => {

const consortium = stripes?.user?.user?.consortium;
const currentUserTenants = stripes?.user?.user?.tenants;
const { assignedToCurrentUser, ...queryOptions } = options;
const {
assignedToCurrentUser,
enabled: enabledOption = true,
...queryOptions
} = options;

const searchParams = {
userId,
Expand All @@ -42,7 +46,8 @@ const useUserAffiliations = ({ userId } = {}, options = {}) => {
const enabled = Boolean(
consortium?.centralTenantId
&& consortium?.id
&& userId,
&& userId
&& enabledOption,
);

const {
Expand Down
9 changes: 6 additions & 3 deletions src/views/UserDetail/UserDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ import HelperApp from '../../components/HelperApp';
import IfConsortium from '../../components/IfConsortium';
import { PatronBlockMessage } from '../../components/PatronBlock';
import { getFormAddressList } from '../../components/data/converters/address';
import { getFullName } from '../../components/util';
import {
getFullName,
isAffiliationsEnabled,
} from '../../components/util';
import RequestFeeFineBlockButtons from '../../components/RequestFeeFineBlockButtons';
import { departmentsShape } from '../../shapes';
import ErrorPane from '../../components/ErrorPane';
Expand Down Expand Up @@ -618,7 +621,7 @@ class UserDetail extends React.Component {
const userDepartments = (user?.departments || [])
.map(departmentId => departments.find(({ id }) => id === departmentId)?.name);
const accounts = resources?.accounts;
const isAffiliationEnabled = user?.type !== USER_TYPES.PATRON;
const isAffiliationsVisible = isAffiliationsEnabled(user);

const isShadowUser = user?.type === USER_TYPES.SHADOW;
const showPatronBlocksSection = hasPatronBlocksPermissions && !isShadowUser;
Expand Down Expand Up @@ -704,7 +707,7 @@ class UserDetail extends React.Component {
<IfConsortium>
<IfConsortiumPermission perm="consortia.user-tenants.collection.get">
{
isAffiliationEnabled && (
isAffiliationsVisible && (
<UserAffiliations
accordionId="affiliationsSection"
expanded={sections.affiliationsSection}
Expand Down
2 changes: 2 additions & 0 deletions src/views/UserEdit/TenantsPermissionsAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
statusFilterConfig,
permissionTypeFilterConfig,
} from '../../components/PermissionsAccordion/helpers/filtersConfig';
import { isAffiliationsEnabled } from '../../components/util';
import {
useUserAffiliations,
useUserTenantPermissions,
Expand Down Expand Up @@ -93,6 +94,7 @@ const TenantsPermissionsAccordion = ({
} = useUserAffiliations(
{ userId },
{
enabled: isAffiliationsEnabled(initialValues),
onError: handleLoadAffiliationsError
},
);
Expand Down

0 comments on commit d7b7313

Please sign in to comment.