Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom forms #297

Merged
merged 9 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@reach/skip-nav": "0.10.3",
"@reach/visually-hidden": "0.10.2",
"base-64": "^0.1.0",
"dotenv": "^8.2.0",
SeHarlan marked this conversation as resolved.
Show resolved Hide resolved
"emotion-theming": "^10.0.27",
"gatsby": "^2.23.3",
"gatsby-cypress-endpoints": "0.0.6",
Expand Down Expand Up @@ -95,4 +94,4 @@
"*.{js,jsx,ts,tsx,d.ts,css,md}": "prettier --write",
"*.{js,jsx,ts,tsx}": "eslint"
}
}
}
6 changes: 4 additions & 2 deletions src/components/Feeds/AllyFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ import { CardWrapper, CardHeading, CardText, CardContent } from '../Card';
import Button from '../Button';
import Image from '../Image';
import SubmitAlly from '../Forms/SubmitAlly';
import AllySignUpForm from '../Forms/AllySignUpForm';

// @TODO :: Add proper content to this modal. Probably pull this out into its own file seeing as its going to be a form
const ModalForm = ({ isOpen, onClose, title }) => (
<Modal isOpen={isOpen} onClose={onClose}>
<Modal isOpen={isOpen} onClose={onClose} closeOnOverlayClick={false}>
<ModalOverlay />
<ModalContent>
<ModalHeader>{title}</ModalHeader>
<ModalCloseButton />
<ModalBody>
<SubmitAlly />
{/* <SubmitAlly */}
SeHarlan marked this conversation as resolved.
Show resolved Hide resolved
<AllySignUpForm />
</ModalBody>
</ModalContent>
</Modal>
Expand Down
141 changes: 141 additions & 0 deletions src/components/Forms/AllySignUpForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import React, { useState } from 'react';
import {
Flex,
FormControl,
FormLabel,
Input,
Select,
useTheme,
Text,
} from '@chakra-ui/core';

import PrimaryButton from '../Buttons/PrimaryButton';
import { submitAlly } from '../../services/AirtableServices';

const skillTypes = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SeHarlan are we able to pull the skill types from Airtable via the API? Just thinking of ways we can possibly keep things as dynamic as possible!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is proving really difficult. I've looked through all the docs and as far as I can see they don't provide access to the select options. There are quite a few complaints about it in the community forums lol. I made a custom hook that grabs the first page of docs and filters for just the specialty field and then I reduce it to only unique items. But this really isn't performant. Not sure what you wanna do with it so I'll leave it in just in case.

{ id: 'business', label: 'Business' },
{ id: 'marketing', label: 'Marketing' },
{ id: 'outreach', label: 'Outreach' },
{ id: 'tech', label: 'Tech' },
{ id: 'government', label: 'Government' },
];

const AllySignUpForm = () => {
const [email, setEmail] = useState(null);
const [firstName, setFirstName] = useState(null);
const [lastName, setLastName] = useState(null);
const [zipcode, setZipcode] = useState(null);
const [skill, setSkill] = useState(null);
const [validationMessage, setValidationMessage] = useState(null);
const [submitted, setSubmitted] = useState(false);
const theme = useTheme();

const handleSubmit = event => {
event.preventDefault();
const infoToSubmit = {
email,
firstName,
lastName,
skill,
zipcode,
};

//Custom Validation
const valuesToValidate = Object.values(infoToSubmit);
//Validates all fields are filled
if (valuesToValidate.includes(null)) {
setValidationMessage('All fields are required.');
return;
}

submitAlly(infoToSubmit);

setSubmitted(true);
};

//renders in place of form once it has been submitted
if (submitted) return <Text fontSize="2xl">Thank you for signing up!</Text>;

return (
<FormControl
isRequired
width="100%"
maxWidth="1000px"
margin="0 auto 3rem"
padding="0 24px"
onKeyPress={event => {
if (event.key === 'Enter') {
handleSubmit(event);
}
}}
>
{/* renders when form is submitted with validation errors */}
{validationMessage && <Text>{validationMessage}</Text>}

<Flex width="100%" direction="column">
<Flex direction="column" margin={theme.spacing.base}>
<FormLabel htmlFor="firstName">First name</FormLabel>
<Input
value={firstName}
id="firstName"
type="text"
placeholder="First name"
onChange={event => setFirstName(event.currentTarget.value)}
/>
</Flex>
<Flex direction="column" margin={theme.spacing.base}>
<FormLabel htmlFor="lastName">Last name</FormLabel>
<Input
value={lastName}
id="lastName"
type="text"
placeholder="Last name"
onChange={event => setLastName(event.currentTarget.value)}
/>
</Flex>
<Flex direction="column" margin={theme.spacing.base}>
<FormLabel htmlFor="email">Email</FormLabel>
<Input
value={email}
id="email"
type="text"
placeholder="Email"
onChange={event => setEmail(event.currentTarget.value)}
/>
</Flex>
<Flex direction="column" margin={theme.spacing.base}>
<FormLabel htmlFor="skill">Specialty</FormLabel>
<Select
id="skill"
placeholder="Specialty"
value={skill}
onChange={event => setSkill(event.currentTarget.value)}
>
{skillTypes.map(skill => {
return (
<option key={skill.id} value={skill.label}>
{skill.label}
</option>
);
})}
</Select>
</Flex>
<Flex direction="column" margin={theme.spacing.base}>
<FormLabel htmlFor="zipcode">Zipcode</FormLabel>
<Input
value={zipcode}
id="zipcode"
type="text"
placeholder="Zipcode"
onChange={event => setZipcode(event.currentTarget.value)}
/>
</Flex>
</Flex>
<Flex width="100%" justify="center">
<PrimaryButton onClick={handleSubmit}>Register</PrimaryButton>
</Flex>
</FormControl>
);
};

export default AllySignUpForm;
Loading