-
Notifications
You must be signed in to change notification settings - Fork 160
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 #670 from input-output-hk/filip/feat/embedded-news…
…letter-form filip(feat): add hubspot newsletter form
- Loading branch information
Showing
4 changed files
with
245 additions
and
0 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 @@ | ||
import React, { useCallback, useState } from 'react' | ||
import HubspotForm from './HubspotForm' | ||
|
||
const ContactHubspotForm = ({ formId, portalId, region }) => { | ||
const [submitted, setSubmitted] = useState(false) | ||
|
||
const onFormSubmitted = useCallback(() => { | ||
setSubmitted(true) | ||
}, []) | ||
|
||
return submitted ? ( | ||
<div className="hs-form-submitted-message"> | ||
<h3 className="hs-form-submitted-title">Enquiry submitted</h3> | ||
<p>We'll be in touch soon!</p> | ||
</div> | ||
) : ( | ||
<HubspotForm | ||
componentId="newsletterHSForm" | ||
region={region} | ||
portalId={portalId} | ||
formId={formId} | ||
onFormSubmitted={onFormSubmitted} | ||
/> | ||
) | ||
} | ||
|
||
export default ContactHubspotForm |
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,56 @@ | ||
//@ts-nocheck | ||
import React, { useEffect, useState, useCallback } from 'react' | ||
import styled, { createGlobalStyle } from 'styled-components' | ||
|
||
const HubspotForm = (props) => { | ||
const { componentId, region, portalId, formId, onFormSubmitted } = props | ||
|
||
const [formReady, setFormReady] = useState(false) | ||
|
||
const onFormReady = useCallback(() => { | ||
setFormReady(true) | ||
}, []) | ||
|
||
const addScript = () => { | ||
let script | ||
if (typeof window !== 'undefined') { | ||
script = document.createElement('script') | ||
script.src = 'https://js.hsforms.net/forms/embed/v2.js' | ||
script.async = true | ||
|
||
script.onload = () => { | ||
if (window) { | ||
if (window.hbspt) { | ||
window.hbspt.forms.create({ | ||
region: region, | ||
portalId: portalId, | ||
formId: formId, | ||
target: `#${componentId}`, | ||
onFormSubmitted: onFormSubmitted, | ||
onFormReady: onFormReady, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
document.body.appendChild(script) | ||
} | ||
|
||
useEffect(() => { | ||
addScript() | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<div id={componentId} /> | ||
{!formReady && ( | ||
<div className="hs-loading-container"> | ||
<div className="hs-loading-spinner" /> | ||
</div> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default HubspotForm |
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
d0c5edd
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.
Deploy preview for cardano-documentation ready!
✅ Preview
https://cardano-documentation-4agni7nl2-iog.vercel.app
https://cardano-documentation.vercel.app
Built with commit d0c5edd.
This pull request is being automatically deployed with vercel-action