Files
calendar/packages/features/ee/support/lib/freshchat/FreshChatScript.tsx
T
29ceaee8d2 feat: Add fresh chat to list of support integration (#7448)
* chore: add fresh chat configs to env.example

* feat: add fresh chat menu item and render

* refactor: remove some event listeners

* chore: make popover closed after the click

* refactor the code and fix some bugs

* feat: auto open chat

---------

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2023-03-08 11:30:24 +00:00

41 lines
1013 B
TypeScript

import Script from "next/script";
import { trpc } from "@calcom/trpc/react";
declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fcWidget: any;
}
}
// eslint-disable-next-line turbo/no-undeclared-env-vars
const host = process.env.NEXT_PUBLIC_FRESHCHAT_HOST;
// eslint-disable-next-line turbo/no-undeclared-env-vars
const token = process.env.NEXT_PUBLIC_FRESHCHAT_TOKEN;
export const isFreshChatEnabled = host !== "undefined" && token !== "undefined";
export default function FreshChatScript() {
const { data } = trpc.viewer.me.useQuery();
return (
<Script
id="fresh-chat-sdk"
src="https://wchat.freshchat.com/js/widget.js"
onLoad={() => {
window.fcWidget.init({
token,
host,
externalId: data?.id,
lastName: data?.name,
email: data?.email,
meta: {
username: data?.username,
},
open: true,
});
}}
/>
);
}