-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): add a chatbot for users (#2144)
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
- Loading branch information
Showing
4 changed files
with
75 additions
and
12 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,35 @@ | ||
import { usePathname } from "next/navigation"; | ||
import { useEffect } from "react"; | ||
|
||
import { useUserData } from "@/lib/hooks/useUserData"; | ||
|
||
import { | ||
boot as bootIntercom, | ||
load as loadIntercom, | ||
update as updateIntercom, | ||
} from "./intercom"; | ||
|
||
export const IntercomProvider = ({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}): React.ReactNode => { | ||
const pathname = usePathname(); | ||
const { userData } = useUserData(); | ||
|
||
if ( | ||
typeof window !== "undefined" && | ||
process.env.NEXT_PUBLIC_INTERCOM_APP_ID | ||
) { | ||
loadIntercom(); | ||
bootIntercom(userData?.email ?? ""); | ||
} | ||
|
||
useEffect(() => { | ||
if (process.env.NEXT_PUBLIC_INTERCOM_APP_ID) { | ||
updateIntercom(); | ||
} | ||
}, [pathname]); | ||
|
||
return children; | ||
}; |
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,17 @@ | ||
/* eslint-disable */ | ||
export const APP_ID = process.env.NEXT_PUBLIC_INTERCOM_APP_ID; | ||
|
||
// prettier-ignore | ||
export const load = (): void => { | ||
(function(){const w=window;const ic=(w as any).Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',(w as any).intercomSettings);}else{const d=document;const i=function(){i.c(arguments);};i.q=[] as any[];i.c=function(args: any){i.q.push(args);};(w as any).Intercom=i;const l=function(){const s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/' + APP_ID;const x=d.getElementsByTagName('script')[0];x.parentNode?.insertBefore(s, x);};if(document.readyState==='complete'){l();}else if((w as any).attachEvent){(window as any).attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})(); | ||
} | ||
|
||
// Initializes Intercom | ||
export const boot = (email: string): void => { | ||
(window as any).Intercom && | ||
(window as any).Intercom("boot", { app_id: APP_ID, email }); | ||
}; | ||
|
||
export const update = (): void => { | ||
window && (window as any).Intercom && (window as any).Intercom("update"); | ||
}; |
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