import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { tutorialId, setError, deleteError } from '../../../actions/tutorialBuilderActions'; import { withStyles } from '@material-ui/core/styles'; import Button from '@material-ui/core/Button'; import OutlinedInput from '@material-ui/core/OutlinedInput'; import InputLabel from '@material-ui/core/InputLabel'; import FormControl from '@material-ui/core/FormControl'; import FormHelperText from '@material-ui/core/FormHelperText'; import { faPlus, faMinus } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; const styles = theme => ({ errorColor: { color: theme.palette.error.dark }, errorColorShrink: { color: `rgba(0, 0, 0, 0.54) !important` }, errorBorder: { borderColor: `${theme.palette.error.dark} !important` } }); class Id extends Component { handleChange = (e) => { var value = parseInt(e.target.value); if (Number.isInteger(value) && value > 0) { this.props.tutorialId(value); if (this.props.error) { this.props.deleteError(undefined, 'id'); } } else { this.props.tutorialId(value.toString()); this.props.setError(undefined, 'id'); } }; handleCounter = (step) => { if (this.props.value + step < 1) { this.props.setError(undefined, 'id'); } else if (this.props.error) { this.props.deleteError(undefined, 'id'); } if (!this.props.value || !Number.isInteger(this.props.value)) { this.props.tutorialId(0 + step); } else { this.props.tutorialId(this.props.value + step); } } render() { return (
ID
} /> {this.props.error ? Gib eine positive ganzzahlige Zahl ein. : null} Beachte, dass die ID eindeutig sein muss. Sie muss sich also zu den anderen Tutorials unterscheiden. ); }; } Id.propTypes = { tutorialId: PropTypes.func.isRequired, setError: PropTypes.func.isRequired, deleteError: PropTypes.func.isRequired }; const mapStateToProps = state => ({ change: state.builder.change }); export default connect(mapStateToProps, { tutorialId, setError, deleteError })(withStyles(styles, { withTheme: true })(Id));