Skip to content

Commit

Permalink
Merge pull request #10 from raisely/add-formspree-example
Browse files Browse the repository at this point in the history
Add Formspree Example
  • Loading branch information
nickpedersen authored Mar 16, 2020
2 parents 2d37eaa + 96c73ab commit 8a68f9d
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions formspree-form/formspree-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
(RaiselyComponents, React) => {
const { Form, styled } = RaiselyComponents;

const formspreeUrl = "https://formspree.io/abc123";

const initialValues = {};

const Wrapper = styled("div")`
.field-wrapper {
margin-bottom: 0.5rem;
}
.contact-form-thanks {
padding: 1rem;
text-align: center;
font-weight: bold;
background: #333;
color: white;
}
`;

return class ContactForm extends React.Component {
state = {};
save = async (data, options) => {
if (!data.firstName || !data.lastName || !data.email) {
throw new Error("Please fill in all the required fields");
}

const response = await fetch(formspreeUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json"
},
body: JSON.stringify(data)
});

this.setState({ complete: true });
};

FinalPage() {
return (
<Wrapper>
<div className="contact-form-thanks">
<p>Thanks! We'll be in touch shortly.</p>
</div>
</Wrapper>
);
}

render() {
if (this.state.complete) return <this.FinalPage />;
return (
<Wrapper>
<Form
global={this.props.global}
unlocked
fields={[
{
active: true,
visible: true,
label: "First Name",
type: "text",
id: "firstName",
required: true,
core: true
},
{
active: true,
visible: true,
label: "Last Name",
type: "text",
id: "lastName",
required: true,
core: true
},
{
active: true,
visible: true,
label: "Email",
type: "email",
id: "email",
required: true,
core: true
},
{
active: true,
visible: true,
label: "Message",
type: "textarea",
id: "message",
required: false,
core: true
}
]}
values={initialValues}
action={this.save}
actionText="Send Message"
/>
</Wrapper>
);
}
};
};

0 comments on commit 8a68f9d

Please sign in to comment.