diff --git a/src/components/Feeds/AllyFeed.js b/src/components/Feeds/AllyFeed.js index e6109f8f..f3db1cd4 100644 --- a/src/components/Feeds/AllyFeed.js +++ b/src/components/Feeds/AllyFeed.js @@ -167,11 +167,7 @@ const AllyFeed = props => { ) : ( )} - + ); diff --git a/src/components/Forms/AllySignUpForm.js b/src/components/Forms/AllySignUpForm.js index 6b7891e6..9d0c174f 100644 --- a/src/components/Forms/AllySignUpForm.js +++ b/src/components/Forms/AllySignUpForm.js @@ -42,9 +42,10 @@ const AllySignUpForm = () => { return; } - submitAlly(infoToSubmit); + const possibleError = submitAlly(infoToSubmit); - setSubmitted(true); + if (possibleError) setValidationMessage(possibleError); + else setSubmitted(true); }; //renders in place of form once it has been submitted @@ -63,6 +64,9 @@ const AllySignUpForm = () => { } }} > + + Sign up to be an Ally + {/* renders when form is submitted with validation errors */} {validationMessage && {validationMessage}} diff --git a/src/components/Forms/BusinessSignUpForm.js b/src/components/Forms/BusinessSignUpForm.js index cd04eb16..af5c78f7 100644 --- a/src/components/Forms/BusinessSignUpForm.js +++ b/src/components/Forms/BusinessSignUpForm.js @@ -92,9 +92,10 @@ const BusinessSignUpForm = ({ isFundraiser = false }) => { return; } - submitBusiness(infoToSubmit); + const possibleError = submitBusiness(infoToSubmit); - setSubmitted(true); + if (possibleError) setValidationMessage(possibleError); + else setSubmitted(true); }; const handleLocationType = event => { @@ -156,6 +157,9 @@ const BusinessSignUpForm = ({ isFundraiser = false }) => { } }} > + + Register your business + {/* renders when form is submitted with validation errors */} {validationMessage && {validationMessage}} diff --git a/src/components/Forms/SuggestionBox.js b/src/components/Forms/SuggestionBox.js new file mode 100644 index 00000000..3f11fa87 --- /dev/null +++ b/src/components/Forms/SuggestionBox.js @@ -0,0 +1,214 @@ +import React, { useState } from 'react'; +import { + FormControl, + Flex, + useTheme, + FormLabel, + Input, + Textarea, + Text, + NumberInput, + NumberInputField, + NumberInputStepper, + NumberIncrementStepper, + NumberDecrementStepper, +} from '@chakra-ui/core'; + +const encode = data => { + return Object.keys(data) + .map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key])) + .join('&'); +}; + +//how to intigrate with netlifys form handling +//https://www.netlify.com/blog/2017/07/20/how-to-integrate-netlifys-form-handling-in-a-react-app/#form-handling-with-static-site-generators + +export default function SuggestionBox() { + const [topic, setTopic] = useState(null); + const [description, setDescription] = useState(null); + const [benefits, setBenefits] = useState(null); + const [urgency, setUrgency] = useState(5); + const [name, setName] = useState(''); + const [email, setEmail] = useState(''); + const [validationMessage, setValidationMessage] = useState(null); + const [submitted, setSubmitted] = useState(false); + + const theme = useTheme(); + + const handleSubmit = event => { + event.preventDefault(); + + const toSubmit = { + topic, + description, + benefits, + urgency, + name, + email, + }; + + //Simple Custom Validation + const valuesToValidate = Object.values(toSubmit); + //Validates all required fields are filled (must be initiated with null). + if (valuesToValidate.includes(null)) { + setValidationMessage('All fields with * are required.'); + return; + } + + //posts to Netlify intigration + fetch('/', { + method: 'POST', + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + body: encode({ 'form-name': 'contact', toSubmit }), + }) + .then(() => { + console.log('Success!'); + setSubmitted(true); + }) + .catch(error => { + console.log(error); + setValidationMessage(error); + }); + }; + + if (submitted) { + return ( + + Thank you for your suggestion! + + ); + } + + return ( + + {/* netlify form handling */} +
+ + + + + Suggestion Box + + + {/* renders when form is submitted with validation errors */} + {validationMessage && ( + {validationMessage} + )} + + + + Topic + + setTopic(event.currentTarget.value)} + /> + + + + + Description + +