From 6f18419a74edbf375ea291c8a09a49758139e5d9 Mon Sep 17 00:00:00 2001 From: Meliora Ho Date: Wed, 27 Mar 2024 15:47:44 +0000 Subject: [PATCH] Added drawer --- compass/app/admin/layout.tsx | 37 ++++++++ compass/app/admin/page.tsx | 87 ++---------------- compass/app/page.tsx | 86 ------------------ compass/app/pages/page/page.tsx | 26 ------ compass/components/admin/PageLayout.tsx | 2 +- compass/components/admin/Table/Index.tsx | 91 +++++++++++++++++++ compass/components/admin/Table/RowAction.tsx | 21 +++++ .../components/admin/Table/TableAction.tsx | 12 +++ .../admin/Table}/users.json | 0 compass/components/page/Drawer.tsx | 2 +- 10 files changed, 172 insertions(+), 192 deletions(-) create mode 100644 compass/app/admin/layout.tsx delete mode 100644 compass/app/page.tsx delete mode 100644 compass/app/pages/page/page.tsx create mode 100644 compass/components/admin/Table/Index.tsx create mode 100644 compass/components/admin/Table/RowAction.tsx create mode 100644 compass/components/admin/Table/TableAction.tsx rename compass/{app/admin => components/admin/Table}/users.json (100%) diff --git a/compass/app/admin/layout.tsx b/compass/app/admin/layout.tsx new file mode 100644 index 0000000..bb7fddd --- /dev/null +++ b/compass/app/admin/layout.tsx @@ -0,0 +1,37 @@ +"use client" + +import Sidebar from '@/components/resource/Sidebar'; +import React, { useState } from 'react'; +import { ChevronDoubleRightIcon } from '@heroicons/react/24/outline'; + +export default function RootLayout({ + + children, +}: { + children: React.ReactNode +}) { + const [isSidebarOpen, setIsSidebarOpen] = useState(false); + + return ( +
+ {/* button to open sidebar */} + + {/* sidebar */} +
+ +
+ {/* page ui */} +
+ {children} +
+
+ ) +} \ No newline at end of file diff --git a/compass/app/admin/page.tsx b/compass/app/admin/page.tsx index 9307b93..8e4d918 100644 --- a/compass/app/admin/page.tsx +++ b/compass/app/admin/page.tsx @@ -1,90 +1,21 @@ "use client"; -// import Table from "@/components/Table"; -import { - ColumnDef, - createColumnHelper, - flexRender, - getCoreRowModel, - useReactTable, -} from "@tanstack/react-table"; -import { useState } from "react"; -import usersImport from "./users.json"; - -const usersExample = usersImport as unknown as User[]; - -type User = { - id: number; - created_at: any; - username: string; - role: "ADMIN" | "EMPLOYEE" | "VOLUNTEER"; - email: string; - program: "DOMESTIC" | "ECONOMIC" | "COMMUNITY"; - experience: number; - group?: string; -}; import { PageLayout } from "@/components/admin/PageLayout"; +import { Table } from "@/components/admin/Table/Index"; + +import { UsersIcon } from "@heroicons/react/24/solid"; + + + -import { BookmarkIcon } from "@heroicons/react/24/solid"; export default function Page() { - const columnHelper = createColumnHelper(); - - const columns = [ - columnHelper.accessor("username", { - cell: (info) => info.getValue(), - }), - columnHelper.accessor("role", { - cell: (info) => info.renderValue(), - }), - columnHelper.accessor("email", { - cell: (info) => info.renderValue(), - }), - columnHelper.accessor("program", { - cell: (info) => info.renderValue(), - }), - ]; - - const [data, setData] = useState([...usersExample]); - - const table = useReactTable({ - columns, - data, - getCoreRowModel: getCoreRowModel(), - }); + return (
{/* icon + title */} - }> - - - {table.getHeaderGroups().map((headerGroup) => ( - - {headerGroup.headers.map((header) => ( - - ))} - - ))} - - - {table.getRowModel().rows.map((row) => ( - - {row.getVisibleCells().map((cell) => ( - - ))} - - ))} - -
- {header.isPlaceholder - ? null - : flexRender( - header.column.columnDef.header, - header.getContext() - )} -
- {flexRender(cell.column.columnDef.cell, cell.getContext())} -
+ }> + ); diff --git a/compass/app/page.tsx b/compass/app/page.tsx deleted file mode 100644 index dba820a..0000000 --- a/compass/app/page.tsx +++ /dev/null @@ -1,86 +0,0 @@ -// pages/index.tsx -"use client"; - -import Button from '@/components/Button'; -import Input from '@/components/Input' -import InlineLink from '@/components/InlineLink'; -import Paper from '@/components/auth/Paper'; -// import { Metadata } from 'next' -import Image from 'next/image'; -import {ChangeEvent, useState} from "react"; - -// export const metadata: Metadata = { -// title: 'Login', -// } - -export default function Page() { - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); - const [error, setError] = useState(""); - - const handleEmailChange = (event: React.ChangeEvent) => { - setEmail(event.currentTarget.value); - console.log("email " + email); - } - - const handlePasswordChange = (event: React.ChangeEvent) => { - setPassword(event.currentTarget.value); - console.log("password " + password) - } - - const handleClick = (event: React.MouseEvent) => { - event.preventDefault(); - // Priority: Incorrect combo > Missing email > Missing password - - if (password.trim().length === 0) { - setError("Please enter your password.") - } - // This shouldn't happen, already provides validation, but just in case. - if (email.trim().length === 0) { - setError("Please enter your email.") - } - // Placeholder for incorrect email + password combo. - if (email === "incorrect@gmail.com" && password) { - setError("Incorrect password.") - } - } - - - - return ( - <> - -
- -

