quivr/frontend/lib/helpers/intercom/IntercomProvider.ts
Antoine Dewez 04d6c3432f
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):
2024-02-04 22:06:24 -08:00

36 lines
727 B
TypeScript

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;
};