1
+ import { useState } from "react" ;
2
+
1
3
import {
2
4
Button ,
5
+ ButtonGroup ,
3
6
FormControl ,
4
7
FormErrorMessage ,
5
8
FormLabel ,
@@ -29,9 +32,15 @@ function CertificateCreateModal({
29
32
isOpen,
30
33
onClose,
31
34
} : CertificateCreateModalProps ) {
35
+ const [ certType , setCertType ] = useState ( "" ) ;
32
36
const toast = useToast ( ) ;
33
37
const { mutate : setCertificate } = useSetCertificate ( ) ;
34
38
39
+ const onModalClose = ( ) => {
40
+ onClose ( ) ;
41
+ setCertType ( "" ) ;
42
+ } ;
43
+
35
44
const onSubmit = async (
36
45
payload : Certificate ,
37
46
{ setErrors, setSubmitting } : any ,
@@ -60,13 +69,13 @@ function CertificateCreateModal({
60
69
showErr ( err . message ) ;
61
70
}
62
71
} ,
63
- onSuccess : ( ) => onClose ( ) ,
72
+ onSuccess : ( ) => onModalClose ( ) ,
64
73
onSettled : ( ) => setSubmitting ( false ) ,
65
74
} ) ;
66
75
} ;
67
76
68
77
return (
69
- < Modal isOpen = { isOpen } onClose = { onClose } closeOnOverlayClick = { false } >
78
+ < Modal isOpen = { isOpen } onClose = { onModalClose } closeOnOverlayClick = { false } >
70
79
< ModalOverlay />
71
80
< ModalContent >
72
81
< Formik
@@ -87,35 +96,61 @@ function CertificateCreateModal({
87
96
</ ModalHeader >
88
97
< ModalCloseButton />
89
98
< ModalBody >
90
- < Stack spacing = { 4 } >
91
- < Field name = "name" validate = { validateString ( 1 , 100 ) } >
92
- { ( { field, form } : any ) => (
93
- < FormControl
94
- isRequired
95
- isInvalid = { form . errors . name && form . touched . name } >
96
- < FormLabel htmlFor = "name" >
97
- { intl . formatMessage ( {
98
- id : "name" ,
99
- } ) }
100
- </ FormLabel >
101
- < Input
102
- { ...field }
103
- id = "name"
104
- placeholder = { intl . formatMessage ( {
105
- id : "name" ,
106
- } ) }
107
- />
108
- < FormErrorMessage > { form . errors . name } </ FormErrorMessage >
109
- </ FormControl >
110
- ) }
111
- </ Field >
112
- </ Stack >
99
+ { certType === "" ? (
100
+ < FormControl >
101
+ < FormLabel htmlFor = "type" >
102
+ Select the Certificate Validation method
103
+ </ FormLabel >
104
+ < ButtonGroup style = { { width : "100%" } } >
105
+ < Button
106
+ onClick = { ( ) => setCertType ( "http" ) }
107
+ style = { { width : "50%" } } >
108
+ HTTP
109
+ </ Button >
110
+ < Button
111
+ onClick = { ( ) => setCertType ( "dns" ) }
112
+ style = { { width : "50%" } } >
113
+ DNS
114
+ </ Button >
115
+ </ ButtonGroup >
116
+ </ FormControl >
117
+ ) : null }
118
+
119
+ { certType !== "" ? (
120
+ < Stack spacing = { 4 } >
121
+ < Field name = "name" validate = { validateString ( 1 , 100 ) } >
122
+ { ( { field, form } : any ) => (
123
+ < FormControl
124
+ isRequired
125
+ isInvalid = { form . errors . name && form . touched . name } >
126
+ < FormLabel htmlFor = "name" >
127
+ { intl . formatMessage ( {
128
+ id : "name" ,
129
+ } ) }
130
+ </ FormLabel >
131
+ < Input
132
+ { ...field }
133
+ id = "name"
134
+ placeholder = { intl . formatMessage ( {
135
+ id : "name" ,
136
+ } ) }
137
+ />
138
+ < FormErrorMessage >
139
+ { form . errors . name }
140
+ </ FormErrorMessage >
141
+ </ FormControl >
142
+ ) }
143
+ </ Field >
144
+ </ Stack >
145
+ ) : null }
113
146
</ ModalBody >
114
147
< ModalFooter >
115
- < PrettyButton mr = { 3 } isLoading = { isSubmitting } >
116
- { intl . formatMessage ( { id : "form.save" } ) }
117
- </ PrettyButton >
118
- < Button onClick = { onClose } isLoading = { isSubmitting } >
148
+ { certType !== "" ? (
149
+ < PrettyButton mr = { 3 } isLoading = { isSubmitting } >
150
+ { intl . formatMessage ( { id : "form.save" } ) }
151
+ </ PrettyButton >
152
+ ) : null }
153
+ < Button onClick = { onModalClose } isLoading = { isSubmitting } >
119
154
{ intl . formatMessage ( { id : "form.cancel" } ) }
120
155
</ Button >
121
156
</ ModalFooter >
0 commit comments