diff --git a/packages/editor/document-editor/src/ui/components/editor-header.tsx b/packages/editor/document-editor/src/ui/components/editor-header.tsx index e16f6768d..74372ae16 100644 --- a/packages/editor/document-editor/src/ui/components/editor-header.tsx +++ b/packages/editor/document-editor/src/ui/components/editor-header.tsx @@ -46,7 +46,7 @@ export const EditorHeader = (props: IEditorHeader) => { return (
-
+
(

{heading} diff --git a/packages/editor/document-editor/src/ui/components/page-renderer.tsx b/packages/editor/document-editor/src/ui/components/page-renderer.tsx index cff043171..f24ec4348 100644 --- a/packages/editor/document-editor/src/ui/components/page-renderer.tsx +++ b/packages/editor/document-editor/src/ui/components/page-renderer.tsx @@ -19,7 +19,7 @@ export const PageRenderer = (props: IPageRenderer) => { return (
-

+

{documentDetails.title}

diff --git a/packages/editor/document-editor/src/ui/components/summary-side-bar.tsx b/packages/editor/document-editor/src/ui/components/summary-side-bar.tsx index dd98e0572..545109735 100644 --- a/packages/editor/document-editor/src/ui/components/summary-side-bar.tsx +++ b/packages/editor/document-editor/src/ui/components/summary-side-bar.tsx @@ -15,7 +15,7 @@ export const SummarySideBar = ({ }: ISummarySideBarProps) => { return (
diff --git a/packages/editor/document-editor/src/ui/index.tsx b/packages/editor/document-editor/src/ui/index.tsx index d0f0bd96c..d2f34989a 100644 --- a/packages/editor/document-editor/src/ui/index.tsx +++ b/packages/editor/document-editor/src/ui/index.tsx @@ -127,14 +127,14 @@ const DocumentEditor = ({ documentDetails={documentDetails} />
-
+
-
+
-
+
); diff --git a/web/components/core/modals/gpt-assistant-modal.tsx b/web/components/core/modals/gpt-assistant-modal.tsx index 82b082c29..9850fbdd6 100644 --- a/web/components/core/modals/gpt-assistant-modal.tsx +++ b/web/components/core/modals/gpt-assistant-modal.tsx @@ -117,38 +117,41 @@ export const GptAssistantModal: React.FC = (props) => { return (
- {((content && content !== "") || (htmlContent && htmlContent !== "

")) && ( -
- Content: - ${content}

`} - customClassName="-m-3" - noBorder - borderOnFocus={false} - ref={editorRef} - /> -
- )} - {response !== "" && ( -
- Response: - ${response}

`} - customClassName="-mx-3 -my-3" - noBorder - borderOnFocus={false} - /> -
- )} - {invalidResponse && ( -
- No response could be generated. This may be due to insufficient content or task information. Please try again. -
- )} +
+ {((content && content !== "") || (htmlContent && htmlContent !== "

")) && ( +
+ Content: + ${content}

`} + customClassName="-m-3" + noBorder + borderOnFocus={false} + ref={editorRef} + /> +
+ )} + {response !== "" && ( +
+ Response: + ${response}

`} + customClassName="-mx-3 -my-3" + noBorder + borderOnFocus={false} + /> +
+ )} + {invalidResponse && ( +
+ No response could be generated. This may be due to insufficient content or task information. Please try + again. +
+ )} +
{ +const PageDetailsPage: NextPageWithLayout = observer(() => { const editorRef = useRef(null); - + // states const [isSubmitting, setIsSubmitting] = useState<"submitting" | "submitted" | "saved">("saved"); - + const [gptModalOpen, setGptModal] = useState(false); + // store + const { + appConfig: { envConfig }, + } = useMobxStore(); + // router const router = useRouter(); const { workspaceSlug, projectId, pageId } = router.query; const { user } = useUser(); - const { handleSubmit, reset, getValues, control } = useForm({ - defaultValues: { name: "" }, + const { handleSubmit, reset, getValues, control, setValue, watch } = useForm({ + defaultValues: { name: "", description_html: "

" }, }); // =================== Fetching Page Details ====================== @@ -167,6 +176,22 @@ const PageDetailsPage: NextPageWithLayout = () => { } }; + const handleAiAssistance = async (response: string) => { + if (!workspaceSlug || !projectId || !pageId) return; + + const newDescription = `${watch("description_html")}

${response}

`; + setValue("description_html", newDescription); + editorRef.current?.setEditorValue(newDescription); + + pageService + .patchPage(workspaceSlug.toString(), projectId.toString(), pageId.toString(), { + description_html: newDescription, + }) + .then(() => { + mutatePageDetails((prevData) => ({ ...prevData, description_html: newDescription } as IPage), false); + }); + }; + useEffect(() => { if (!pageDetails) return; @@ -227,45 +252,71 @@ const PageDetailsPage: NextPageWithLayout = () => { } /> ) : ( - ( -

" : value} - customClassName="tracking-tight self-center px-0 h-full w-full" - onChange={(_description_json: Object, description_html: string) => { - onChange(description_html); - setIsSubmitting("submitting"); - debouncedFormSave(); - }} - duplicationConfig={{ action: duplicate_page }} - pageArchiveConfig={ - user && pageDetails.owned_by === user.id - ? { - is_archived: pageDetails.archived_at ? true : false, - action: pageDetails.archived_at ? unArchivePage : archivePage, - } - : undefined - } - pageLockConfig={ - user && pageDetails.owned_by === user.id ? { is_locked: false, action: lockPage } : undefined - } - /> +
+ ( +

" : value} + customClassName="tracking-tight self-center px-0 h-full w-full" + onChange={(_description_json: Object, description_html: string) => { + onChange(description_html); + setIsSubmitting("submitting"); + debouncedFormSave(); + }} + duplicationConfig={{ action: duplicate_page }} + pageArchiveConfig={ + user && pageDetails.owned_by === user.id + ? { + is_archived: pageDetails.archived_at ? true : false, + action: pageDetails.archived_at ? unArchivePage : archivePage, + } + : undefined + } + pageLockConfig={ + user && pageDetails.owned_by === user.id ? { is_locked: false, action: lockPage } : undefined + } + /> + )} + /> + {projectId && envConfig?.has_openai_configured && ( + <> + + { + setGptModal(false); + }} + inset="top-9 right-[68px] !w-1/2 !max-h-[50%]" + content="" + onResponse={(response) => { + handleAiAssistance(response); + }} + projectId={projectId.toString()} + /> + )} - /> +
)}
@@ -276,7 +327,7 @@ const PageDetailsPage: NextPageWithLayout = () => { )} ); -}; +}); PageDetailsPage.getLayout = function getLayout(page: ReactElement) { return (