mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-15 17:43:03 +03:00
36 lines
727 B
TypeScript
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;
|
||
|
};
|