From 4b3f1e87507eb6ec87fd0584d3a5fce90813129a Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Sat, 20 May 2023 18:41:15 +0100 Subject: [PATCH] Improve sidebar UX --- src/components/Sidebar/index.tsx | 65 +++++++++++++++++++++----------- src/pages/AddProject/index.tsx | 2 - src/pages/AddTemplate/index.tsx | 2 +- src/pages/AddTemplate/styles.ts | 11 +++++- 4 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index 75f1092..781e0b8 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -120,6 +120,16 @@ const Sidebar = () => { }; }, [location.pathname]); + const showAddButton = (role: string, pathname: string) => { + switch (role) { + case 'client': return (/project/i.test(pathname)); + case 'productOwner': return (/template/i.test(pathname)); + case 'developer': return (/feature/i.test(pathname) || /category/i.test(pathname)); + } + + return false; + } + return ( {role !== 'admin' && ( @@ -210,27 +220,40 @@ const Sidebar = () => { ))} - - } - color={role} - onClick={() => { - if (/project/i.test(location.pathname)) { - navigate('/add-project'); - } - if (/template/i.test(location.pathname)) { - navigate('/add-template'); - } - if (/feature/i.test(location.pathname)) { - navigate('/add-feature'); - } - if (/category/i.test(location.pathname)) { - navigate('/add-category'); - } - }} - /> - - {/\/project/i.test(location.pathname) && ( + {showAddButton(role, location.pathname) && ( + + } + color={role} + onClick={() => { + switch(role) { + case 'client': { + if (/project/i.test(location.pathname)) { + navigate('/add-project'); + } + } + case 'productOwner': { + if (/project/i.test(location.pathname)) { + navigate('/add-project'); + } + if (/template/i.test(location.pathname)) { + navigate('/add-template'); + } + } + case 'developer': { + if (/feature/i.test(location.pathname)) { + navigate('/add-feature'); + } + if (/category/i.test(location.pathname)) { + navigate('/add-category'); + } + } + } + }} + /> + + )} + {/project/i.test(location.pathname) && ['client', 'productOwner'].includes(role) && ( } diff --git a/src/pages/AddProject/index.tsx b/src/pages/AddProject/index.tsx index d58fbcd..d4a9b9b 100644 --- a/src/pages/AddProject/index.tsx +++ b/src/pages/AddProject/index.tsx @@ -418,12 +418,10 @@ const AddProject = () => { .required('Email is required') .email('Email is invalid'), prefix: Yup.string().required('Prefix is required'), - // prettier-ignore number: Yup.number().typeError('Phone must be a number').required('Phone is required'), place: Yup.string().required('Address is required'), city: Yup.string().required('City is required'), country: Yup.string().required('Country is required'), - // prettier-ignore zip: Yup.number().typeError('Zip must be a number').required('Zip is required'), }), onSubmit: ({ diff --git a/src/pages/AddTemplate/index.tsx b/src/pages/AddTemplate/index.tsx index f395032..1cb24a1 100644 --- a/src/pages/AddTemplate/index.tsx +++ b/src/pages/AddTemplate/index.tsx @@ -278,7 +278,7 @@ const AddTemplate = () => { ); - if (categoriesError || featuresError || !availableFeatures || !categories) return ( + if (categoriesError || featuresError || !categories) return ( ` padding: 35px 45px 35px 120px; + + .empty { + fill: ${({ theme, color }) => + color ? theme.colors[color].main : theme.colors.client.main}; + } `;