This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
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 #462 from 0xProject/test/serverless
Add new Form integration and upgrade Node Version
- Loading branch information
Showing
11 changed files
with
1,469 additions
and
415 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,27 @@ | ||
export function validateContactForm(entries: { [s: string]: string }): { [s: string]: string } { | ||
const newErrors: { [s: string]: string } = {}; | ||
const requiredFields = [ | ||
'email', | ||
'firstName', | ||
'lastName', | ||
'companyName', | ||
'linkToProductOrWebsite', | ||
'usageDescription', | ||
'referral', | ||
] as const; | ||
|
||
for (const field of requiredFields) { | ||
if (entries[field] === '') { | ||
newErrors[field] = 'Field is required'; | ||
} | ||
} | ||
|
||
if (!newErrors.email && !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(entries.email)) { | ||
newErrors.email = 'No valid email address'; | ||
} | ||
|
||
if (entries.chainOfInterest === 'Other' && entries.chainOfInterestOther === '') { | ||
newErrors.chainOfInterestOther = 'Field is required'; | ||
} | ||
return newErrors; | ||
} |
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,68 @@ | ||
import type { VercelRequest, VercelResponse } from '@vercel/node'; | ||
import fetch from 'node-fetch'; | ||
|
||
import { validateContactForm } from './_utils'; | ||
|
||
// tslint:disable-next-line:no-default-export | ||
export default async function handlerAsync(req: VercelRequest, res: VercelResponse): Promise<VercelResponse> { | ||
const { body } = req; | ||
|
||
if (Object.keys(body || {}).length === 0) { | ||
return res.status(401).send('Body missing'); | ||
} | ||
|
||
const errors = validateContactForm(req.body); | ||
|
||
if (Object.keys(errors).length > 0) { | ||
return res.status(422).send('Invalid payload'); | ||
} | ||
|
||
const { | ||
firstName, | ||
lastName, | ||
email, | ||
linkToProductOrWebsite, | ||
companyName, | ||
typeOfBusiness, | ||
role, | ||
currentTradingVolume, | ||
isApplicationLive, | ||
productOfInterest, | ||
chainOfInterest, | ||
// usageDescription, | ||
timelineForIntegration, | ||
chainOfInterestOther, | ||
isApiKeyRequired, | ||
referral, | ||
} = body; | ||
|
||
const payload = { | ||
oid: process.env.SALESFORCE_OID, | ||
first_name: firstName, | ||
last_name: lastName, | ||
email, | ||
website: linkToProductOrWebsite, | ||
company: companyName, | ||
'00N8c00000drpGS': typeOfBusiness, | ||
'00N8c00000drpLI': role, | ||
'00N8c00000drpLS': currentTradingVolume, | ||
'00N8c00000drpLm': `${isApplicationLive}`, | ||
'00N8c00000drpLw': productOfInterest, | ||
'00N8c00000drr36': chainOfInterest, | ||
'00N8c00000ds8KX': timelineForIntegration, | ||
// '00N8c00000drpgB': usageDescription, | ||
...(chainOfInterest === 'Other' ? { '00N8c00000drr3B': chainOfInterestOther } : {}), | ||
'00N8c00000drpgL': `${isApiKeyRequired}`, | ||
'00N8c00000drvT8': referral, | ||
}; | ||
|
||
await fetch('https://webto.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: new URLSearchParams(payload as { [s: string]: string }), | ||
}); | ||
|
||
return res.send('Created successfully'); | ||
} |
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
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
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
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
Oops, something went wrong.
921bc20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
website – ./
0x-website.vercel.app
website-0x-eng.vercel.app
0x-website-refresh.vercel.app
www.0x.org
verceltest.0x.org
0x.org
website-git-development-0x-eng.vercel.app