Files
Braden MacDonald 3c661e15cb Convert "Pages & Resources" page to a plugin system (#638)
* feat: Make "Pages & Resources" course apps into plugins

* feat: move ora_settings

* feat: move proctoring

* feat: move progress

* feat: move teams

* feat: move wiki

* feat: move Xpert settings

* fix: add webpack.prod.config.js

* fix: clean up unused parts of package.json files

* feat: Add an error message when displaying a Course App Plugin fails

* chore: fix various eslint warnings

* chore: fix jest tests

* fix: error preventing "npm ci" from working

* feat: better tests for <SettingsComponent>

* chore: move xpert_unit_summary into same dir as other plugins

* fix: eslint-import-resolver-webpack is a dev dependency

* chore: move learning_assistant to be a plugin too

* feat: for compatibility, install 2U plugins by default

* fix: bug with learning_assistant package.json
2024-02-28 11:50:54 -05:00

87 lines
2.6 KiB
JavaScript

import { addModel, addModels, updateModel } from 'CourseAuthoring/generic/model-store';
import { RequestStatus } from 'CourseAuthoring/data/constants';
import {
getLiveConfiguration,
getLiveProviders,
postLiveConfiguration,
normalizeSettings,
deNormalizeSettings,
} from './api';
import { loadApps, updateStatus, updateSaveStatus } from './slice';
function updateLiveSettingsState({
appConfig,
...liveSettings
}) {
return async (dispatch) => {
dispatch(addModel({ modelType: 'liveAppConfigs', model: appConfig }));
dispatch(loadApps(liveSettings));
};
}
export function fetchLiveProviders(courseId) {
return async (dispatch) => {
const { activeAppId, selectedAppId, apps } = await getLiveProviders(courseId);
dispatch(addModels({ modelType: 'liveApps', models: apps }));
dispatch(loadApps({
activeAppId,
selectedAppId,
appIds: apps.map((app) => app.id),
}));
};
}
export function fetchLiveConfiguration(courseId) {
return async (dispatch) => {
const settings = await getLiveConfiguration(courseId);
dispatch(updateLiveSettingsState(settings));
};
}
export function fetchLiveData(courseId) {
return async (dispatch) => {
dispatch(updateStatus({ status: RequestStatus.IN_PROGRESS }));
try {
await dispatch(fetchLiveProviders(courseId));
await dispatch(fetchLiveConfiguration(courseId));
} catch (error) {
if (error.response && error.response.status === 403) {
dispatch(updateStatus({ status: RequestStatus.DENIED }));
} else {
dispatch(updateStatus({ status: RequestStatus.FAILED }));
}
}
};
}
export function saveLiveConfiguration(courseId, config, navigate) {
return async (dispatch) => {
dispatch(updateSaveStatus({ status: RequestStatus.IN_PROGRESS }));
try {
const apps = await postLiveConfiguration(courseId, config);
dispatch(updateLiveSettingsState(apps));
dispatch(updateSaveStatus({ status: RequestStatus.SUCCESSFUL }));
navigate(`/course/${courseId}/pages-and-resources/`);
} catch (error) {
if (error.response && error.response.status === 403) {
dispatch(updateSaveStatus({ status: RequestStatus.DENIED }));
dispatch(updateStatus({ status: RequestStatus.DENIED }));
} else {
dispatch(updateSaveStatus({ status: RequestStatus.FAILED }));
}
}
};
}
export function saveLiveConfigurationAsDraft(config) {
return async (dispatch) => {
const { appConfig, ...liveSettings } = normalizeSettings(deNormalizeSettings(config));
dispatch(updateModel({ modelType: 'liveAppConfigs', model: appConfig }));
dispatch(loadApps(liveSettings));
};
}