+
- )
-}
-
+ );
+};
const DocumentReadOnlyEditorWithRef = forwardRef<
EditorHandle,
@@ -118,4 +119,4 @@ const DocumentReadOnlyEditorWithRef = forwardRef<
DocumentReadOnlyEditorWithRef.displayName = "DocumentReadOnlyEditorWithRef";
-export { DocumentReadOnlyEditor, DocumentReadOnlyEditorWithRef }
+export { DocumentReadOnlyEditor, DocumentReadOnlyEditorWithRef };
diff --git a/packages/editor/document-editor/src/ui/utils/menu-options.ts b/packages/editor/document-editor/src/ui/utils/menu-options.ts
index 152ff4ac3..7b8dac067 100644
--- a/packages/editor/document-editor/src/ui/utils/menu-options.ts
+++ b/packages/editor/document-editor/src/ui/utils/menu-options.ts
@@ -1,75 +1,94 @@
-import { Editor } from "@tiptap/react"
-import { Archive, ArchiveIcon, ArchiveRestoreIcon, ClipboardIcon, Copy, Link, Lock, Unlock, XCircle } from "lucide-react"
-import { NextRouter } from "next/router"
-import { IVerticalDropdownItemProps } from "../components/vertical-dropdown-menu"
-import { IDuplicationConfig, IPageArchiveConfig, IPageLockConfig } from "../types/menu-actions"
-import { copyMarkdownToClipboard, CopyPageLink } from "./menu-actions"
+import { Editor } from "@tiptap/react";
+import {
+ Archive,
+ ArchiveIcon,
+ ArchiveRestoreIcon,
+ ClipboardIcon,
+ Copy,
+ Link,
+ Lock,
+ Unlock,
+ XCircle,
+} from "lucide-react";
+import { NextRouter } from "next/router";
+import { IVerticalDropdownItemProps } from "../components/vertical-dropdown-menu";
+import {
+ IDuplicationConfig,
+ IPageArchiveConfig,
+ IPageLockConfig,
+} from "../types/menu-actions";
+import { copyMarkdownToClipboard, CopyPageLink } from "./menu-actions";
-export interface MenuOptionsProps{
- editor: Editor,
- router: NextRouter,
- duplicationConfig?: IDuplicationConfig,
- pageLockConfig?: IPageLockConfig ,
- pageArchiveConfig?: IPageArchiveConfig,
+export interface MenuOptionsProps {
+ editor: Editor;
+ router: NextRouter;
+ duplicationConfig?: IDuplicationConfig;
+ pageLockConfig?: IPageLockConfig;
+ pageArchiveConfig?: IPageArchiveConfig;
}
-export const getMenuOptions = ({ editor, router, duplicationConfig, pageLockConfig, pageArchiveConfig } : MenuOptionsProps) => {
-
+export const getMenuOptions = ({
+ editor,
+ router,
+ duplicationConfig,
+ pageLockConfig,
+ pageArchiveConfig,
+}: MenuOptionsProps) => {
const KanbanMenuOptions: IVerticalDropdownItemProps[] = [
{
- key: 1,
+ key: 1,
type: "copy_markdown",
Icon: ClipboardIcon,
action: () => copyMarkdownToClipboard(editor),
- label: "Copy Markdown"
+ label: "Copy markdown",
},
+ // {
+ // key: 2,
+ // type: "close_page",
+ // Icon: XCircle,
+ // action: () => router.back(),
+ // label: "Close page",
+ // },
{
- key: 2,
- type: "close_page",
- Icon: XCircle,
- action: () => router.back(),
- label: "Close the page"
- },
- {
- key: 3,
+ key: 3,
type: "copy_page_link",
Icon: Link,
action: () => CopyPageLink(),
- label: "Copy Page Link"
+ label: "Copy page link",
},
- ]
+ ];
// If duplicateConfig is given, page duplication will be allowed
if (duplicationConfig) {
KanbanMenuOptions.push({
- key: KanbanMenuOptions.length++,
+ key: KanbanMenuOptions.length++,
type: "duplicate_page",
Icon: Copy,
action: duplicationConfig.action,
- label: "Make a copy"
- })
+ label: "Make a copy",
+ });
}
// If Lock Configuration is given then, lock page option will be available in the kanban menu
if (pageLockConfig) {
KanbanMenuOptions.push({
- key: KanbanMenuOptions.length++,
+ key: KanbanMenuOptions.length++,
type: pageLockConfig.is_locked ? "unlock_page" : "lock_page",
Icon: pageLockConfig.is_locked ? Unlock : Lock,
- label: pageLockConfig.is_locked ? "Unlock Page" : "Lock Page",
- action: pageLockConfig.action
- })
+ label: pageLockConfig.is_locked ? "Unlock page" : "Lock page",
+ action: pageLockConfig.action,
+ });
}
// Archiving will be visible in the menu bar config once the pageArchiveConfig is given.
if (pageArchiveConfig) {
KanbanMenuOptions.push({
- key: KanbanMenuOptions.length++,
+ key: KanbanMenuOptions.length++,
type: pageArchiveConfig.is_archived ? "unarchive_page" : "archive_page",
Icon: pageArchiveConfig.is_archived ? ArchiveRestoreIcon : Archive,
- label: pageArchiveConfig.is_archived ? "Restore Page" : "Archive Page",
+ label: pageArchiveConfig.is_archived ? "Restore page" : "Archive page",
action: pageArchiveConfig.action,
- })
+ });
}
- return KanbanMenuOptions
-}
+ return KanbanMenuOptions;
+};
diff --git a/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx b/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx
index c725f2b89..778b0d94f 100644
--- a/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx
+++ b/web/pages/[workspaceSlug]/projects/[projectId]/pages/[pageId].tsx
@@ -1,12 +1,13 @@
import React, { useEffect, useRef, useState, ReactElement } from "react";
import { useRouter } from "next/router";
-import useSWR, { mutate } from "swr";
+import useSWR from "swr";
import { Controller, useForm } from "react-hook-form";
// services
import { PageService } from "services/page.service";
-import { useDebouncedCallback } from "use-debounce";
+import { FileService } from "services/file.service";
// hooks
import useUser from "hooks/use-user";
+import { useDebouncedCallback } from "use-debounce";
// layouts
import { AppLayout } from "layouts/app-layout";
// components
@@ -24,7 +25,6 @@ import { NextPageWithLayout } from "types/app";
import { IPage } from "types";
// fetch-keys
import { PAGE_DETAILS } from "constants/fetch-keys";
-import { FileService } from "services/file.service";
// services
const fileService = new FileService();
@@ -45,10 +45,14 @@ const PageDetailsPage: NextPageWithLayout = () => {
});
// =================== Fetching Page Details ======================
- const { data: pageDetails, error } = useSWR(
- workspaceSlug && projectId && pageId ? PAGE_DETAILS(pageId as string) : null,
- workspaceSlug && projectId
- ? () => pageService.getPageDetails(workspaceSlug as string, projectId as string, pageId as string)
+ const {
+ data: pageDetails,
+ mutate: mutatePageDetails,
+ error,
+ } = useSWR(
+ workspaceSlug && projectId && pageId ? PAGE_DETAILS(pageId.toString()) : null,
+ workspaceSlug && projectId && pageId
+ ? () => pageService.getPageDetails(workspaceSlug.toString(), projectId.toString(), pageId.toString())
: null
);
@@ -57,20 +61,23 @@ const PageDetailsPage: NextPageWithLayout = () => {
if (!formData.name || formData.name.length === 0 || formData.name === "") return;
- await pageService.patchPage(workspaceSlug as string, projectId as string, pageId as string, formData).then(() => {
- mutate
(
- PAGE_DETAILS(pageId as string),
- (prevData) => ({
- ...prevData,
- ...formData,
- }),
- false
- );
- });
+ await pageService
+ .patchPage(workspaceSlug.toString(), projectId.toString(), pageId.toString(), formData)
+ .then(() => {
+ mutatePageDetails(
+ (prevData) => ({
+ ...prevData,
+ ...formData,
+ }),
+ false
+ );
+ });
};
const createPage = async (payload: Partial) => {
- await pageService.createPage(workspaceSlug as string, projectId as string, payload);
+ if (!workspaceSlug || !projectId) return;
+
+ await pageService.createPage(workspaceSlug.toString(), projectId.toString(), payload);
};
// ================ Page Menu Actions ==================
@@ -84,79 +91,79 @@ const PageDetailsPage: NextPageWithLayout = () => {
};
const archivePage = async () => {
+ if (!workspaceSlug || !projectId || !pageId) return;
+
try {
- await pageService.archivePage(workspaceSlug as string, projectId as string, pageId as string).then(() => {
- mutate(
- PAGE_DETAILS(pageId as string),
- (prevData) => {
- if (prevData && prevData.is_locked) {
- prevData.archived_at = renderDateFormat(new Date());
- return prevData;
- }
- },
- true
- );
- });
+ mutatePageDetails((prevData) => {
+ if (!prevData) return;
+
+ return {
+ ...prevData,
+ archived_at: renderDateFormat(new Date()),
+ };
+ }, true);
+
+ await pageService.archivePage(workspaceSlug.toString(), projectId.toString(), pageId.toString());
} catch (e) {
- console.log(e);
+ mutatePageDetails();
}
};
const unArchivePage = async () => {
+ if (!workspaceSlug || !projectId || !pageId) return;
+
try {
- await pageService.restorePage(workspaceSlug as string, projectId as string, pageId as string).then(() => {
- mutate(
- PAGE_DETAILS(pageId as string),
- (prevData) => {
- if (prevData && prevData.is_locked) {
- prevData.archived_at = null;
- return prevData;
- }
- },
- true
- );
- });
+ mutatePageDetails((prevData) => {
+ if (!prevData) return;
+
+ return {
+ ...prevData,
+ archived_at: null,
+ };
+ }, false);
+
+ await pageService.restorePage(workspaceSlug.toString(), projectId.toString(), pageId.toString());
} catch (e) {
- console.log(e);
+ mutatePageDetails();
}
};
// ========================= Page Lock ==========================
const lockPage = async () => {
+ if (!workspaceSlug || !projectId || !pageId) return;
+
try {
- await pageService.lockPage(workspaceSlug as string, projectId as string, pageId as string).then(() => {
- mutate(
- PAGE_DETAILS(pageId as string),
- (prevData) => {
- if (prevData && prevData.is_locked) {
- prevData.is_locked = true;
- }
- return prevData;
- },
- true
- );
- });
+ mutatePageDetails((prevData) => {
+ if (!prevData) return;
+
+ return {
+ ...prevData,
+ is_locked: true,
+ };
+ }, false);
+
+ await pageService.lockPage(workspaceSlug.toString(), projectId.toString(), pageId.toString());
} catch (e) {
- console.log(e);
+ mutatePageDetails();
}
};
const unlockPage = async () => {
+ if (!workspaceSlug || !projectId || !pageId) return;
+
try {
- await pageService.unlockPage(workspaceSlug as string, projectId as string, pageId as string).then(() => {
- mutate(
- PAGE_DETAILS(pageId as string),
- (prevData) => {
- if (prevData && prevData.is_locked) {
- prevData.is_locked = false;
- return prevData;
- }
- },
- true
- );
- });
+ mutatePageDetails((prevData) => {
+ if (!prevData) return;
+
+ return {
+ ...prevData,
+ is_locked: false,
+ };
+ }, false);
+
+ await pageService.unlockPage(workspaceSlug.toString(), projectId.toString(), pageId.toString());
} catch (e) {
- console.log(e);
+ mutatePageDetails();
}
};
@@ -185,8 +192,8 @@ const PageDetailsPage: NextPageWithLayout = () => {
}}
/>
) : pageDetails ? (
-
-
+
+
{pageDetails.is_locked || pageDetails.archived_at ? (