Files
plane/web/ee/components/pi-chat/floating-bot.tsx
Akshita Goyal 8e0a919750 fix: pi chat bug fixes (#1670)
* chore: pi empty state

* fix: response change handled

* fix: handled api failure

* fix: formatted ai messages

* fix: reverted the pi pallete

* fix: integrated  models api

* fix: disabled regenerating new chat

* fix: page loading fixed

* fix: dynamically imported markdown

* fix: removed extras

* fix: minor css

* fix: handled pi chat in bulk ops
2024-11-08 13:33:00 +05:30

57 lines
1.7 KiB
TypeScript

import { useRef, useState } from "react";
import { useParams, usePathname } from "next/navigation";
import { X } from "lucide-react";
import { cn } from "@plane/editor";
import { useOutsideClickDetector } from "@plane/helpers";
import { PiChatLogo } from "@plane/ui";
import { WithFeatureFlagHOC } from "../feature-flags";
import { PiChatBase } from "./base";
export const FloatingBot = () => {
// states
const [isOpen, setIsOpen] = useState(false);
const ref = useRef(null);
// query params
const pathName = usePathname();
const { workspaceSlug } = useParams();
useOutsideClickDetector(ref, () => {
setIsOpen(false);
});
if (pathName.includes("pi-chat")) return null;
return (
<WithFeatureFlagHOC workspaceSlug={workspaceSlug?.toString()} flag="PI_CHAT" fallback={<></>}>
<div ref={ref} id="floating-bot">
{" "}
<button
className={cn("absolute bottom-4 right-4 bg-gradient-to-br rounded-full w-[40px] h-[40px] shadow-md z-[20]", {
"from-pi-500 to-pi-700": !isOpen,
"from-pi-200 to-pi-400": isOpen,
})}
onClick={() => {
setIsOpen((state) => !state);
}}
>
{!isOpen ? (
<PiChatLogo className="size-6 text-white fill-current m-auto align-center" />
) : (
<X className="size-6 text-white fill-current m-auto align-center" />
)}
</button>
<div
className={cn(
"absolute bottom-16 right-4 z-[20]",
"transform transition-all duration-300 ease-in-out",
isOpen ? "translate-y-[0%] h-[690px]" : "translate-y-[100%] h-0"
)}
>
{isOpen && <PiChatBase />}{" "}
</div>
</div>
</WithFeatureFlagHOC>
);
};