import React, { FC, memo, useCallback, useState, } from '../../lib/teact/teact'; import { withGlobal, getActions } from '../../modules'; import { ApiUser } from '../../api/types'; import { selectUser } from '../../modules/selectors'; import { getUserFirstOrLastName, getUserFullName } from '../../modules/helpers'; import useLang from '../../hooks/useLang'; import useFlag from '../../hooks/useFlag'; import Button from '../ui/Button'; import ConfirmDialog from '../ui/ConfirmDialog'; import Checkbox from '../ui/Checkbox'; import './UserReportPanel.scss'; type OwnProps = { userId: string; }; type StateProps = { user?: ApiUser; }; const UserReportPanel: FC = ({ userId, user }) => { const { addContact, blockContact, reportSpam, deleteChat, toggleChatArchived, } = getActions(); const lang = useLang(); const [isBlockUserModalOpen, openBlockUserModal, closeBlockUserModal] = useFlag(); const [shouldReportSpam, setShouldReportSpam] = useState(true); const [shouldDeleteChat, setShouldDeleteChat] = useState(true); const { settings, accessHash } = user || {}; const { isAutoArchived, canReportSpam, canAddContact, canBlockContact, } = settings || {}; const handleAddContact = useCallback(() => { addContact({ userId }); if (isAutoArchived) { toggleChatArchived({ chatId: userId }); } }, [addContact, isAutoArchived, toggleChatArchived, userId]); const handleConfirmBlock = useCallback(() => { closeBlockUserModal(); blockContact({ contactId: userId, accessHash }); if (canReportSpam && shouldReportSpam) { reportSpam({ userId }); } if (shouldDeleteChat) { deleteChat({ chatId: userId }); } }, [ accessHash, blockContact, closeBlockUserModal, deleteChat, reportSpam, canReportSpam, shouldDeleteChat, shouldReportSpam, userId, ]); if (!settings) { return undefined; } return (
{canAddContact && ( )} {canBlockContact && ( )} {canReportSpam && ( )}
); }; export default memo(withGlobal( (global, { userId }): StateProps => ({ user: selectUser(global, userId) }), )(UserReportPanel));