Skip to content

Commit 1b61176

Browse files
committed
Basis for create certificate dialog
1 parent 374447c commit 1b61176

File tree

1 file changed

+64
-29
lines changed

1 file changed

+64
-29
lines changed

frontend/src/modals/CertificateCreateModal.tsx

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { useState } from "react";
2+
13
import {
24
Button,
5+
ButtonGroup,
36
FormControl,
47
FormErrorMessage,
58
FormLabel,
@@ -29,9 +32,15 @@ function CertificateCreateModal({
2932
isOpen,
3033
onClose,
3134
}: CertificateCreateModalProps) {
35+
const [certType, setCertType] = useState("");
3236
const toast = useToast();
3337
const { mutate: setCertificate } = useSetCertificate();
3438

39+
const onModalClose = () => {
40+
onClose();
41+
setCertType("");
42+
};
43+
3544
const onSubmit = async (
3645
payload: Certificate,
3746
{ setErrors, setSubmitting }: any,
@@ -60,13 +69,13 @@ function CertificateCreateModal({
6069
showErr(err.message);
6170
}
6271
},
63-
onSuccess: () => onClose(),
72+
onSuccess: () => onModalClose(),
6473
onSettled: () => setSubmitting(false),
6574
});
6675
};
6776

6877
return (
69-
<Modal isOpen={isOpen} onClose={onClose} closeOnOverlayClick={false}>
78+
<Modal isOpen={isOpen} onClose={onModalClose} closeOnOverlayClick={false}>
7079
<ModalOverlay />
7180
<ModalContent>
7281
<Formik
@@ -87,35 +96,61 @@ function CertificateCreateModal({
8796
</ModalHeader>
8897
<ModalCloseButton />
8998
<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}
113146
</ModalBody>
114147
<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}>
119154
{intl.formatMessage({ id: "form.cancel" })}
120155
</Button>
121156
</ModalFooter>

0 commit comments

Comments
 (0)