1
+ import { Form , FormGroup , Switch } from '@patternfly/react-core' ;
2
+
1
3
import { ProductMilestone } from 'pnc-api-types-ts' ;
2
4
5
+ import { productMilestoneCloseRequestEntityAttributes } from 'common/productMilestoneCloseRequestEntityAttributes' ;
6
+
7
+ import { IFieldConfigs , IFieldValues , useForm } from 'hooks/useForm' ;
3
8
import { useServiceContainer } from 'hooks/useServiceContainer' ;
4
9
5
10
import { ActionModal } from 'components/ActionModal/ActionModal' ;
11
+ import { FormInput } from 'components/FormInput/FormInput' ;
12
+ import { TooltipWrapper } from 'components/TooltipWrapper/TooltipWrapper' ;
6
13
7
14
import * as productMilestoneApi from 'services/productMilestoneApi' ;
8
15
16
+ const fieldConfigs = {
17
+ skipBrewPush : {
18
+ value : false ,
19
+ } ,
20
+ } satisfies IFieldConfigs ;
21
+
9
22
export interface IProductMilestoneCloseModalProps {
10
23
isModalOpen : boolean ;
11
24
toggleModal : ( ) => void ;
@@ -15,9 +28,11 @@ export interface IProductMilestoneCloseModalProps {
15
28
export const ProductMilestoneCloseModal = ( { isModalOpen, toggleModal, productMilestone } : IProductMilestoneCloseModalProps ) => {
16
29
const serviceContainerProductMilestoneClose = useServiceContainer ( productMilestoneApi . closeProductMilestone , 0 ) ;
17
30
18
- const confirmModal = ( ) => {
31
+ const { register, handleSubmit, isSubmitDisabled, hasFormChanged } = useForm ( ) ;
32
+
33
+ const confirmModal = ( data : IFieldValues ) => {
19
34
return serviceContainerProductMilestoneClose . run ( {
20
- serviceData : { id : productMilestone . id } ,
35
+ serviceData : { id : productMilestone . id , data : { skipBrewPush : data . skipBrewPush } } ,
21
36
onError : ( ) => console . error ( 'Failed to close Product Milestone.' ) ,
22
37
} ) ;
23
38
} ;
@@ -28,11 +43,37 @@ export const ProductMilestoneCloseModal = ({ isModalOpen, toggleModal, productMi
28
43
actionTitle = "Close Milestone"
29
44
isOpen = { isModalOpen }
30
45
onToggle = { toggleModal }
31
- onSubmit = { confirmModal }
46
+ isSubmitDisabled = { isSubmitDisabled }
47
+ wereSubmitDataChanged = { hasFormChanged }
48
+ onSubmit = { handleSubmit ( confirmModal ) }
32
49
serviceContainer = { serviceContainerProductMilestoneClose }
33
- modalVariant = "medium "
50
+ modalVariant = "large "
34
51
>
35
- Product Milestone < b > { productMilestone . version } </ b > will be closed.
52
+ < Form
53
+ onSubmit = { ( e ) => {
54
+ e . preventDefault ( ) ;
55
+ } }
56
+ >
57
+ < FormGroup
58
+ label = { productMilestoneCloseRequestEntityAttributes . skipBrewPush . title }
59
+ fieldId = { productMilestoneCloseRequestEntityAttributes . skipBrewPush . id }
60
+ labelIcon = { < TooltipWrapper tooltip = { productMilestoneCloseRequestEntityAttributes . skipBrewPush . tooltip } /> }
61
+ >
62
+ < FormInput < boolean >
63
+ { ...register < boolean > ( productMilestoneCloseRequestEntityAttributes . skipBrewPush . id , fieldConfigs . skipBrewPush ) }
64
+ render = { ( { value, ...rest } ) => (
65
+ < Switch
66
+ id = { productMilestoneCloseRequestEntityAttributes . skipBrewPush . id }
67
+ name = { productMilestoneCloseRequestEntityAttributes . skipBrewPush . id }
68
+ label = "Enabled"
69
+ labelOff = "Disabled"
70
+ isChecked = { value }
71
+ { ...rest }
72
+ />
73
+ ) }
74
+ />
75
+ </ FormGroup >
76
+ </ Form >
36
77
</ ActionModal >
37
78
) ;
38
79
} ;
0 commit comments