From c0c09139a095246b22113fe5c490d972f591e9a1 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Fri, 28 May 2021 17:42:41 +0100 Subject: [PATCH] Complete sidebar component --- src/components/Sidebar/index.tsx | 198 +++++++++++++++++-------------- 1 file changed, 106 insertions(+), 92 deletions(-) diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index 185a583..ceda1ff 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -74,18 +74,18 @@ const Sidebar = () => { }); useEffect(() => { - if (/project/.test(location.pathname)) { + if (/project/i.test(location.pathname)) { getProjects(); } - if (/template/.test(location.pathname)) { + if (/template/i.test(location.pathname)) { getTemplates(); } - if (/feature/.test(location.pathname)) { + if (/feature/i.test(location.pathname)) { getFeatures(); } - if (/category/.test(location.pathname)) { + if (/category/i.test(location.pathname)) { getCategories(); } @@ -101,94 +101,108 @@ const Sidebar = () => { return ( - - {projects && - projects.map((project) => ( - -
- history.push(`/project/${project.id}`)} - /> -
- {}, label: project.name }]} - /> -
- ))} - {templates && - templates.map((template) => ( - -
- history.push(`/template/${template.id}`)} - /> -
- {}, label: template.name }]} - /> -
- ))} - {features && - features.map((feature) => ( - -
- history.push(`/feature/${feature.id}`)} - /> -
- {}, label: feature.name }]} - /> -
- ))} - {categories && - categories.map((category) => ( - -
- history.push(`/category/${category.id}`)} - /> -
- {}, label: category.name }]} - /> -
- ))} -
- - {role !== 'admin' && ( - } - color={role} - onClick={() => { - if (/project/.test(location.pathname)) { - history.push('/add-project'); - } - if (/template/.test(location.pathname)) { - history.push('/add-template'); - } - if (/feature/.test(location.pathname)) { - history.push('/add-feature'); - } - if (/category/.test(location.pathname)) { - history.push('/add-category'); - } - }} - /> - )} - + {role !== 'admin' && ( + <> + + {projects && + projects.map((project) => ( + +
+ history.push(`/project/${project.id}`)} + /> +
+ {}, label: project.name }]} + /> +
+ ))} + {templates && + templates.map((template) => ( + +
+ history.push(`/template/${template.id}`)} + /> +
+ {}, label: template.name }]} + /> +
+ ))} + {features && + features.map((feature) => ( + +
+ history.push(`/feature/${feature.id}`)} + /> +
+ {}, label: feature.name }]} + /> +
+ ))} + {categories && + categories.map((category) => ( + +
+ history.push(`/category/${category.id}`)} + /> +
+ {}, label: category.name }]} + /> +
+ ))} +
+ + } + color={role} + onClick={() => { + if (/project/i.test(location.pathname)) { + history.push('/add-project'); + } + if (/template/i.test(location.pathname)) { + history.push('/add-template'); + } + if (/feature/i.test(location.pathname)) { + history.push('/add-feature'); + } + if (/category/i.test(location.pathname)) { + history.push('/add-category'); + } + }} + /> + + + )}
); };