mirror of
https://github.com/LaconicNetwork/laconic.com.git
synced 2026-01-20 09:24:07 +00:00
hubspot subcribe function fixed
This commit is contained in:
parent
a8c4ba5b1d
commit
b5ab6bbea9
@ -1,4 +1,8 @@
|
||||
/* eslint-disable no-console */
|
||||
|
||||
// import { Client } from '@hubspot/api-client'
|
||||
import useAxios from 'axios-hooks'
|
||||
// import Hubspot from 'hubspot'
|
||||
// import clsx from 'clsx'
|
||||
import { useRouter } from 'next/router'
|
||||
import { useTheme } from 'next-themes'
|
||||
@ -123,6 +127,18 @@ export const Footer = ({ data }: Props) => {
|
||||
const [email, setEmail] = useState('')
|
||||
const [pageUri, setPageUri] = useState<string>()
|
||||
|
||||
// const YOUR_ACCESS_TOKEN = process.env.HUBSPOT_API_KEY
|
||||
|
||||
// const hubspotClient = new hubspot.Client({
|
||||
// accessToken: YOUR_ACCESS_TOKEN
|
||||
// })
|
||||
|
||||
// hubspotClient.apiRequest({
|
||||
// method: 'POST',
|
||||
// path: '/api/emailSignup',
|
||||
// body: { key: 'value' }
|
||||
// })
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const [{ loading }, refetch] = useAxios(
|
||||
{
|
||||
@ -221,7 +237,9 @@ export const Footer = ({ data }: Props) => {
|
||||
/>
|
||||
<button
|
||||
type={'submit'}
|
||||
onClick={() => refetch()}
|
||||
onClick={() => {
|
||||
refetch
|
||||
}}
|
||||
disabled={loading}
|
||||
>
|
||||
<ArrowLink />
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
import axios from 'axios'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
const HUBSPOT_API_KEY = process.env.HUBSPOT_API_KEY
|
||||
const HUBSPOT_PORTAL_ID = '22316985' // Replace this
|
||||
const HUBSPOT_FORM_GUID = '5d0cab17-2376-44bc-bbe9-cb477bff0360' // Replace this
|
||||
|
||||
const DEV_KEY = process.env.HUBSPOT_API_KEY
|
||||
const HUBSPOT_PORTAL_ID = '22316985'
|
||||
const HUBSPOT_FORM_GUID = '5d0cab17-2376-44bc-bbe9-cb477bff0360'
|
||||
type Response = {
|
||||
success: boolean
|
||||
email?: string
|
||||
@ -12,28 +11,29 @@ type Response = {
|
||||
|
||||
export default async (req: NextApiRequest, res: NextApiResponse<Response>) => {
|
||||
const { email, pageUri } = req.body
|
||||
const { method } = req
|
||||
|
||||
if (method !== 'POST') {
|
||||
return res.status(405).end()
|
||||
}
|
||||
|
||||
if (typeof email !== 'string') {
|
||||
return res.status(400).json({ success: false })
|
||||
}
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const response = await axios({
|
||||
await axios({
|
||||
method: 'POST',
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
url: `https://api.hsforms.com/submissions/v3/integration/secure/submit/${HUBSPOT_PORTAL_ID}/${HUBSPOT_FORM_GUID}/?hapikey/=${HUBSPOT_API_KEY}`,
|
||||
url: `https://api.hsforms.com/submissions/v3/integration/secure/submit/${HUBSPOT_PORTAL_ID}/${HUBSPOT_FORM_GUID}?hapikey=${DEV_KEY}`,
|
||||
data: {
|
||||
fields: [{ name: 'email', value: email }],
|
||||
context: { pageUri }
|
||||
},
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(response)
|
||||
res.status(200).json({ success: true, email })
|
||||
} catch (error) {
|
||||
return res.status(500).json({ success: false })
|
||||
}
|
||||
|
||||
res.status(200).json({ success: true, email })
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user