Created
April 6, 2016 07:05
-
-
Save rommsen/ec707755511150590d957a13d8e08525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import {connect} from "react-redux"; | |
import {changingOfMonthFeeWasRequested} from "./monthDucks"; | |
import ChangeMonthFeeForm from "./ChangeMonthFeeForm"; | |
/** | |
* component | |
*/ | |
export const Month = ({showForm, month, onClick}) => { | |
return ( | |
<tr> | |
<td> | |
{month.name} | |
</td> | |
<td> | |
{month.year} | |
</td> | |
<td> | |
{showForm | |
? <ChangeMonthFeeForm month={month}/> | |
: <a onClick={onClick}>{month.amount}</a> | |
} | |
</td> | |
</tr> | |
); | |
}; | |
// ownProps contains the props of the rendered component | |
function mapStateToProps(state, ownProps) { | |
return { | |
showForm: state.app.showChangeMonthFeeForm === ownProps.month.id, | |
} | |
} | |
function mapDispatchToProps(dispatch, ownProps) { | |
return { | |
onClick: () => { | |
dispatch(changingOfMonthFeeWasRequested(ownProps.month.id)); | |
} | |
} | |
} | |
/** | |
* container | |
*/ | |
export default connect(mapStateToProps, mapDispatchToProps)(Month); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment