From 01a38570e4ef4102c646712b81cbb9106540cf0f Mon Sep 17 00:00:00 2001 From: corpulent Date: Sun, 21 Aug 2022 18:40:37 +0300 Subject: [PATCH] feat: call project on select on new project --- .../src/components/Projects/index.tsx | 40 +++++++++++-------- .../src/components/global/SideBar.tsx | 29 ++++++++++---- 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/services/frontend/src/components/Projects/index.tsx b/services/frontend/src/components/Projects/index.tsx index 6f8d7ab..f941ac1 100644 --- a/services/frontend/src/components/Projects/index.tsx +++ b/services/frontend/src/components/Projects/index.tsx @@ -1,7 +1,8 @@ import { useState } from "react"; -import { Link, useNavigate } from "react-router-dom"; +import { useNavigate } from "react-router-dom"; import { PROJECTS_FETCH_LIMIT } from "../../constants"; import ModalImport from "../modals/import"; +import ModalNewProject from "../modals/new-project"; import { IProject } from "../../types"; import { toaster } from "../../utils"; import Spinner from "../../components/global/Spinner"; @@ -17,13 +18,10 @@ const Projects = () => { const [offset, setOffset] = useState(0); const [importing, setImporting] = useState(false); const [showImportModal, setShowImportModal] = useState(false); + const [showNewProjectModal, setShowNewProjectModal] = useState(false); const { isLoading, isError, error, data, isFetching, isPreviousData } = useProjects(limit, offset); - const onImportClick = () => { - setShowImportModal(true); - }; - const handleImport = (values: IImportFinalValues) => { setImporting(true); importProject(values) @@ -49,10 +47,14 @@ const Projects = () => { /> ) : null} + {showNewProjectModal ? ( + setShowNewProjectModal(false)} /> + ) : null} +
-
-
+
+

Projects

@@ -60,26 +62,26 @@ const Projects = () => { {data && data.results.length > 0 && (
- setShowNewProjectModal(true)} className="btn-util text-white bg-blue-600 hover:bg-blue-700 sm:w-auto" - to="/projects/new" > Create new project - +
)}
-
+
{!isFetching && !isLoading && ( <> -
+
{error && (

@@ -117,11 +119,17 @@ const Projects = () => { Get started by creating a new project

- - +

)} diff --git a/services/frontend/src/components/global/SideBar.tsx b/services/frontend/src/components/global/SideBar.tsx index cb25374..1148c03 100644 --- a/services/frontend/src/components/global/SideBar.tsx +++ b/services/frontend/src/components/global/SideBar.tsx @@ -1,9 +1,11 @@ import { useLocation } from "react-router-dom"; import { BookOpenIcon, PlusIcon } from "@heroicons/react/outline"; import { Link } from "react-router-dom"; +import ModalNewProject from "../modals/new-project"; import UserMenu from "./UserMenu"; import Logo from "./logo"; import { classNames } from "../../utils/styles"; +import { useState } from "react"; interface ISideBarProps { state: any; @@ -21,20 +23,17 @@ export default function SideBar(props: ISideBarProps) { icon: BookOpenIcon, current: pathname.match(projRegex) || pathname == "/" ? true : false, visible: isAuthenticated - }, - { - name: "New project", - href: "/projects/new", - icon: PlusIcon, - current: false, - visible: true } ]; - + const [showNewProjectModal, setShowNewProjectModal] = useState(false); const userName = state.user ? state.user.username : ""; return ( <> + {showNewProjectModal ? ( + setShowNewProjectModal(false)} /> + ) : null} +
@@ -67,6 +66,20 @@ export default function SideBar(props: ISideBarProps) { ); } })} + +