Skip to content

Instantly share code, notes, and snippets.

@rommsen
Created April 6, 2016 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rommsen/1ebee79e59043a5660d9436b84fbd3ba to your computer and use it in GitHub Desktop.
Save rommsen/1ebee79e59043a5660d9436b84fbd3ba to your computer and use it in GitHub Desktop.
import React from "react";
import {connect} from "react-redux";
import {changeMonthFeeWasFinished, changeMonthFeeWasCancelled} from "./monthDucks";
/**
* component
*/
export const ChangeMonthFeeForm = ({month, submit, reset}) => {
let fee;
function onSubmit(e) {
e.preventDefault();
if (fee.value) {
submit(fee.value);
}
}
function onReset(e) {
e.preventDefault();
reset();
}
return (
<form onSubmit={onSubmit} className="form-inline">
<input
ref={node => fee = node}
type="text"
className="form-control"
placeholder="Betrag"
defaultValue={month.amount}
/>
<button className="btn btn-primary" onClick={onSubmit}>
<span className="glyphicon glyphicon-ok-sign"/>
</button>
<button className="btn btn-danger" onClick={onReset}>
<span className="glyphicon glyphicon-remove"/>
</button>
</form>
);
};
function mapDispatchToProps(dispatch) {
return {
submit: function(fee) {
dispatch(changeMonthFeeWasFinished(fee))
},
reset: function() {
dispatch(changeMonthFeeWasCancelled())
}
}
}
/**
* container
*/
export default connect(null, mapDispatchToProps)(ChangeMonthFeeForm);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment