diff --git a/src/action_creators/EnrollActionCreator.js b/src/action_creators/EnrollActionCreator.js index ffb9bb7..48bcd55 100644 --- a/src/action_creators/EnrollActionCreator.js +++ b/src/action_creators/EnrollActionCreator.js @@ -1,4 +1,5 @@ import ActionTypes from '../constants/ActionTypes'; +import API from '../lib/API'; const EnrollActionCreator = { toggleBasicInfo() { @@ -11,7 +12,50 @@ const EnrollActionCreator = { return { type: ActionTypes.TOGGLE_PREFERENCES } + }, + + requestStudentEnrollment(student) { + var that = this; + + function successEnrollment(dispatch){ + return function(students) { + dispatch(that._receivedStudentEnrollmentSuccess(students)); + } + }; + + function errorEnrollment(dispatch){ + return function(errors) { + dispatch(that._receivedStudentEnrollmentFailure(errors)); + } + }; + + return (dispatch) => { + dispatch(this._enrollmentInProgress()); + return new API(). + addStudent(student.name, student.surname, student.house, student.pet). + then(successEnrollment(dispatch), errorEnrollment(dispatch)); + }; + }, + + _receivedStudentEnrollmentSuccess(students) { + return { + type: ActionTypes.ENROLL_STUDENT_SUCCESS, + students: students, + } + }, + + _receivedStudentEnrollmentFailure(errors) { + return { + type: ActionTypes.ENROLL_STUDENT_FAILURE, + errors: errors + } + }, + + _enrollmentInProgress(){ + return { + type: ActionTypes.ENROLL_STUDENT_INPROGRESS + } } -} +}; export default EnrollActionCreator; diff --git a/src/action_creators/ParticipantsActionCreator.js b/src/action_creators/ParticipantsActionCreator.js index 8ced454..4461cb7 100644 --- a/src/action_creators/ParticipantsActionCreator.js +++ b/src/action_creators/ParticipantsActionCreator.js @@ -16,6 +16,6 @@ const PaticipantsActionCreator = { students: students }; } -} +}; export default PaticipantsActionCreator; diff --git a/src/components/enroll/BasicInfo.js b/src/components/enroll/BasicInfo.js index c1383ff..788fd92 100644 --- a/src/components/enroll/BasicInfo.js +++ b/src/components/enroll/BasicInfo.js @@ -1,7 +1,5 @@ import React from 'react'; import Error from '../shared/Error'; -import EnrollActionCreator from '../../action_creators/EnrollActionCreator'; -import { connect } from 'react-redux'; class BasicInfo extends React.Component { value() { @@ -11,16 +9,11 @@ class BasicInfo extends React.Component { } } - toggleForm() { - const action = EnrollActionCreator.toggleBasicInfo(); - this.props.dispatch(action); - } - formVisibilityCss() { - const { open } = this.props; + const { isOpen } = this.props; const common = "fields"; const visible = "active"; - return open ? `${common} ${visible}` : common; + return isOpen ? `${common} ${visible}` : common; } renderErrorForField(field) { @@ -32,7 +25,7 @@ class BasicInfo extends React.Component { render() { return (