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

Add Formspree Example #10

Merged
merged 2 commits into from
Mar 16, 2020
Merged
Changes from all 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
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>
);
}
};
};