Login

-
- -
-
- -
-
- - Forgot password? - - - - -
- -

- © 2024 Compass Center -

-
- - ); -}; \ No newline at end of file diff --git a/compass/app/pages/page/page.tsx b/compass/app/pages/page/page.tsx deleted file mode 100644 index dce1122..0000000 --- a/compass/app/pages/page/page.tsx +++ /dev/null @@ -1,26 +0,0 @@ -// pages/index.tsx -"use client"; - - -import Drawer from '@/components/page/Drawer'; -// import { Metadata } from 'next' -import {ChangeEvent, useState} from "react"; - -// export const metadata: Metadata = { -// title: 'Login', -// } - -export default function Page() { - const [pageContent, setPageContent] = useState("") - - const handleDrawerContentChange = (newContent) => { - setPageContent(newContent); - }; - - return ( - <> -

Resources

- {pageContent} - - ); -}; \ No newline at end of file diff --git a/compass/components/admin/PageLayout.tsx b/compass/components/admin/PageLayout.tsx index 80a96f5..c655296 100644 --- a/compass/components/admin/PageLayout.tsx +++ b/compass/components/admin/PageLayout.tsx @@ -15,7 +15,7 @@ export const PageLayout: React.FC = ({ icon, title, children }) {/* data */} -
+
{children}
diff --git a/compass/components/admin/Table/Index.tsx b/compass/components/admin/Table/Index.tsx new file mode 100644 index 0000000..5a12c1b --- /dev/null +++ b/compass/components/admin/Table/Index.tsx @@ -0,0 +1,91 @@ +// for showcasing to compass + +import usersImport from "./users.json"; +import { + ColumnDef, + createColumnHelper, + flexRender, + getCoreRowModel, + useReactTable, +} from "@tanstack/react-table"; +import { useState } from "react"; +import { RowAction } from "./RowAction"; +import { TableAction } from "./TableAction"; + +const usersExample = usersImport as unknown as User[]; + +type User = { + id: number; + created_at: any; + username: string; + role: "ADMIN" | "EMPLOYEE" | "VOLUNTEER"; + email: string; + program: "DOMESTIC" | "ECONOMIC" | "COMMUNITY"; + experience: number; + group?: string; +}; + + +export const Table = () => { + const columnHelper = createColumnHelper(); + + const columns = [ + columnHelper.accessor("username", { + cell: (info) => , + }), + columnHelper.accessor("role", { + cell: (info) => info.renderValue(), + }), + columnHelper.accessor("email", { + cell: (info) => info.renderValue(), + }), + columnHelper.accessor("program", { + cell: (info) => info.renderValue(), + }), + ]; + + const [data, setData] = useState([...usersExample]); + + const table = useReactTable({ + columns, + data, + getCoreRowModel: getCoreRowModel(), + }); + + return( +
+
+ +
+
+ + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => ( + + ))} + + ))} + + + {table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + ))} + + ))} + +
+ {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext() + )} +
+ {flexRender(cell.column.columnDef.cell, cell.getContext())} +
+
+ ) +} \ No newline at end of file diff --git a/compass/components/admin/Table/RowAction.tsx b/compass/components/admin/Table/RowAction.tsx new file mode 100644 index 0000000..37b0215 --- /dev/null +++ b/compass/components/admin/Table/RowAction.tsx @@ -0,0 +1,21 @@ +import Drawer from "@/components/page/Drawer"; +import {ChangeEvent, useState} from "react"; + +export const RowAction = ({ title }) => { + const [pageContent, setPageContent] = useState("") + + const handleDrawerContentChange = (newContent) => { + setPageContent(newContent); + }; + + + + return ( +
+ {title} + + {pageContent} + +
+ ); +}; diff --git a/compass/components/admin/Table/TableAction.tsx b/compass/components/admin/Table/TableAction.tsx new file mode 100644 index 0000000..be4a309 --- /dev/null +++ b/compass/components/admin/Table/TableAction.tsx @@ -0,0 +1,12 @@ +import { MagnifyingGlassIcon } from "@heroicons/react/24/solid"; + +export const TableAction = () => { + return ( +
+ Filter + Sort + +
+ ); + }; + \ No newline at end of file diff --git a/compass/app/admin/users.json b/compass/components/admin/Table/users.json similarity index 100% rename from compass/app/admin/users.json rename to compass/components/admin/Table/users.json diff --git a/compass/components/page/Drawer.tsx b/compass/components/page/Drawer.tsx index 217fbd2..d80cd9f 100644 --- a/compass/components/page/Drawer.tsx +++ b/compass/components/page/Drawer.tsx @@ -44,7 +44,7 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita return (
- +

{title}