Skip to content

Commit

Permalink
Add onSuccess reload data
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-slobodian committed May 29, 2024
1 parent b9c1ba6 commit 86ded62
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function App() {
certificates,
currentCertificatDelete,
currentCertificateViewerValue,
handleCertificatesDataReload,
handleProviderChange,
handleCertificatesSearch,
handleCertificateDeleteDialogOpen,
Expand All @@ -47,6 +48,7 @@ export function App() {
providers,
currentProviderId,
fortifyClient,
onSuccess: (providerId) => handleCertificatesDataReload(providerId),
});

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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"),
Expand Down
19 changes: 19 additions & 0 deletions src/hooks/app/useApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -249,6 +267,7 @@ export function useApp() {
certificates,
currentCertificatDelete,
currentCertificateViewerValue,
handleCertificatesDataReload,
handleProviderChange,
handleCertificatesSearch,
handleCertificateDeleteDialogOpen,
Expand Down

0 comments on commit 86ded62

Please sign in to comment.