Files
frontend-app-discussions/src/discussions/empty-posts/EmptyPosts.jsx
sundasnoreen12 a0269115b4 feat: added rate limit dialogue (#796)
* feat: added rate limit dialogue

* test: added test cases for post comment

* test: added test for content creation dialogue

* test: added test cases for empty topics

* test: added test cases

* feat: added content rate limit dialogue on post API for post and comment

* fix: fixed editor close issue on submit

* test: addd test cases
2025-08-05 12:31:12 +05:00

77 lines
2.4 KiB
JavaScript

import React, { useCallback } from 'react';
import propTypes from 'prop-types';
import { useDispatch, useSelector } from 'react-redux';
import { useIntl } from '@edx/frontend-platform/i18n';
import withPostingRestrictions from '../common/withPostingRestrictions';
import { useIsOnTablet } from '../data/hooks';
import {
selectAreThreadsFiltered,
selectContentCreationRateLimited,
selectPostThreadCount,
selectShouldShowEmailConfirmation,
} from '../data/selectors';
import messages from '../messages';
import { showPostEditor } from '../posts/data';
import postMessages from '../posts/post-actions-bar/messages';
import EmptyPage from './EmptyPage';
const EmptyPosts = ({ subTitleMessage, openRestrictionDialogue }) => {
const intl = useIntl();
const dispatch = useDispatch();
const isOnTabletorDesktop = useIsOnTablet();
const isFiltered = useSelector(selectAreThreadsFiltered);
const totalThreads = useSelector(selectPostThreadCount);
const shouldShowEmailConfirmation = useSelector(selectShouldShowEmailConfirmation);
const contentCreationRateLimited = useSelector(selectContentCreationRateLimited);
const addPost = useCallback(() => {
if (shouldShowEmailConfirmation || contentCreationRateLimited) {
openRestrictionDialogue();
} else {
dispatch(showPostEditor());
}
}, [shouldShowEmailConfirmation, openRestrictionDialogue, contentCreationRateLimited]);
let title = messages.noPostSelected;
let subTitle = null;
let action = null;
let actionText = null;
let fullWidth = false;
const isEmpty = [0, null].includes(totalThreads) && !isFiltered;
if (!(isOnTabletorDesktop || isEmpty)) {
return null;
} if (isEmpty) {
subTitle = subTitleMessage;
title = messages.emptyTitle;
action = addPost;
actionText = postMessages.addAPost;
fullWidth = true;
}
return (
<EmptyPage
title={intl.formatMessage(title)}
subTitle={subTitle ? intl.formatMessage(subTitle) : null}
action={action}
actionText={actionText ? intl.formatMessage(actionText) : null}
fullWidth={fullWidth}
/>
);
};
EmptyPosts.propTypes = {
subTitleMessage: propTypes.shape({
id: propTypes.string,
defaultMessage: propTypes.string,
description: propTypes.string,
}).isRequired,
openRestrictionDialogue: propTypes.func.isRequired,
};
export default React.memo(withPostingRestrictions(EmptyPosts));