diff --git a/pages/_app.js b/pages/_app.js index 2a67ba6..73a6088 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -58,6 +58,7 @@ function MyApp({ Component, pageProps }) { setAuthenticationStatus("authenticated"); const data = await res.json(); dispatch(setUserInfo(data.user)); + setLoginStatus(true); } }; @@ -122,9 +123,9 @@ function MyApp({ Component, pageProps }) { { const handleShow = () => setShow(!show); const handleInvalidPassword = () => setIsPasswordInvalid(false); + const handleClose = () => { + router.push("/"); + }; const handleSubmit = async (event) => { event.preventDefault(); @@ -54,61 +57,85 @@ const Admin = () => { }; return ( - router.push("/")}> - - ADMIN LOGIN - -
- - - Email - - - - - Password - +
+ + + ADMIN LOGIN + + + + + Email - - - - - {isPasswordInvalid && ( - - Wrong Credentials - - )} - - + + + + Password + + + + + + + {isPasswordInvalid && ( + + Wrong Credentials + + )} + + - - - - - - - + + + + + + + +
); }; diff --git a/pages/chakra_theme/theme.js b/pages/chakra_theme/theme.js index 7be1f64..7056d54 100644 --- a/pages/chakra_theme/theme.js +++ b/pages/chakra_theme/theme.js @@ -20,6 +20,9 @@ function CustomChakraProvider({ children }) { diff --git a/pages/components/CreateProjectComponent.js b/pages/components/CreateProjectComponent.js new file mode 100644 index 0000000..bbecf7f --- /dev/null +++ b/pages/components/CreateProjectComponent.js @@ -0,0 +1,117 @@ +import React, { useState } from "react"; +import { useSelector } from "react-redux"; +import { selectUserInfo } from "../../store/userSlice"; +import { + Modal, + ModalContent, + ModalHeader, + ModalOverlay, + ModalCloseButton, + ModalBody, + FormControl, + FormLabel, + Input, + ModalFooter, + Button, +} from "@chakra-ui/react"; + +const CreateProjectComponent = ({ isOpen, setIsOpen }) => { + const user = useSelector(selectUserInfo); + + const handleSubmit = async (event) => { + event.preventDefault(); + + const projectData = { + email: event?.target[0]?.value, + password: event?.target[1]?.value, + }; + + if (user.role === "admin") { + const res = await fetch(API_URL + "login", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(projectData), + }); + + if (res?.ok) { + const data = await res.json(); + localStorage.setItem("token", "Bearer " + data.token); + localStorage.setItem("manualLogin", true); + dispatch(setUserInfo(data.user)); + router.push("/"); + } else { + setIsPasswordInvalid(true); + } + } + }; + + return ( + setIsOpen(false)}> + + + CREATE PROJECT + +
+ + + Email + + + + + Password + + + + + + + + +
+
+
+ ); +}; + +export default CreateProjectComponent; diff --git a/pages/components/Footer.jsx b/pages/components/Footer.jsx index b81e9f0..833f7c3 100644 --- a/pages/components/Footer.jsx +++ b/pages/components/Footer.jsx @@ -4,7 +4,12 @@ import React from "react"; function Footer() { return ( <> - + diff --git a/pages/components/Navbar.jsx b/pages/components/Navbar.jsx index 4d1ca5e..68bc2a6 100644 --- a/pages/components/Navbar.jsx +++ b/pages/components/Navbar.jsx @@ -1,16 +1,17 @@ import React from "react"; import { Flex, Image, Box, Spacer, Button } from "@chakra-ui/react"; import { ConnectButton } from "@rainbow-me/rainbowkit"; -import { useSelector } from "react-redux"; -import { selectUserInfo } from "../../store/userSlice"; +import { useSelector, useDispatch } from "react-redux"; +import { selectUserInfo, setUserInfo } from "../../store/userSlice"; function Navbar() { const user = useSelector(selectUserInfo); - // console.log(user); + const dispatch = useDispatch(); + const handleLogout = () => { localStorage.removeItem("token"); localStorage.removeItem("manualLogin"); - window.location.reload(false); + dispatch(setUserInfo({})); }; return ( @@ -28,9 +29,18 @@ function Navbar() { {user.role === "admin" && localStorage.getItem("manualLogin") ? ( diff --git a/pages/components/Projects.jsx b/pages/components/Projects.jsx index 581322a..1c3f7be 100644 --- a/pages/components/Projects.jsx +++ b/pages/components/Projects.jsx @@ -1,17 +1,51 @@ -import { Container, Text, Heading } from "@chakra-ui/react"; -import React from "react"; +import React, { useState } from "react"; +import { Container, Text, Heading, Button } from "@chakra-ui/react"; +import { useSelector } from "react-redux"; +import { selectUserInfo } from "../../store/userSlice"; +import CreateProjectComponent from "./CreateProjectComponent"; + +const API_URL = process.env.NEXT_PUBLIC_API_URL; function Projects() { + const user = useSelector(selectUserInfo); + const [isOpenCreateProjectComponent, setIsOpenCreateProjectComponent] = + useState(false); + + const handleDisplayCreateProject = () => { + if (user.role === "admin") { + setIsOpenCreateProjectComponent(true); + } + }; + return ( <> - - + + Racks Project Manager - - Projects... - + {user.role === "admin" && ( + + )} + Projects... + ); } diff --git a/styles/globals.css b/styles/globals.css index b5c61c9..e3a2e33 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -1,3 +1,23 @@ @tailwind base; @tailwind components; @tailwind utilities; + +/* body { + background-color: transparent !important; +} */ + +[data-theme="dark"], +[data-theme="dark"] body { + color: white; + background: linear-gradient(90deg, #0e0f13 0, #21262c); +} + +.bg-overlay { + background: linear-gradient(90deg, #0e0f13 0, #21262c); + height: 100vh; + width: 100vw; +} + +.chakra-modal__content { + background: linear-gradient(90deg, #282d33 0, #222222) !important; +}