From 4be1db6eb96acfc006db57feb6f1c4a5a6c9e1a2 Mon Sep 17 00:00:00 2001 From: alex-slobodian Date: Thu, 19 Sep 2024 13:35:42 +0300 Subject: [PATCH] Closes the dialogs belonging to the extracted token --- src/app.tsx | 23 +++++++++++++++++-- .../useCertificateDeleteDialog.tsx | 1 + .../useCertificateViewerDialog.tsx | 1 + .../useProviderInfoDialog.tsx | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index ab85c544..23be4448 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,5 +1,6 @@ import "./global.scss"; import "./i18n"; +import { useUpdateEffect } from "react-use"; import { useApp } from "./hooks/app"; import { FetchingStatusOwerlay } from "./components/fetching-status-owerlay"; import { CertificatesList } from "./components/certificates-list"; @@ -41,6 +42,7 @@ export function App() { const { open: handleCertificateDeleteDialogOpen, + close: handleCertificateDeleteDialogClose, dialog: certificateDeleteDialog, } = useCertificateDeleteDialog({ fortifyClient, @@ -82,11 +84,28 @@ export function App() { const { open: handleCertificateViewerDialogOpen, + close: handleCertificateViewerDialogClose, dialog: certificateViewerDialog, } = useCertificateViewerDialog(); - const { open: handleProviderInfoDialogOpen, dialog: providerInfoDialog } = - useProviderInfoDialog(); + const { + open: handleProviderInfoDialogOpen, + close: handleProviderInfoDialogClose, + dialog: providerInfoDialog, + } = useProviderInfoDialog(); + + // Closes the dialogs belonging to the extracted token + useUpdateEffect(() => { + if (providers?.length && currentProviderId === undefined) { + return; + } + const curProvider = providers.find(({ id }) => currentProviderId === id); + if (!curProvider) { + handleProviderInfoDialogClose(); + handleCertificateViewerDialogClose(); + handleCertificateDeleteDialogClose(); + } + }, [providers, currentProviderId]); return ( <> diff --git a/src/dialogs/certificate-delete-dialog/useCertificateDeleteDialog.tsx b/src/dialogs/certificate-delete-dialog/useCertificateDeleteDialog.tsx index dbda982e..c703e2fa 100644 --- a/src/dialogs/certificate-delete-dialog/useCertificateDeleteDialog.tsx +++ b/src/dialogs/certificate-delete-dialog/useCertificateDeleteDialog.tsx @@ -71,6 +71,7 @@ export function useCertificateDeleteDialog( return { open: handleOpen, + close: handleClose, dialog: () => fortifyClient && isOpen && openParamsRef.current ? ( isOpen && certificateRef.current ? ( isOpen && providerRef.current ? (