diff --git a/apps/app/components/cycles/modal.tsx b/apps/app/components/cycles/modal.tsx index e90811ab8..a71b380fe 100644 --- a/apps/app/components/cycles/modal.tsx +++ b/apps/app/components/cycles/modal.tsx @@ -23,7 +23,6 @@ import { CYCLE_DRAFT_LIST, CYCLE_INCOMPLETE_LIST, } from "constants/fetch-keys"; -import { IncomingMessage } from "http"; type CycleModalProps = { isOpen: boolean; diff --git a/apps/app/components/pages/create-update-block-inline.tsx b/apps/app/components/pages/create-update-block-inline.tsx index a44fa6932..443b32803 100644 --- a/apps/app/components/pages/create-update-block-inline.tsx +++ b/apps/app/components/pages/create-update-block-inline.tsx @@ -1,9 +1,17 @@ +import React, { useCallback, useEffect, useState } from "react"; + import { useRouter } from "next/router"; import dynamic from "next/dynamic"; -import { mutate } from "swr"; +import useSWR, { mutate } from "swr"; -import { SparklesIcon } from "@heroicons/react/24/outline"; +import { LayerDiagonalIcon } from "components/icons"; +import { ArrowPathIcon, LinkIcon } from "@heroicons/react/20/solid"; +import { + BoltIcon, + SparklesIcon, + TrashIcon, +} from "@heroicons/react/24/outline"; // react-hook-form import { Controller, useForm } from "react-hook-form"; @@ -12,22 +20,24 @@ import pagesService from "services/pages.service"; // hooks import useToast from "hooks/use-toast"; // ui -import { Input, Loader, PrimaryButton, SecondaryButton } from "components/ui"; +import { Loader, PrimaryButton, SecondaryButton, CustomMenu, TextArea } from "components/ui"; // types import { IPageBlock } from "types"; // fetch-keys import { PAGE_BLOCKS_LIST } from "constants/fetch-keys"; -import { useCallback, useEffect } from "react"; import issuesService from "services/issues.service"; +import aiService from "services/ai.service"; type Props = { handleClose: () => void; data?: IPageBlock; setIsSyncing?: React.Dispatch>; focus?: keyof IPageBlock; - handelAutoGenerateDescription?: () => Promise; - iAmFeelingLucky?: boolean; setGptAssistantModal: () => void; + handleBlockSync?: () => void; + handleCopyText?: () => void; + pushBlockIntoIssues?: () => void; + deletePageBlock?: () => void; }; const defaultValues = { @@ -49,10 +59,15 @@ export const CreateUpdateBlockInline: React.FC = ({ data, setIsSyncing, focus, - handelAutoGenerateDescription, setGptAssistantModal, - iAmFeelingLucky, + handleBlockSync, + handleCopyText, + pushBlockIntoIssues, + deletePageBlock, }) => { + + const [iAmFeelingLucky, setIAmFeelingLucky] = useState(false); + const router = useRouter(); const { workspaceSlug, projectId, pageId } = router.query; @@ -141,6 +156,46 @@ export const CreateUpdateBlockInline: React.FC = ({ .finally(() => onClose()); }; + const handleAutoGenerateDescription = async () => { + if (!workspaceSlug || !projectId) return; + + setIAmFeelingLucky(true); + + aiService + .createGptTask(workspaceSlug as string, projectId as string, { + prompt: watch("name"), + task: "Generate a proper description for this issue in context of a project management software.", + }) + .then((res) => { + if (res.response === "") + setToastAlert({ + type: "error", + title: "Error!", + message: + "Block title isn't informative enough to generate the description. Please try with a different title.", + }); + else { + setValue("description", {}); + setValue("description_html", `${watch("description_html")}

${res.response}

`); + } + }) + .catch((err) => { + if (err.status === 429) + setToastAlert({ + type: "error", + title: "Error!", + message: + "You have reached the maximum number of requests of 50 requests per month per user.", + }); + else + setToastAlert({ + type: "error", + title: "Error!", + message: "Some error occurred. Please try again.", + }); + }).finally(()=>setIAmFeelingLucky(false)); + }; + useEffect(() => { if (focus) setFocus(focus); @@ -167,49 +222,82 @@ export const CreateUpdateBlockInline: React.FC = ({ }, [handleClose]); return ( -
-
- -
- ( - setValue("description", jsonValue)} - onHTMLChange={(htmlValue) => setValue("description_html", htmlValue)} - placeholder="Description" - aria-hidden - customClassName="text-sm" - noBorder - borderOnFocus={false} - /> - )} - /> -
-
- { data && - <> - {console.log(handelAutoGenerateDescription, setGptAssistantModal, iAmFeelingLucky)} +
+ +
+
+