Skip to content

Commit

Permalink
Move duplicated HubSpot code into HubSpot component (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Blunden committed Mar 5, 2020
1 parent 0a0add4 commit 5ce5208
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 67 deletions.
21 changes: 21 additions & 0 deletions website/src/components/HubSpot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export interface HubSpotForm {
portalId: string
formId: string
targetId: string
onFormSubmit?: () => void
}

export function createHubSpotForm({ portalId, formId, targetId, onFormSubmit }: HubSpotForm): void {
const script = document.createElement('script')
script.src = '//js.hsforms.net/forms/v2.js'
const hubspot = document.getElementById(targetId)
hubspot!.appendChild(script)
script.addEventListener('load', () => {
;(window as any).hbspt.forms.create({
portalId,
formId,
target: `#${targetId}`,
onFormSubmit,
})
})
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useLayoutEffect } from 'react'
import Layout from '../../components/Layout'
import { CustomerLogosSection } from '../../components/product/CustomerLogosSection'
import { createHubSpotForm } from './sales'
import { createHubSpotForm } from '../../components/HubSpot'

export default ((props: any) => {
useLayoutEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/contact/request-demo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useLayoutEffect } from 'react'
import Layout from '../../components/Layout'
import { CustomerLogosSection } from '../../components/product/CustomerLogosSection'
import { createHubSpotForm } from './sales'
import { createHubSpotForm } from '../../components/HubSpot'

export default ((props: any) => {
useLayoutEffect(() => {
Expand Down
23 changes: 1 addition & 22 deletions website/src/pages/contact/sales.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
import React, { useLayoutEffect } from 'react'
import Layout from '../../components/Layout'
import { CustomerLogosSection } from '../../components/product/CustomerLogosSection'

interface HubSpotForm {
portalId: string
formId: string
targetId: string
onFormSubmit?: () => void
}

export function createHubSpotForm({ portalId, formId, targetId, onFormSubmit }: HubSpotForm): void {
const script = document.createElement('script')
script.src = '//js.hsforms.net/forms/v2.js'
const hubspot = document.getElementById(targetId)
hubspot!.appendChild(script)
script.addEventListener('load', () => {
;(window as any).hbspt.forms.create({
portalId,
formId,
target: `#${targetId}`,
onFormSubmit,
})
})
}
import { createHubSpotForm } from '../../components/HubSpot'

export default ((props: any) => {
useLayoutEffect(() => {
Expand Down
23 changes: 1 addition & 22 deletions website/src/pages/resources/universal-code-search-ebook.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,7 @@
import React, { useLayoutEffect } from 'react'
import Layout from '../../components/Layout'
import { ContentPage } from '../../components/content/ContentPage'

interface HubSpotForm {
portalId: string
formId: string
targetId: string
onFormSubmit?: () => void
}

export function createHubSpotForm({ portalId, formId, targetId, onFormSubmit }: HubSpotForm): void {
const script = document.createElement('script')
script.src = '//js.hsforms.net/forms/v2.js'
const hubspot = document.getElementById(targetId)
hubspot!.appendChild(script)
script.addEventListener('load', () => {
;(window as any).hbspt.forms.create({
portalId,
formId,
target: `#${targetId}`,
onFormSubmit,
})
})
}
import { createHubSpotForm } from '../../components/HubSpot'


export default ((props: any) => {
Expand Down
22 changes: 1 addition & 21 deletions website/src/pages/webinars/signup-webinar-jan2020.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
import React, { useLayoutEffect } from 'react'
import Layout from '../../components/Layout'
import { CustomerLogosSection } from '../../components/product/CustomerLogosSection'
import { createHubSpotForm } from '../../components/HubSpot'

interface HubSpotForm {
portalId: string
formId: string
targetId: string
onFormSubmit?: () => void
}

export function createHubSpotForm({ portalId, formId, targetId, onFormSubmit }: HubSpotForm): void {
const script = document.createElement('script')
script.src = '//js.hsforms.net/forms/v2.js'
const hubspot = document.getElementById(targetId)
hubspot!.appendChild(script)
script.addEventListener('load', () => {
;(window as any).hbspt.forms.create({
portalId,
formId,
target: `#${targetId}`,
onFormSubmit,
})
})
}

export default ((props: any) => {
useLayoutEffect(() => {
Expand Down

0 comments on commit 5ce5208

Please sign in to comment.