@@ -5,7 +5,6 @@ import { useCallback } from 'react';
5
5
import {
6
6
Anchor ,
7
7
Button ,
8
- CardProps ,
9
8
Container ,
10
9
PaperProps ,
11
10
SimpleGrid ,
@@ -18,6 +17,7 @@ import { IconPlus } from '@tabler/icons-react';
18
17
import NewProjectDrawer from '@/app/apps/projects/components/NewProjectDrawer' ;
19
18
import ProjectsCard from '@/app/apps/projects/components/ProjectsCard/ProjectsCard' ;
20
19
import { ErrorAlert , PageHeader } from '@/components' ;
20
+ import { useAuth } from '@/hooks/useAuth' ;
21
21
import { PATH_DASHBOARD } from '@/routes' ;
22
22
import { IApiResponse } from '@/types/api-response' ;
23
23
import { IProject } from '@/types/projects' ;
@@ -39,13 +39,17 @@ const CARD_PROPS: Omit<PaperProps, 'children'> = {
39
39
} ;
40
40
41
41
function Projects ( ) {
42
+ const { user, isAuthenticated, permissions } = useAuth ( ) ;
42
43
const {
43
44
data : projectsData ,
44
45
loading : projectsLoading ,
45
46
error : projectsError ,
46
47
refetch : refetchProjects ,
47
48
} = useFetch < IApiResponse < IProject [ ] > > ( '/api/projects' ) ;
48
49
50
+ // Check if the user has a can add project
51
+ const canAddProject = permissions ?. includes ( 'Permissions.Projects.Create' ) ;
52
+
49
53
const [ newProjectOpened , { open : newProjectOpen , close : newProjectClose } ] =
50
54
useDisclosure ( false ) ;
51
55
@@ -61,18 +65,7 @@ function Projects() {
61
65
return (
62
66
< Container fluid >
63
67
< Stack gap = "lg" >
64
- < PageHeader
65
- title = "Projects"
66
- breadcrumbItems = { items }
67
- actionButton = {
68
- < Button
69
- leftSection = { < IconPlus size = { 18 } /> }
70
- onClick = { newProjectOpen }
71
- >
72
- New Project
73
- </ Button >
74
- }
75
- />
68
+ < PageHeader title = "Projects" breadcrumbItems = { items } />
76
69
< SimpleGrid
77
70
cols = { { base : 1 , sm : 2 , lg : 3 , xl : 4 } }
78
71
spacing = { { base : 10 , sm : 'xl' } }
@@ -95,18 +88,7 @@ function Projects() {
95
88
return (
96
89
< Container fluid >
97
90
< Stack gap = "lg" >
98
- < PageHeader
99
- title = "Projects"
100
- breadcrumbItems = { items }
101
- actionButton = {
102
- < Button
103
- leftSection = { < IconPlus size = { 18 } /> }
104
- onClick = { newProjectOpen }
105
- >
106
- New Project
107
- </ Button >
108
- }
109
- />
91
+ < PageHeader title = "Projects" breadcrumbItems = { items } />
110
92
< ErrorAlert
111
93
title = "Error loading projects"
112
94
message = { projectsError . toString ( ) }
@@ -131,12 +113,14 @@ function Projects() {
131
113
title = "Projects"
132
114
breadcrumbItems = { items }
133
115
actionButton = {
134
- < Button
135
- leftSection = { < IconPlus size = { 18 } /> }
136
- onClick = { newProjectOpen }
137
- >
138
- New Project
139
- </ Button >
116
+ canAddProject && (
117
+ < Button
118
+ leftSection = { < IconPlus size = { 18 } /> }
119
+ onClick = { newProjectOpen }
120
+ >
121
+ New Project
122
+ </ Button >
123
+ )
140
124
}
141
125
/>
142
126
0 commit comments