/* eslint react/prop-types: 0 */ import React from 'react'; import PropTypes from 'prop-types'; import { useSelector } from 'react-redux'; import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; import { Icon, OverlayTrigger, Tooltip } from '@edx/paragon'; import { HelpOutline, PostOutline, Report } from '@edx/paragon/icons'; import { selectUserHasModerationPrivileges, selectUserIsGroupTa, } from '../discussions/data/selectors'; import messages from '../discussions/in-context-topics/messages'; const TopicStats = ({ threadCounts, activeFlags, inactiveFlags, intl, }) => { const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges); const userIsGroupTa = useSelector(selectUserIsGroupTa); const canSeeReportedStats = (activeFlags || inactiveFlags) && (userHasModerationPrivileges || userIsGroupTa); return (
{intl.formatMessage(messages.discussions, { count: threadCounts?.discussion || 0, })}
)} >
{threadCounts?.discussion || 0}
{intl.formatMessage(messages.questions, { count: threadCounts?.question || 0, })}
)} >
{threadCounts?.question || 0}
{Boolean(canSeeReportedStats) && (
{Boolean(activeFlags) && ( {intl.formatMessage(messages.reported, { reported: activeFlags })} )} {Boolean(inactiveFlags) && ( {intl.formatMessage(messages.previouslyReported, { previouslyReported: inactiveFlags })} )}
)} >
{activeFlags}{Boolean(inactiveFlags) && `/${inactiveFlags}`}
)}
); }; TopicStats.propTypes = { threadCounts: PropTypes.shape({ discussions: PropTypes.number, questions: PropTypes.number, }), activeFlags: PropTypes.number, inactiveFlags: PropTypes.number, intl: intlShape.isRequired, }; TopicStats.defaultProps = { threadCounts: { discussions: 0, questions: 0, }, activeFlags: null, inactiveFlags: null, }; export default injectIntl(TopicStats);