From ee3bf592b9a84fed820640e716e42078d5664882 Mon Sep 17 00:00:00 2001 From: Michael Esch Date: Tue, 31 Jul 2018 15:19:10 -0400 Subject: [PATCH 1/2] Add ErrorList component --- src/components/App.js | 8 +++++++- src/components/Contest.js | 11 +++++++++-- src/components/ErrorList.js | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/components/ErrorList.js diff --git a/src/components/App.js b/src/components/App.js index fdf7d66..886b394 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -89,6 +89,10 @@ class App extends React.Component { }).catch(console.error); } + validateForm = () => { + + } + currentContest() { const { contests, currentContestId } = this.state; return contests[currentContestId]; @@ -102,7 +106,7 @@ class App extends React.Component { } currentContent() { - const { contests, currentContestId } = this.state; + const { contests, currentContestId, errors } = this.state; if (currentContestId) { return ( ); diff --git a/src/components/Contest.js b/src/components/Contest.js index 9841f57..1d03dee 100644 --- a/src/components/Contest.js +++ b/src/components/Contest.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import ErrorList from './ErrorList'; class Contest extends React.Component { componentDidMount() { @@ -10,8 +11,11 @@ class Contest extends React.Component { handleSubmit = (event) => { const { addName, _id } = this.props; event.preventDefault(); - addName(this.newNameInput.value, _id); - this.newNameInput.value = ''; + if (this.validateForm()) { + addName(this.newNameInput.value, _id); + this.newNameInput.value = ''; + } + } render() { @@ -20,6 +24,7 @@ class Contest extends React.Component { contestListClick, lookupName, nameIds, + errors, } = this.props; return ( @@ -61,6 +66,7 @@ class Contest extends React.Component {
+
{ this.newNameInput = element; }} className="form-control" + required />