-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port over hubspot form loading fix (#164)
* Port over hubspot form loading fix * add code insights to header, add chilipiper to code insights * Remove redundant meta img value Co-authored-by: Becca Steinbrecher <becca.steinbrecher@sourcegraph.com@Beccas-MBP.lan> Co-authored-by: Tim Zielonko <tim.zielonko@sourcegraph.com>
- Loading branch information
1 parent
7bfa75e
commit 38d64da
Showing
21 changed files
with
427 additions
and
403 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
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,67 @@ | ||
import { useEffect } from 'react' | ||
|
||
declare global { | ||
interface Window { | ||
ChiliPiper?: IChiliPiper | ||
} | ||
} | ||
|
||
export interface MessageEventData { | ||
type: string | ||
eventName: string | ||
data: { name: string; value: string }[] | ||
} | ||
|
||
interface IChiliPiper { | ||
submit: ( | ||
domain: string, | ||
router: string, | ||
options?: { | ||
lead: { [key: string]: string | number } | ||
handleSubmit?: boolean | ||
formId?: string | ||
debug?: boolean | ||
map?: boolean | ||
domain?: string | ||
router?: string | ||
title?: string | ||
titleStyle?: string | ||
onSuccess?: () => void | ||
onError?: () => void | ||
onClose?: () => void | ||
onRouted?: () => void | ||
closeOnOutside?: boolean | ||
dynamicRedirectLink?: string | ||
mobileRedirectLink?: string | ||
injectRootCss?: boolean | ||
locale?: string | ||
webHook?: string | ||
} | ||
) => void | ||
} | ||
|
||
export const useChiliPiper = (): void => { | ||
useEffect(() => { | ||
const chiliPiperScript = '//js.chilipiper.com/marketing.js' | ||
const script = document.createElement('script') | ||
script.src = chiliPiperScript | ||
document.head.append(script) | ||
const cpTenantDomain = 'sourcegraph' | ||
const cpRouterName = 'contact-sales' | ||
window.addEventListener('message', event => { | ||
const data = event.data as MessageEventData | ||
if (data.type === 'hsFormCallback' && data.eventName === 'onFormSubmit') { | ||
const lead = data.data.reduce((object, item) => Object.assign(object, { [item.name]: item.value }), {}) | ||
const chilipiper = window.ChiliPiper | ||
chilipiper?.submit(cpTenantDomain, cpRouterName, { | ||
map: true, | ||
lead, | ||
}) | ||
} | ||
}) | ||
|
||
return () => { | ||
script?.remove() | ||
} | ||
}, []) | ||
} |
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.