@@ -8,12 +8,9 @@ import { Project, isGuest, isAdmin, isLeadership } from 'shared';
88import { projectWbsPipe , wbsPipe } from '../../../utils/pipes' ;
99import ProjectDetails from './ProjectDetails' ;
1010import { routes } from '../../../utils/routes' ;
11- import { NERButton } from '../../../components/NERButton' ;
12- import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown' ;
1311import EditIcon from '@mui/icons-material/Edit' ;
14- import ListItemIcon from '@mui/material/ListItemIcon' ;
1512import SyncAltIcon from '@mui/icons-material/SyncAlt' ;
16- import { Box , Menu , MenuItem } from '@mui/material' ;
13+ import { Box } from '@mui/material' ;
1714import { useState } from 'react' ;
1815import { useSetProjectTeam } from '../../../hooks/projects.hooks' ;
1916import { useToast } from '../../../hooks/toasts.hooks' ;
@@ -35,6 +32,7 @@ import SavingsIcon from '@mui/icons-material/Savings';
3532import { TaskList } from './TaskList/v2' ;
3633import { useGetMaterialsForWbsElement } from '../../../hooks/bom.hooks' ;
3734import ChangeRequestTab from '../../../components/ChangeRequestTab' ;
35+ import ActionsMenu from '../../../components/ActionsMenu' ;
3836
3937interface ProjectViewContainerProps {
4038 project : Project ;
@@ -58,9 +56,8 @@ const ProjectViewContainer: React.FC<ProjectViewContainerProps> = ({ project, en
5856 const handleClickDelete = ( ) => {
5957 setDeleteModalShow ( true ) ;
6058 } ;
61- const [ anchorEl , setAnchorEl ] = useState < null | HTMLElement > ( null ) ;
59+ const [ _ , setAnchorEl ] = useState < null | HTMLElement > ( null ) ;
6260 const [ tab , setTab ] = useState ( 0 ) ;
63- const dropdownOpen = Boolean ( anchorEl ) ;
6461
6562 if ( isError ) return < ErrorPage message = { error . message } /> ;
6663 if ( materialsIsError ) return < ErrorPage message = { materialsError . message } /> ;
@@ -71,10 +68,6 @@ const ProjectViewContainer: React.FC<ProjectViewContainerProps> = ({ project, en
7168 const { teamAsHeadId } = user ;
7269 const projectIsFavorited = favoriteProjects . map ( ( favoriteProject ) => favoriteProject . id ) . includes ( project . id ) ;
7370
74- const handleClick = ( event : React . MouseEvent < HTMLElement > ) => {
75- setAnchorEl ( event . currentTarget ) ;
76- } ;
77-
7871 const handleDropdownClose = ( ) => {
7972 setAnchorEl ( null ) ;
8073 } ;
@@ -96,124 +89,73 @@ const ProjectViewContainer: React.FC<ProjectViewContainerProps> = ({ project, en
9689 }
9790 } ;
9891
99- const EditButton = ( ) => (
100- < MenuItem onClick = { handleClickEdit } disabled = { isGuest ( user . role ) } >
101- < ListItemIcon >
102- < EditIcon fontSize = "small" />
103- </ ListItemIcon >
104- Edit
105- </ MenuItem >
106- ) ;
107-
108- const CreateChangeRequestButton = ( ) => (
109- < MenuItem
110- component = { Link }
111- to = { routes . CHANGE_REQUESTS_NEW_WITH_WBS + wbsPipe ( project . wbsNum ) }
112- disabled = { isGuest ( user . role ) }
113- onClick = { handleDropdownClose }
114- >
115- < ListItemIcon >
116- < SyncAltIcon fontSize = "small" />
117- </ ListItemIcon >
118- Request Change
119- </ MenuItem >
120- ) ;
121-
122- const SuggestBudgetIncreaseButton = ( ) => {
123- const budgetIncrease = materials . reduce ( addMaterialCosts , 0 ) - project . budget ;
124- return (
125- < MenuItem
126- onClick = { ( ) =>
127- history . push (
128- `${ routes . CHANGE_REQUESTS_NEW } ?wbsNum=${ projectWbsPipe ( project . wbsNum ) } &budgetChange=${ budgetIncrease } `
129- )
130- }
131- disabled = { ! isLeadership ( user . role ) || budgetIncrease <= 0 }
132- >
133- < ListItemIcon >
134- < SavingsIcon fontSize = "small" />
135- </ ListItemIcon >
136- Suggest Budget Increase
137- </ MenuItem >
138- ) ;
139- } ;
140-
141- const AssignToMyTeamButton = ( ) => {
142- const assignToTeamText = project . teams . map ( ( team ) => team . teamId ) . includes ( teamAsHeadId ! )
143- ? 'Unassign from My Team'
144- : 'Assign to My Team' ;
145-
146- return (
147- < MenuItem onClick = { handleAssignToMyTeam } >
148- < ListItemIcon >
149- < GroupIcon fontSize = "small" />
150- </ ListItemIcon >
151- { assignToTeamText }
152- </ MenuItem >
153- ) ;
154- } ;
155-
156- const buildURLForCreateWorkPackage = ( ) => {
157- return `${ routes . WORK_PACKAGE_NEW } ?wbs=${ projectWbsPipe ( project . wbsNum ) } &crId=null` ;
158- } ;
159- const CreateWorkPackageButton = ( ) => {
160- return (
161- < MenuItem onClick = { ( ) => history . push ( buildURLForCreateWorkPackage ( ) ) } disabled = { isGuest ( user . role ) } >
162- < ListItemIcon >
163- < ContentPasteIcon fontSize = "small" />
164- </ ListItemIcon >
165- Create New Work Package
166- </ MenuItem >
167- ) ;
168- } ;
169-
170- const DeleteButton = ( ) => (
171- < MenuItem onClick = { handleClickDelete } disabled = { ! isAdmin ( user . role ) } >
172- < ListItemIcon >
173- < DeleteIcon fontSize = "small" />
174- </ ListItemIcon >
175- Delete
176- </ MenuItem >
177- ) ;
92+ const budgetIncrease = materials . reduce ( addMaterialCosts , 0 ) - project . budget ;
93+ const assignToTeamText = project . teams . map ( ( team ) => team . teamId ) . includes ( teamAsHeadId ! )
94+ ? 'Unassign from My Team'
95+ : 'Assign to My Team' ;
17896
17997 const projectActionsDropdown = (
180- < Box ml = { 2 } >
181- < NERButton
182- endIcon = { < ArrowDropDownIcon style = { { fontSize : 28 } } /> }
183- variant = "contained"
184- id = "project-actions-dropdown"
185- onClick = { handleClick }
186- disabled = { isGuest ( user . role ) }
187- >
188- Actions
189- </ NERButton >
190- < Menu
191- open = { dropdownOpen }
192- anchorEl = { anchorEl }
193- onClose = { handleDropdownClose }
194- anchorOrigin = { {
195- vertical : 'bottom' ,
196- horizontal : 'right'
197- } }
198- transformOrigin = { {
199- vertical : 'top' ,
200- horizontal : 'right'
201- } }
202- >
203- < EditButton />
204- < CreateChangeRequestButton />
205- < SuggestBudgetIncreaseButton />
206- { teamAsHeadId && < AssignToMyTeamButton /> }
207- < CreateWorkPackageButton />
208- < DeleteButton />
209- </ Menu >
210- </ Box >
98+ < div style = { { marginTop : '10px' } } >
99+ < ActionsMenu
100+ buttons = { [
101+ {
102+ title : 'Edit' ,
103+ onClick : handleClickEdit ,
104+ disabled : isGuest ( user . role ) ,
105+ icon : < EditIcon fontSize = "small" />
106+ } ,
107+ {
108+ title : 'Request Change' ,
109+ onClick : handleDropdownClose ,
110+ disabled : isGuest ( user . role ) ,
111+ icon : < SyncAltIcon fontSize = "small" /> ,
112+ component : Link ,
113+ to : routes . CHANGE_REQUESTS_NEW_WITH_WBS + wbsPipe ( project . wbsNum )
114+ } ,
115+ {
116+ title : 'Suggest Budget Increase' ,
117+ onClick : ( ) => {
118+ history . push (
119+ `${ routes . CHANGE_REQUESTS_NEW } ?wbsNum=${ projectWbsPipe ( project . wbsNum ) } &budgetChange=${ budgetIncrease } `
120+ ) ;
121+ } ,
122+ disabled : ! isLeadership ( user . role ) || budgetIncrease <= 0 ,
123+ icon : < SavingsIcon fontSize = "small" />
124+ } ,
125+ ...( teamAsHeadId
126+ ? [
127+ {
128+ title : assignToTeamText ,
129+ onClick : handleAssignToMyTeam ,
130+ disabled : false ,
131+ icon : < GroupIcon fontSize = "small" />
132+ }
133+ ]
134+ : [ ] ) ,
135+ {
136+ title : 'Create New Work Package' ,
137+ onClick : ( ) => {
138+ history . push ( `${ routes . WORK_PACKAGE_NEW } ?wbs=${ projectWbsPipe ( project . wbsNum ) } &crId=null` ) ;
139+ } ,
140+ disabled : isGuest ( user . role ) ,
141+ icon : < ContentPasteIcon fontSize = "small" />
142+ } ,
143+ {
144+ title : 'Delete' ,
145+ onClick : handleClickDelete ,
146+ disabled : ! isAdmin ( user . role ) ,
147+ icon : < DeleteIcon fontSize = "small" /> ,
148+ dividerTop : true
149+ }
150+ ] }
151+ />
152+ </ div >
211153 ) ;
212154
213155 const pageTitle = `${ wbsPipe ( project . wbsNum ) } - ${ project . name } ` ;
214156
215157 const headerRight = (
216- < Box display = "flex" justifyContent = "flex-end" >
158+ < Box display = "flex" justifyContent = "flex-end" alignItems = "Center" >
217159 < FavoriteProjectButton wbsNum = { project . wbsNum } projectIsFavorited = { projectIsFavorited } />
218160 { projectActionsDropdown }
219161 </ Box >
0 commit comments