From 81994c629edc2def77035c5cc113f2abab74410c Mon Sep 17 00:00:00 2001 From: Habibur Rahman Date: Wed, 4 Jan 2023 21:42:40 +0600 Subject: [PATCH] complete dashboard page design and create site added functionality --- components/AddSiteModal.jsx | 82 +++++++++++++++++++++++++++++++ components/DashboardShell.jsx | 56 +++++++++++++++++++++ components/EmptyState.jsx | 28 +++++++++++ components/FreePlanEmptyState.jsx | 18 +++++++ lib/db.js | 17 ++++++- package.json | 1 + pages/dashboard.js | 21 ++++++++ pages/index.js | 10 ++-- yarn.lock | 5 ++ 9 files changed, 233 insertions(+), 5 deletions(-) create mode 100644 components/AddSiteModal.jsx create mode 100644 components/DashboardShell.jsx create mode 100644 components/EmptyState.jsx create mode 100644 components/FreePlanEmptyState.jsx create mode 100644 pages/dashboard.js diff --git a/components/AddSiteModal.jsx b/components/AddSiteModal.jsx new file mode 100644 index 0000000..cfad2c3 --- /dev/null +++ b/components/AddSiteModal.jsx @@ -0,0 +1,82 @@ +import { createSite } from "@/lib/db"; +import { useRef } from "react"; +import { useForm } from "react-hook-form"; + +const { + Button, + Modal, + ModalOverlay, + ModalContent, + ModalHeader, + ModalCloseButton, + ModalBody, + FormControl, + FormLabel, + Input, + ModalFooter, + useDisclosure, +} = require("@chakra-ui/react"); + +const AddSiteModal = () => { + const { isOpen, onOpen, onClose } = useDisclosure(); + + const initialRef = useRef(null); + // const finalRef = useRef(null); + + const { handleSubmit, register, reset } = useForm(); + const onSubmit = (values) => { + createSite(values); + // onClose(); + reset(); + }; + + return ( + <> + + + + + + Add Site + + + + Name + + + + + Link + + + + + + + + + + + + ); +}; + +export default AddSiteModal; diff --git a/components/DashboardShell.jsx b/components/DashboardShell.jsx new file mode 100644 index 0000000..0bbec68 --- /dev/null +++ b/components/DashboardShell.jsx @@ -0,0 +1,56 @@ +import { useAuth } from "@/lib/auth"; +import { + Avatar, + Breadcrumb, + BreadcrumbItem, + BreadcrumbLink, + Flex, + Heading, + Stack, +} from "@chakra-ui/react"; +import Link from "next/link"; +import React from "react"; + +const DashboardShell = ({ children }) => { + const auth = useAuth(); + + return ( + + + + Feedback + Sites + + + + Account + + + + + + + + + + Sites + + + + + Sites + + {children} + + + + ); +}; + +export default DashboardShell; diff --git a/components/EmptyState.jsx b/components/EmptyState.jsx new file mode 100644 index 0000000..0afefe9 --- /dev/null +++ b/components/EmptyState.jsx @@ -0,0 +1,28 @@ +import { Box, Button, Flex, Heading, Text } from "@chakra-ui/react"; +import Link from "next/link"; +import React from "react"; +import AddSiteModal from "./AddSiteModal"; +import DashboardShell from "./DashboardShell"; + +const EmptyState = () => { + return ( + + + + You haven't added any sites + + Welcome. Let's get started + + + + ); +}; + +export default EmptyState; diff --git a/components/FreePlanEmptyState.jsx b/components/FreePlanEmptyState.jsx new file mode 100644 index 0000000..ff5d22f --- /dev/null +++ b/components/FreePlanEmptyState.jsx @@ -0,0 +1,18 @@ +import { Box, Button, Heading, Text } from "@chakra-ui/react"; +import Link from "next/link"; +import React from "react"; +import DashboardShell from "./DashboardShell"; + +const FreePlanEmptyState = () => { + return ( + + + Get feedback on your site instantly. + Start today, then grow with us. + + + + ); +}; + +export default FreePlanEmptyState; diff --git a/lib/db.js b/lib/db.js index 3e1f8f3..9dc7f49 100644 --- a/lib/db.js +++ b/lib/db.js @@ -1,5 +1,11 @@ import "@/lib/firebase"; -import { doc, getFirestore, setDoc } from "firebase/firestore"; +import { + addDoc, + collection, + doc, + getFirestore, + setDoc, +} from "firebase/firestore"; const db = getFirestore(); @@ -11,3 +17,12 @@ export async function createUser(uid, data) { console.log(error); } } + +export async function createSite(data) { + try { + const docRef = await addDoc(collection(db, "sites"), { ...data }); + // return docRef; + } catch (error) { + console.log("Error", error); + } +} diff --git a/package.json b/package.json index 724df59..83757e3 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "next": "13.0.2", "react": "18.2.0", "react-dom": "18.2.0", + "react-hook-form": "^7.41.5", "sass": "^1.57.1" } } diff --git a/pages/dashboard.js b/pages/dashboard.js new file mode 100644 index 0000000..19f6382 --- /dev/null +++ b/pages/dashboard.js @@ -0,0 +1,21 @@ +import EmptyState from "@/components/EmptyState"; +import Head from "next/head"; +import { useAuth } from "../lib/auth"; + +const Dashboard = () => { + const auth = useAuth(); + + if (!auth.user) { + return "Loading..."; + } + return ( + <> + + Dashboard + + ; + + ); +}; + +export default Dashboard; diff --git a/pages/index.js b/pages/index.js index 2f17855..4f52629 100644 --- a/pages/index.js +++ b/pages/index.js @@ -1,3 +1,4 @@ +import EmptyState from "@/components/EmptyState"; import { Button, Flex, Heading, Text } from "@chakra-ui/react"; import Head from "next/head"; import { useAuth } from "../lib/auth"; @@ -21,12 +22,13 @@ export default function Home() { justifyContent="center" > Rapid Review - {!auth.user && ( - - )} {auth.user && {auth.user.email}} {auth.user && {auth.user.name}} - {auth.user && } + {auth.user ? ( + + ) : ( + + )} ); diff --git a/yarn.lock b/yarn.lock index f75239c..80ed17c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3342,6 +3342,11 @@ react-focus-lock@^2.9.1: use-callback-ref "^1.3.0" use-sidecar "^1.1.2" +react-hook-form@^7.41.5: + version "7.41.5" + resolved "https://registry.yarnpkg.com/react-hook-form/-/react-hook-form-7.41.5.tgz#dcd0e7438c15044eadc99df6deb889da5858a03b" + integrity sha512-DAKjSJ7X9f16oQrP3TW2/eD9N6HOgrmIahP4LOdFphEWVfGZ2LulFd6f6AQ/YS/0cx/5oc4j8a1PXxuaurWp/Q== + react-is@^16.13.1, react-is@^16.7.0: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"