2024-04-11 15:58:59 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { observer } from "mobx-react";
|
2024-05-26 11:07:10 +00:00
|
|
|
import { Lock, Sparkle } from "lucide-react";
|
2024-04-11 15:58:59 +00:00
|
|
|
// editor
|
|
|
|
import { EditorReadOnlyRefApi, EditorRefApi } from "@plane/document-editor";
|
|
|
|
// ui
|
|
|
|
import { ArchiveIcon } from "@plane/ui";
|
|
|
|
// components
|
|
|
|
import { GptAssistantPopover } from "@/components/core";
|
|
|
|
import { PageInfoPopover, PageOptionsDropdown } from "@/components/pages";
|
|
|
|
// helpers
|
|
|
|
import { renderFormattedDate } from "@/helpers/date-time.helper";
|
|
|
|
// hooks
|
2024-05-08 17:31:20 +00:00
|
|
|
import { useInstance } from "@/hooks/store";
|
2024-04-11 15:58:59 +00:00
|
|
|
// store
|
|
|
|
import { IPageStore } from "@/store/pages/page.store";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
editorRef: React.RefObject<EditorRefApi>;
|
|
|
|
handleDuplicatePage: () => void;
|
2024-05-26 11:07:10 +00:00
|
|
|
page: IPageStore;
|
2024-04-11 15:58:59 +00:00
|
|
|
projectId: string;
|
|
|
|
readOnlyEditorRef: React.RefObject<EditorReadOnlyRefApi>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const PageExtraOptions: React.FC<Props> = observer((props) => {
|
2024-05-26 11:07:10 +00:00
|
|
|
const { editorRef, handleDuplicatePage, page, projectId, readOnlyEditorRef } = props;
|
2024-04-11 15:58:59 +00:00
|
|
|
// states
|
|
|
|
const [gptModalOpen, setGptModal] = useState(false);
|
|
|
|
// store hooks
|
2024-05-18 10:52:53 +00:00
|
|
|
const { config } = useInstance();
|
2024-04-11 15:58:59 +00:00
|
|
|
// derived values
|
2024-05-26 11:07:10 +00:00
|
|
|
const { archived_at, isContentEditable, is_locked } = page;
|
2024-04-11 15:58:59 +00:00
|
|
|
|
|
|
|
const handleAiAssistance = async (response: string) => {
|
|
|
|
if (!editorRef) return;
|
|
|
|
editorRef.current?.setEditorValueAtCursorPosition(response);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="flex flex-grow items-center justify-end gap-3">
|
|
|
|
{is_locked && (
|
|
|
|
<div className="flex h-7 items-center gap-2 rounded-full bg-custom-background-80 px-3 py-0.5 text-xs font-medium text-custom-text-300">
|
|
|
|
<Lock className="h-3 w-3" />
|
|
|
|
<span>Locked</span>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{archived_at && (
|
|
|
|
<div className="flex h-7 items-center gap-2 rounded-full bg-blue-500/20 px-3 py-0.5 text-xs font-medium text-blue-500">
|
|
|
|
<ArchiveIcon className="h-3 w-3" />
|
|
|
|
<span>Archived at {renderFormattedDate(archived_at)}</span>
|
|
|
|
</div>
|
|
|
|
)}
|
2024-05-18 10:52:53 +00:00
|
|
|
{isContentEditable && config?.has_openai_configured && (
|
2024-04-11 15:58:59 +00:00
|
|
|
<GptAssistantPopover
|
|
|
|
isOpen={gptModalOpen}
|
|
|
|
projectId={projectId}
|
|
|
|
handleClose={() => {
|
|
|
|
setGptModal((prevData) => !prevData);
|
|
|
|
// this is done so that the title do not reset after gpt popover closed
|
|
|
|
// reset(getValues());
|
|
|
|
}}
|
|
|
|
onResponse={handleAiAssistance}
|
|
|
|
placement="top-end"
|
|
|
|
button={
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-custom-background-90"
|
|
|
|
onClick={() => setGptModal((prevData) => !prevData)}
|
|
|
|
>
|
|
|
|
<Sparkle className="h-4 w-4" />
|
|
|
|
AI
|
|
|
|
</button>
|
|
|
|
}
|
|
|
|
className="!min-w-[38rem]"
|
|
|
|
/>
|
|
|
|
)}
|
2024-05-26 11:07:10 +00:00
|
|
|
<PageInfoPopover page={page} />
|
2024-04-11 15:58:59 +00:00
|
|
|
<PageOptionsDropdown
|
|
|
|
editorRef={isContentEditable ? editorRef.current : readOnlyEditorRef.current}
|
|
|
|
handleDuplicatePage={handleDuplicatePage}
|
2024-05-26 11:07:10 +00:00
|
|
|
page={page}
|
2024-04-11 15:58:59 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
});
|