Skip to content

Commit

Permalink
feat(web): support chat
Browse files Browse the repository at this point in the history
  • Loading branch information
waltergalvao committed Jun 30, 2024
1 parent df7ff5b commit a2c051b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@tabler/icons": "^2.40.0",
"@tabler/icons-react": "^2.40.0",
"@tanstack/react-query": "^5.22.2",
"crisp-sdk-web": "^1.0.25",
"date-fns": "^2.30.0",
"dayjs": "^1.11.10",
"echarts": "^5.5.0",
Expand Down
23 changes: 18 additions & 5 deletions apps/web/src/components/navbar/navbar-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IconSpeakerphone,
IconBuilding,
IconBook2,
IconLifebuoy,
} from "@tabler/icons-react";
import { FC } from "react";
import { logout } from "../../providers/auth.provider";
Expand All @@ -20,13 +21,15 @@ import { WorkspaceSwitcher } from "../workspace-switcher";
import { AvatarUser } from "../avatar-user";
import classes from "./navbar-user.module.css";
import { useAppStore } from "../../providers/app.provider";
import { useSupportChat } from "./use-support-chat";

interface NavbarUserProps {
onNavigate: () => void;
}

export const NavbarUser: FC<NavbarUserProps> = () => {
const { authenticatedUser: user, availableWorkspaces } = useAppStore();
const { openChat } = useSupportChat();

const handleLogout = () => {
logout();
Expand Down Expand Up @@ -60,16 +63,14 @@ export const NavbarUser: FC<NavbarUserProps> = () => {
</Stack>
</Group>

<Menu.Divider />
<Menu.Divider mx={-4} />

<Menu.Label>Switch workspace</Menu.Label>
<Box m="sm" mt={0}>
<WorkspaceSwitcher workspaces={availableWorkspaces} />
</Box>
<Menu.Divider mx={-4} />

<Menu.Divider />

<Menu.Label>Options</Menu.Label>
<Menu.Item
leftSection={<IconBuilding size={14} stroke={1.5} />}
component="a"
Expand All @@ -78,6 +79,9 @@ export const NavbarUser: FC<NavbarUserProps> = () => {
>
Connect new organization
</Menu.Item>
<Menu.Divider mx={-4} />

<Menu.Label>Options</Menu.Label>
<Menu.Item
leftSection={<IconBook2 size={14} stroke={1.5} />}
component="a"
Expand All @@ -87,6 +91,15 @@ export const NavbarUser: FC<NavbarUserProps> = () => {
Documentation
</Menu.Item>

<Menu.Item
leftSection={<IconLifebuoy size={14} stroke={1.5} />}
onClick={() => {
openChat();
}}
>
Chat with support
</Menu.Item>

<Menu.Item
leftSection={<IconSpeakerphone size={14} stroke={1.5} />}
component="a"
Expand All @@ -97,7 +110,7 @@ export const NavbarUser: FC<NavbarUserProps> = () => {
Give feedback
</Menu.Item>

<Menu.Divider />
<Menu.Divider mx={-4} />

<Menu.Item
component="a"
Expand Down
29 changes: 29 additions & 0 deletions apps/web/src/components/navbar/use-support-chat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use client";

import { useEffect, useState } from "react";
import { Crisp } from "crisp-sdk-web";

export const useSupportChat = () => {
const [isOpen, setOpen] = useState(false);

useEffect(() => {
Crisp.configure("41518479-f2b4-481b-8841-c3a8c3a9ba34");
Crisp.chat.hide();

Crisp.chat.onChatClosed(() => {
Crisp.chat.hide();
setOpen(false);
});
}, []);

useEffect(() => {
if (isOpen) {
Crisp.chat.show();
Crisp.chat.open();
}
}, [isOpen]);

return {
openChat: () => setOpen(true),
};
};
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2c051b

Please sign in to comment.