Skip to content

Commit

Permalink
feat(editing): display a status alert after grades have updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Nov 15, 2018
1 parent 7a02330 commit cd2a5ae
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
16 changes: 15 additions & 1 deletion src/components/Gradebook/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Button, Modal, SearchField, Table, InputSelect } from '@edx/paragon';
import { Button, InputSelect, Modal, SearchField, StatusAlert, Table } from '@edx/paragon';
import queryString from 'query-string';
import { configuration } from '../../config';

Expand Down Expand Up @@ -62,7 +62,15 @@ export default class Gradebook extends React.Component {
},
},
]);

this.setState({
modalModel: [{}],
modalOpen: false,
updateModuleId: null,
updateUserId: null,
});
}

updateQueryParams = (queryKey, queryValue) => {
const parsed = queryString.parse(this.props.location.search);
parsed[queryKey] = queryValue;
Expand Down Expand Up @@ -292,6 +300,12 @@ export default class Gradebook extends React.Component {
</div>
</div>
<br />
<StatusAlert
alertType="success"
dialog="The grade has been successfully edited."
onClose={() => this.props.updateBanner(false)}
open={this.props.showSuccess}
/>
<div className="gbook">
<Table
columns={this.props.headings}
Expand Down
5 changes: 5 additions & 0 deletions src/containers/GradebookPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
updateGrades,
toggleGradeFormat,
filterColumns,
updateBanner,
} from '../../data/actions/grades';
import { fetchCohorts } from '../../data/actions/cohorts';
import { fetchTracks } from '../../data/actions/tracks';
Expand All @@ -20,6 +21,7 @@ const mapStateToProps = state => (
selectedTrack: state.grades.selectedTrack,
selectedCohort: state.grades.selectedCohort,
format: state.grades.gradeFormat,
showSuccess: state.grades.showSuccess,
}
);

Expand All @@ -46,6 +48,9 @@ const mapDispatchToProps = dispatch => (
filterColumns: (filterType, exampleUser) => {
dispatch(filterColumns(filterType, exampleUser));
},
updateBanner: (showSuccess) => {
dispatch(updateBanner(showSuccess));
},
}
);

Expand Down
12 changes: 9 additions & 3 deletions src/data/actions/grades.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TOGGLE_GRADE_FORMAT,
SORT_GRADES,
FILTER_COLUMNS,
UPDATE_BANNER,
} from '../constants/actionTypes/grades';
import LmsApiService from '../services/LmsApiService';
import { headingMapper } from './utils';
Expand All @@ -25,7 +26,7 @@ const gotGrades = (grades, cohort, track, headings) => ({
});

const gradeUpdateRequest = () => ({ type: GRADE_UPDATE_REQUEST });
const gradeUpdateSuccess = responseData => ({
const gradeUpdateSuccess = (responseData) => ({
type: GRADE_UPDATE_SUCCESS,
payload: { responseData },
});
Expand All @@ -43,14 +44,17 @@ const filterColumns = (filterType, exampleUser) => ({
headings: headingMapper[filterType](exampleUser)
});

const fetchGrades = (courseId, cohort, track) => (
const updateBanner = (showSuccess) => ({ type: UPDATE_BANNER, showSuccess });

const fetchGrades = (courseId, cohort, track, showSuccess) => (
(dispatch) => {
dispatch(startedFetchingGrades());
return LmsApiService.fetchGradebookData(courseId, null, cohort, track)
.then(response => response.data)
.then((data) => {
dispatch(gotGrades(data.results, cohort, track, headingMapper.all(data.results[0])));
dispatch(finishedFetchingGrades());
dispatch(updateBanner(!!showSuccess));
})
.catch(() => {
dispatch(errorFetchingGrades());
Expand Down Expand Up @@ -79,7 +83,8 @@ const updateGrades = (courseId, updateData) => (
return LmsApiService.updateGradebookData(courseId, updateData)
.then(response => response.data)
.then((data) => {
dispatch(gradeUpdateSuccess(data));
dispatch(gradeUpdateSuccess(data))
dispatch(fetchGrades(courseId, null, null, true))
})
.catch((error) => {
dispatch(gradeUpdateFailure(error));
Expand All @@ -101,4 +106,5 @@ export {
toggleGradeFormat,
sortGrades,
filterColumns,
updateBanner,
};
2 changes: 2 additions & 0 deletions src/data/constants/actionTypes/grades.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const GRADE_UPDATE_FAILURE = 'GRADE_UPDATE_FAILURE';
const TOGGLE_GRADE_FORMAT = 'TOGGLE_GRADE_FORMAT';
const SORT_GRADES = 'SORT_GRADES';
const FILTER_COLUMNS = 'FILTER_COLUMNS';
const UPDATE_BANNER = 'UPDATE_BANNER';

export {
STARTED_FETCHING_GRADES,
Expand All @@ -22,4 +23,5 @@ export {
TOGGLE_GRADE_FORMAT,
SORT_GRADES,
FILTER_COLUMNS,
UPDATE_BANNER,
};
8 changes: 8 additions & 0 deletions src/data/reducers/grades.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
GOT_GRADES,
TOGGLE_GRADE_FORMAT,
FILTER_COLUMNS,
GRADE_UPDATE_SUCCESS,
UPDATE_BANNER,
} from '../constants/actionTypes/grades';

const initialState = {
Expand All @@ -13,6 +15,7 @@ const initialState = {
finishedFetching: false,
errorFetching: false,
gradeFormat: 'percent',
showSuccess: false,
};

const grades = (state = initialState, action) => {
Expand Down Expand Up @@ -49,6 +52,11 @@ const grades = (state = initialState, action) => {
...state,
headings: action.headings,
};
case UPDATE_BANNER:
return {
...state,
showSuccess: action.showSuccess,
};
default:
return state;
}
Expand Down

0 comments on commit cd2a5ae

Please sign in to comment.