From 0706406f894ddb4a40fdc0a58bc7cf2f2001b6f0 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Wed, 25 Sep 2024 15:35:39 +0700 Subject: [PATCH 01/11] add badge --- .../content/article/[documentId]/page.tsx | 68 ++++++++++++------- libs/ui-components/src/Badge.tsx | 12 ++++ libs/ui-components/src/common/PageHeader.tsx | 2 +- libs/ui-components/src/index.ts | 1 + 4 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 libs/ui-components/src/Badge.tsx diff --git a/apps/cms/src/app/(protected)/content/article/[documentId]/page.tsx b/apps/cms/src/app/(protected)/content/article/[documentId]/page.tsx index 644074c9..c6c9d388 100644 --- a/apps/cms/src/app/(protected)/content/article/[documentId]/page.tsx +++ b/apps/cms/src/app/(protected)/content/article/[documentId]/page.tsx @@ -1,6 +1,6 @@ "use client"; import {UserNotification} from "@tanam/domain-frontend"; -import {Button, Input, Loader, Notification, PageHeader, TiptapEditor} from "@tanam/ui-components"; +import {Badge, Button, Input, Loader, Notification, PageHeader, TiptapEditor} from "@tanam/ui-components"; import {useParams, useRouter} from "next/navigation"; import {Suspense, useEffect, useState} from "react"; import {useCrudTanamDocument, useTanamDocument} from "../../../../../hooks/useTanamDocuments"; @@ -12,8 +12,9 @@ export default function DocumentDetailsPage() { const {update, error: writeError} = useCrudTanamDocument(); const [title, setTitle] = useState(""); + const [tags, setTags] = useState([]); const [readonlyMode] = useState(false); - const [updateTitleShown, setUpdateTitleShown] = useState(false); + const [updateMetadata, setUpdateMetadata] = useState(false); const [notification, setNotification] = useState(null); useEffect(() => { @@ -27,17 +28,22 @@ export default function DocumentDetailsPage() { }, [documentError, writeError]); useEffect(() => { - if (updateTitleShown) return; + if (updateMetadata) return; onDocumentTitleChange(title); - }, [updateTitleShown]); + }, [updateMetadata]); useEffect(() => { if (document) { + console.info("document :: ", document); setTitle(document.data.title as string); + setTags(document.data.tags as string[]); } - return () => setTitle(""); + return () => { + setTitle(""); + setTags([]); + }; }, [document]); async function onDocumentTitleChange(title: string) { @@ -69,27 +75,37 @@ export default function DocumentDetailsPage() { }> {document ? ( <> -
- {!updateTitleShown && } - - {updateTitleShown && ( - setTitle(e.target.value)} - /> - )} - - +
+
+ +
+ +
+ {!updateMetadata && } + + {updateMetadata && ( + setTitle(e.target.value)} + /> + )} +
+ +
+ {tags && tags.map((tag, index) => )} +
+ +
{document?.data.content && ( diff --git a/libs/ui-components/src/Badge.tsx b/libs/ui-components/src/Badge.tsx new file mode 100644 index 00000000..199a79b9 --- /dev/null +++ b/libs/ui-components/src/Badge.tsx @@ -0,0 +1,12 @@ +interface BadgeProps { + title: string; + className?: string; +} + +export function Badge(props: BadgeProps) { + const {title, className} = props; + + const badgeClassName = `block border px-3 py-1 text-xs font-semibold rounded-full ${className}`; + + return {title}; +} diff --git a/libs/ui-components/src/common/PageHeader.tsx b/libs/ui-components/src/common/PageHeader.tsx index 33220242..926430c9 100644 --- a/libs/ui-components/src/common/PageHeader.tsx +++ b/libs/ui-components/src/common/PageHeader.tsx @@ -5,7 +5,7 @@ interface PageHeaderProps { export function PageHeader({pageName, pageActions = []}: PageHeaderProps) { return ( -
+

{pageName}

{pageActions.length > 0 &&
{pageActions.map((action) => action)}
}
diff --git a/libs/ui-components/src/index.ts b/libs/ui-components/src/index.ts index 5ef018ba..423ff29c 100644 --- a/libs/ui-components/src/index.ts +++ b/libs/ui-components/src/index.ts @@ -11,6 +11,7 @@ export * from "./Table"; export * from "./Tiptap/TiptapEditor"; // Other Components +export * from "./Badge"; export * from "./Button"; export * from "./CropImage"; export * from "./FilePicker"; From acad8f8396543f62ddd3b86cba80ba233083c5e1 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Wed, 25 Sep 2024 15:47:41 +0700 Subject: [PATCH 02/11] add description article --- .../content/article/[documentId]/page.tsx | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/apps/cms/src/app/(protected)/content/article/[documentId]/page.tsx b/apps/cms/src/app/(protected)/content/article/[documentId]/page.tsx index c6c9d388..3134a158 100644 --- a/apps/cms/src/app/(protected)/content/article/[documentId]/page.tsx +++ b/apps/cms/src/app/(protected)/content/article/[documentId]/page.tsx @@ -1,6 +1,6 @@ "use client"; import {UserNotification} from "@tanam/domain-frontend"; -import {Badge, Button, Input, Loader, Notification, PageHeader, TiptapEditor} from "@tanam/ui-components"; +import {Badge, Button, Input, Loader, Notification, PageHeader, TextArea, TiptapEditor} from "@tanam/ui-components"; import {useParams, useRouter} from "next/navigation"; import {Suspense, useEffect, useState} from "react"; import {useCrudTanamDocument, useTanamDocument} from "../../../../../hooks/useTanamDocuments"; @@ -12,6 +12,7 @@ export default function DocumentDetailsPage() { const {update, error: writeError} = useCrudTanamDocument(); const [title, setTitle] = useState(""); + const [description, setDescription] = useState(""); const [tags, setTags] = useState([]); const [readonlyMode] = useState(false); const [updateMetadata, setUpdateMetadata] = useState(false); @@ -37,15 +38,21 @@ export default function DocumentDetailsPage() { if (document) { console.info("document :: ", document); setTitle(document.data.title as string); + setDescription(document.data.blurb as string); setTags(document.data.tags as string[]); } return () => { - setTitle(""); - setTags([]); + pruneState(); }; }, [document]); + function pruneState() { + setTitle(""); + setDescription(""); + setTags([]); + } + async function onDocumentTitleChange(title: string) { console.log("[onDocumentTitleChange]", title); if (!document) { @@ -101,8 +108,23 @@ export default function DocumentDetailsPage() { )}
+
+ {!updateMetadata &&

{document.data.blurb as string}

} + + {updateMetadata && ( +