diff --git a/src/app.tsx b/src/app.tsx index d1290a1b..3d4726d8 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -6,7 +6,7 @@ import { CertificatesList } from "./components/certificates-list"; import { CertificatesSidebar } from "./components/certificates-sidebar"; import { CertificatesProvidersList } from "./components/certificates-providers-list"; import { CertificatesTopbar } from "./components/certificates-topbar"; -import { CertificateViewerDialog } from "./components/certificate-viewer-dialog"; +import { useCertificateViewerDialog } from "./dialogs/certificate-viewer-dialog"; import { useCertificateDeleteDialog } from "./dialogs/certificate-delete-dialog"; import { useSortList } from "./hooks/sort-list"; import { useSearchList } from "./hooks/search-list"; @@ -23,11 +23,8 @@ export function App() { providers, currentProviderId, certificates, - currentCertificateViewerValue, handleCertificatesDataReload, handleProviderChange, - handleCertificateViewerOpen, - handleCertificateViewerClose, } = useApp(); const { @@ -77,6 +74,11 @@ export function App() { }, }); + const { + open: handleCertificateViewerDialogOpen, + dialog: certificateViewerDialog, + } = useCertificateViewerDialog(); + return ( <> @@ -94,29 +96,19 @@ export function App() { onImport={handleCertificateImportDialogOpen} onCreate={handleCertificateCreateDialogOpen} > - {fetching.certificates ? ( - - ) : null} - + - {currentCertificateViewerValue ? ( - - ) : null} + {certificateViewerDialog()} {certificateDeleteDialog()} {certificateImportDialog()} {certificateCreateDialog()} diff --git a/src/dialogs/certificate-viewer-dialog/index.ts b/src/dialogs/certificate-viewer-dialog/index.ts new file mode 100644 index 00000000..4bbd08f7 --- /dev/null +++ b/src/dialogs/certificate-viewer-dialog/index.ts @@ -0,0 +1 @@ +export * from "./useCertificateViewerDialog"; diff --git a/src/dialogs/certificate-viewer-dialog/useCertificateViewerDialog.tsx b/src/dialogs/certificate-viewer-dialog/useCertificateViewerDialog.tsx new file mode 100644 index 00000000..98cfc50b --- /dev/null +++ b/src/dialogs/certificate-viewer-dialog/useCertificateViewerDialog.tsx @@ -0,0 +1,32 @@ +import React from "react"; +import { useLockBodyScroll } from "react-use"; +import { CertificateViewerDialog } from "../../components/certificate-viewer-dialog"; +import { CertificateProps } from "../../types"; + +export function useCertificateViewerDialog() { + const [isOpen, setIsOpen] = React.useState(false); + const certificateRef = React.useRef(); + + const handleOpen = (certificaate: CertificateProps) => { + certificateRef.current = certificaate; + setIsOpen(true); + }; + + const handleClose = () => { + certificateRef.current = undefined; + setIsOpen(false); + }; + + useLockBodyScroll(isOpen); + + return { + open: handleOpen, + dialog: () => + isOpen && certificateRef.current ? ( + + ) : null, + }; +} diff --git a/src/hooks/app/useApp.tsx b/src/hooks/app/useApp.tsx index 86426b25..4a667b8b 100644 --- a/src/hooks/app/useApp.tsx +++ b/src/hooks/app/useApp.tsx @@ -23,9 +23,6 @@ export function useApp() { connectionDetect: "pending", }); - const [currentCertificateViewerValue, setCurrentCertificateViewerValue] = - React.useState(undefined); - /** * */ @@ -207,14 +204,6 @@ export function useApp() { } }; - const handleCertificateViewerOpen = (certificate: ICertificate) => { - setCurrentCertificateViewerValue(certificate); - }; - - const handleCertificateViewerClose = () => { - setCurrentCertificateViewerValue(undefined); - }; - return { fortifyClient: fortifyClient.current, fetching, @@ -222,10 +211,7 @@ export function useApp() { providers, currentProviderId, certificates, - currentCertificateViewerValue, handleCertificatesDataReload, handleProviderChange, - handleCertificateViewerOpen, - handleCertificateViewerClose, }; }