From 692a607e804c1153f88fb142d62d8743cf6a6c4b Mon Sep 17 00:00:00 2001 From: Alisher Musurmonov Date: Mon, 18 Sep 2023 18:19:24 +0500 Subject: [PATCH] UIU-2942: Assign/unassign a users affiliations adjustments --- CHANGELOG.md | 1 + .../AffiliationsManagerModal.js | 8 +++- .../useAffiliationsAssignment.js | 6 ++- src/views/UserDetail/UserDetail.js | 44 +++++++++---------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b6de427b..01212fc94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ * Add dropdown to specify user type: Patron or Staff. Refs UIU-2936. * *BREAKING* bump `react-intl` to `v6.4.4`. Refs UIU-2946. * Generate "Create request" url for users without barcode. Refs UIU-2869. +* Assign/unassign a users affiliations adjustments. Refs UIU-2942. ## [9.0.0](https://github.com/folio-org/ui-users/tree/v9.0.0) (2023-02-20) [Full Changelog](https://github.com/folio-org/ui-users/compare/v8.1.0...v9.0.0) diff --git a/src/components/AffiliationsManager/AffiliationsManagerModal/AffiliationsManagerModal.js b/src/components/AffiliationsManager/AffiliationsManagerModal/AffiliationsManagerModal.js index e35fc1a44..8cb9be4fc 100644 --- a/src/components/AffiliationsManager/AffiliationsManagerModal/AffiliationsManagerModal.js +++ b/src/components/AffiliationsManager/AffiliationsManagerModal/AffiliationsManagerModal.js @@ -115,12 +115,16 @@ const AffiliationManagerModal = ({ onClose, onSubmit, userId }) => { orderBy( filtersConfig .reduce((filtered, config) => config.filter(filtered, activeFilters, assignment), tenants) - .filter(({ name }) => (searchQuery ? name.toLowerCase().includes(searchQuery.toLowerCase()) : true)), + .filter(({ name, isCentral, id }) => { + if (isCentral || !affiliationIds.includes(id)) return false; + + return (searchQuery ? name.toLowerCase().includes(searchQuery.toLowerCase()) : true); + }), sorters[sortOrder], sortDirection.name, ) ); - }, [assignment, filters, sortDirection.name, sortOrder, sorters, tenants]); + }, [affiliationIds, assignment, filters, sortDirection.name, sortOrder, sorters, tenants]); return ( { setAssignment(() => { const affiliationsMap = keyBy(affiliations, 'tenantId'); - return tenants.reduce((acc, { id }) => { - acc[id] = Boolean(affiliationsMap[id]); + return tenants.reduce((acc, { id, isCentral }) => { + if (!isCentral) { + acc[id] = Boolean(affiliationsMap[id]); + } return acc; }, {}); diff --git a/src/views/UserDetail/UserDetail.js b/src/views/UserDetail/UserDetail.js index d28be72b5..f547abf62 100644 --- a/src/views/UserDetail/UserDetail.js +++ b/src/views/UserDetail/UserDetail.js @@ -50,29 +50,22 @@ import { UserAffiliations, UserServicePoints, } from '../../components/UserDetailSections'; - 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 { PatronBlockMessage } from '../../components/PatronBlock'; +import { getFormAddressList } from '../../components/data/converters/address'; +import { getFullName } from '../../components/util'; import RequestFeeFineBlockButtons from '../../components/RequestFeeFineBlockButtons'; import { departmentsShape } from '../../shapes'; - -import OpenTransactionModal from './components/OpenTransactionModal'; -import DeleteUserModal from './components/DeleteUserModal'; -import ExportFeesFinesReportButton from './components'; import ErrorPane from '../../components/ErrorPane'; -import ActionMenuEditButton from './components/ActionMenuEditButton'; -import ActionMenuDeleteButton from './components/ActionMenuDeleteButton'; import LostItemsLink from '../../components/LostItemsLink'; import IfConsortiumPermission from '../../components/IfConsortiumPermission'; +import { USER_TYPES } from '../../constants'; +import ActionMenuEditButton from './components/ActionMenuEditButton'; +import ActionMenuDeleteButton from './components/ActionMenuDeleteButton'; +import OpenTransactionModal from './components/OpenTransactionModal'; +import DeleteUserModal from './components/DeleteUserModal'; +import ExportFeesFinesReportButton from './components'; class UserDetail extends React.Component { static propTypes = { @@ -621,6 +614,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; if (this.userNotFound()) { return ( @@ -702,13 +696,17 @@ class UserDetail extends React.Component { - + { + isAffiliationEnabled && ( + + ) + }