import { Button, FormControl, FormErrorMessage, FormLabel, Input, Modal, ModalOverlay, ModalContent, ModalHeader, ModalCloseButton, ModalBody, ModalFooter, Stack, useToast, } from "@chakra-ui/react"; import { Certificate } from "api/npm"; import { PrettyButton } from "components"; import { Formik, Form, Field } from "formik"; import { useSetCertificate } from "hooks"; import { intl } from "locale"; import { validateString } from "modules/Validations"; interface CertificateCreateModalProps { isOpen: boolean; onClose: () => void; } function CertificateCreateModal({ isOpen, onClose, }: CertificateCreateModalProps) { const toast = useToast(); const { mutate: setCertificate } = useSetCertificate(); const onSubmit = async ( payload: Certificate, { setErrors, setSubmitting }: any, ) => { const showErr = (msg: string) => { toast({ description: intl.formatMessage({ id: `error.${msg}`, }), status: "error", position: "top", duration: 3000, isClosable: true, }); }; setCertificate(payload, { onError: (err: any) => { if (err.message === "ca-bundle-does-not-exist") { setErrors({ caBundle: intl.formatMessage({ id: `error.${err.message}`, }), }); } else { showErr(err.message); } }, onSuccess: () => onClose(), onSettled: () => setSubmitting(false), }); }; return ( {({ isSubmitting }) => (
{intl.formatMessage({ id: "certificate.create" })} {({ field, form }: any) => ( {intl.formatMessage({ id: "name", })} {form.errors.name} )} {intl.formatMessage({ id: "form.save" })} )}
); } export { CertificateCreateModal };