import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback, useMemo } from '../../../lib/teact/teact'; import { withGlobal } from '../../../global'; import type { ApiChatMember, ApiUser, ApiUserStatus } from '../../../api/types'; import { ManagementScreens } from '../../../types'; import { selectChat, selectChatFullInfo } from '../../../global/selectors'; import { sortUserIds, isChatChannel } from '../../../global/helpers'; import useHistoryBack from '../../../hooks/useHistoryBack'; import PrivateChatInfo from '../../common/PrivateChatInfo'; import ListItem from '../../ui/ListItem'; import NothingFound from '../../common/NothingFound'; type OwnProps = { chatId: string; onScreenSelect: (screen: ManagementScreens) => void; onChatMemberSelect: (memberId: string) => void; onClose: NoneToVoidFunction; isActive: boolean; }; type StateProps = { usersById: Record; userStatusesById: Record; members?: ApiChatMember[]; isChannel?: boolean; }; const ManageGroupUserPermissionsCreate: FC = ({ usersById, userStatusesById, members, isChannel, onScreenSelect, onChatMemberSelect, onClose, isActive, }) => { useHistoryBack({ isActive, onBack: onClose, }); const memberIds = useMemo(() => { if (!members || !usersById) { return undefined; } return sortUserIds( members.filter((member) => !member.isOwner).map(({ userId }) => userId), usersById, userStatusesById, ); }, [members, usersById, userStatusesById]); const handleExceptionMemberClick = useCallback((memberId: string) => { onChatMemberSelect(memberId); onScreenSelect(ManagementScreens.GroupUserPermissions); }, [onChatMemberSelect, onScreenSelect]); return (
{memberIds ? ( memberIds.map((id, i) => ( handleExceptionMemberClick(id)} > )) ) : ( )}
); }; export default memo(withGlobal( (global, { chatId }): StateProps => { const chat = selectChat(global, chatId); const { byId: usersById, statusesById: userStatusesById } = global.users; const members = selectChatFullInfo(global, chatId)?.members; const isChannel = chat && isChatChannel(chat); return { members, usersById, userStatusesById, isChannel, }; }, )(ManageGroupUserPermissionsCreate));