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,87 +233,101 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
|
|||||||
}, [createPageBlock, updatePageBlock, data, handleSubmit]);
|
}, [createPageBlock, updatePageBlock, data, handleSubmit]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<div className="relative">
|
||||||
className="divide-y divide-brand-base rounded-[10px] border border-brand-base shadow"
|
<form
|
||||||
onSubmit={data ? handleSubmit(updatePageBlock) : handleSubmit(createPageBlock)}
|
className="divide-y divide-brand-base rounded-[10px] border border-brand-base shadow"
|
||||||
>
|
onSubmit={data ? handleSubmit(updatePageBlock) : handleSubmit(createPageBlock)}
|
||||||
<div className="pt-2">
|
>
|
||||||
<div className="flex justify-between">
|
<div className="pt-2">
|
||||||
<Input
|
<div className="flex justify-between">
|
||||||
id="name"
|
<Input
|
||||||
name="name"
|
id="name"
|
||||||
placeholder="Title"
|
name="name"
|
||||||
register={register}
|
placeholder="Title"
|
||||||
className="min-h-10 block w-full resize-none overflow-hidden border-none bg-transparent py-1 text-lg font-medium"
|
register={register}
|
||||||
autoComplete="off"
|
className="min-h-10 block w-full resize-none overflow-hidden border-none bg-transparent py-1 text-lg font-medium"
|
||||||
maxLength={255}
|
autoComplete="off"
|
||||||
/>
|
maxLength={255}
|
||||||
</div>
|
/>
|
||||||
<div className="page-block-section relative -mt-2 text-brand-secondary">
|
</div>
|
||||||
<Controller
|
<div className="page-block-section relative -mt-2 text-brand-secondary">
|
||||||
name="description"
|
<Controller
|
||||||
control={control}
|
name="description"
|
||||||
render={({ field: { value } }) => (
|
control={control}
|
||||||
<RemirrorRichTextEditor
|
render={({ field: { value } }) => (
|
||||||
value={
|
<RemirrorRichTextEditor
|
||||||
!value || (typeof value === "object" && Object.keys(value).length === 0)
|
value={
|
||||||
? watch("description_html")
|
!value || (typeof value === "object" && Object.keys(value).length === 0)
|
||||||
: value
|
? watch("description_html")
|
||||||
}
|
: value
|
||||||
onJSONChange={(jsonValue) => setValue("description", jsonValue)}
|
}
|
||||||
onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)}
|
onJSONChange={(jsonValue) => setValue("description", jsonValue)}
|
||||||
placeholder="Write something..."
|
onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)}
|
||||||
customClassName="text-sm"
|
placeholder="Write something..."
|
||||||
noBorder
|
customClassName="text-sm"
|
||||||
borderOnFocus={false}
|
noBorder
|
||||||
/>
|
borderOnFocus={false}
|
||||||
)}
|
/>
|
||||||
/>
|
|
||||||
<div className="m-2 mt-6 flex">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
className={`flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-brand-surface-1 ${
|
|
||||||
iAmFeelingLucky ? "cursor-wait bg-brand-surface-1" : ""
|
|
||||||
}`}
|
|
||||||
onClick={handleAutoGenerateDescription}
|
|
||||||
disabled={iAmFeelingLucky}
|
|
||||||
>
|
|
||||||
{iAmFeelingLucky ? (
|
|
||||||
"Generating response..."
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<SparklesIcon className="h-4 w-4" />I{"'"}m feeling lucky
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</button>
|
/>
|
||||||
{data && (
|
<div className="m-2 mt-6 flex">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={`flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-brand-surface-1 ${
|
||||||
|
iAmFeelingLucky ? "cursor-wait bg-brand-surface-1" : ""
|
||||||
|
}`}
|
||||||
|
onClick={handleAutoGenerateDescription}
|
||||||
|
disabled={iAmFeelingLucky}
|
||||||
|
>
|
||||||
|
{iAmFeelingLucky ? (
|
||||||
|
"Generating response..."
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<SparklesIcon className="h-4 w-4" />I{"'"}m feeling lucky
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
|
||||||
<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>
|
<div className="flex items-center justify-end gap-2 p-4">
|
||||||
<div className="flex items-center justify-end gap-2 p-4">
|
<SecondaryButton onClick={handleClose}>Cancel</SecondaryButton>
|
||||||
<SecondaryButton onClick={handleClose}>Cancel</SecondaryButton>
|
<PrimaryButton type="submit" disabled={watch("name") === ""} loading={isSubmitting}>
|
||||||
<PrimaryButton type="submit" disabled={watch("name") === ""} loading={isSubmitting}>
|
{data
|
||||||
{data
|
? isSubmitting
|
||||||
? isSubmitting
|
? "Updating..."
|
||||||
? "Updating..."
|
: "Update block"
|
||||||
: "Update block"
|
: isSubmitting
|
||||||
: isSubmitting
|
? "Adding..."
|
||||||
? "Adding..."
|
: "Add block"}
|
||||||
: "Add block"}
|
</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