From 86ded6296eaa1cd03fce03131d811730f98284ad Mon Sep 17 00:00:00 2001 From: alex-slobodian Date: Wed, 29 May 2024 15:12:22 +0300 Subject: [PATCH] Add onSuccess reload data --- src/app.tsx | 2 ++ .../useCertificateCreateDialog.tsx | 5 +++-- src/hooks/app/useApp.tsx | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index 3ae4b1ca..4cba57fe 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -23,6 +23,7 @@ export function App() { certificates, currentCertificatDelete, currentCertificateViewerValue, + handleCertificatesDataReload, handleProviderChange, handleCertificatesSearch, handleCertificateDeleteDialogOpen, @@ -47,6 +48,7 @@ export function App() { providers, currentProviderId, fortifyClient, + onSuccess: (providerId) => handleCertificatesDataReload(providerId), }); return ( diff --git a/src/dialogs/certificate-create-dialog/useCertificateCreateDialog.tsx b/src/dialogs/certificate-create-dialog/useCertificateCreateDialog.tsx index 466de6e0..a8e4579c 100644 --- a/src/dialogs/certificate-create-dialog/useCertificateCreateDialog.tsx +++ b/src/dialogs/certificate-create-dialog/useCertificateCreateDialog.tsx @@ -19,8 +19,9 @@ export function useCertificateCreateDialog(props: { providers: IProviderInfo[]; currentProviderId?: string; fortifyClient: FortifyAPI | null; + onSuccess: (providerId: string) => void; }) { - const { providers, currentProviderId, fortifyClient } = props; + const { providers, currentProviderId, fortifyClient, onSuccess } = props; const { addToast } = useToast(); const { t } = useTranslation(); @@ -55,7 +56,7 @@ export function useCertificateCreateDialog(props: { ); if (newCert) { console.log("newCert => ", newCert); - + 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 4fb66eb1..1b490018 100644 --- a/src/hooks/app/useApp.tsx +++ b/src/hooks/app/useApp.tsx @@ -199,6 +199,24 @@ export function useApp() { start(); }, []); + const handleCertificatesDataReload = async (providerId: string) => { + if (!fortifyClient.current) { + return; + } + + setFetchingValue("certificates", "pending"); + + try { + setCertificates( + await fortifyClient.current.getCertificatesByProviderId(providerId) + ); + setCurrentProviderId(providerId); + setFetchingValue("certificates", "resolved"); + } catch (error) { + setFetchingValue("certificates", "rejected"); + } + }; + const handleCertificatesSearch = (value: string) => { // TODO: add logic console.log(value); @@ -249,6 +267,7 @@ export function useApp() { certificates, currentCertificatDelete, currentCertificateViewerValue, + handleCertificatesDataReload, handleProviderChange, handleCertificatesSearch, handleCertificateDeleteDialogOpen,