diff --git a/apicalls/test.tsx b/apicalls/test.tsx new file mode 100644 index 0000000..4f64d92 --- /dev/null +++ b/apicalls/test.tsx @@ -0,0 +1,65 @@ +"use server"; +import NextCrypto from "next-crypto"; +import { redirect } from "next/navigation"; + +const nextCrypto = new NextCrypto( + "2f3c097b29fc4a70084403ad7b2f9def1ba0bf6e96c892457b0bebd15d3f48fd7396120708cb7efdf7f4b09003701710c0904addaaf991d412403b47d9762aa9" +); + +export async function defaultPagination() { + const paginate = await encryptQuery({ + size: 10, + page: 1, + orderBy: "uu_id", + orderType: "desc", + query: {}, + }); + return paginate.replaceAll(" ", "+"); +} + +export async function decryptQuery(query: string) { + if (!query) return {}; + const decryptURL = await nextCrypto.decrypt(String(query.replace(/ /g, "+"))); + try { + const cleanedString = String(decryptURL).replace(/\\/g, ""); + const decodedString = decodeURI(cleanedString || "{}"); + const parsedObject = JSON.parse(decodedString); + if (typeof parsedObject !== "object") { + return JSON.parse(parsedObject); + } + return parsedObject; + } catch (error) { + return {}; + } +} + +export async function encryptQuery(queryObject: any) { + const encodedURL = encodeURI(JSON.stringify(queryObject)); + return (await nextCrypto.encrypt(encodedURL)).replaceAll(";", "%3B"); +} + +export async function handleFormSubmission(formData: FormData): Promise { + let inputs: any = {}; + formData.forEach((value, key) => { + if (key.includes("page")) { + inputs.page = value; + } else if (key.includes("size")) { + inputs.size = value; + } else if (key.includes("orderBy")) { + inputs.orderBy = value; + } else if (key.includes("orderType")) { + inputs.orderType = value; + } else if (key.includes("section")) { + } else if (key.includes("ACTION_ID")) { + } else { + inputs.query = { + ...inputs.query, + [key]: value, + }; + } + }); + const queryEncrypt = await encryptQuery(inputs); + redirect( + `/${formData.get("section")}?q=${queryEncrypt.replaceAll(" ", "+")}` + ); +} diff --git a/src/app/accounts/page.tsx b/src/app/accounts/page.tsx new file mode 100644 index 0000000..bfc961a --- /dev/null +++ b/src/app/accounts/page.tsx @@ -0,0 +1,57 @@ +"use server"; +import React from "react"; +import { RefreshCcw } from "lucide-react"; +import Pagination from "./pagination"; +import TableComponent from "./table"; +import { + decryptQuery, + defaultPagination, + handleFormSubmission, +} from "@/apicalls/test"; +import MainBodyWithHeader from "@/components/defaultLayout/MainBodyWithHeader"; +import { redirect } from "next/navigation"; + +const DashboardPage = async ({ searchParams }: { searchParams: any }) => { + const searchParamsKeys = await searchParams; + if (!searchParamsKeys?.q) { + const defaultURL = await defaultPagination(); + console.log(defaultURL); + redirect(`/accounts?q=${defaultURL}`); + } + const queryEncrypt = await decryptQuery( + searchParamsKeys?.q.replace(/ /g, "+") + ); + const accountPage = ( +
+

Dashboard

+
+
+

Welcome to your dashboard

+

{JSON.stringify(queryEncrypt)}

+ + + + +
+
+
+ ); + return ; +}; + +export default DashboardPage; diff --git a/src/app/accounts/pagination.tsx b/src/app/accounts/pagination.tsx new file mode 100644 index 0000000..fedbd42 --- /dev/null +++ b/src/app/accounts/pagination.tsx @@ -0,0 +1,81 @@ +"use client"; +import React from "react"; +const Pagination = ({ + page, + totalPage, + size, + orderBy, + orderType, +}: { + page: number; + size: number; + totalPage: number; + orderBy: string; + orderType: string; +}) => { + const [pageInfo, setPageInfo] = React.useState(page); + + function increasePageInfo(event: any) { + if (pageInfo < totalPage) { + setPageInfo(pageInfo + 1); + } else { + event.preventDefault(); + } + } + + function decreasePageInfo(event: any) { + if (pageInfo > 1) { + setPageInfo(pageInfo - 1); + } else { + event.preventDefault(); + } + } + + return ( +
+ +
+ Page + + of + {totalPage} + Size:{" "} + + orderBy: + + orderType: + +
+ +
+ ); +}; + +export default Pagination; diff --git a/src/app/accounts/table.tsx b/src/app/accounts/table.tsx new file mode 100644 index 0000000..5babaef --- /dev/null +++ b/src/app/accounts/table.tsx @@ -0,0 +1,27 @@ +"use client"; + +interface TableComponentInterFace { + inputHeaders: any; +} +const TableComponent: React.FC = ({ + inputHeaders, +}) => { + return ( +
+ {Object.entries(inputHeaders).map(([key, value]) => ( +
+

{key} :

+ +
+ ))} +
+ ); +}; + +export default TableComponent; diff --git a/src/app/building/page.tsx b/src/app/building/page.tsx index 008aab6..93373af 100644 --- a/src/app/building/page.tsx +++ b/src/app/building/page.tsx @@ -1,15 +1,10 @@ "use server"; import React from "react"; +import MainBodyWithHeader from "@/components/defaultLayout/MainBodyWithHeader"; +import BuildChildComponent from "@/pages/Build/Build"; const Page = () => { - return ( -
-

Building Management

-
-

Building page content goes here

-
-
- ); + return } />; }; export default Page; diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx deleted file mode 100644 index fed481a..0000000 --- a/src/app/dashboard/page.tsx +++ /dev/null @@ -1,17 +0,0 @@ -"use server"; -import React from "react"; - -const DashboardPage = () => { - return ( -
-

Dashboard

-
-
-

Welcome to your dashboard

-
-
-
- ); -}; - -export default DashboardPage; diff --git a/src/app/e/accounts/table.tsx b/src/app/e/accounts/table.tsx new file mode 100644 index 0000000..b00f606 --- /dev/null +++ b/src/app/e/accounts/table.tsx @@ -0,0 +1,29 @@ +"use client"; + +interface TableComponentInterFace { + inputHeaders: any; +} +const TableComponent: React.FC = ({ + inputHeaders, +}) => { + return ( + <> +
+ {Object.entries(inputHeaders).map(([key, value]) => ( +
+

{key} :

+ +
+ ))} +
+ + ); +}; + +export default TableComponent; diff --git a/src/components/defaultLayout/MainBodyWithHeader.tsx b/src/components/defaultLayout/MainBodyWithHeader.tsx new file mode 100644 index 0000000..52c89d3 --- /dev/null +++ b/src/components/defaultLayout/MainBodyWithHeader.tsx @@ -0,0 +1,27 @@ +"use server"; +import React, { FC, ReactNode } from "react"; + +interface MainBodyWithHeaderProps { + children: ReactNode; +} + +const MainBodyWithHeader: FC = ({ children }) => { + return ( +
+
+
01
+
02
+
+
+
+

Sticky Header

+
+
+ {children} +
+
+
+ ); +}; + +export default MainBodyWithHeader; diff --git a/src/pages/Build/Build.tsx b/src/pages/Build/Build.tsx new file mode 100644 index 0000000..ad50b43 --- /dev/null +++ b/src/pages/Build/Build.tsx @@ -0,0 +1,33 @@ +"use server"; +import React from "react"; + +const BuildChildComponent = () => { + return ( + <> +

Building Management

+
+

Building page content goes here

+
+
+

More content goes here

+
+
+

Building page content goes here

+
+
+

More content goes here

+
+
+

Building page content goes here

+
+
+

More content goes here

+
+
+

Even more content goes here

+
+ + ); +}; + +export default BuildChildComponent;