* 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
77 lines
2.4 KiB
JavaScript
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));
|