* feat: group configurations - index page * feat: [AXIMST-63] Index group configurations page * fix: resolve discussions * fix: resolve second round discussions * feat: group configurations - content group actions * feat: [AXIMST-75, AXIMST-69, AXIMST-81] Content group actions * fix: resolve conversations * feat: group configurations - sidebar * feat: [AXIMST-87] group-configuration page sidebar * refactor: [AXIMST-87] add changes after review * refactor: [AXIMST-87] add changes after review * refactor: [AXIMST-87] add changes ater review --------- Co-authored-by: Kyrylo Hudym-Levkovych <kyr.hudym@kyrs-MacBook-Pro.local> * fix: group configurations - the page reloads after the user saves changes * feat: group configurations - experiment groups * feat: [AXIMST-93, 99, 105] Group configuration - Experiment Groups * fix: [AXIMST-518, 537] Group configuration - resolve bugs * fix: review discussions * fix: revert classname case * fix: group configurations - resolve discussions fix: [AXIMST-714] icon is aligned with text (#210) * fix: add hook tests * fix: add thunk tests * fix: add slice tests * chore: group configurations - messages * fix: group configurations - remove delete in edit mode --------- Co-authored-by: Kyr <40792129+khudym@users.noreply.github.com> Co-authored-by: Kyrylo Hudym-Levkovych <kyr.hudym@kyrs-MacBook-Pro.local> Co-authored-by: monteri <lansevermore>
149 lines
5.1 KiB
JavaScript
149 lines
5.1 KiB
JavaScript
import { RequestStatus } from '../../data/constants';
|
|
import { NOTIFICATION_MESSAGES } from '../../constants';
|
|
import {
|
|
hideProcessingNotification,
|
|
showProcessingNotification,
|
|
} from '../../generic/processing-notification/data/slice';
|
|
import {
|
|
getGroupConfigurations,
|
|
createContentGroup,
|
|
editContentGroup,
|
|
deleteContentGroup,
|
|
createExperimentConfiguration,
|
|
editExperimentConfiguration,
|
|
deleteExperimentConfiguration,
|
|
} from './api';
|
|
import {
|
|
fetchGroupConfigurations,
|
|
updateLoadingStatus,
|
|
updateSavingStatuses,
|
|
updateGroupConfigurationsSuccess,
|
|
deleteGroupConfigurationsSuccess,
|
|
updateExperimentConfigurationSuccess,
|
|
deleteExperimentConfigurationSuccess,
|
|
} from './slice';
|
|
|
|
export function fetchGroupConfigurationsQuery(courseId) {
|
|
return async (dispatch) => {
|
|
dispatch(updateLoadingStatus({ status: RequestStatus.IN_PROGRESS }));
|
|
|
|
try {
|
|
const groupConfigurations = await getGroupConfigurations(courseId);
|
|
dispatch(fetchGroupConfigurations({ groupConfigurations }));
|
|
dispatch(updateLoadingStatus({ status: RequestStatus.SUCCESSFUL }));
|
|
} catch (error) {
|
|
dispatch(updateLoadingStatus({ status: RequestStatus.FAILED }));
|
|
}
|
|
};
|
|
}
|
|
|
|
export function createContentGroupQuery(courseId, group) {
|
|
return async (dispatch) => {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.PENDING }));
|
|
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.saving));
|
|
|
|
try {
|
|
const data = await createContentGroup(courseId, group);
|
|
dispatch(updateGroupConfigurationsSuccess({ data }));
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL }));
|
|
return true;
|
|
} catch (error) {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.FAILED }));
|
|
return false;
|
|
} finally {
|
|
dispatch(hideProcessingNotification());
|
|
}
|
|
};
|
|
}
|
|
|
|
export function editContentGroupQuery(courseId, group) {
|
|
return async (dispatch) => {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.PENDING }));
|
|
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.saving));
|
|
|
|
try {
|
|
const data = await editContentGroup(courseId, group);
|
|
dispatch(updateGroupConfigurationsSuccess({ data }));
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL }));
|
|
return true;
|
|
} catch (error) {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.FAILED }));
|
|
return false;
|
|
} finally {
|
|
dispatch(hideProcessingNotification());
|
|
}
|
|
};
|
|
}
|
|
|
|
export function deleteContentGroupQuery(courseId, parentGroupId, groupId) {
|
|
return async (dispatch) => {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.PENDING }));
|
|
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.deleting));
|
|
|
|
try {
|
|
await deleteContentGroup(courseId, parentGroupId, groupId);
|
|
dispatch(deleteGroupConfigurationsSuccess({ parentGroupId, groupId }));
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL }));
|
|
} catch (error) {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.FAILED }));
|
|
} finally {
|
|
dispatch(hideProcessingNotification());
|
|
}
|
|
};
|
|
}
|
|
|
|
export function createExperimentConfigurationQuery(courseId, newConfiguration) {
|
|
return async (dispatch) => {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.PENDING }));
|
|
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.saving));
|
|
|
|
try {
|
|
const configuration = await createExperimentConfiguration(courseId, newConfiguration);
|
|
dispatch(updateExperimentConfigurationSuccess({ configuration }));
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL }));
|
|
return true;
|
|
} catch (error) {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.FAILED }));
|
|
return false;
|
|
} finally {
|
|
dispatch(hideProcessingNotification());
|
|
}
|
|
};
|
|
}
|
|
|
|
export function editExperimentConfigurationQuery(courseId, editedConfiguration) {
|
|
return async (dispatch) => {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.PENDING }));
|
|
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.saving));
|
|
|
|
try {
|
|
const configuration = await editExperimentConfiguration(courseId, editedConfiguration);
|
|
dispatch(updateExperimentConfigurationSuccess({ configuration }));
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL }));
|
|
return true;
|
|
} catch (error) {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.FAILED }));
|
|
return false;
|
|
} finally {
|
|
dispatch(hideProcessingNotification());
|
|
}
|
|
};
|
|
}
|
|
|
|
export function deleteExperimentConfigurationQuery(courseId, configurationId) {
|
|
return async (dispatch) => {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.PENDING }));
|
|
dispatch(showProcessingNotification(NOTIFICATION_MESSAGES.deleting));
|
|
|
|
try {
|
|
await deleteExperimentConfiguration(courseId, configurationId);
|
|
dispatch(deleteExperimentConfigurationSuccess({ configurationId }));
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.SUCCESSFUL }));
|
|
} catch (error) {
|
|
dispatch(updateSavingStatuses({ status: RequestStatus.FAILED }));
|
|
} finally {
|
|
dispatch(hideProcessingNotification());
|
|
}
|
|
};
|
|
}
|