import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/styles'; import { Field } from 'redux-form/immutable'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { CheckboxRedux, SelectRedux, TextFieldRedux, SwitchRedux } from 'ba-components/Forms/ReduxFormMUI'; import { fetchAction, addAction, closeAction, submitAction, removeAction, editAction, closeNotifAction } from 'ba-actions/CrudTbFrmActions'; import { CrudTableForm, Notification } from 'ba-components'; import { Paper, MenuItem, InputLabel, Radio, RadioGroup, FormControl, FormLabel, FormControlLabel, } from '@material-ui/core'; import { anchorTable, dataApi } from './sampleData'; const branch = 'crudTbFrmDemo'; const renderRadioGroup = ({ input, ...rest }) => ( input.onChange(value)} /> ); // validation functions const required = value => (value == null ? 'Required' : undefined); const email = value => ( value && !/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(value) ? 'Invalid email' : undefined ); const styles = ({ root: { flexGrow: 1, }, field: { width: '100%', marginBottom: 20 }, fieldBasic: { width: '100%', marginBottom: 20, marginTop: 10 }, inlineWrap: { display: 'flex', flexDirection: 'row' } }); class CrudTbFormDemo extends Component { saveRef = ref => { this.ref = ref; return this.ref; }; render() { const { classes, fetchData, addNew, closeForm, submit, removeRow, editRow, dataTable, openForm, initValues, closeNotif, messageNotif, } = this.props; const trueBool = true; return (
closeNotif(branch)} message={messageNotif} /> {/* Create Your own form, then arrange or custom it as You like */}
Choose One Option } label="Option 1" /> } label="Option 2" />
Selection Option One Option Two Option Three
Toggle Input
} label="On/OF Switch" /> } label="Checkbox" />
{/* No need create button or submit, because that already made in this component */}
); } } renderRadioGroup.propTypes = { input: PropTypes.object.isRequired, }; CrudTbFormDemo.propTypes = { dataTable: PropTypes.object.isRequired, openForm: PropTypes.bool.isRequired, classes: PropTypes.object.isRequired, fetchData: PropTypes.func.isRequired, addNew: PropTypes.func.isRequired, closeForm: PropTypes.func.isRequired, submit: PropTypes.func.isRequired, removeRow: PropTypes.func.isRequired, editRow: PropTypes.func.isRequired, initValues: PropTypes.object.isRequired, closeNotif: PropTypes.func.isRequired, messageNotif: PropTypes.string.isRequired, }; const mapStateToProps = state => ({ force: state, // force state from reducer initValues: state.getIn([branch, 'formValues']), dataTable: state.getIn([branch, 'dataTable']), openForm: state.getIn([branch, 'showFrm']), messageNotif: state.getIn([branch, 'notifMsg']), }); const mapDispatchToProps = dispatch => ({ fetchData: bindActionCreators(fetchAction, dispatch), addNew: bindActionCreators(addAction, dispatch), closeForm: bindActionCreators(closeAction, dispatch), submit: bindActionCreators(submitAction, dispatch), removeRow: bindActionCreators(removeAction, dispatch), editRow: bindActionCreators(editAction, dispatch), closeNotif: bindActionCreators(closeNotifAction, dispatch), }); const CrudTbFormDemoMapped = connect( mapStateToProps, mapDispatchToProps )(CrudTbFormDemo); export default withStyles(styles)(CrudTbFormDemoMapped);