@@ -5,14 +5,18 @@ import { isAdmin } from 'shared/src/permission-utils';
55import { useCurrentUser } from '../../../hooks/users.hooks' ;
66import LoadingIndicator from '../../../components/LoadingIndicator' ;
77import ErrorPage from '../../ErrorPage' ;
8- import { useAllWorkPackageTemplates , useDeleteWorkPackageTemplate } from '../../../hooks/work-packages.hooks' ;
8+ import { WorkPackageTemplate } from 'shared' ;
9+ import { routes } from '../../../utils/routes' ;
910import { Delete } from '@mui/icons-material' ;
11+ import { useAllWorkPackageTemplates , useDeleteWorkPackageTemplate } from '../../../hooks/work-packages.hooks' ;
12+ import { useHistory } from 'react-router-dom' ;
1013import { useState } from 'react' ;
1114import NERModal from '../../../components/NERModal' ;
12- import { WorkPackageTemplate } from 'shared' ;
1315
1416const WorkPackageTemplateTable = ( ) => {
1517 const currentUser = useCurrentUser ( ) ;
18+ const history = useHistory ( ) ;
19+
1620 const {
1721 data : workPackageTemplates ,
1822 isLoading : workPackageTemplatesIsLoading ,
@@ -28,26 +32,37 @@ const WorkPackageTemplateTable = () => {
2832 if ( workPackageTemplatesIsError ) return < ErrorPage message = { workPackageTemplatesError . message } /> ;
2933
3034 const workPackageTemplateRows = workPackageTemplates . map ( ( workPackageTemplate ) => (
31- < TableRow >
35+ < TableRow
36+ key = { workPackageTemplate . workPackageTemplateId }
37+ onClick = { ( ) => history . push ( `${ routes . WORK_PACKAGE_TEMPLATE_EDIT } ?id=${ workPackageTemplate . workPackageTemplateId } ` ) }
38+ sx = { { cursor : 'pointer' } }
39+ >
3240 < TableCell align = "left" sx = { { border : '2px solid black' } } >
3341 { workPackageTemplate . templateName }
3442 </ TableCell >
3543 < TableCell sx = { { border : '2px solid black' , verticalAlign : 'middle' } } > { workPackageTemplate . templateNotes } </ TableCell >
3644 < TableCell align = "center" sx = { { border : '2px solid black' , verticalAlign : 'middle' } } >
37- < IconButton onClick = { ( ) => setTemplateToDelete ( workPackageTemplate ) } >
45+ < IconButton
46+ onClick = { ( event ) => {
47+ event . stopPropagation ( ) ;
48+ setTemplateToDelete ( workPackageTemplate ) ;
49+ } }
50+ >
3851 < Delete />
3952 </ IconButton >
4053 </ TableCell >
4154 </ TableRow >
4255 ) ) ;
4356
4457 return (
45- < >
46- < Box >
47- < AdminToolTable columns = { [ { name : 'Name' } , { name : 'Description' } , { name : '' } ] } rows = { workPackageTemplateRows } />
48- < Box sx = { { display : 'flex' , justifyContent : 'right' , marginTop : '10px' } } >
49- { isAdmin ( currentUser . role ) && < NERButton variant = "contained" > New Work Package Template</ NERButton > }
50- </ Box >
58+ < Box >
59+ < AdminToolTable columns = { [ { name : 'Name' } , { name : 'Description' } ] } rows = { workPackageTemplateRows } />
60+ < Box sx = { { display : 'flex' , justifyContent : 'right' , marginTop : '10px' } } >
61+ { isAdmin ( currentUser . role ) && (
62+ < NERButton variant = "contained" size = "small" onClick = { ( ) => history . push ( routes . WORK_PACKAGE_TEMPLATE_NEW ) } >
63+ New Work Package Template
64+ </ NERButton >
65+ ) }
5166 </ Box >
5267 < NERModal
5368 open = { ! ! templateToDelete }
@@ -68,7 +83,7 @@ const WorkPackageTemplateTable = () => {
6883 </ Typography >
6984 < Typography fontWeight = "bold" > This action cannot be undone!</ Typography >
7085 </ NERModal >
71- </ >
86+ </ Box >
7287 ) ;
7388} ;
7489
0 commit comments