diff --git a/package.json b/package.json index 93b100f..57495af 100644 --- a/package.json +++ b/package.json @@ -148,7 +148,8 @@ "webpack": "4.28.3", "webpack-dev-server": "3.1.14", "webpack-manifest-plugin": "2.0.4", - "workbox-webpack-plugin": "3.6.3" + "workbox-webpack-plugin": "3.6.3", + "yup": "^0.27.0" }, "browserslist": [ ">0.2%", diff --git a/src/components/base/TextField.jsx b/src/components/base/TextField.jsx index d45aacc..57f4c39 100644 --- a/src/components/base/TextField.jsx +++ b/src/components/base/TextField.jsx @@ -61,6 +61,12 @@ const useStyles = makeStyles((theme) => ({ gridRowStart: 4, gridColumnStart: 1, }, + red: { + color: '#db0000' + }, + errorBorder: { + border: '1px solid #db0000' + }, topRight: { gridRowStart: 1, gridColumnStart: 12, @@ -83,10 +89,12 @@ function Input({ idFor, isRequired, endAdornment, + errorBorder, InputProps, inputClass, label, bottomRightLabel, + bottomRightError, bottomLeftLabel, placeholder, className, @@ -101,7 +109,9 @@ function Input({ const labelForm = label ? renderLabel(classnames(classes.formLabel, classes.top), idFor, label, isRequired) : null const topRightLabel = topRight ? renderLabel(classnames(classes.topRight), idFor, topRight) : null const bottomLeft = bottomLeftLabel ? renderLabel(classnames(classes.formLabel, classes.bottomLeft), idFor, bottomLeftLabel) : null - const bottomRight = bottomRightLabel ? renderLabel(classnames(classes.formLabel, classes.bottomRight), idFor, bottomRightLabel) : null + const bottomRight = bottomRightLabel ? renderLabel(classnames(classes.formLabel, classes.bottomRight, { + [classes.red]: bottomRightError + }), idFor, bottomRightLabel) : null return ( hours * 60 * 60 const helperText = 'The length of time the Project has to veto when the project delegates to another delegate and they pledge those funds to a project' const generateChatRoom = title => `#status-${title.replace(/\s/g, '')}` +const validationSchema = Yup.object().shape({ + title: Yup.string().max(20, TOO_LONG).required(REQUIRED) +}); const styles = theme => ({ adornmentText: { @@ -203,6 +210,7 @@ const SubmissionSection = ({ classes, history }) => { description: '', commitTime: 24 }} + validationSchema={validationSchema} onSubmit={async (values, { resetForm }) => { const { title, commitTime } = values const manifest = createJSON(values) @@ -231,8 +239,8 @@ const SubmissionSection = ({ classes, history }) => { > {({ values, - errors: _errors, - touched: _touched, + errors, + touched, handleChange, handleBlur, handleSubmit, @@ -244,6 +252,7 @@ const SubmissionSection = ({ classes, history }) => { const { firstHalf, secondHalf, fullWidth } = classes const { goalToken, goal } = values const usdValue = convertTokenAmountUsd(goalToken, goal, prices) + console.log({errors, touched}) return (
{ name="title" label="Project Name" bottomRightLabel="Max 20" + bottomRightError={errors.title === TOO_LONG} + errorBorder={errors.title === REQUIRED} placeholder="e.g. ‘Tribute to Talk’ or ‘Bob’" onChange={handleChange} onBlur={handleBlur} @@ -408,7 +419,7 @@ const SubmissionSection = ({ classes, history }) => {
-