created local deployment method that excludes crisp
This commit is contained in:
parent
5e52e096a2
commit
23de0a3bca
7 changed files with 160 additions and 38 deletions
|
|
@ -12,9 +12,8 @@ import { makeStyles } from '@mui/styles'
|
|||
import { CssBaseline, Theme } from '@mui/material'
|
||||
import { AppThemeProvider } from 'theme/AppThemeProvider'
|
||||
import HTTPProvider from 'providers/http'
|
||||
import { Crisp } from "crisp-sdk-web";
|
||||
import { useMobile, useSnackbar } from 'hooks'
|
||||
import { initCrisp } from '../chat/CrispChat'
|
||||
import { initCrisp, isCrispEnabled } from '../chat/CrispChat'
|
||||
// import FirmwareLoader from './FirmwareLoader'
|
||||
|
||||
const reducer = (state: GlobalState, action: GlobalStateAction): GlobalState => {
|
||||
|
|
@ -72,9 +71,6 @@ export default function UserWrapper(props: Props) {
|
|||
|
||||
const user_id = or(useAuth.user?.sub, "")
|
||||
|
||||
const crispInitialized = useRef(false);
|
||||
Crisp.configure(import.meta.env.VITE_CRISP_WEBSITE_ID);
|
||||
|
||||
const loadUser = useCallback(() => {
|
||||
if (!userAPI.getUserWithTeam) return;
|
||||
if (hasFetched.current) return;
|
||||
|
|
@ -114,15 +110,14 @@ export default function UserWrapper(props: Props) {
|
|||
}, [setGlobal])
|
||||
|
||||
useEffect(() => {
|
||||
if (global?.user) {
|
||||
initCrisp({
|
||||
websiteId: import.meta.env.VITE_CRISP_WEBSITE_ID,
|
||||
email: global.user.settings.email,
|
||||
nickname: global.user.settings.name || global.user.settings.email,
|
||||
phone: global.user.settings.phoneNumber,
|
||||
tokenId: global.user.id(),
|
||||
});
|
||||
}
|
||||
if (!global?.user || !isCrispEnabled()) return;
|
||||
initCrisp({
|
||||
websiteId: import.meta.env.VITE_CRISP_WEBSITE_ID,
|
||||
email: global.user.settings.email,
|
||||
nickname: global.user.settings.name || global.user.settings.email,
|
||||
phone: global.user.settings.phoneNumber,
|
||||
tokenId: global.user.id(),
|
||||
});
|
||||
}, [global]);
|
||||
|
||||
// useEffect(() => {
|
||||
|
|
@ -150,6 +145,7 @@ export default function UserWrapper(props: Props) {
|
|||
// }, [isMobile]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isCrispEnabled()) return;
|
||||
let style = document.getElementById("crisp-offset-override");
|
||||
if (!style) {
|
||||
style = document.createElement("style");
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import Chat from "./Chat";
|
|||
import { pond } from "protobuf-ts/pond";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTeamAPI } from "providers";
|
||||
import { closeCrispChat, openCrispChat } from './CrispChat';
|
||||
import { closeCrispChat, isCrispEnabled, openCrispChat } from './CrispChat';
|
||||
import RobotIcon from "products/CommonIcons/robotIcon";
|
||||
|
||||
const useStyles = makeStyles<Theme>((theme: Theme) => ({
|
||||
|
|
@ -68,7 +68,7 @@ export function ChatDrawer(props: Props) {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
if (open && isCrispEnabled()) {
|
||||
closeCrispChat()
|
||||
}
|
||||
}, [open])
|
||||
|
|
@ -108,13 +108,15 @@ export function ChatDrawer(props: Props) {
|
|||
<Avatar src={team.settings.avatar} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Tooltip title={"Chat Assistant"} placement="right">
|
||||
<IconButton
|
||||
onClick={openCrisp}
|
||||
>
|
||||
<RobotIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
{isCrispEnabled() && (
|
||||
<Tooltip title={"Chat Assistant"} placement="right">
|
||||
<IconButton
|
||||
onClick={openCrisp}
|
||||
>
|
||||
<RobotIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
)}
|
||||
<Box width={"100%"} borderBottom={"1px solid grey"} />
|
||||
{teams.map((t, i)=> {
|
||||
if (t.settings?.key === team.key()) return null;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ const ANIMATION_DURATION_MS = 300;
|
|||
|
||||
let initialized = false;
|
||||
|
||||
export function isCrispEnabled(): boolean {
|
||||
const id = import.meta.env.VITE_CRISP_WEBSITE_ID;
|
||||
return typeof id === "string" && id.trim() !== "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize Crisp and immediately hide the default chat button.
|
||||
* Call this once on app load (e.g., in UserWrapper after user data is ready).
|
||||
|
|
@ -17,6 +22,7 @@ export function initCrisp(opts: {
|
|||
tokenId?: string;
|
||||
}) {
|
||||
if (initialized) return;
|
||||
if (!opts.websiteId?.trim()) return;
|
||||
|
||||
Crisp.configure(opts.websiteId);
|
||||
Crisp.session.reset();
|
||||
|
|
@ -71,6 +77,7 @@ function injectCrispStyles() {
|
|||
* Safe to call from any onClick handler.
|
||||
*/
|
||||
export function openCrispChat() {
|
||||
if (!initialized) return;
|
||||
const chatbox = document.getElementById("crisp-chatbox");
|
||||
if (chatbox) {
|
||||
chatbox.classList.add("crisp-visible");
|
||||
|
|
@ -86,6 +93,7 @@ export function openCrispChat() {
|
|||
* Close the chat window and hide the widget.
|
||||
*/
|
||||
export function closeCrispChat() {
|
||||
if (!initialized) return;
|
||||
Crisp.chat.close();
|
||||
hideCrispChatButton();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue