import React, { FC, memo } from '../../lib/teact/teact'; import { getDispatch, withGlobal } from '../../lib/teact/teactn'; import { ApiError, ApiInviteInfo } from '../../api/types'; import getReadableErrorText from '../../util/getReadableErrorText'; import { pick } from '../../util/iteratees'; import useLang from '../../hooks/useLang'; import renderText from '../common/helpers/renderText'; import Modal from '../ui/Modal'; import Button from '../ui/Button'; import './Dialogs.scss'; type StateProps = { dialogs: (ApiError | ApiInviteInfo)[]; }; const Dialogs: FC = ({ dialogs }) => { const { dismissDialog, acceptInviteConfirmation } = getDispatch(); const lang = useLang(); if (!dialogs.length) { return undefined; } const renderInvite = (invite: ApiInviteInfo) => { const { hash, title, participantsCount, isChannel, } = invite; const handleJoinClick = () => { acceptInviteConfirmation({ hash, }); dismissDialog(); }; const participantsText = isChannel ? lang('Subscribers', participantsCount, 'i') : lang('Members', participantsCount, 'i'); const joinText = isChannel ? lang('ChannelJoin') : lang('JoinGroup'); return ( {participantsCount !== undefined &&

{participantsText}

}
); }; const renderError = (error: ApiError) => { return ( {error.hasErrorKey ? getReadableErrorText(error) : renderText(error.message!, ['emoji', 'br'])}
); }; const renderDialog = (dialog: ApiError | ApiInviteInfo) => { if ('hash' in dialog) { return renderInvite(dialog); } return renderError(dialog); }; return (
{dialogs.map(renderDialog)}
); }; function getErrorHeader(error: ApiError) { if (error.isSlowMode) { return 'Slowmode enabled'; } if (!error.hasErrorKey) { return 'Telegram'; } return 'Something went wrong'; } export default memo(withGlobal( (global): StateProps => pick(global, ['dialogs']), )(Dialogs));