-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from ResetNetwork/contact-form
Builds contact form that submits to Sanity
- Loading branch information
Showing
11 changed files
with
449 additions
and
13,155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Oops, something went wrong.