From ba3030083b7ffd242494e4077bba9baa386c5203 Mon Sep 17 00:00:00 2001 From: alex-slobodian Date: Thu, 6 Jun 2024 17:16:07 +0300 Subject: [PATCH] Fixed useCertificateCreateDialog --- src/app.tsx | 9 ++---- .../useCertificateCreateDialog.tsx | 23 +++++---------- src/hooks/app/useApp.tsx | 29 ------------------- 3 files changed, 10 insertions(+), 51 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index 833587b8..ea345cc7 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -24,7 +24,6 @@ export function App() { currentCertificatDelete, currentCertificateViewerValue, handleCertificatesDataReload, - handleAddCSRToList, handleProviderChange, handleCertificatesSearch, handleCertificateDeleteDialogOpen, @@ -49,12 +48,8 @@ export function App() { providers, currentProviderId, fortifyClient, - onSuccess: (type, providerId, certRaw, label) => { - if (type === "x509") { - handleCertificatesDataReload(providerId); - } else if (type === "csr") { - handleAddCSRToList(providerId, certRaw, label); - } + onSuccess: (providerId) => { + handleCertificatesDataReload(providerId); }, }); diff --git a/src/dialogs/certificate-create-dialog/useCertificateCreateDialog.tsx b/src/dialogs/certificate-create-dialog/useCertificateCreateDialog.tsx index 32885a4b..de6d7d4c 100644 --- a/src/dialogs/certificate-create-dialog/useCertificateCreateDialog.tsx +++ b/src/dialogs/certificate-create-dialog/useCertificateCreateDialog.tsx @@ -18,13 +18,8 @@ import { CertificateType } from "../../types"; export function useCertificateCreateDialog(props: { providers: IProviderInfo[]; currentProviderId?: string; - fortifyClient: FortifyAPI | null; - onSuccess: ( - type: CertificateType, - providerId: string, - certRaw: ArrayBuffer, - label: string - ) => void; + fortifyClient?: FortifyAPI | null; + onSuccess: (providerId: string) => void; }) { const { providers, currentProviderId, fortifyClient, onSuccess } = props; const { addToast } = useToast(); @@ -38,6 +33,9 @@ export function useCertificateCreateDialog(props: { const dialogType = useRef("x509"); const handleCertificateCreate = async (data: CertificateCreateDataProps) => { + if (!fortifyClient) { + return; + } if (!localCurrentProviderId?.current) { localCurrentProviderId.current = currentProviderId; } @@ -47,7 +45,7 @@ export function useCertificateCreateDialog(props: { try { let newCert; if (type === "x509") { - newCert = await fortifyClient?.createX509( + newCert = await fortifyClient.createX509( localCurrentProviderId.current as string, { subjectName: subject, @@ -56,7 +54,7 @@ export function useCertificateCreateDialog(props: { } ); } else if (type === "csr") { - newCert = await fortifyClient?.createPKCS10( + newCert = await fortifyClient.createPKCS10( localCurrentProviderId.current as string, { subjectName: subject, @@ -66,12 +64,7 @@ export function useCertificateCreateDialog(props: { ); } if (newCert) { - onSuccess( - type, - localCurrentProviderId.current as string, - newCert.der, - data.subject.CN - ); + onSuccess(localCurrentProviderId.current as string); setIsOpen(false); addToast({ message: t("certificates.dialog.create.success-message"), diff --git a/src/hooks/app/useApp.tsx b/src/hooks/app/useApp.tsx index ff42f0f0..1b490018 100644 --- a/src/hooks/app/useApp.tsx +++ b/src/hooks/app/useApp.tsx @@ -217,34 +217,6 @@ export function useApp() { } }; - const handleAddCSRToList = ( - providerId: string, - certRaw: ArrayBuffer, - label: string - ) => { - setCurrentProviderId(providerId); - - const today = new Date(); - const nextYear = new Date( - today.getFullYear() + 1, - today.getMonth(), - today.getDate() - ); - - setCertificates([ - ...certificates, - { - id: today.getTime(), - notAfter: nextYear, - notBefore: today, - raw: certRaw, - serialNumber: "01", - type: "csr" as unknown as "x509", - label, - } as unknown as ICertificate, - ]); - }; - const handleCertificatesSearch = (value: string) => { // TODO: add logic console.log(value); @@ -296,7 +268,6 @@ export function useApp() { currentCertificatDelete, currentCertificateViewerValue, handleCertificatesDataReload, - handleAddCSRToList, handleProviderChange, handleCertificatesSearch, handleCertificateDeleteDialogOpen,