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:
Aaryan Khandelwal 2023-05-05 15:45:10 +05:30 committed by GitHub
parent fd96c54b43
commit b34cf0c471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 97 additions and 91 deletions

View File

@ -121,7 +121,7 @@ export const GptAssistantModal: React.FC<Props> = ({
return (
<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"
}`}
>
@ -138,7 +138,7 @@ export const GptAssistantModal: React.FC<Props> = ({
</div>
)}
{response !== "" && (
<div className="text-sm page-block-section">
<div className="page-block-section text-sm">
Response:
<RemirrorRichTextEditor
value={`<p>${response}</p>`}

View File

@ -15,8 +15,10 @@ import issuesService from "services/issues.service";
import aiService from "services/ai.service";
// hooks
import useToast from "hooks/use-toast";
// components
import { GptAssistantModal } from "components/core";
// ui
import { Input, Loader, PrimaryButton, SecondaryButton, TextArea } from "components/ui";
import { Input, Loader, PrimaryButton, SecondaryButton } from "components/ui";
// types
import { IPageBlock } from "types";
// fetch-keys
@ -25,9 +27,9 @@ import { PAGE_BLOCKS_LIST } from "constants/fetch-keys";
type Props = {
handleClose: () => void;
data?: IPageBlock;
handleAiAssistance?: (response: string) => void;
setIsSyncing?: React.Dispatch<React.SetStateAction<boolean>>;
focus?: keyof IPageBlock;
setGptAssistantModal: () => void;
};
const defaultValues = {
@ -48,11 +50,12 @@ const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor
export const CreateUpdateBlockInline: React.FC<Props> = ({
handleClose,
data,
handleAiAssistance,
setIsSyncing,
focus,
setGptAssistantModal,
}) => {
const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false);
const [gptAssistantModal, setGptAssistantModal] = useState(false);
const router = useRouter();
const { workspaceSlug, projectId, pageId } = router.query;
@ -230,6 +233,7 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
}, [createPageBlock, updatePageBlock, data, handleSubmit]);
return (
<div className="relative">
<form
className="divide-y divide-brand-base rounded-[10px] border border-brand-base shadow"
onSubmit={data ? handleSubmit(updatePageBlock) : handleSubmit(createPageBlock)}
@ -283,19 +287,15 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
</>
)}
</button>
{data && (
<button
type="button"
className="ml-2 flex items-center gap-1 rounded px-1.5 py-1 text-xs hover:bg-brand-surface-1"
onClick={() => {
onClose();
setGptAssistantModal();
}}
onClick={() => setGptAssistantModal(true)}
>
<SparklesIcon className="h-4 w-4" />
AI
</button>
)}
</div>
</div>
</div>
@ -312,5 +312,22 @@ export const CreateUpdateBlockInline: React.FC<Props> = ({
</PrimaryButton>
</div>
</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>
);
};

View File

@ -2,12 +2,11 @@ import { useEffect, useState, useRef } from "react";
import { useRouter } from "next/router";
import Link from "next/link";
import dynamic from "next/dynamic";
import { mutate } from "swr";
// react-hook-form
import { Controller, useForm } from "react-hook-form";
import { useForm } from "react-hook-form";
// react-beautiful-dnd
import { Draggable } from "react-beautiful-dnd";
// services
@ -21,7 +20,7 @@ import useOutsideClickDetector from "hooks/use-outside-click-detector";
import { GptAssistantModal } from "components/core";
import { CreateUpdateBlockInline } from "components/pages";
// ui
import { CustomMenu, Loader } from "components/ui";
import { CustomMenu } from "components/ui";
// icons
import { LayerDiagonalIcon } from "components/icons";
import { ArrowPathIcon, LinkIcon } from "@heroicons/react/20/solid";
@ -46,15 +45,6 @@ type Props = {
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 }) => {
const [isSyncing, setIsSyncing] = useState(false);
const [createBlockForm, setCreateBlockForm] = useState(false);
@ -291,7 +281,7 @@ export const SinglePageBlock: React.FC<Props> = ({ block, projectDetails, index
{...provided.dragHandleProps}
>
<CreateUpdateBlockInline
setGptAssistantModal={() => setGptAssistantModal((prev) => !prev)}
handleAiAssistance={handleAiAssistance}
handleClose={() => setCreateBlockForm(false)}
data={block}
setIsSyncing={setIsSyncing}

View File

@ -543,7 +543,6 @@ const SinglePage: NextPage = () => {
<CreateUpdateBlockInline
handleClose={() => setCreateBlockForm(false)}
focus="name"
setGptAssistantModal={() => {}}
/>
</div>
)}