From 38527c26214bf4ab65f2bc4ff1805544958a42ad Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Thu, 11 May 2023 19:16:19 +0100 Subject: [PATCH] Improve networking, loading and redirection --- src/App.tsx | 10 +- src/components/Sidebar/index.tsx | 23 +- src/pages/AddCategory/index.tsx | 15 +- src/pages/AddFeature/index.tsx | 16 +- src/pages/AddProject/index.tsx | 15 +- src/pages/AddTemplate/index.tsx | 171 +-- src/pages/Category/index.tsx | 123 +- src/pages/CategorySettings/index.tsx | 50 +- src/pages/CreateUser/index.tsx | 8 +- src/pages/Feature/index.tsx | 247 ++-- src/pages/FeatureSettings/index.tsx | 528 ++++---- src/pages/FeatureSettings/styles.ts | 1 + src/pages/Project/index.tsx | 1147 ++++++++--------- src/pages/Prototype/index.tsx | 298 +++-- .../{SupportMessaging => Support}/index.tsx | 8 +- .../{SupportMessaging => Support}/styles.ts | 0 src/pages/Template/index.tsx | 364 +++--- src/pages/UpdateProject/index.tsx | 33 +- src/pages/UserSettings/index.tsx | 40 +- src/pages/Users/index.tsx | 396 +++--- src/pages/Users/styles.ts | 3 +- src/pages/index.tsx | 4 +- 22 files changed, 1750 insertions(+), 1750 deletions(-) rename src/pages/{SupportMessaging => Support}/index.tsx (98%) rename src/pages/{SupportMessaging => Support}/styles.ts (100%) diff --git a/src/App.tsx b/src/App.tsx index 3839ed3..0960dc2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -28,7 +28,7 @@ import { AddProject, UpdateProject, Payments, - SupportMessaging, + Support, } from './pages'; import { GetUserByIdQuery, GetUserByIdQueryVariables } from './graphql/types'; import { GET_USER_BY_ID } from './graphql/auth.api'; @@ -136,18 +136,18 @@ const App = () => { } /> - + } /> - + } /> diff --git a/src/components/Sidebar/index.tsx b/src/components/Sidebar/index.tsx index 235d61e..75f1092 100644 --- a/src/components/Sidebar/index.tsx +++ b/src/components/Sidebar/index.tsx @@ -56,8 +56,7 @@ const Sidebar = () => { }, onCompleted({ getAllProjectsByClientId }) { setProjects(getAllProjectsByClientId); - }, - fetchPolicy: 'network-only', + } }); const [getProjects] = useLazyQuery< @@ -66,8 +65,7 @@ const Sidebar = () => { >(GET_ALL_PROJECTS, { onCompleted({ getAllProjects }) { setProjects(getAllProjects); - }, - fetchPolicy: 'network-only', + } }); const [getTemplates] = useLazyQuery< @@ -77,7 +75,6 @@ const Sidebar = () => { onCompleted({ getAllTemplates }) { setTemplates(getAllTemplates); }, - fetchPolicy: 'network-only', }); const [getFeatures] = useLazyQuery< @@ -87,7 +84,6 @@ const Sidebar = () => { onCompleted({ getAllFeatures }) { setFeatures(getAllFeatures); }, - fetchPolicy: 'network-only', }); const [getCategories] = useLazyQuery< @@ -97,7 +93,6 @@ const Sidebar = () => { onCompleted({ getAllCategories }) { setCategories(getAllCategories); }, - fetchPolicy: 'network-only', }); useEffect(() => { @@ -123,8 +118,6 @@ const Sidebar = () => { setFeatures([]); setCategories([]); }; - - // eslint-disable-next-line }, [location.pathname]); return ( @@ -133,14 +126,15 @@ const Sidebar = () => { <> {projects && - projects.map((project) => ( + new RegExp(/project/, 'i').test(location.pathname) && + projects.map((project, index) => (
navigate(`/project/${project.id}`)} /> @@ -152,6 +146,7 @@ const Sidebar = () => { ))} {templates && + new RegExp(/template/, 'i').test(location.pathname) && templates.map((template, index) => (
@@ -172,6 +167,7 @@ const Sidebar = () => { ))} {features && + new RegExp(/feature/, 'i').test(location.pathname) && features.map((feature, index) => (
@@ -192,6 +188,7 @@ const Sidebar = () => { ))} {categories && + new RegExp(/category/, 'i').test(location.pathname) && categories.map((category, index) => (
diff --git a/src/pages/AddCategory/index.tsx b/src/pages/AddCategory/index.tsx index 6c3de69..f33ef83 100644 --- a/src/pages/AddCategory/index.tsx +++ b/src/pages/AddCategory/index.tsx @@ -66,7 +66,14 @@ const AddCategory = () => { }, }); - return role === 'developer' ? ( + if (role !== 'developer') return ( + <> + {role === 'admin' && } + {['client', 'productOwer'].includes(role as string) && } + + ) + + return (