Complete sidebar component

This commit is contained in:
Hazem Krimi
2021-05-28 17:42:41 +01:00
parent 57493dbc36
commit c0c09139a0
+24 -10
View File
@@ -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,6 +101,8 @@ const Sidebar = () => {
return (
<Wrapper color={role}>
{role !== 'admin' && (
<>
<Box display='flex' flexDirection='column'>
{projects &&
projects.map((project) => (
@@ -108,6 +110,9 @@ const Sidebar = () => {
<div id={`project-${project.id}`}>
<SidebarItem
color={role}
selected={new RegExp(project.id, 'i').test(
location.pathname
)}
text={project.name[0]}
onClick={() => history.push(`/project/${project.id}`)}
/>
@@ -124,6 +129,9 @@ const Sidebar = () => {
<div id={`template-${template.id}`}>
<SidebarItem
color={role}
selected={new RegExp(template.id, 'i').test(
location.pathname
)}
text={template.name[0]}
onClick={() => history.push(`/template/${template.id}`)}
/>
@@ -140,6 +148,9 @@ const Sidebar = () => {
<div id={`feature-${feature.id}`}>
<SidebarItem
color={role}
selected={new RegExp(feature.id, 'i').test(
location.pathname
)}
text={feature.name[0]}
onClick={() => history.push(`/feature/${feature.id}`)}
/>
@@ -156,6 +167,9 @@ const Sidebar = () => {
<div id={`category-${category.id}`}>
<SidebarItem
color={role}
selected={new RegExp(category.id, 'i').test(
location.pathname
)}
text={category.name[0]}
onClick={() => history.push(`/category/${category.id}`)}
/>
@@ -168,27 +182,27 @@ const Sidebar = () => {
))}
</Box>
<Box>
{role !== 'admin' && (
<IconButton
icon={<Add />}
color={role}
onClick={() => {
if (/project/.test(location.pathname)) {
if (/project/i.test(location.pathname)) {
history.push('/add-project');
}
if (/template/.test(location.pathname)) {
if (/template/i.test(location.pathname)) {
history.push('/add-template');
}
if (/feature/.test(location.pathname)) {
if (/feature/i.test(location.pathname)) {
history.push('/add-feature');
}
if (/category/.test(location.pathname)) {
if (/category/i.test(location.pathname)) {
history.push('/add-category');
}
}}
/>
)}
</Box>
</>
)}
</Wrapper>
);
};