Skip to content

Commit

Permalink
Add ability to set fields in an issue in redux
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgepigdaniel committed Oct 13, 2017
1 parent 4c6ad1a commit 5068c24
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ export const commitIssue = dispatch => {
})
})
}

export const changeField = (key, value) => ({
type: 'UPDATE_ISSUE',
key,
value,
})
89 changes: 64 additions & 25 deletions src/components/MeetingTable.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
import React from 'react'
import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import { changeField } from '../actions'
import { selectDraftIssue } from '../selectors/issues'
import styles from '../css/MeetingTable'

const MeetingTable = () => (
<div className={styles.meetingTable}>
<div className={styles.meetingRows}>
<label htmlFor='MettingPoint' className={styles.meetingLabels}>
Meeting point
</label>
<input className='form-control' />
</div>
<div className={styles.meetingRows}>
<label htmlFor='ShortDesc' className={styles.meetingLabels}>
{' '}
Short Desc{' '}
</label>
<textarea className='form-control' />
</div>
<div className={styles.meetingRows}>
<label htmlFor='NumVotes' className={styles.meetingLabels}>
{' '}
Num of votes reqd{' '}
</label>
<input />
</div>
</div>
)
class _MeetingTable extends PureComponent {
onChangeNumVotes = event => {
this.props.changeField('numVotes', event.currentTarget.value)
}

onChangeDescription = event => {
this.props.changeField('description', event.currentTarget.value)
}

onChangeLabel = event => {
this.props.changeField('label', event.currentTarget.value)
}

render() {
return (
<div className={styles.meetingTable}>
<div className={styles.meetingRows}>
<label htmlFor='ShortDesc' className={styles.meetingLabels}>
{' '}
Issue label{' '}
</label>
<textarea
className='form-control'
value={this.props.draftIssue.get('label')}
onChange={this.onChangeLabel}
/>
</div>
<div className={styles.meetingRows}>
<label htmlFor='MettingPoint' className={styles.meetingLabels}>
Issue description
</label>
<input
className='form-control'
value={this.props.draftIssue.get('description')}
onChange={this.onChangeDescription}
/>
</div>
<div className={styles.meetingRows}>
<label htmlFor='NumVotes' className={styles.meetingLabels}>
{' '}
Num of votes reqd{' '}
</label>
<input
value={this.props.draftIssue.get('numVotes')}
onChange={this.onChangeNumVotes}
/>
</div>
</div>
)
}
}

const MeetingTable = connect(
state => ({
draftIssue: selectDraftIssue(state),
}),
dispatch => ({
changeField: (field, value) => dispatch(changeField(field, value)),
})
)(_MeetingTable)

export default MeetingTable
7 changes: 6 additions & 1 deletion src/reducers/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ const updaters = new Map([

const INITIAL_STATE = fromJS({
committed: [],
draft: {},
draft: {
numVotes: 0,
description: '',
label: '',
date: '',
},
})

export default (state = INITIAL_STATE, action) => {
Expand Down
4 changes: 4 additions & 0 deletions src/selectors/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export const selectCurrentIssue = createSelector(
selectLocation,
(issues, location) => issues.get(location.payload.issueId)
)

export const selectDraftIssue = createSelector(selectIssues, issues =>
issues.get('draft')
)

0 comments on commit 5068c24

Please sign in to comment.