import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; import { tutorialTitle, jsonString, changeContent, setError, deleteError, } from "../../../actions/tutorialBuilderActions"; import withStyles from '@mui/styles/withStyles'; import OutlinedInput from "@mui/material/OutlinedInput"; import InputLabel from "@mui/material/InputLabel"; import FormControl from "@mui/material/FormControl"; import FormHelperText from "@mui/material/FormHelperText"; const styles = (theme) => ({ multiline: { padding: "18.5px 14px 18.5px 24px", }, errorColor: { color: `${theme.palette.error.dark} !important`, }, errorColorShrink: { color: `rgba(0, 0, 0, 0.54) !important`, }, errorBorder: { borderColor: `${theme.palette.error.dark} !important`, }, }); class Textfield extends Component { handleChange = (e) => { var value = e.target.value; if (this.props.property === "title") { this.props.tutorialTitle(value); } else if (this.props.property === "json") { this.props.jsonString(value); } else { this.props.changeContent( value, this.props.index, this.props.property, this.props.property2 ); } if (value.replace(/\s/g, "") === "") { this.props.setError(this.props.index, this.props.property); } else { this.props.deleteError(this.props.index, this.props.property); } }; render() { return ( {this.props.label} this.handleChange(e)} /> {this.props.error ? ( this.props.property === "title" ? ( Gib einen Titel für das Tutorial ein. ) : this.props.property === "json" ? ( Gib einen JSON-String ein und bestätige diesen mit einem Klick auf den entsprechenden Button ) : ( {this.props.errorText} ) ) : null} ); } } Textfield.propTypes = { tutorialTitle: PropTypes.func.isRequired, jsonString: PropTypes.func.isRequired, changeContent: PropTypes.func.isRequired, }; export default connect(null, { tutorialTitle, jsonString, changeContent, setError, deleteError, })(withStyles(styles, { withTheme: true })(Textfield));