Skip to content

Commit

Permalink
display missing affiliations
Browse files Browse the repository at this point in the history
  • Loading branch information
alisher-epam committed Sep 21, 2023
1 parent 7f91b68 commit f2e5ef8
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const AffiliationManagerModal = ({ onClose, onSubmit, userId }) => {
isLoading: isConsortiumTenantsLoading,
} = useConsortiumTenants();

const visibleAffiliations = useMemo(() => affiliations.filter(({ isPrimary }) => !isPrimary), [affiliations]);
const primaryAffiliation = useMemo(() => affiliations.find(({ isPrimary }) => isPrimary), [affiliations]);

const {
assignment,
Expand All @@ -69,15 +69,15 @@ const AffiliationManagerModal = ({ onClose, onSubmit, userId }) => {
toggleAll,
totalAssigned,
} = useAffiliationsAssignment({
affiliations: visibleAffiliations,
affiliations,
tenants,
});

const isLoading = isConsortiumTenantsLoading || isUsersAffiliationsLoading;

const affiliationIds = useMemo(() => {
return visibleAffiliations.map(({ tenantId }) => tenantId);
}, [visibleAffiliations]);
return affiliations.map(({ tenantId }) => tenantId);
}, [affiliations]);

const handleOnSubmit = useCallback(async () => {
const getAffiliationIds = (assigned) => (
Expand Down Expand Up @@ -120,15 +120,23 @@ const AffiliationManagerModal = ({ onClose, onSubmit, userId }) => {
filtersConfig
.reduce((filtered, config) => config.filter(filtered, activeFilters, assignment), tenants)
.filter(({ name, isCentral, id }) => {
if (isCentral || !affiliationIds.includes(id)) return false;
if (isCentral || primaryAffiliation.tenantId === id) return false;

return (searchQuery ? name.toLowerCase().includes(searchQuery.toLowerCase()) : true);
}),
sorters[sortOrder],
sortDirection.name,
)
);
}, [affiliationIds, assignment, filters, sortDirection.name, sortOrder, sorters, tenants]);
}, [
assignment,
filters,
primaryAffiliation.tenantId,
sortDirection.name,
sortOrder,
sorters,
tenants,
]);

return (
<Modal
Expand Down

0 comments on commit f2e5ef8

Please sign in to comment.