From 6875165eb3594494723db0086ef384ac4dd10da3 Mon Sep 17 00:00:00 2001 From: sundasnoreen12 <72802712+sundasnoreen12@users.noreply.github.com> Date: Tue, 27 Feb 2024 14:25:40 +0500 Subject: [PATCH] fix: now content unavailable ui is only for learner (#672) Co-authored-by: Awais Ansari <79941147+awais-ansari@users.noreply.github.com> --- src/components/NavigationBar/data/slice.js | 1 + src/discussions/data/selectors.js | 23 +++++++++++++++++++ .../discussions-home/DiscussionsHome.jsx | 11 +++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/components/NavigationBar/data/slice.js b/src/components/NavigationBar/data/slice.js index 1d27c0c9b..1b73b42e5 100644 --- a/src/components/NavigationBar/data/slice.js +++ b/src/components/NavigationBar/data/slice.js @@ -13,6 +13,7 @@ const slice = createSlice({ tabs: [], courseTitle: null, courseNumber: null, + isEnrolled: false, org: null, }, reducers: { diff --git a/src/discussions/data/selectors.js b/src/discussions/data/selectors.js index acdd06d2e..b2e6c984b 100644 --- a/src/discussions/data/selectors.js +++ b/src/discussions/data/selectors.js @@ -1,3 +1,5 @@ +import { createSelector } from '@reduxjs/toolkit'; + import { PostsStatusFilter, ThreadType } from '../../data/constants'; export const selectAnonymousPostingConfig = state => ({ @@ -60,3 +62,24 @@ export function selectTopicThreadCount(topicId) { export function selectPostThreadCount(state) { return state.threads.totalThreads; } + +export const selectIsUserLearner = createSelector( + selectUserHasModerationPrivileges, + selectUserIsGroupTa, + selectUserIsStaff, + selectIsCourseAdmin, + selectIsCourseStaff, + ( + userHasModerationPrivileges, + userIsGroupTa, + userIsStaff, + userIsCourseAdmin, + userIsCourseStaff, + ) => ( + !userHasModerationPrivileges + && !userIsGroupTa + && !userIsStaff + && !userIsCourseAdmin + && !userIsCourseStaff + ), +); diff --git a/src/discussions/discussions-home/DiscussionsHome.jsx b/src/discussions/discussions-home/DiscussionsHome.jsx index a884519c6..a9bf772c3 100644 --- a/src/discussions/discussions-home/DiscussionsHome.jsx +++ b/src/discussions/discussions-home/DiscussionsHome.jsx @@ -12,14 +12,14 @@ import { LearningHeader as Header } from '@edx/frontend-component-header'; import { Spinner } from '../../components'; import selectCourseTabs from '../../components/NavigationBar/data/selectors'; -import { LOADED } from '../../components/NavigationBar/data/slice'; +import { LOADING } from '../../components/NavigationBar/data/slice'; import { ALL_ROUTES, DiscussionProvider, Routes as ROUTES } from '../../data/constants'; import DiscussionContext from '../common/context'; import ContentUnavailable from '../course-content-unavailable/CourseContentUnavailable'; import { useCourseDiscussionData, useIsOnDesktop, useRedirectToThread, useSidebarVisible, } from '../data/hooks'; -import { selectDiscussionProvider, selectEnableInContext } from '../data/selectors'; +import { selectDiscussionProvider, selectEnableInContext, selectIsUserLearner } from '../data/selectors'; import { EmptyLearners, EmptyTopics } from '../empty-posts'; import EmptyPosts from '../empty-posts/EmptyPosts'; import { EmptyTopic as InContextEmptyTopics } from '../in-context-topics/components'; @@ -46,6 +46,7 @@ const DiscussionsHome = () => { const { courseNumber, courseTitle, org, courseStatus, isEnrolled, } = useSelector(selectCourseTabs); + const isUserLearner = useSelector(selectIsUserLearner); const pageParams = useMatch(ROUTES.COMMENTS.PAGE)?.params; const page = pageParams?.page || null; const matchPattern = ALL_ROUTES.find((route) => matchPath({ path: route }, location.pathname)); @@ -84,7 +85,7 @@ const DiscussionsHome = () => { )}
{!enableInContextSidebar && } - {(isEnrolled || enableInContextSidebar) && ( + {(isEnrolled || !isUserLearner || enableInContextSidebar) && (
{ )} - {(courseStatus === LOADED || enableInContextSidebar) && ( + {(courseStatus !== LOADING || enableInContextSidebar) && (
- { isEnrolled === false ? ( + { isEnrolled === false && isUserLearner ? ( )}> {ALL_ROUTES.map((route) => (