Browse Source

restrictions

logicp 6 years ago
parent
commit
ff3862e0d3
1 changed files with 17 additions and 16 deletions
  1. 17 16
      src/form.js

+ 17 - 16
src/form.js

@@ -102,25 +102,26 @@ class TextFields extends React.Component {
   }
 
   submitForm = async () => {
-    console.log(this.state)
-    const body = JSON.stringify({
-      name: this.state.name,
-      cat: this.state.cat,
-      guest: this.state.significantOther,
-    })
+    if (this.state.name && this.state.name.length > 0) {
+      const body = JSON.stringify({
+        name: this.state.name,
+        cat: this.state.cat,
+        guest: this.state.significantOther,
+      })
 
-    const response = await fetch('/attendee', {
-      method: 'post',
-      body: body,
-      headers: new Headers({
-        'Content-Type': 'application/json'
+      const response = await fetch('/attendee', {
+        method: 'post',
+        body: body,
+        headers: new Headers({
+          'Content-Type': 'application/json'
+        })
       })
-    })
 
-    if (!response.error) {
-      console.log('Success')
-      this.setState({attendees: MakeAttendees(await this.fetchAttendees())})
-      addHugeAssImage()
+      if (!response.error) {
+        console.log('Success')
+        this.setState({attendees: MakeAttendees(await this.fetchAttendees())})
+        addHugeAssImage()
+      }
     }
   }