@@ -21,45 +21,73 @@ import { UserContext } from '../../../context';
21
21
import CodeActionButton from '../../components/CustomButtons/CodeActionButton' ;
22
22
import { Box } from '@material-ui/core' ;
23
23
24
+ interface RepoData {
25
+ project : string ;
26
+ name : string ;
27
+ proxyURL : string ;
28
+ url : string ;
29
+ users : {
30
+ canAuthorise : string [ ] ;
31
+ canPush : string [ ] ;
32
+ } ;
33
+ }
34
+
35
+ export interface UserContextType {
36
+ user : {
37
+ admin : boolean ;
38
+ } ;
39
+ }
40
+
24
41
const useStyles = makeStyles ( ( theme ) => ( {
25
42
root : {
26
43
'& .MuiTextField-root' : {
27
44
margin : theme . spacing ( 1 ) ,
28
45
width : '100%' ,
29
46
} ,
30
47
} ,
48
+ table : {
49
+ minWidth : 650 ,
50
+ } ,
31
51
} ) ) ;
32
52
33
- export default function RepoDetails ( ) {
53
+ const RepoDetails : React . FC = ( ) => {
34
54
const navigate = useNavigate ( ) ;
35
55
const classes = useStyles ( ) ;
36
- const [ data , setData ] = useState ( [ ] ) ;
56
+ const [ data , setData ] = useState < RepoData | null > ( null ) ;
37
57
const [ , setAuth ] = useState ( true ) ;
38
58
const [ isLoading , setIsLoading ] = useState ( true ) ;
39
59
const [ isError , setIsError ] = useState ( false ) ;
40
- const { user } = useContext ( UserContext ) ;
41
- const { id : repoName } = useParams ( ) ;
60
+ const { user } = useContext < UserContextType > ( UserContext ) ;
61
+ const { id : repoName } = useParams < { id : string } > ( ) ;
42
62
43
63
useEffect ( ( ) => {
44
- getRepo ( setIsLoading , setData , setAuth , setIsError , repoName ) ;
45
- } , [ ] ) ;
64
+ if ( repoName ) {
65
+ getRepo ( setIsLoading , setData , setAuth , setIsError , repoName ) ;
66
+ }
67
+ } , [ repoName ] ) ;
46
68
47
- const removeUser = async ( userToRemove , action ) => {
69
+ const removeUser = async ( userToRemove : string , action : 'authorise' | 'push' ) => {
70
+ if ( ! repoName ) return ;
48
71
await deleteUser ( userToRemove , repoName , action ) ;
49
72
getRepo ( setIsLoading , setData , setAuth , setIsError , repoName ) ;
50
73
} ;
51
74
52
- const removeRepository = async ( name ) => {
75
+ const removeRepository = async ( name : string ) => {
53
76
await deleteRepo ( name ) ;
54
77
navigate ( '/dashboard/repo' , { replace : true } ) ;
55
78
} ;
56
79
57
- const refresh = ( ) => getRepo ( setIsLoading , setData , setAuth , setIsError , repoName ) ;
80
+ const refresh = ( ) => {
81
+ if ( repoName ) {
82
+ getRepo ( setIsLoading , setData , setAuth , setIsError , repoName ) ;
83
+ }
84
+ } ;
58
85
59
86
if ( isLoading ) return < div > Loading...</ div > ;
60
87
if ( isError ) return < div > Something went wrong ...</ div > ;
88
+ if ( ! data ) return < div > No repository data found</ div > ;
61
89
62
- const { project : org , name, proxyURL } = data || { } ;
90
+ const { project : org , name, proxyURL } = data ;
63
91
const cloneURL = `${ proxyURL } /${ org } /${ name } .git` ;
64
92
65
93
return (
@@ -74,7 +102,7 @@ export default function RepoDetails() {
74
102
color = 'secondary'
75
103
onClick = { ( ) => removeRepository ( data . name ) }
76
104
>
77
- < Delete > </ Delete >
105
+ < Delete / >
78
106
</ Button >
79
107
</ div >
80
108
) }
@@ -86,10 +114,11 @@ export default function RepoDetails() {
86
114
< GridContainer >
87
115
< GridItem xs = { 1 } sm = { 1 } md = { 1 } >
88
116
< img
89
- width = { '75px' }
117
+ width = '75px'
90
118
style = { { borderRadius : '5px' } }
91
119
src = { `https://github.com/${ data . project } .png` }
92
- > </ img >
120
+ alt = { `${ data . project } logo` }
121
+ />
93
122
</ GridItem >
94
123
< GridItem xs = { 2 } sm = { 2 } md = { 2 } >
95
124
< FormLabel component = 'legend' > Organization</ FormLabel >
@@ -130,11 +159,11 @@ export default function RepoDetails() {
130
159
< GridContainer >
131
160
< GridItem xs = { 12 } sm = { 12 } md = { 12 } >
132
161
< h3 >
133
- < Visibility > </ Visibility > Reviewers
162
+ < Visibility / > Reviewers
134
163
</ h3 >
135
164
{ user . admin && (
136
165
< div style = { { textAlign : 'right' } } >
137
- < AddUser repoName = { repoName } type = 'authorise' refreshFn = { refresh } > </ AddUser >
166
+ < AddUser repoName = { repoName || '' } type = 'authorise' refreshFn = { refresh } / >
138
167
</ div >
139
168
) }
140
169
< TableContainer component = { Paper } >
@@ -146,73 +175,67 @@ export default function RepoDetails() {
146
175
</ TableRow >
147
176
</ TableHead >
148
177
< TableBody >
149
- { data . users . canAuthorise . map ( ( row ) => {
150
- if ( row )
151
- return (
152
- < TableRow key = { row } >
153
- < TableCell align = 'left' >
154
- < a href = { `/dashboard/admin/user/${ row } ` } > { row } </ a >
155
- </ TableCell >
156
- { user . admin && (
157
- < TableCell align = 'right' component = 'th' scope = 'row' >
158
- < Button
159
- variant = 'contained'
160
- color = 'secondary'
161
- onClick = { ( ) => removeUser ( row , 'authorise' ) }
162
- >
163
- < RemoveCircle > </ RemoveCircle >
164
- </ Button >
165
- </ TableCell >
166
- ) }
167
- </ TableRow >
168
- ) ;
169
- } ) }
178
+ { data . users . canAuthorise . map ( ( row ) => (
179
+ < TableRow key = { row } >
180
+ < TableCell align = 'left' >
181
+ < a href = { `/dashboard/user/${ row } ` } > { row } </ a >
182
+ </ TableCell >
183
+ { user . admin && (
184
+ < TableCell align = 'right' component = 'th' scope = 'row' >
185
+ < Button
186
+ variant = 'contained'
187
+ color = 'secondary'
188
+ onClick = { ( ) => removeUser ( row , 'authorise' ) }
189
+ >
190
+ < RemoveCircle />
191
+ </ Button >
192
+ </ TableCell >
193
+ ) }
194
+ </ TableRow >
195
+ ) ) }
170
196
</ TableBody >
171
197
</ Table >
172
198
</ TableContainer >
173
199
</ GridItem >
174
200
</ GridContainer >
201
+
175
202
< GridContainer >
176
203
< GridItem xs = { 12 } sm = { 12 } md = { 12 } >
177
204
< h3 >
178
- < Code > </ Code > Contributors
205
+ < Code / > Contributors
179
206
</ h3 >
180
207
{ user . admin && (
181
208
< div style = { { textAlign : 'right' } } >
182
- < AddUser repoName = { repoName } type = 'push' refreshFn = { refresh } />
209
+ < AddUser repoName = { repoName || '' } type = 'push' refreshFn = { refresh } />
183
210
</ div >
184
211
) }
185
212
< TableContainer component = { Paper } >
186
- < Table className = { classes . table } aria-label = 'simple table' >
213
+ < Table className = { classes . table } aria-label = 'contributors table' >
187
214
< TableHead >
188
215
< TableRow >
189
216
< TableCell align = 'left' > Username</ TableCell >
190
217
{ user . admin && < TableCell align = 'right' > </ TableCell > }
191
218
</ TableRow >
192
219
</ TableHead >
193
220
< TableBody >
194
- { data . users . canPush . map ( ( row ) => {
195
- if ( row ) {
196
- return (
197
- < TableRow key = { row } >
198
- < TableCell align = 'left' >
199
- < a href = { `/dashboard/admin/user/${ row } ` } > { row } </ a >
200
- </ TableCell >
201
- { user . admin && (
202
- < TableCell align = 'right' component = 'th' scope = 'row' >
203
- < Button
204
- variant = 'contained'
205
- color = 'secondary'
206
- onClick = { ( ) => removeUser ( row , 'push' ) }
207
- >
208
- < RemoveCircle > </ RemoveCircle >
209
- </ Button >
210
- </ TableCell >
211
- ) }
212
- </ TableRow >
213
- ) ;
214
- }
215
- } ) }
221
+ { data . users . canPush . map ( ( row ) => (
222
+ < TableRow key = { row } >
223
+ < TableCell align = 'left' >
224
+ < a href = { `/dashboard/user/${ row } ` } > { row } </ a >
225
+ </ TableCell >
226
+ { user . admin && (
227
+ < TableCell align = 'right' component = 'th' scope = 'row' >
228
+ < Button
229
+ variant = 'contained'
230
+ color = 'secondary'
231
+ onClick = { ( ) => removeUser ( row , 'push' ) }
232
+ >
233
+ < RemoveCircle />
234
+ </ Button >
235
+ </ TableCell >
236
+ ) }
237
+ </ TableRow >
238
+ ) ) }
216
239
</ TableBody >
217
240
</ Table >
218
241
</ TableContainer >
@@ -223,4 +246,6 @@ export default function RepoDetails() {
223
246
</ GridItem >
224
247
</ GridContainer >
225
248
) ;
226
- }
249
+ } ;
250
+
251
+ export default RepoDetails ;
0 commit comments