[WEB-2103] chore: intercom trigger updates from sidebar and command palette helper actions (#5314)
* chore: handled intercom operations programatically. * fix: app sidebar improvement --------- Co-authored-by: Anmol Singh Bhatia <anmolsinghbhatia@plane.so>
This commit is contained in:
parent
2fa92fda75
commit
9715922fc1
9 changed files with 78 additions and 19 deletions
|
|
@ -96,7 +96,7 @@ export const HelpSection: FC = observer(() => {
|
||||||
leaveTo="transform opacity-0 scale-95"
|
leaveTo="transform opacity-0 scale-95"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={`absolute bottom-2 min-w-[10rem] ${
|
className={`absolute bottom-2 min-w-[10rem] z-[15] ${
|
||||||
isSidebarCollapsed ? "left-full" : "-left-[75px]"
|
isSidebarCollapsed ? "left-full" : "-left-[75px]"
|
||||||
} divide-y divide-custom-border-200 whitespace-nowrap rounded bg-custom-background-100 p-1 shadow-custom-shadow-xs`}
|
} divide-y divide-custom-border-200 whitespace-nowrap rounded bg-custom-background-100 p-1 shadow-custom-shadow-xs`}
|
||||||
ref={helpOptionsRef}
|
ref={helpOptionsRef}
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,14 @@ export const AppSidebar: FC<IAppSidebar> = observer(() => {
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("size-full flex flex-col flex-1 pt-4 pb-0", {
|
className={cn("size-full flex flex-col flex-1 pt-4 pb-0", {
|
||||||
"p-2": sidebarCollapsed,
|
"p-2 pt-4": sidebarCollapsed,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<div className="px-4">
|
<div
|
||||||
|
className={cn("px-2", {
|
||||||
|
"px-4": !sidebarCollapsed,
|
||||||
|
})}
|
||||||
|
>
|
||||||
<SidebarDropdown />
|
<SidebarDropdown />
|
||||||
<div className="flex-shrink-0 h-4" />
|
<div className="flex-shrink-0 h-4" />
|
||||||
<SidebarAppSwitcher />
|
<SidebarAppSwitcher />
|
||||||
|
|
@ -69,8 +73,8 @@ export const AppSidebar: FC<IAppSidebar> = observer(() => {
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
className={cn("overflow-x-hidden scrollbar-sm h-full w-full overflow-y-auto px-4", {
|
className={cn("overflow-x-hidden scrollbar-sm h-full w-full overflow-y-auto px-2", {
|
||||||
"vertical-scrollbar": !sidebarCollapsed,
|
"vertical-scrollbar px-4": !sidebarCollapsed,
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<SidebarUserMenu />
|
<SidebarUserMenu />
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,21 @@
|
||||||
"use client";
|
"use client";
|
||||||
import { Command } from "cmdk";
|
import { Command } from "cmdk";
|
||||||
|
import { observer } from "mobx-react";
|
||||||
import { FileText, GithubIcon, MessageSquare, Rocket } from "lucide-react";
|
import { FileText, GithubIcon, MessageSquare, Rocket } from "lucide-react";
|
||||||
// ui
|
// ui
|
||||||
import { DiscordIcon } from "@plane/ui";
|
import { DiscordIcon } from "@plane/ui";
|
||||||
// hooks
|
// hooks
|
||||||
import { useCommandPalette } from "@/hooks/store";
|
import { useCommandPalette, useTransient } from "@/hooks/store";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
closePalette: () => void;
|
closePalette: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CommandPaletteHelpActions: React.FC<Props> = (props) => {
|
export const CommandPaletteHelpActions: React.FC<Props> = observer((props) => {
|
||||||
const { closePalette } = props;
|
const { closePalette } = props;
|
||||||
// hooks
|
// hooks
|
||||||
const { toggleShortcutModal } = useCommandPalette();
|
const { toggleShortcutModal } = useCommandPalette();
|
||||||
|
const { toggleIntercom } = useTransient();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Command.Group heading="Help">
|
<Command.Group heading="Help">
|
||||||
|
|
@ -68,9 +70,7 @@ export const CommandPaletteHelpActions: React.FC<Props> = (props) => {
|
||||||
<Command.Item
|
<Command.Item
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
closePalette();
|
closePalette();
|
||||||
if (window) {
|
toggleIntercom(true);
|
||||||
window.$crisp.push(["do", "chat:show"]);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
className="focus:outline-none"
|
className="focus:outline-none"
|
||||||
>
|
>
|
||||||
|
|
@ -81,4 +81,4 @@ export const CommandPaletteHelpActions: React.FC<Props> = (props) => {
|
||||||
</Command.Item>
|
</Command.Item>
|
||||||
</Command.Group>
|
</Command.Group>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { DiscordIcon, GithubIcon, Tooltip } from "@plane/ui";
|
||||||
// helpers
|
// helpers
|
||||||
import { cn } from "@/helpers/common.helper";
|
import { cn } from "@/helpers/common.helper";
|
||||||
// hooks
|
// hooks
|
||||||
import { useAppTheme, useCommandPalette, useInstance } from "@/hooks/store";
|
import { useAppTheme, useCommandPalette, useInstance, useTransient } from "@/hooks/store";
|
||||||
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
||||||
import { usePlatformOS } from "@/hooks/use-platform-os";
|
import { usePlatformOS } from "@/hooks/use-platform-os";
|
||||||
// components
|
// components
|
||||||
|
|
@ -45,15 +45,14 @@ export const SidebarHelpSection: React.FC<WorkspaceHelpSectionProps> = observer(
|
||||||
const { toggleShortcutModal } = useCommandPalette();
|
const { toggleShortcutModal } = useCommandPalette();
|
||||||
const { isMobile } = usePlatformOS();
|
const { isMobile } = usePlatformOS();
|
||||||
const { config } = useInstance();
|
const { config } = useInstance();
|
||||||
|
const { isIntercomToggle, toggleIntercom } = useTransient();
|
||||||
// states
|
// states
|
||||||
const [isNeedHelpOpen, setIsNeedHelpOpen] = useState(false);
|
const [isNeedHelpOpen, setIsNeedHelpOpen] = useState(false);
|
||||||
// refs
|
// refs
|
||||||
const helpOptionsRef = useRef<HTMLDivElement | null>(null);
|
const helpOptionsRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const handleCrispWindowShow = () => {
|
const handleCrispWindowShow = () => {
|
||||||
if (window) {
|
toggleIntercom(!isIntercomToggle);
|
||||||
window.$crisp.push(["do", "chat:show"]);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
useOutsideClickDetector(helpOptionsRef, () => setIsNeedHelpOpen(false));
|
useOutsideClickDetector(helpOptionsRef, () => setIsNeedHelpOpen(false));
|
||||||
|
|
@ -133,7 +132,7 @@ export const SidebarHelpSection: React.FC<WorkspaceHelpSectionProps> = observer(
|
||||||
leaveTo="transform opacity-0 scale-95"
|
leaveTo="transform opacity-0 scale-95"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={`absolute bottom-2 min-w-[10rem] ${
|
className={`absolute bottom-2 min-w-[10rem] z-[15] ${
|
||||||
isCollapsed ? "left-full" : "-left-[75px]"
|
isCollapsed ? "left-full" : "-left-[75px]"
|
||||||
} divide-y divide-custom-border-200 whitespace-nowrap rounded bg-custom-background-100 p-1 shadow-custom-shadow-xs`}
|
} divide-y divide-custom-border-200 whitespace-nowrap rounded bg-custom-background-100 p-1 shadow-custom-shadow-xs`}
|
||||||
ref={helpOptionsRef}
|
ref={helpOptionsRef}
|
||||||
|
|
|
||||||
|
|
@ -30,3 +30,4 @@ export * from "./use-router-params";
|
||||||
export * from "./use-webhook";
|
export * from "./use-webhook";
|
||||||
export * from "./use-workspace";
|
export * from "./use-workspace";
|
||||||
export * from "./user";
|
export * from "./user";
|
||||||
|
export * from "./use-transient";
|
||||||
|
|
|
||||||
11
web/core/hooks/store/use-transient.ts
Normal file
11
web/core/hooks/store/use-transient.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { useContext } from "react";
|
||||||
|
// mobx store
|
||||||
|
import { StoreContext } from "@/lib/store-context";
|
||||||
|
// types
|
||||||
|
import { ITransientStore } from "@/store/transient.store";
|
||||||
|
|
||||||
|
export const useTransient = (): ITransientStore => {
|
||||||
|
const context = useContext(StoreContext);
|
||||||
|
if (context === undefined) throw new Error("useTransient must be used within StoreProvider");
|
||||||
|
return context.transient;
|
||||||
|
};
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { FC, useEffect } from "react";
|
import React, { FC, useEffect } from "react";
|
||||||
import Intercom from "@intercom/messenger-js-sdk";
|
import { Intercom, show, hide, onHide } from "@intercom/messenger-js-sdk";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
// store hooks
|
// store hooks
|
||||||
import { useUser, useInstance } from "@/hooks/store";
|
import { useUser, useInstance, useTransient } from "@/hooks/store";
|
||||||
|
|
||||||
export type IntercomProviderProps = {
|
export type IntercomProviderProps = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
|
@ -15,6 +15,16 @@ const IntercomProvider: FC<IntercomProviderProps> = observer((props) => {
|
||||||
// hooks
|
// hooks
|
||||||
const { data: user } = useUser();
|
const { data: user } = useUser();
|
||||||
const { config } = useInstance();
|
const { config } = useInstance();
|
||||||
|
const { isIntercomToggle, toggleIntercom } = useTransient();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isIntercomToggle) show();
|
||||||
|
else hide();
|
||||||
|
}, [isIntercomToggle]);
|
||||||
|
|
||||||
|
onHide(() => {
|
||||||
|
toggleIntercom(false);
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user && config?.is_intercom_enabled && config.intercom_app_id) {
|
if (user && config?.is_intercom_enabled && config.intercom_app_id) {
|
||||||
|
|
@ -23,9 +33,10 @@ const IntercomProvider: FC<IntercomProviderProps> = observer((props) => {
|
||||||
user_id: user.id,
|
user_id: user.id,
|
||||||
name: `${user.first_name} ${user.last_name}`,
|
name: `${user.first_name} ${user.last_name}`,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
|
hide_default_launcher: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [user, config]);
|
}, [user, config, toggleIntercom]);
|
||||||
|
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import { IProjectViewStore, ProjectViewStore } from "./project-view.store";
|
||||||
import { RouterStore, IRouterStore } from "./router.store";
|
import { RouterStore, IRouterStore } from "./router.store";
|
||||||
import { IStateStore, StateStore } from "./state.store";
|
import { IStateStore, StateStore } from "./state.store";
|
||||||
import { ThemeStore, IThemeStore } from "./theme.store";
|
import { ThemeStore, IThemeStore } from "./theme.store";
|
||||||
|
import { ITransientStore, TransientStore } from "./transient.store";
|
||||||
import { IUserStore, UserStore } from "./user";
|
import { IUserStore, UserStore } from "./user";
|
||||||
import { IWorkspaceRootStore, WorkspaceRootStore } from "./workspace";
|
import { IWorkspaceRootStore, WorkspaceRootStore } from "./workspace";
|
||||||
|
|
||||||
|
|
@ -54,6 +55,7 @@ export class CoreRootStore {
|
||||||
multipleSelect: IMultipleSelectStore;
|
multipleSelect: IMultipleSelectStore;
|
||||||
workspaceNotification: IWorkspaceNotificationStore;
|
workspaceNotification: IWorkspaceNotificationStore;
|
||||||
favorite: IFavoriteStore;
|
favorite: IFavoriteStore;
|
||||||
|
transient: ITransientStore;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.router = new RouterStore();
|
this.router = new RouterStore();
|
||||||
|
|
@ -81,6 +83,7 @@ export class CoreRootStore {
|
||||||
this.projectEstimate = new ProjectEstimateStore(this);
|
this.projectEstimate = new ProjectEstimateStore(this);
|
||||||
this.workspaceNotification = new WorkspaceNotificationStore(this);
|
this.workspaceNotification = new WorkspaceNotificationStore(this);
|
||||||
this.favorite = new FavoriteStore(this);
|
this.favorite = new FavoriteStore(this);
|
||||||
|
this.transient = new TransientStore();
|
||||||
}
|
}
|
||||||
|
|
||||||
resetOnSignOut() {
|
resetOnSignOut() {
|
||||||
|
|
@ -110,5 +113,7 @@ export class CoreRootStore {
|
||||||
this.multipleSelect = new MultipleSelectStore();
|
this.multipleSelect = new MultipleSelectStore();
|
||||||
this.projectEstimate = new ProjectEstimateStore(this);
|
this.projectEstimate = new ProjectEstimateStore(this);
|
||||||
this.workspaceNotification = new WorkspaceNotificationStore(this);
|
this.workspaceNotification = new WorkspaceNotificationStore(this);
|
||||||
|
this.favorite = new FavoriteStore(this);
|
||||||
|
this.transient = new TransientStore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
28
web/core/store/transient.store.ts
Normal file
28
web/core/store/transient.store.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { action, observable, makeObservable } from "mobx";
|
||||||
|
|
||||||
|
export interface ITransientStore {
|
||||||
|
// observables
|
||||||
|
isIntercomToggle: boolean;
|
||||||
|
// actions
|
||||||
|
toggleIntercom: (intercomToggle: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TransientStore implements ITransientStore {
|
||||||
|
// observables
|
||||||
|
isIntercomToggle: boolean = false;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
makeObservable(this, {
|
||||||
|
// observable
|
||||||
|
isIntercomToggle: observable.ref,
|
||||||
|
// action
|
||||||
|
toggleIntercom: action,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Toggle the intercom collapsed state
|
||||||
|
* @param { boolean } intercomToggle
|
||||||
|
*/
|
||||||
|
toggleIntercom = (intercomToggle: boolean) => (this.isIntercomToggle = intercomToggle);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue