import type { FC } from '../../../lib/teact/teact'; import React, { memo, useCallback, useEffect } from '../../../lib/teact/teact'; import { getActions, withGlobal } from '../../../global'; import type { ApiChat } from '../../../api/types'; import { STICKER_SIZE_JOIN_REQUESTS } from '../../../config'; import { LOCAL_TGS_URLS } from '../../common/helpers/animatedAssets'; import useHistoryBack from '../../../hooks/useHistoryBack'; import { selectChat } from '../../../global/selectors'; import { isChatChannel, isUserId } from '../../../global/helpers'; import useLang from '../../../hooks/useLang'; import useFlag from '../../../hooks/useFlag'; import JoinRequest from './JoinRequest'; import Button from '../../ui/Button'; import ConfirmDialog from '../../ui/ConfirmDialog'; import Spinner from '../../ui/Spinner'; import AnimatedIcon from '../../common/AnimatedIcon'; type OwnProps = { chatId: string; onClose: NoneToVoidFunction; isActive: boolean; }; type StateProps = { chat?: ApiChat; isChannel?: boolean; }; const ManageJoinRequests: FC = ({ chat, chatId, isActive, isChannel, onClose, }) => { const { hideAllChatJoinRequests, loadChatJoinRequests } = getActions(); const [isAcceptAllDialogOpen, openAcceptAllDialog, closeAcceptAllDialog] = useFlag(); const [isRejectAllDialogOpen, openRejectAllDialog, closeRejectAllDialog] = useFlag(); const lang = useLang(); useHistoryBack({ isActive, onBack: onClose, }); useEffect(() => { if (!chat?.joinRequests && !isUserId(chatId)) { loadChatJoinRequests({ chatId }); } }, [chat, chatId, loadChatJoinRequests]); const handleAcceptAllRequests = useCallback(() => { hideAllChatJoinRequests({ chatId, isApproved: true }); closeAcceptAllDialog(); }, [hideAllChatJoinRequests, chatId, closeAcceptAllDialog]); const handleRejectAllRequests = useCallback(() => { hideAllChatJoinRequests({ chatId, isApproved: false }); closeRejectAllDialog(); }, [hideAllChatJoinRequests, chatId, closeRejectAllDialog]); return (
{Boolean(chat?.joinRequests?.length) && (
)}

{!chat?.joinRequests ? lang('Loading') : chat.joinRequests.length ? lang('JoinRequests', chat.joinRequests.length) : lang('NoMemberRequests')}

{!chat?.joinRequests && ( )} {chat?.joinRequests?.length === 0 && (

{isChannel ? lang('NoSubscribeRequestsDescription') : lang('NoMemberRequestsDescription')}

)} {chat?.joinRequests?.map(({ userId, about, date }) => ( ))}
); }; export default memo(withGlobal( (global, { chatId }): StateProps => { const chat = selectChat(global, chatId); return { chat, isChannel: chat && isChatChannel(chat), }; }, )(ManageJoinRequests));