Skip to content

Commit

Permalink
Merge pull request #63 from ResetNetwork/contact-form
Browse files Browse the repository at this point in the history
Builds contact form that submits to Sanity
  • Loading branch information
harumhelmy authored Jan 19, 2022
2 parents db576ab + 6d5a5df commit ed43828
Show file tree
Hide file tree
Showing 11 changed files with 449 additions and 13,155 deletions.
31 changes: 31 additions & 0 deletions functions/submission-created.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const sanityClient = require("@sanity/client");
const client = sanityClient({
projectId: process.env.SANITY_PROJECT_ID,
dataset: process.env.SANITY_DATASET,
token: process.env.SANITY_ACCESS_TOKEN,
useCDN: false,
});

exports.handler = async function (event, context, callback) {
const { payload } = JSON.parse(event.body);

const isContactForm = payload.data.formId === "contact-form";

// Build the document JSON and submit it to SANITY
if (isContactForm) {
const contact = {
_type: "contact_submission", // must match the name of the contact document type on the Sanity schema
name: payload.data.name,
email: payload.data.email,
message: payload.data.message,
};

const result = await client
.create(contact)
.catch((err) => console.log(err));
}

callback(null, {
statusCode: 200,
});
};
1 change: 1 addition & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[build]
publish = ".next"
command = "./stackbit-build.sh"
functions = "functions/"

[[plugins]]
package = "@netlify/plugin-nextjs"
Loading

0 comments on commit ed43828

Please sign in to comment.