From a584df2de98c3e030f11d72b8fb2e01531c31841 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Mon, 1 Jul 2024 14:44:04 +0700 Subject: [PATCH 01/23] prevent reformatting the import code with space in bracket --- .vscode/settings.json | 9 ++++++--- .../content/[documentTypeId]/[documentId]/page.tsx | 1 + .../app/(protected)/content/[documentTypeId]/page.tsx | 5 +++-- .../{article => articlesssss}/[documentId]/page.tsx | 0 .../content/{article => articlesssss}/page.tsx | 0 .../components/DocumentType/DocumentTypeGenericList.tsx | 2 ++ 6 files changed, 12 insertions(+), 5 deletions(-) rename hosting/src/app/(protected)/content/{article => articlesssss}/[documentId]/page.tsx (100%) rename hosting/src/app/(protected)/content/{article => articlesssss}/page.tsx (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 962d1d9b..91552d06 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,10 @@ { - "editor.codeActionsOnSave": { - "source.organizeImports": "always" - }, + // This config make my local change the import path with space in bracket eg: { foo, bar }, + // You need to run `npm run codecheck` to reformatting the code. + // So I comment this stuff to prevent reformatting the import code with space in bracket + // "editor.codeActionsOnSave": { + // "source.organizeImports": "always" + // }, "javascript.preferences.quoteStyle": "single", "typescript.preferences.quoteStyle": "single", "html.format.indentInnerHtml": true, diff --git a/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx b/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx index e838aa60..a16f0fce 100644 --- a/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx +++ b/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx @@ -103,6 +103,7 @@ const DocumentDetailsPage = () => { return ( <> + dynamic idsss }> {documentType ? : } diff --git a/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx b/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx index 0cb670a8..b41d4fac 100644 --- a/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx +++ b/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx @@ -5,9 +5,9 @@ import Notification from "@/components/common/Notification"; import PageHeader from "@/components/common/PageHeader"; import {useTanamDocumentType} from "@/hooks/useTanamDocumentTypes"; import {useTanamDocuments} from "@/hooks/useTanamDocuments"; -import {Suspense, useEffect, useState} from "react"; -import {useParams} from "next/navigation"; import {UserNotification} from "@/models/UserNotification"; +import {useParams} from "next/navigation"; +import {Suspense, useEffect, useState} from "react"; export default function DocumentTypeDocumentsPage() { const {documentTypeId} = useParams<{documentTypeId: string}>() ?? {}; @@ -21,6 +21,7 @@ export default function DocumentTypeDocumentsPage() { return ( <> + dynamic }> {documentType ? : } diff --git a/hosting/src/app/(protected)/content/article/[documentId]/page.tsx b/hosting/src/app/(protected)/content/articlesssss/[documentId]/page.tsx similarity index 100% rename from hosting/src/app/(protected)/content/article/[documentId]/page.tsx rename to hosting/src/app/(protected)/content/articlesssss/[documentId]/page.tsx diff --git a/hosting/src/app/(protected)/content/article/page.tsx b/hosting/src/app/(protected)/content/articlesssss/page.tsx similarity index 100% rename from hosting/src/app/(protected)/content/article/page.tsx rename to hosting/src/app/(protected)/content/articlesssss/page.tsx diff --git a/hosting/src/components/DocumentType/DocumentTypeGenericList.tsx b/hosting/src/components/DocumentType/DocumentTypeGenericList.tsx index 667cb3a7..dd865483 100644 --- a/hosting/src/components/DocumentType/DocumentTypeGenericList.tsx +++ b/hosting/src/components/DocumentType/DocumentTypeGenericList.tsx @@ -11,12 +11,14 @@ interface TableOverviewGenericProps { export function DocumentTypeGenericList({documents, documentType}: TableOverviewGenericProps) { return ( <> + documents :: {JSON.stringify(documents)} [

{document.data[documentType.titleField] as string}

, +

{document.createdAt.toDate().toUTCString()}

, From 2dde76f0be633da52b8ec8b97451d34530358cc8 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Mon, 1 Jul 2024 14:44:31 +0700 Subject: [PATCH 02/23] remove unused --- .../articlesssss/[documentId]/page.tsx | 49 ------------------- .../(protected)/content/articlesssss/page.tsx | 34 ------------- 2 files changed, 83 deletions(-) delete mode 100644 hosting/src/app/(protected)/content/articlesssss/[documentId]/page.tsx delete mode 100644 hosting/src/app/(protected)/content/articlesssss/page.tsx diff --git a/hosting/src/app/(protected)/content/articlesssss/[documentId]/page.tsx b/hosting/src/app/(protected)/content/articlesssss/[documentId]/page.tsx deleted file mode 100644 index a7fc1533..00000000 --- a/hosting/src/app/(protected)/content/articlesssss/[documentId]/page.tsx +++ /dev/null @@ -1,49 +0,0 @@ -"use client"; -import TiptapEditor from "@/components/Tiptap/TiptapEditor"; -import Loader from "@/components/common/Loader"; -import Notification from "@/components/common/Notification"; -import PageHeader from "@/components/common/PageHeader"; -import {useCrudTanamDocument, useTanamDocument} from "@/hooks/useTanamDocuments"; -import {UserNotification} from "@/models/UserNotification"; -import {useParams, useRouter} from "next/navigation"; -import {Suspense, useEffect, useState} from "react"; - -export default function DocumentDetailsPage() { - const router = useRouter(); - const {documentId} = useParams<{documentId: string}>() ?? {}; - const {data: document, error: documentError} = useTanamDocument(documentId); - const {update, error: writeError} = useCrudTanamDocument(documentId); - const [readonlyMode] = useState(false); - const [notification, setNotification] = useState(null); - if (!!document?.documentType && document?.documentType !== "article") { - router.push(`/content/${document?.documentType}/${document?.id}`); - return ; - } - - useEffect(() => { - setNotification(documentError || writeError); - }, [documentError, writeError]); - - async function onDocumentContentChange(content: string) { - console.log("[onDocumentContentChange]", content); - await update({data: {content}}); - } - - return ( - <> - }> - {document ? : } - - {notification && ( - - )} - - - - ); -} diff --git a/hosting/src/app/(protected)/content/articlesssss/page.tsx b/hosting/src/app/(protected)/content/articlesssss/page.tsx deleted file mode 100644 index b850db2a..00000000 --- a/hosting/src/app/(protected)/content/articlesssss/page.tsx +++ /dev/null @@ -1,34 +0,0 @@ -"use client"; -import {DocumentTypeGenericList} from "@/components/DocumentType/DocumentTypeGenericList"; -import Loader from "@/components/common/Loader"; -import Notification from "@/components/common/Notification"; -import PageHeader from "@/components/common/PageHeader"; -import {useTanamDocumentType} from "@/hooks/useTanamDocumentTypes"; -import {useTanamDocuments} from "@/hooks/useTanamDocuments"; -import {UserNotification} from "@/models/UserNotification"; -import {Suspense, useEffect, useState} from "react"; - -export default function DocumentTypeDocumentsPage() { - const {data: documentType} = useTanamDocumentType("article"); - const {data: documents, error: docsError} = useTanamDocuments("article"); - const [notification, setNotification] = useState(null); - - useEffect(() => { - setNotification(docsError); - }, [docsError]); - - return ( - <> - }> - {documentType ? : } - - {notification && ( - - )} - - }> - {documentType ? : } - - - ); -} From 00525744851b4b4eb8fe357ce8b68c89a363c318 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Mon, 1 Jul 2024 15:17:06 +0700 Subject: [PATCH 03/23] error handler when user type wrong documenttypeid --- .../content/[documentTypeId]/page.tsx | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx b/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx index b41d4fac..9c4b3cbb 100644 --- a/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx +++ b/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx @@ -5,19 +5,26 @@ import Notification from "@/components/common/Notification"; import PageHeader from "@/components/common/PageHeader"; import {useTanamDocumentType} from "@/hooks/useTanamDocumentTypes"; import {useTanamDocuments} from "@/hooks/useTanamDocuments"; -import {UserNotification} from "@/models/UserNotification"; import {useParams} from "next/navigation"; -import {Suspense, useEffect, useState} from "react"; +import {Suspense} from "react"; export default function DocumentTypeDocumentsPage() { const {documentTypeId} = useParams<{documentTypeId: string}>() ?? {}; const {data: documents, error: docsError} = useTanamDocuments(documentTypeId); - const {data: documentType} = useTanamDocumentType(documentTypeId); - const [notification, setNotification] = useState(null); + const {data: documentType, error: typesError} = useTanamDocumentType(documentTypeId); - useEffect(() => { - setNotification(docsError); - }, [docsError]); + if (docsError || typesError) { + return ( + <> + + + + ); + } return ( <> @@ -25,10 +32,6 @@ export default function DocumentTypeDocumentsPage() { }> {documentType ? : } - {notification && ( - - )} - {docsError && } }> {documentType ? : } From 4082c396eefb530da5a20dac66804800ebb23f28 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Mon, 1 Jul 2024 15:37:08 +0700 Subject: [PATCH 04/23] add errorpage component handler --- .../[documentTypeId]/[documentId]/page.tsx | 13 +++++++++++ .../content/[documentTypeId]/page.tsx | 12 +++++----- hosting/src/components/Error/ErrorPage.tsx | 22 +++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 hosting/src/components/Error/ErrorPage.tsx diff --git a/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx b/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx index a16f0fce..3c5233f3 100644 --- a/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx +++ b/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx @@ -101,6 +101,19 @@ const DocumentDetailsPage = () => { } }; + if (documentError || typeError || fieldsError) { + return ( + <> + + + + ); + } + return ( <> dynamic idsss diff --git a/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx b/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx index 9c4b3cbb..8e141f45 100644 --- a/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx +++ b/hosting/src/app/(protected)/content/[documentTypeId]/page.tsx @@ -1,8 +1,8 @@ "use client"; import {DocumentTypeGenericList} from "@/components/DocumentType/DocumentTypeGenericList"; import Loader from "@/components/common/Loader"; -import Notification from "@/components/common/Notification"; import PageHeader from "@/components/common/PageHeader"; +import {ErrorPage} from '@/components/Error/ErrorPage'; import {useTanamDocumentType} from "@/hooks/useTanamDocumentTypes"; import {useTanamDocuments} from "@/hooks/useTanamDocuments"; import {useParams} from "next/navigation"; @@ -16,11 +16,11 @@ export default function DocumentTypeDocumentsPage() { if (docsError || typesError) { return ( <> - - ); diff --git a/hosting/src/components/Error/ErrorPage.tsx b/hosting/src/components/Error/ErrorPage.tsx new file mode 100644 index 00000000..1a257bb7 --- /dev/null +++ b/hosting/src/components/Error/ErrorPage.tsx @@ -0,0 +1,22 @@ +import Notification from "@/components/common/Notification"; +import PageHeader from "@/components/common/PageHeader"; + +interface ErrorPageProps { + pageName: string; + notificationType: "warning" | "success" | "error"; + notificationTitle: string; + notificationMessage: string; +} + +export function ErrorPage({pageName, notificationType, notificationTitle, notificationMessage}: ErrorPageProps) { + return ( + <> + + + + ); +}; \ No newline at end of file From 4eb49e8ae45ee52169e573ff28a1756917c20926 Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Mon, 1 Jul 2024 15:40:06 +0700 Subject: [PATCH 05/23] implement errorpage componnent in document details --- .../[documentTypeId]/[documentId]/page.tsx | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx b/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx index 3c5233f3..3e670eef 100644 --- a/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx +++ b/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx @@ -12,16 +12,15 @@ import { TextArea, } from "@/components/Form"; import Loader from "@/components/common/Loader"; -import Notification from "@/components/common/Notification"; import PageHeader from "@/components/common/PageHeader"; +import {ErrorPage} from '@/components/Error/ErrorPage'; import {useTanamDocumentFields} from "@/hooks/useTanamDocumentFields"; import {useTanamDocumentType} from "@/hooks/useTanamDocumentTypes"; import {useTanamDocument} from "@/hooks/useTanamDocuments"; -import {UserNotification} from "@/models/UserNotification"; import {TanamDocumentField} from "@functions/models/TanamDocumentField"; import {Timestamp} from "firebase/firestore"; import {useParams, useRouter} from "next/navigation"; -import {Suspense, useEffect, useState} from "react"; +import {Suspense, useState} from "react"; const DocumentDetailsPage = () => { const router = useRouter(); @@ -31,17 +30,12 @@ const DocumentDetailsPage = () => { const {data: documentFields, error: fieldsError} = useTanamDocumentFields(documentTypeId); const [readonlyMode] = useState(true); - const [notification, setNotification] = useState(null); if (!!document?.documentType && document?.documentType !== documentTypeId) { router.push(`/content/${document?.documentType}/${document?.id}`); return ; } - useEffect(() => { - setNotification(documentError ?? typeError ?? fieldsError); - }, [documentError]); - const renderFormElement = (field: TanamDocumentField, value: any) => { const formgroupKey = `formgroup-${field.id}`; const inputKey = `input-${field.id}`; @@ -104,11 +98,11 @@ const DocumentDetailsPage = () => { if (documentError || typeError || fieldsError) { return ( <> - - ); @@ -120,9 +114,6 @@ const DocumentDetailsPage = () => { }> {documentType ? : } - {notification && ( - - )} {documentType && document && (
From 3ab6dfed06176e7fc8d41757a3444cb598131b9a Mon Sep 17 00:00:00 2001 From: Nurfirliana Muzanella Date: Mon, 1 Jul 2024 16:22:33 +0700 Subject: [PATCH 06/23] add create document page --- .../[documentTypeId]/[documentId]/page.tsx | 1 - .../content/[documentTypeId]/create/page.tsx | 123 ++++++++++++++++++ .../content/[documentTypeId]/page.tsx | 15 ++- .../DocumentType/DocumentTypeGenericList.tsx | 1 - hosting/src/hooks/useTanamDocumentTypes.tsx | 2 + 5 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 hosting/src/app/(protected)/content/[documentTypeId]/create/page.tsx diff --git a/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx b/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx index 3e670eef..911912e9 100644 --- a/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx +++ b/hosting/src/app/(protected)/content/[documentTypeId]/[documentId]/page.tsx @@ -110,7 +110,6 @@ const DocumentDetailsPage = () => { return ( <> - dynamic idsss }> {documentType ? : } diff --git a/hosting/src/app/(protected)/content/[documentTypeId]/create/page.tsx b/hosting/src/app/(protected)/content/[documentTypeId]/create/page.tsx new file mode 100644 index 00000000..a467695d --- /dev/null +++ b/hosting/src/app/(protected)/content/[documentTypeId]/create/page.tsx @@ -0,0 +1,123 @@ +"use client"; +import ContentCard from "@/components/Containers/ContentCard"; +import { + Checkbox, + DatePicker, + Dropdown, + FileUpload, + FormGroup, + Input, + RadioButton, + Switcher, + TextArea, +} from "@/components/Form"; +import Loader from "@/components/common/Loader"; +import PageHeader from "@/components/common/PageHeader"; +import {ErrorPage} from '@/components/Error/ErrorPage'; +import {useTanamDocumentFields} from "@/hooks/useTanamDocumentFields"; +import {useTanamDocumentType} from "@/hooks/useTanamDocumentTypes"; +import {TanamDocumentField} from "@functions/models/TanamDocumentField"; +import {Timestamp} from "firebase/firestore"; +import {useParams} from "next/navigation"; +import {Suspense, useState} from "react"; + +const DocumentCreatePage = () => { + const {documentTypeId} = useParams<{documentTypeId: string;}>() ?? {}; + const {data: documentType, error: typeError} = useTanamDocumentType(documentTypeId); + const {data: documentFields, error: fieldsError} = useTanamDocumentFields(documentTypeId); + + console.info('documentTypeId :: ', documentTypeId) + + const [readonlyMode] = useState(false); + + const renderFormElement = (field: TanamDocumentField, value: any) => { + const formgroupKey = `formgroup-${field.id}`; + const inputKey = `input-${field.id}`; + switch (field.type) { + case "input-text": + case "text-line": + return ( + + + + ); + case "html": + case "textbox-rich": + case "text-rich": + return ( + +