forked from github/plane
fix: ai button not working on creating a page block (#1013)
* fix: ai button not working on creating page block * fix: build error
This commit is contained in:
parent
fd96c54b43
commit
b34cf0c471
@ -121,7 +121,7 @@ export const GptAssistantModal: React.FC<Props> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`absolute ${inset} z-20 w-full space-y-4 rounded-[10px] border border-brand-base bg-brand-surface-2 p-4 shadow ${
|
className={`absolute ${inset} z-20 w-full space-y-4 rounded-[10px] border border-brand-base bg-brand-base p-4 shadow ${
|
||||||
isOpen ? "block" : "hidden"
|
isOpen ? "block" : "hidden"
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
@ -138,7 +138,7 @@ export const GptAssistantModal: React.FC<Props> = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{response !== "" && (
|
{response !== "" && (
|
||||||
<div className="text-sm page-block-section">
|
<div className="page-block-section text-sm">
|
||||||
Response:
|
Response:
|
||||||
<RemirrorRichTextEditor
|
<RemirrorRichTextEditor
|
||||||
value={`<p>${response}</p>`}
|
value={`<p>${response}</p>`}
|
||||||
|
@ -15,8 +15,10 @@ import issuesService from "services/issues.service";
|
|||||||
import aiService from "services/ai.service";
|
import aiService from "services/ai.service";
|
||||||
// hooks
|
// hooks
|
||||||
import useToast from "hooks/use-toast";
|
import useToast from "hooks/use-toast";
|
||||||
|
// components
|
||||||
|
import { GptAssistantModal } from "components/core";
|
||||||
// ui
|
// ui
|
||||||
import { Input, Loader, PrimaryButton, SecondaryButton, TextArea } from "components/ui";
|
import { Input, Loader, PrimaryButton, SecondaryButton } from "components/ui";
|
||||||
// types
|
// types
|
||||||
import { IPageBlock } from "types";
|
import { IPageBlock } from "types";
|
||||||
// fetch-keys
|
// fetch-keys
|
||||||
@ -25,9 +27,9 @@ import { PAGE_BLOCKS_LIST } from "constants/fetch-keys";
|
|||||||
type Props = {
|
type Props = {
|
||||||
handleClose: () => void;
|
handleClose: () => void;
|
||||||
data?: IPageBlock;
|
data?: IPageBlock;
|
||||||
|
handleAiAssistance?: (response: string) => void;
|
||||||
setIsSyncing?: React.Dispatch<React.SetStateAction<boolean>>;
|
setIsSyncing?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
focus?: keyof IPageBlock;
|
focus?: keyof IPageBlock;
|
||||||
setGptAssistantModal: () => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
@ -48,11 +50,12 @@ const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor
|
|||||||
export const CreateUpdateBlockInline: React.FC<Props> = ({
|
export const CreateUpdateBlockInline: React.FC<Props> = ({
|
||||||
handleClose,
|
handleClose,
|
||||||
data,
|
data,
|
||||||
|
handleAiAssistance,
|
||||||
setIsSyncing,
|
setIsSyncing,
|
||||||
focus,
|
focus,
|
||||||
setGptAssistantModal,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
|
||||||
|
const [gptAssistantModal, setGptAssistantModal] = useState(false);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { workspaceSlug, projectId, pageId } = router.query;
|
const { workspaceSlug, projectId, pageId } = router.query;
|
||||||
@ -230,6 +233,7 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
|
|||||||
}, [createPageBlock, updatePageBlock, data, handleSubmit]);
|
}, [createPageBlock, updatePageBlock, data, handleSubmit]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<div className="relative">
|
||||||
<form
|
<form
|
||||||
className="divide-y divide-brand-base rounded-[10px] border border-brand-base shadow"
|
className="divide-y divide-brand-base rounded-[10px] border border-brand-base shadow"
|
||||||
onSubmit={data ? handleSubmit(updatePageBlock) : handleSubmit(createPageBlock)}
|
onSubmit={data ? handleSubmit(updatePageBlock) : handleSubmit(createPageBlock)}
|
||||||
@ -283,19 +287,15 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
{data && (
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="ml-2 flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-brand-surface-1"
|
className="ml-2 flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-brand-surface-1"
|
||||||
onClick={() => {
|
onClick={() => setGptAssistantModal(true)}
|
||||||
onClose();
|
|
||||||
setGptAssistantModal();
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<SparklesIcon className="h-4 w-4" />
|
<SparklesIcon className="h-4 w-4" />
|
||||||
AI
|
AI
|
||||||
</button>
|
</button>
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -312,5 +312,22 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
|
|||||||
</PrimaryButton>
|
</PrimaryButton>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<GptAssistantModal
|
||||||
|
block={data ? data : undefined}
|
||||||
|
isOpen={gptAssistantModal}
|
||||||
|
handleClose={() => setGptAssistantModal(false)}
|
||||||
|
inset="top-8 left-0"
|
||||||
|
content={watch("description_html")}
|
||||||
|
htmlContent={watch("description_html")}
|
||||||
|
onResponse={(response) => {
|
||||||
|
if (data && handleAiAssistance) handleAiAssistance(response);
|
||||||
|
else {
|
||||||
|
setValue("description", {});
|
||||||
|
setValue("description_html", `${watch("description_html")}<p>${response}</p>`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
projectId={projectId?.toString() ?? ""}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,12 +2,11 @@ import { useEffect, useState, useRef } from "react";
|
|||||||
|
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import dynamic from "next/dynamic";
|
|
||||||
|
|
||||||
import { mutate } from "swr";
|
import { mutate } from "swr";
|
||||||
|
|
||||||
// react-hook-form
|
// react-hook-form
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
// react-beautiful-dnd
|
// react-beautiful-dnd
|
||||||
import { Draggable } from "react-beautiful-dnd";
|
import { Draggable } from "react-beautiful-dnd";
|
||||||
// services
|
// services
|
||||||
@ -21,7 +20,7 @@ import useOutsideClickDetector from "hooks/use-outside-click-detector";
|
|||||||
import { GptAssistantModal } from "components/core";
|
import { GptAssistantModal } from "components/core";
|
||||||
import { CreateUpdateBlockInline } from "components/pages";
|
import { CreateUpdateBlockInline } from "components/pages";
|
||||||
// ui
|
// ui
|
||||||
import { CustomMenu, Loader } from "components/ui";
|
import { CustomMenu } from "components/ui";
|
||||||
// icons
|
// icons
|
||||||
import { LayerDiagonalIcon } from "components/icons";
|
import { LayerDiagonalIcon } from "components/icons";
|
||||||
import { ArrowPathIcon, LinkIcon } from "@heroicons/react/20/solid";
|
import { ArrowPathIcon, LinkIcon } from "@heroicons/react/20/solid";
|
||||||
@ -46,15 +45,6 @@ type Props = {
|
|||||||
index: number;
|
index: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor"), {
|
|
||||||
ssr: false,
|
|
||||||
loading: () => (
|
|
||||||
<Loader className="mx-4 mt-6">
|
|
||||||
<Loader.Item height="100px" width="100%" />
|
|
||||||
</Loader>
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const SinglePageBlock: React.FC<Props> = ({ block, projectDetails, index }) => {
|
export const SinglePageBlock: React.FC<Props> = ({ block, projectDetails, index }) => {
|
||||||
const [isSyncing, setIsSyncing] = useState(false);
|
const [isSyncing, setIsSyncing] = useState(false);
|
||||||
const [createBlockForm, setCreateBlockForm] = useState(false);
|
const [createBlockForm, setCreateBlockForm] = useState(false);
|
||||||
@ -291,7 +281,7 @@ export const SinglePageBlock: React.FC<Props> = ({ block, projectDetails, index
|
|||||||
{...provided.dragHandleProps}
|
{...provided.dragHandleProps}
|
||||||
>
|
>
|
||||||
<CreateUpdateBlockInline
|
<CreateUpdateBlockInline
|
||||||
setGptAssistantModal={() => setGptAssistantModal((prev) => !prev)}
|
handleAiAssistance={handleAiAssistance}
|
||||||
handleClose={() => setCreateBlockForm(false)}
|
handleClose={() => setCreateBlockForm(false)}
|
||||||
data={block}
|
data={block}
|
||||||
setIsSyncing={setIsSyncing}
|
setIsSyncing={setIsSyncing}
|
||||||
|
@ -543,7 +543,6 @@ const SinglePage: NextPage = () => {
|
|||||||
<CreateUpdateBlockInline
|
<CreateUpdateBlockInline
|
||||||
handleClose={() => setCreateBlockForm(false)}
|
handleClose={() => setCreateBlockForm(false)}
|
||||||
focus="name"
|
focus="name"
|
||||||
setGptAssistantModal={() => {}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user