-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* HelpScout POC enabled with LaunchDarkly * Revert changes to NDAWrapper that were from testing
- Loading branch information
1 parent
d4b1058
commit d32a4be
Showing
10 changed files
with
77 additions
and
18 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ declare global { | |
|
||
interface Window { | ||
Cypress: any; | ||
Beacon: any; | ||
store: any; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { ReactNode, useEffect } from 'react'; | ||
import { useOktaAuth } from '@okta/okta-react'; | ||
import { useFlags } from 'launchdarkly-react-client-sdk'; | ||
|
||
const BEACON_ID = process.env.REACT_APP_BEACON_ID; | ||
|
||
// BeaconWrapper manages the state necessary for child components to | ||
// use the useBeacon hook. | ||
const BeaconWrapper = ({ children }: { children: ReactNode }) => { | ||
const [beaconInitialized, setBeaconInitialized] = React.useState(false); | ||
const { authState } = useOktaAuth(); | ||
const flags = useFlags(); | ||
|
||
// Initialize / destroy the beacon based on authentication state | ||
useEffect(() => { | ||
const shouldShowBeacon = | ||
authState?.isAuthenticated && flags?.helpScoutEnabled; | ||
if (shouldShowBeacon && !beaconInitialized) { | ||
window.Beacon('init', BEACON_ID); | ||
setBeaconInitialized(true); | ||
|
||
// Only identify if we have the information to do so | ||
const name = authState?.idToken?.claims?.name; | ||
const email = authState?.idToken?.claims?.email; | ||
if (name && email) { | ||
window.Beacon('identify', { | ||
name, | ||
}); | ||
} | ||
} else if (!shouldShowBeacon && beaconInitialized) { | ||
window.Beacon('destroy'); | ||
setBeaconInitialized(false); | ||
} | ||
}, [ | ||
authState?.isAuthenticated, | ||
authState?.idToken?.claims?.name, | ||
authState?.idToken?.claims?.email, | ||
flags?.helpScoutEnabled, | ||
beaconInitialized | ||
]); | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
export default BeaconWrapper; |
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