diff --git a/apps/app/components/pages/single-page-block.tsx b/apps/app/components/pages/single-page-block.tsx index 3a0b4f81c..aa438df70 100644 --- a/apps/app/components/pages/single-page-block.tsx +++ b/apps/app/components/pages/single-page-block.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import { useRouter } from "next/router"; +import Link from "next/link"; import dynamic from "next/dynamic"; import { mutate } from "swr"; @@ -9,7 +10,6 @@ import { mutate } from "swr"; import { Controller, useForm } from "react-hook-form"; // services import pagesService from "services/pages.service"; -import aiService from "services/ai.service"; // hooks import useToast from "hooks/use-toast"; // components @@ -18,13 +18,16 @@ import { GptAssistantModal } from "components/core"; // ui import { CustomMenu, Loader, TextArea } from "components/ui"; // icons -import { WaterDropIcon } from "components/icons"; +import { LayerDiagonalIcon, WaterDropIcon } from "components/icons"; // helpers import { copyTextToClipboard } from "helpers/string.helper"; // types -import { IPageBlock, IProject } from "types"; +import { IIssue, IPageBlock, IProject } from "types"; // fetch-keys import { PAGE_BLOCKS_LIST } from "constants/fetch-keys"; +import { ArrowTopRightOnSquareIcon, CheckIcon } from "@heroicons/react/24/outline"; +import issuesService from "services/issues.service"; +import { ArrowPathIcon } from "@heroicons/react/20/solid"; type Props = { block: IPageBlock; @@ -42,6 +45,7 @@ const RemirrorRichTextEditor = dynamic(() => import("components/rich-text-editor export const SinglePageBlock: React.FC = ({ block, projectDetails }) => { const [createUpdateIssueModal, setCreateUpdateIssueModal] = useState(false); + const [isSyncing, setIsSyncing] = useState(false); const [gptAssistantModal, setGptAssistantModal] = useState(false); @@ -63,6 +67,8 @@ export const SinglePageBlock: React.FC = ({ block, projectDetails }) => { if (!formData.name || formData.name.length === 0 || formData.name === "") return; + if (block.issue && block.sync) setIsSyncing(true); + mutate( PAGE_BLOCKS_LIST(pageId as string), (prevData) => @@ -80,8 +86,16 @@ export const SinglePageBlock: React.FC = ({ block, projectDetails }) => { description: formData.description, description_html: formData.description_html, }) - .then(() => { + .then((res) => { mutate(PAGE_BLOCKS_LIST(pageId as string)); + if (block.issue && block.sync) + issuesService + .patchIssue(workspaceSlug as string, projectId as string, block.issue, { + name: res.name, + description: res.description, + description_html: res.description_html, + }) + .finally(() => setIsSyncing(false)); }); }; @@ -95,12 +109,12 @@ export const SinglePageBlock: React.FC = ({ block, projectDetails }) => { pageId as string, block.id ) - .then((res) => { + .then((res: IIssue) => { mutate( PAGE_BLOCKS_LIST(pageId as string), (prevData) => (prevData ?? []).map((p) => { - if (p.id === block.id) return { ...p, issue: res.id }; + if (p.id === block.id) return { ...p, issue: res.id, issue_detail: res }; return p; }), @@ -181,6 +195,31 @@ export const SinglePageBlock: React.FC = ({ block, projectDetails }) => { }); }; + const handleBlockSync = () => { + if (!workspaceSlug || !projectId || !pageId) return; + + mutate( + PAGE_BLOCKS_LIST(pageId as string), + (prevData) => + (prevData ?? []).map((p) => { + if (p.id === block.id) return { ...p, sync: !block.sync }; + + return p; + }), + false + ); + + pagesService.patchPageBlock( + workspaceSlug as string, + projectId as string, + pageId as string, + block.id, + { + sync: !block.sync, + } + ); + }; + const handleCopyText = () => { const originURL = typeof window !== "undefined" && window.location.origin ? window.location.origin : ""; @@ -217,26 +256,48 @@ export const SinglePageBlock: React.FC = ({ block, projectDetails }) => {