* chore: removed eslint-disable statements * refactor: removed unnecessary files and unintentional eslint-disable statements * refactor: removed eslint import/no-cycle error * fix: failing testcase * style: removed comments * fix: failing testcase --------- Co-authored-by: sohailfatima <23100065@lums.edu.pk> Co-authored-by: Fatima Sohail <68312464+sohailfatima@users.noreply.github.com>
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import { camelCaseObject } from '@edx/frontend-platform';
|
|
import { logError } from '@edx/frontend-platform/logging';
|
|
|
|
import {
|
|
DiscussionProvider, LearnersOrdering,
|
|
PostsStatusFilter,
|
|
} from '../../data/constants';
|
|
import { setSortedBy } from '../learners/data';
|
|
import { setStatusFilter } from '../posts/data';
|
|
import { getHttpErrorStatus } from '../utils';
|
|
import { getDiscussionsConfig, getDiscussionsSettings } from './api';
|
|
import {
|
|
fetchConfigDenied, fetchConfigFailed, fetchConfigRequest, fetchConfigSuccess,
|
|
} from './slices';
|
|
|
|
/**
|
|
* Fetches the configuration data for the course
|
|
* @param {string} courseId The course ID for the course to fetch config for.
|
|
* @returns {(function(*): Promise<void>)|*}
|
|
*/
|
|
export default function fetchCourseConfig(courseId) {
|
|
return async (dispatch) => {
|
|
try {
|
|
let learnerSort = LearnersOrdering.BY_LAST_ACTIVITY;
|
|
const postsFilterStatus = PostsStatusFilter.ALL;
|
|
dispatch(fetchConfigRequest());
|
|
|
|
const config = await getDiscussionsConfig(courseId);
|
|
if (config.has_moderation_privileges) {
|
|
const settings = await getDiscussionsSettings(courseId);
|
|
Object.assign(config, { settings });
|
|
}
|
|
|
|
if ((config.has_moderation_privileges || config.is_group_ta)) {
|
|
learnerSort = LearnersOrdering.BY_FLAG;
|
|
}
|
|
|
|
dispatch(fetchConfigSuccess(camelCaseObject({
|
|
...config,
|
|
enable_in_context: config.provider === DiscussionProvider.OPEN_EDX,
|
|
})));
|
|
dispatch(setSortedBy(learnerSort));
|
|
dispatch(setStatusFilter(postsFilterStatus));
|
|
} catch (error) {
|
|
if (getHttpErrorStatus(error) === 403) {
|
|
dispatch(fetchConfigDenied());
|
|
} else {
|
|
dispatch(fetchConfigFailed());
|
|
}
|
|
logError(error);
|
|
}
|
|
};
|
|
}
|