add state for selected course

fixes CNVS-31156

Test Plan:
- Click find appointment button
- Select a course and click submit
- Click close

Change-Id: I92efbd9db093f58c326e5afadb37735c89f625a0
Reviewed-on: https://gerrit.instructure.com/89388
Reviewed-by: Clay Diffrient <cdiffrient@instructure.com>
Tested-by: Jenkins
QA-Review: Heath Hales <hhales@instructure.com>
Product-Review: Steven Burnett <sburnett@instructure.com>
This commit is contained in:
Steven Burnett 2016-08-31 16:35:36 -06:00
parent 3f5dc31d17
commit 9b0c8bc453
6 changed files with 62 additions and 16 deletions

View File

@ -5,11 +5,13 @@ define([
const { createAction } = ReduxActions; const { createAction } = ReduxActions;
const keys = { const keys = {
SET_FIND_APPOINTMENT_MODE: 'SET_FIND_APPOINTMENT_MODE' SET_FIND_APPOINTMENT_MODE: 'SET_FIND_APPOINTMENT_MODE',
SET_COURSE: 'SET_COURSE'
} }
const actions = { const actions = {
setFindAppointmentMode: createAction(keys.SET_FIND_APPOINTMENT_MODE) setFindAppointmentMode: createAction(keys.SET_FIND_APPOINTMENT_MODE),
setCourse: createAction(keys.SET_COURSE)
}; };
return { return {

View File

@ -13,17 +13,28 @@ define([
constructor (props) { constructor (props) {
super(props) super(props)
this.state = { isModalOpen: false } this.state = {
isModalOpen: false,
selectedCourse: {}
}
this.openModal = this.openModal.bind(this) this.openModal = this.openModal.bind(this)
this.closeModal = this.closeModal.bind(this) this.closeModal = this.closeModal.bind(this)
this.handleSubmit = this.handleSubmit.bind(this) this.handleSubmit = this.handleSubmit.bind(this)
this.endAppointmentMode = this.endAppointmentMode.bind(this) this.endAppointmentMode = this.endAppointmentMode.bind(this)
this.selectCourse = this.selectCourse.bind(this)
} }
handleSubmit () { handleSubmit () {
this.props.store.dispatch(Actions.actions.setFindAppointmentMode(!this.props.store.getState().inFindAppointmentMode)) this.props.store.dispatch(Actions.actions.setFindAppointmentMode(!this.props.store.getState().inFindAppointmentMode))
this.props.store.dispatch(Actions.actions.setCourse(this.state.selectedCourse))
this.setState ({ this.setState ({
isModalOpen: false, isModalOpen: false,
selectedCourse: {}
})
}
selectCourse (e) {
this.setState({
selectedCourse: this.props.courses.find((c) => c.id === e.target.value)
}) })
} }
openModal () { openModal () {
@ -33,7 +44,6 @@ define([
} }
endAppointmentMode () { endAppointmentMode () {
this.props.store.dispatch(Actions.actions.setFindAppointmentMode(false)) this.props.store.dispatch(Actions.actions.setFindAppointmentMode(false))
// Probably should set the state here to close the grey view thing.
this.setState({ this.setState({
isModalOpen: false, isModalOpen: false,
}) })
@ -75,7 +85,7 @@ define([
</div> </div>
<div className="ReactModal__Body"> <div className="ReactModal__Body">
<div className="ic-Form-control"> <div className="ic-Form-control">
<select className="ic-Input"> <select onChange={this.selectCourse} value={this.state.selectedCourse.id} className="ic-Input">
{this.props.courses.map((c, index) => { {this.props.courses.map((c, index) => {
if (c.asset_string.indexOf("user") === -1) { if (c.asset_string.indexOf("user") === -1) {
return(<option key={c.id} value={c.id}>{c.name}</option>) return(<option key={c.id} value={c.id}>{c.name}</option>)

View File

@ -1,15 +1,23 @@
define([ define([
'redux-actions', 'redux-actions',
'./actions' './actions',
], (ReduxActions, SchedulerActions) => { './store/initialState'
], (ReduxActions, SchedulerActions, initialState) => {
const { handleActions } = ReduxActions; const { handleActions } = ReduxActions;
const reducer = handleActions({ const reducer = handleActions({
[SchedulerActions.keys.SET_FIND_APPOINTMENT_MODE]: (state, action) => { [SchedulerActions.keys.SET_FIND_APPOINTMENT_MODE]: (state = initialState, action) => {
return { return {
...state,
inFindAppointmentMode: action.payload inFindAppointmentMode: action.payload
} }
},
[SchedulerActions.keys.SET_COURSE]: (state = initialState, action) => {
return {
...state,
selectedCourse: action.payload
}
} }
}); });

View File

@ -1,7 +1,8 @@
define([], () => { define([], () => {
const initialState = { const initialState = {
inFindAppointmentMode: false inFindAppointmentMode: false,
selectedCourse: {}
}; };

View File

@ -12,6 +12,16 @@ define([
}; };
deepEqual(actual, expected); deepEqual(actual, expected);
}); })
}); test('setCourse returns the proper action', () => {
const actual = Actions.actions.setCourse({id: 4, name:'blah'});
const expected = {
type: 'SET_COURSE',
payload: {id: 4, name:'blah'}
};
deepEqual(actual, expected)
})
})

View File

@ -7,15 +7,30 @@ define([
test('sets inFindAppointmentMode on SET_FIND_APPOINTMENT_MODE', () => { test('sets inFindAppointmentMode on SET_FIND_APPOINTMENT_MODE', () => {
const initialState = { const initialState = {
inFindAppointmentMode: false inFindAppointmentMode: false,
}; setCourse: {}
}
const newState = reducer(initialState, { const newState = reducer(initialState, {
type: 'SET_FIND_APPOINTMENT_MODE', type: 'SET_FIND_APPOINTMENT_MODE',
payload: true payload: true
}); })
ok(newState.inFindAppointmentMode) ok(newState.inFindAppointmentMode)
}); })
}); test('sets selectedCourse on SET_COURSE', () => {
const initialState = {
inFindAppointmentMode: false,
selectedCourse : null
}
const newState = reducer(initialState, {
type: 'SET_COURSE',
payload: {id: 1, name: "blah"}
})
ok(newState.selectedCourse)
})
})