44 */
55
66import { WbsNumber , wbsPipe } from 'shared' ;
7- import {
8- Dialog ,
9- DialogActions ,
10- DialogContent ,
11- DialogTitle ,
12- FormControl ,
13- FormLabel ,
14- IconButton ,
15- Typography
16- } from '@mui/material' ;
7+ import { FormControl , FormLabel , Typography } from '@mui/material' ;
178import { useForm } from 'react-hook-form' ;
18- import NERSuccessButton from '../../components/NERSuccessButton' ;
199import * as yup from 'yup' ;
2010import { yupResolver } from '@hookform/resolvers/yup' ;
21- import NERFailButton from '../../components/NERFailButton' ;
2211import ReactHookTextField from '../../components/ReactHookTextField' ;
23- import CloseIcon from '@mui/icons-material/Close' ;
2412import { DeleteProjectInputs } from './DeleteProject' ;
13+ import NERFormModal from '../../components/NERFormModal' ;
2514
2615interface DeleteProjectViewProps {
2716 project : WbsNumber ;
@@ -34,12 +23,16 @@ const DeleteProjectView: React.FC<DeleteProjectViewProps> = ({ project, modalSho
3423 const projectWbsNumTester = ( wbsNum : string | undefined ) => wbsNum !== undefined && wbsNum === wbsPipe ( project ) ;
3524
3625 const schema = yup . object ( ) . shape ( {
37- wbsNum : yup . string ( ) . required ( ) . test ( 'project-wbs-test' , 'Project WBS does not match' , projectWbsNumTester )
26+ wbsNum : yup
27+ . string ( )
28+ . required ( 'Project WBS is required' )
29+ . test ( 'project-wbs-test' , 'Project WBS does not match' , projectWbsNumTester )
3830 } ) ;
3931
4032 const {
4133 handleSubmit,
4234 control,
35+ reset,
4336 formState : { errors, isValid }
4437 } = useForm ( {
4538 resolver : yupResolver ( schema ) ,
@@ -54,68 +47,34 @@ const DeleteProjectView: React.FC<DeleteProjectViewProps> = ({ project, modalSho
5447 } ;
5548
5649 return (
57- < Dialog open = { modalShow } onClose = { onHide } >
58- < DialogTitle
59- className = "font-weight-bold"
60- sx = { {
61- '&.MuiDialogTitle-root' : {
62- padding : '1rem 1.5rem 0'
63- }
64- } }
65- > { `Delete Project #${ wbsPipe ( project ) } ` } </ DialogTitle >
66- < IconButton
67- aria-label = "close"
68- onClick = { onHide }
69- sx = { {
70- position : 'absolute' ,
71- right : 8 ,
72- top : 8 ,
73- color : ( theme ) => theme . palette . grey [ 500 ]
74- } }
75- >
76- < CloseIcon />
77- </ IconButton >
78- < DialogContent
79- sx = { {
80- '&.MuiDialogContent-root' : {
81- padding : '1rem 1.5rem'
82- }
83- } }
84- >
85- < Typography sx = { { marginBottom : '1rem' } } > Are you sure you want to delete Project #{ wbsPipe ( project ) } ?</ Typography >
86- < Typography sx = { { fontWeight : 'bold' } } > This action cannot be undone!</ Typography >
87- < form
88- id = "delete-project-form"
89- onSubmit = { ( e ) => {
90- e . preventDefault ( ) ;
91- e . stopPropagation ( ) ;
92- handleSubmit ( onSubmitWrapper ) ( e ) ;
93- } }
94- >
95- < FormControl >
96- < FormLabel sx = { { marginTop : '1rem' , marginBottom : '1rem' } } >
97- To confirm deletion, please type in the WBS number of this Project.
98- </ FormLabel >
99- < ReactHookTextField
100- control = { control }
101- name = "wbsNum"
102- errorMessage = { errors . wbsNum }
103- placeholder = "Enter Project WBS here"
104- sx = { { width : 1 } }
105- type = "string"
106- />
107- </ FormControl >
108- </ form >
109- </ DialogContent >
110- < DialogActions >
111- < NERSuccessButton variant = "contained" sx = { { mx : 1 } } onClick = { onHide } >
112- Cancel
113- </ NERSuccessButton >
114- < NERFailButton variant = "contained" type = "submit" form = "delete-project-form" sx = { { mx : 1 } } disabled = { ! isValid } >
115- Delete
116- </ NERFailButton >
117- </ DialogActions >
118- </ Dialog >
50+ < NERFormModal
51+ open = { modalShow }
52+ onHide = { onHide }
53+ title = { `Delete Project #${ wbsPipe ( project ) } ` }
54+ reset = { ( ) => reset ( { wbsNum : '' } ) }
55+ submitText = "Delete"
56+ handleUseFormSubmit = { handleSubmit }
57+ onFormSubmit = { onSubmitWrapper }
58+ formId = "delete-wp-form"
59+ disabled = { ! isValid }
60+ showCloseButton
61+ >
62+ < Typography sx = { { marginBottom : '1rem' } } > Are you sure you want to delete Project #{ wbsPipe ( project ) } ?</ Typography >
63+ < Typography sx = { { fontWeight : 'bold' } } > This action cannot be undone!</ Typography >
64+ < FormControl >
65+ < FormLabel sx = { { marginTop : '1rem' , marginBottom : '1rem' } } >
66+ To confirm deletion, please type in the WBS number of this Project.
67+ </ FormLabel >
68+ < ReactHookTextField
69+ control = { control }
70+ name = "wbsNum"
71+ errorMessage = { errors . wbsNum }
72+ placeholder = "Enter Project WBS here"
73+ sx = { { width : 1 } }
74+ type = "string"
75+ />
76+ </ FormControl >
77+ </ NERFormModal >
11978 ) ;
12079} ;
12180
0 commit comments