1- import { Autocomplete , Box , Checkbox , Grid , TextField , useTheme } from '@mui/material' ;
1+ import { Autocomplete , Box , Checkbox , Grid , IconButton , TextField , Typography , useTheme } from '@mui/material' ;
22import PageLayout from '../../../components/PageLayout' ;
33import { usersToAvailabilities , existingMeetingData } from '../../../utils/design-review.utils' ;
44import AvailabilityView from './AvailabilityView' ;
5- import { useAllUsers } from '../../../hooks/users.hooks' ;
5+ import { useAllUsers , useCurrentUser } from '../../../hooks/users.hooks' ;
66import LoadingIndicator from '../../../components/LoadingIndicator' ;
77import ErrorPage from '../../ErrorPage' ;
88import { userToAutocompleteOption } from '../../../utils/teams.utils' ;
99import { useState } from 'react' ;
1010import CheckBoxIcon from '@mui/icons-material/CheckBox' ;
1111import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank' ;
1212import { routes } from '../../../utils/routes' ;
13- import { DesignReview , wbsPipe } from 'shared' ;
13+ import { DesignReview , isAdmin , wbsPipe } from 'shared' ;
14+ import { useDeleteDesignReview } from '../../../hooks/design-reviews.hooks' ;
15+ import { useHistory } from 'react-router-dom' ;
16+ import { useToast } from '../../../hooks/toasts.hooks' ;
17+ import NERModal from '../../../components/NERModal' ;
18+ import DeleteIcon from '@mui/icons-material/Delete' ;
1419
1520interface DesignReviewDetailPageProps {
1621 designReview : DesignReview ;
1722}
1823
1924const DesignReviewDetailPage : React . FC < DesignReviewDetailPageProps > = ( { designReview, designReview : { teamType } } ) => {
2025 const theme = useTheme ( ) ;
26+ const user = useCurrentUser ( ) ;
2127 const { isLoading : allUsersIsLoading , isError : allUsersIsError , error : allUsersError , data : allUsers } = useAllUsers ( ) ;
2228 const [ requiredUsers , setRequiredUsers ] = useState ( [ ] . map ( userToAutocompleteOption ) ) ;
2329 const [ optionalUsers , setOptionalUsers ] = useState ( [ ] . map ( userToAutocompleteOption ) ) ;
30+ const [ showDeleteModal , setShowDeleteModal ] = useState ( false ) ;
31+ const { mutateAsync : deleteDesignReview } = useDeleteDesignReview ( designReview . designReviewId ) ;
32+ const history = useHistory ( ) ;
33+ const toast = useToast ( ) ;
2434 if ( allUsersIsError ) return < ErrorPage message = { allUsersError ?. message } /> ;
2535 if ( allUsersIsLoading || ! allUsers ) return < LoadingIndicator /> ;
2636 const designReviewName = `${ wbsPipe ( designReview . wbsNum ) } - ${ designReview . wbsName } ` ;
2737 const users = allUsers . map ( userToAutocompleteOption ) ;
2838
39+ const handleDelete = ( ) => {
40+ try {
41+ deleteDesignReview ( ) ;
42+ history . push ( routes . CALENDAR ) ;
43+ } catch ( e : unknown ) {
44+ if ( e instanceof Error ) {
45+ toast . error ( e . message , 3000 ) ;
46+ }
47+ }
48+ } ;
49+
50+ const DeleteModal = ( ) => {
51+ return (
52+ < NERModal
53+ open = { showDeleteModal }
54+ onHide = { ( ) => setShowDeleteModal ( false ) }
55+ title = "Warning!"
56+ cancelText = "No"
57+ submitText = "Yes"
58+ onSubmit = { handleDelete }
59+ >
60+ < Typography > Are you sure you want to delete this design review?</ Typography >
61+ </ NERModal >
62+ ) ;
63+ } ;
64+
65+ const hasDeletePerms = user . userId === designReview . userCreated . userId || isAdmin ( user . role ) ;
66+
2967 return (
3068 < PageLayout
69+ headerRight = {
70+ hasDeletePerms && (
71+ < IconButton onClick = { ( ) => setShowDeleteModal ( true ) } >
72+ < DeleteIcon />
73+ </ IconButton >
74+ )
75+ }
3176 title = "Scheduling"
3277 previousPages = { [
3378 {
@@ -36,6 +81,7 @@ const DesignReviewDetailPage: React.FC<DesignReviewDetailPageProps> = ({ designR
3681 }
3782 ] }
3883 >
84+ < DeleteModal />
3985 < Grid container spacing = { 3 } display = { 'flex' } paddingBottom = { 2 } >
4086 < Grid item xs = { 1 } >
4187 < Box
0 commit comments