From 10be8bcd4e87176bf7b32519d6b998271c1756ff Mon Sep 17 00:00:00 2001 From: Alex Dusenbery Date: Thu, 22 Mar 2018 12:27:37 -0400 Subject: [PATCH] add entitlement support creation and reissue Learner-3925 --- .babelrc | 3 +- .../components/EntitlementForm/container.jsx | 27 +++ .../components/EntitlementForm/index.jsx | 163 ++++++++++++++++++ .../jsx/entitlements/components/Main/Main.jsx | 37 +++- .../components/Main/MainContainer.jsx | 4 + .../Table/EntitlementSupportTable.jsx | 24 ++- .../EntitlementSupportTableContainer.jsx | 6 + .../entitlements/data/actions/constants.js | 12 -- .../entitlements/data/actions/entitlement.js | 69 +++++++- .../jsx/entitlements/data/actions/error.js | 2 +- .../jsx/entitlements/data/actions/form.js | 21 +++ .../jsx/entitlements/data/api/client.js | 13 +- .../jsx/entitlements/data/api/endpoints.js | 2 +- .../data/constants/actionTypes.js | 25 +++ .../entitlements/data/constants/formTypes.js | 4 + .../data/reducers/entitlements.js | 11 +- .../jsx/entitlements/data/reducers/error.js | 2 +- .../jsx/entitlements/data/reducers/form.js | 24 +++ .../jsx/entitlements/data/reducers/index.js | 3 +- .../support/jsx/entitlements/data/store.js | 5 + package-lock.json | 28 +-- 21 files changed, 419 insertions(+), 66 deletions(-) create mode 100644 lms/djangoapps/support/static/support/jsx/entitlements/components/EntitlementForm/container.jsx create mode 100644 lms/djangoapps/support/static/support/jsx/entitlements/components/EntitlementForm/index.jsx delete mode 100644 lms/djangoapps/support/static/support/jsx/entitlements/data/actions/constants.js create mode 100644 lms/djangoapps/support/static/support/jsx/entitlements/data/actions/form.js create mode 100644 lms/djangoapps/support/static/support/jsx/entitlements/data/constants/actionTypes.js create mode 100644 lms/djangoapps/support/static/support/jsx/entitlements/data/constants/formTypes.js create mode 100644 lms/djangoapps/support/static/support/jsx/entitlements/data/reducers/form.js diff --git a/.babelrc b/.babelrc index 20a87235f4..c844f15918 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,7 @@ { "plugins": [ - "transform-object-assign" + "transform-object-assign", + "transform-object-rest-spread" ], "presets": [ [ diff --git a/lms/djangoapps/support/static/support/jsx/entitlements/components/EntitlementForm/container.jsx b/lms/djangoapps/support/static/support/jsx/entitlements/components/EntitlementForm/container.jsx new file mode 100644 index 0000000000..5063648066 --- /dev/null +++ b/lms/djangoapps/support/static/support/jsx/entitlements/components/EntitlementForm/container.jsx @@ -0,0 +1,27 @@ +import { connect } from 'react-redux'; + +import { createEntitlement, reissueEntitlement } from '../../data/actions/entitlement'; +import { closeForm } from '../../data/actions/form'; + +import EntitlementForm from './index.jsx'; + +const mapStateToProps = state => ({ + formType: state.form.formType, + isOpen: state.form.isOpen, + entitlement: state.form.activeEntitlement, +}); + +const mapDispatchToProps = dispatch => ({ + createEntitlement: ({ username, courseUuid, mode, comments }) => + dispatch(createEntitlement({ username, courseUuid, mode, comments })), + reissueEntitlement: ({ entitlement, comments }) => + dispatch(reissueEntitlement({ entitlement, comments })), + closeForm: () => dispatch(closeForm()), +}); + +const EntitlementFormContainer = connect( + mapStateToProps, + mapDispatchToProps, +)(EntitlementForm); + +export default EntitlementFormContainer; diff --git a/lms/djangoapps/support/static/support/jsx/entitlements/components/EntitlementForm/index.jsx b/lms/djangoapps/support/static/support/jsx/entitlements/components/EntitlementForm/index.jsx new file mode 100644 index 0000000000..7bba4c712c --- /dev/null +++ b/lms/djangoapps/support/static/support/jsx/entitlements/components/EntitlementForm/index.jsx @@ -0,0 +1,163 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import { Button, InputSelect, InputText, TextArea } from '@edx/paragon'; +import { formTypes } from '../../data/constants/formTypes'; + +class EntitlementForm extends React.Component { + constructor(props) { + super(props); + + if (props.formType === formTypes.REISSUE) { + const { courseUuid, mode, user } = props.entitlement; + this.state = { + courseUuid, + mode, + username: user, + comments: '', + }; + } else { + this.state = { + courseUuid: '', + mode: '', + username: '', + comments: '', + }; + } + + this.onClose = this.onClose.bind(this); + this.handleCourseUUIDChange = this.handleCourseUUIDChange.bind(this); + this.handleUsernameChange = this.handleUsernameChange.bind(this); + this.handleModeChange = this.handleModeChange.bind(this); + this.handleCommentsChange = this.handleCommentsChange.bind(this); + this.submitForm = this.submitForm.bind(this); + } + + onClose() { + this.props.closeForm(); + } + + handleCourseUUIDChange(courseUuid) { + this.setState({ courseUuid }); + } + + handleUsernameChange(username) { + this.setState({ username }); + } + + handleModeChange(mode) { + this.setState({ mode }); + } + + handleCommentsChange(comments) { + this.setState({ comments }); + } + + submitForm() { + const { courseUuid, username, mode, comments } = this.state; + const { formType, entitlement } = this.props; + if (formType === formTypes.REISSUE) { // if there is an active entitlement we are updating an entitlement + this.props.reissueEntitlement({ entitlement, comments }); + } else { // if there is no active entitlement we are creating a new entitlement + this.props.createEntitlement({ courseUuid, username, mode, comments }); + } + } + + render() { + const { courseUuid, username, mode, comments } = this.state; + const isReissue = this.props.formType === formTypes.REISSUE; + const title = isReissue ? 'Re-issue Entitlement' : 'Create Entitlement'; + + const body = ( +
+

{title}

+ + + +