Skip to content

Commit

Permalink
Merge branch 'donskov/v2' into aslobodian/v2-add-key-usege-for-certif…
Browse files Browse the repository at this point in the history
…icate-creation
  • Loading branch information
aleksandr-slobodian committed Jul 23, 2024
2 parents 374d757 + 04d3582 commit be29863
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 40 deletions.
44 changes: 18 additions & 26 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -23,11 +23,8 @@ export function App() {
providers,
currentProviderId,
certificates,
currentCertificateViewerValue,
handleCertificatesDataReload,
handleProviderChange,
handleCertificateViewerOpen,
handleCertificateViewerClose,
} = useApp();

const {
Expand Down Expand Up @@ -77,6 +74,11 @@ export function App() {
},
});

const {
open: handleCertificateViewerDialogOpen,
dialog: certificateViewerDialog,
} = useCertificateViewerDialog();

return (
<>
<CertificatesSidebar className={styles.sidebar}>
Expand All @@ -94,29 +96,19 @@ export function App() {
onImport={handleCertificateImportDialogOpen}
onCreate={handleCertificateCreateDialogOpen}
></CertificatesTopbar>
{fetching.certificates ? (
<CertificatesList
currentSortName={currentSortName}
currentSortDir={currentSortDir}
onSort={handleSort}
className={styles.certificate_list}
certificates={sortedCertificates}
onDelete={handleCertificateDeleteDialogOpen}
onViewDetails={handleCertificateViewerOpen}
loading={
!fetching.certificates || fetching.certificates === "pending"
}
highlightedText={searchedText}
/>
) : null}

<CertificatesList
currentSortName={currentSortName}
currentSortDir={currentSortDir}
onSort={handleSort}
className={styles.certificate_list}
certificates={sortedCertificates}
onDelete={handleCertificateDeleteDialogOpen}
onViewDetails={handleCertificateViewerDialogOpen}
loading={!fetching.certificates || fetching.certificates === "pending"}
highlightedText={searchedText}
/>
<FetchingStatusOwerlay fetching={fetching} challenge={challenge} />
{currentCertificateViewerValue ? (
<CertificateViewerDialog
certificate={currentCertificateViewerValue}
onClose={handleCertificateViewerClose}
/>
) : null}
{certificateViewerDialog()}
{certificateDeleteDialog()}
{certificateImportDialog()}
{certificateCreateDialog()}
Expand Down
1 change: 1 addition & 0 deletions src/dialogs/certificate-viewer-dialog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./useCertificateViewerDialog";
Original file line number Diff line number Diff line change
@@ -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<CertificateProps>();

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 ? (
<CertificateViewerDialog
certificate={certificateRef.current}
onClose={handleClose}
/>
) : null,
};
}
14 changes: 0 additions & 14 deletions src/hooks/app/useApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export function useApp() {
connectionDetect: "pending",
});

const [currentCertificateViewerValue, setCurrentCertificateViewerValue] =
React.useState<ICertificate | undefined>(undefined);

/**
*
*/
Expand Down Expand Up @@ -207,25 +204,14 @@ export function useApp() {
}
};

const handleCertificateViewerOpen = (certificate: ICertificate) => {
setCurrentCertificateViewerValue(certificate);
};

const handleCertificateViewerClose = () => {
setCurrentCertificateViewerValue(undefined);
};

return {
fortifyClient: fortifyClient.current,
fetching,
challenge,
providers,
currentProviderId,
certificates,
currentCertificateViewerValue,
handleCertificatesDataReload,
handleProviderChange,
handleCertificateViewerOpen,
handleCertificateViewerClose,
};
}

0 comments on commit be29863

Please sign in to comment.