diff --git a/web/modals/threads/members/members-modal.react.js b/web/modals/threads/members/members-modal.react.js index 1874f1902..d8394aa0a 100644 --- a/web/modals/threads/members/members-modal.react.js +++ b/web/modals/threads/members/members-modal.react.js @@ -1,165 +1,175 @@ // @flow import * as React from 'react'; import { useModalContext } from 'lib/components/modal-provider.react.js'; import { useAddUsersPermissions } from 'lib/permissions/add-users-permissions.js'; import { useUserSearchIndex } from 'lib/selectors/nav-selectors.js'; import { threadInfoSelector } from 'lib/selectors/thread-selectors.js'; import { roleIsAdminRole } from 'lib/shared/thread-utils.js'; import type { RelativeMemberInfo } from 'lib/types/minimally-encoded-thread-permissions-types.js'; import { useRolesFromCommunityThreadInfo } from 'lib/utils/role-utils.js'; import { AddMembersModal } from './add-members-modal.react.js'; import ThreadMembersList from './members-list.react.js'; import css from './members-modal.css'; import Button from '../../../components/button.react.js'; import Tabs, { type TabData } from '../../../components/tabs.react.js'; import ManageInviteLinksModal from '../../../invite-links/manage-invite-links-modal.react.js'; import ViewInviteLinkModal from '../../../invite-links/view-invite-link-modal.react.js'; import { useSelector } from '../../../redux/redux-utils.js'; import SearchModal from '../../search-modal.react.js'; type TabType = 'All Members' | 'Admins'; const tabsData: $ReadOnlyArray> = [ { id: 'All Members', header: 'All Members', }, { id: 'Admins', header: 'Admins', }, ]; type ContentProps = { +searchText: string, +threadID: string, }; function ThreadMembersModalContent(props: ContentProps): React.Node { const { threadID, searchText } = props; const [tab, setTab] = React.useState('All Members'); const threadInfo = useSelector(state => threadInfoSelector(state)[threadID]); const { members: threadMembersNotFiltered } = threadInfo; const userSearchIndex = useUserSearchIndex(threadMembersNotFiltered); const userIDs = React.useMemo( () => userSearchIndex.getSearchResults(searchText), [searchText, userSearchIndex], ); const allMembers = React.useMemo( () => threadMembersNotFiltered.filter( (member: RelativeMemberInfo) => searchText.length === 0 || userIDs.includes(member.id), ), [searchText.length, threadMembersNotFiltered, userIDs], ); const roles = useRolesFromCommunityThreadInfo(threadInfo, allMembers); const adminMembers = React.useMemo( () => allMembers.filter((member: RelativeMemberInfo) => roleIsAdminRole(roles.get(member.id)), ), [allMembers, roles], ); const tabs = React.useMemo( () => , [tab], ); const tabContent = React.useMemo(() => { if (tab === 'All Members') { return ( ); } return ( ); }, [adminMembers, allMembers, tab, threadInfo]); - const threadMembersModalContent = React.useMemo( - () => ( + const threadMembersModalContent = React.useMemo(() => { + if (adminMembers.length === 0) { + return ( +
+ +
+ ); + } + + return (
{tabs}
{tabContent}
- ), - [tabContent, tabs], - ); + ); + }, [tabContent, tabs, adminMembers.length, allMembers, threadInfo]); return threadMembersModalContent; } type Props = { +threadID: string, +onClose: () => void, }; function ThreadMembersModal(props: Props): React.Node { const { onClose, threadID } = props; const renderModalContent = React.useCallback( (searchText: string) => ( ), [threadID], ); const { pushModal, popModal } = useModalContext(); const threadInfo = useSelector(state => threadInfoSelector(state)[threadID]); const { inviteLink, canManageLinks, canAddMembers, isCommunityRoot } = useAddUsersPermissions(threadInfo); const onClickAddMembers = React.useCallback(() => { if (!isCommunityRoot) { pushModal(); } else if (inviteLink) { pushModal(); } else if (canManageLinks) { pushModal(); } }, [ canManageLinks, inviteLink, isCommunityRoot, popModal, pushModal, threadID, ]); const addMembersButton = React.useMemo(() => { if (!canAddMembers) { return null; } return (
); }, [canAddMembers, onClickAddMembers]); return ( {renderModalContent} ); } export default ThreadMembersModal;