refactor: made hook to get privilage users
This commit is contained in:
@@ -10,12 +10,10 @@ import { Button, useToggle } from '@edx/paragon';
|
||||
import HTMLLoader from '../../../components/HTMLLoader';
|
||||
import { ContentActions } from '../../../data/constants';
|
||||
import { AlertBanner, DeleteConfirmation, EndorsedAlertBanner } from '../../common';
|
||||
import {
|
||||
selectBlackoutDate, selectIsCourseAdmin,
|
||||
selectIsCourseStaff, selectUserHasModerationPrivileges, selectUserIsGroupTa, selectUserIsStaff,
|
||||
} from '../../data/selectors';
|
||||
import { useUserPrivilage } from '../../data/hooks';
|
||||
import { selectBlackoutDate } from '../../data/selectors';
|
||||
import { fetchThread } from '../../posts/data/thunks';
|
||||
import { handleAddPostForRoles, inBlackoutDateRange } from '../../utils';
|
||||
import { inBlackoutDateRange } from '../../utils';
|
||||
import CommentIcons from '../comment-icons/CommentIcons';
|
||||
import { selectCommentCurrentPage, selectCommentHasMorePages, selectCommentResponses } from '../data/selectors';
|
||||
import { editComment, fetchCommentResponses, removeComment } from '../data/thunks';
|
||||
@@ -42,14 +40,7 @@ function Comment({
|
||||
const hasMorePages = useSelector(selectCommentHasMorePages(comment.id));
|
||||
const currentPage = useSelector(selectCommentCurrentPage(comment.id));
|
||||
const blackoutDateRange = useSelector(selectBlackoutDate);
|
||||
const isUserAdmin = useSelector(selectUserIsStaff);
|
||||
const userHasModerationPrivilages = useSelector(selectUserHasModerationPrivileges);
|
||||
const isUserGroupTA = useSelector(selectUserIsGroupTa);
|
||||
const isCourseAdmin = useSelector(selectIsCourseAdmin);
|
||||
const isCourseStaff = useSelector(selectIsCourseStaff);
|
||||
|
||||
const hasPrivilege = handleAddPostForRoles(isUserAdmin, userHasModerationPrivilages,
|
||||
isUserGroupTA, isCourseAdmin, isCourseStaff);
|
||||
const hasPrivilege = useUserPrivilage();
|
||||
|
||||
const handleAddComment = () => {
|
||||
if ((!(inBlackoutDateRange(blackoutDateRange)))) {
|
||||
|
||||
@@ -8,11 +8,9 @@ import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';
|
||||
import { Button } from '@edx/paragon';
|
||||
|
||||
import { DiscussionContext } from '../../common/context';
|
||||
import {
|
||||
selectBlackoutDate, selectIsCourseAdmin,
|
||||
selectIsCourseStaff, selectUserHasModerationPrivileges, selectUserIsGroupTa, selectUserIsStaff,
|
||||
} from '../../data/selectors';
|
||||
import { handleAddPostForRoles, inBlackoutDateRange } from '../../utils';
|
||||
import { useUserPrivilage } from '../../data/hooks';
|
||||
import { selectBlackoutDate } from '../../data/selectors';
|
||||
import { inBlackoutDateRange } from '../../utils';
|
||||
import messages from '../messages';
|
||||
import CommentEditor from './CommentEditor';
|
||||
|
||||
@@ -24,19 +22,12 @@ function ResponseEditor({
|
||||
const { inContext } = useContext(DiscussionContext);
|
||||
const [addingResponse, setAddingResponse] = useState(false);
|
||||
const blackoutDateRange = useSelector(selectBlackoutDate);
|
||||
const isUserAdmin = useSelector(selectUserIsStaff);
|
||||
const userHasModerationPrivilages = useSelector(selectUserHasModerationPrivileges);
|
||||
const isUserGroupTA = useSelector(selectUserIsGroupTa);
|
||||
const isCourseAdmin = useSelector(selectIsCourseAdmin);
|
||||
const isCourseStaff = useSelector(selectIsCourseStaff);
|
||||
const hasPrivilege = useUserPrivilage();
|
||||
|
||||
useEffect(() => {
|
||||
setAddingResponse(false);
|
||||
}, [postId]);
|
||||
|
||||
const hasPrivilege = handleAddPostForRoles(isUserAdmin, userHasModerationPrivilages,
|
||||
isUserGroupTA, isCourseAdmin, isCourseStaff);
|
||||
|
||||
const handleAddResponse = () => {
|
||||
if ((!(inBlackoutDateRange(blackoutDateRange)))) {
|
||||
return true;
|
||||
|
||||
@@ -17,13 +17,17 @@ import { DiscussionContext } from '../common/context';
|
||||
import { clearRedirect } from '../posts/data';
|
||||
import { selectTopics } from '../topics/data/selectors';
|
||||
import { fetchCourseTopics } from '../topics/data/thunks';
|
||||
import { discussionsPath } from '../utils';
|
||||
import { discussionsPath, handleAddPostForRoles } from '../utils';
|
||||
import {
|
||||
selectAreThreadsFiltered, selectLearnersTabEnabled,
|
||||
selectAreThreadsFiltered,
|
||||
selectIsCourseAdmin,
|
||||
selectIsCourseStaff,
|
||||
selectLearnersTabEnabled,
|
||||
selectModerationSettings,
|
||||
selectPostThreadCount,
|
||||
selectUserHasModerationPrivileges,
|
||||
selectUserIsGroupTa,
|
||||
selectUserIsStaff,
|
||||
} from './selectors';
|
||||
import { fetchCourseConfig } from './thunks';
|
||||
|
||||
@@ -174,3 +178,16 @@ export const useCurrentDiscussionTopic = () => {
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
export const useUserPrivilage = () => {
|
||||
const isUserAdmin = useSelector(selectUserIsStaff);
|
||||
const userHasModerationPrivilages = useSelector(selectUserHasModerationPrivileges);
|
||||
const isUserGroupTA = useSelector(selectUserIsGroupTa);
|
||||
const isCourseAdmin = useSelector(selectIsCourseAdmin);
|
||||
const isCourseStaff = useSelector(selectIsCourseStaff);
|
||||
|
||||
return (
|
||||
handleAddPostForRoles(isUserAdmin, userHasModerationPrivilages,
|
||||
isUserGroupTA, isCourseAdmin, isCourseStaff)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -12,13 +12,9 @@ import { Close } from '@edx/paragon/icons';
|
||||
|
||||
import Search from '../../../components/Search';
|
||||
import { RequestStatus } from '../../../data/constants';
|
||||
import {
|
||||
selectBlackoutDate, selectconfigLoadingStatus,
|
||||
selectIsCourseAdmin, selectIsCourseStaff,
|
||||
selectUserHasModerationPrivileges, selectUserIsGroupTa,
|
||||
selectUserIsStaff,
|
||||
} from '../../data/selectors';
|
||||
import { handleAddPostForRoles, inBlackoutDateRange, postMessageToParent } from '../../utils';
|
||||
import { useUserPrivilage } from '../../data/hooks';
|
||||
import { selectBlackoutDate, selectconfigLoadingStatus } from '../../data/selectors';
|
||||
import { inBlackoutDateRange, postMessageToParent } from '../../utils';
|
||||
import { showPostEditor } from '../data';
|
||||
import messages from './messages';
|
||||
|
||||
@@ -31,19 +27,12 @@ function PostActionsBar({
|
||||
const dispatch = useDispatch();
|
||||
const loadingStatus = useSelector(selectconfigLoadingStatus);
|
||||
const blackoutDateRange = useSelector(selectBlackoutDate);
|
||||
const isUserAdmin = useSelector(selectUserIsStaff);
|
||||
const userHasModerationPrivilages = useSelector(selectUserHasModerationPrivileges);
|
||||
const isUserGroupTA = useSelector(selectUserIsGroupTa);
|
||||
const isCourseAdmin = useSelector(selectIsCourseAdmin);
|
||||
const isCourseStaff = useSelector(selectIsCourseStaff);
|
||||
const hasPrivilege = useUserPrivilage();
|
||||
|
||||
const handleCloseInContext = () => {
|
||||
postMessageToParent('learning.events.sidebar.close');
|
||||
};
|
||||
|
||||
const hasPrivilege = handleAddPostForRoles(isUserAdmin, userHasModerationPrivilages,
|
||||
isUserGroupTA, isCourseAdmin, isCourseStaff);
|
||||
|
||||
const handleAddPost = () => {
|
||||
if (loadingStatus === RequestStatus.SUCCESSFUL && (!(inBlackoutDateRange(blackoutDateRange)))) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user