From da35ec90bcde4fae9f8b4f59d75e437c5001959d Mon Sep 17 00:00:00 2001 From: Daniel Hougaard Date: Tue, 11 Feb 2025 05:07:43 +0400 Subject: [PATCH] fix(native-integrations): delete integrations from details page --- .../IntegrationsDetailsByIDPage.tsx | 100 +++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/secret-manager/IntegrationsDetailsByIDPage/IntegrationsDetailsByIDPage.tsx b/frontend/src/pages/secret-manager/IntegrationsDetailsByIDPage/IntegrationsDetailsByIDPage.tsx index ba6b8834e..6f13e5bd7 100644 --- a/frontend/src/pages/secret-manager/IntegrationsDetailsByIDPage/IntegrationsDetailsByIDPage.tsx +++ b/frontend/src/pages/secret-manager/IntegrationsDetailsByIDPage/IntegrationsDetailsByIDPage.tsx @@ -2,12 +2,15 @@ import { Helmet } from "react-helmet"; import { useTranslation } from "react-i18next"; import { faRefresh, faTrash } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { useParams } from "@tanstack/react-router"; +import { useNavigate, useParams } from "@tanstack/react-router"; import { twMerge } from "tailwind-merge"; +import { createNotification } from "@app/components/notifications"; import { OrgPermissionCan } from "@app/components/permissions"; import { Button, + Checkbox, + DeleteActionModal, DropdownMenu, DropdownMenuContent, DropdownMenuItem, @@ -18,8 +21,10 @@ import { } from "@app/components/v2"; import { ROUTE_PATHS } from "@app/const/routes"; import { OrgPermissionActions, OrgPermissionSubjects, useWorkspace } from "@app/context"; +import { usePopUp, useToggle } from "@app/hooks"; import { useGetIntegration } from "@app/hooks/api"; -import { useSyncIntegration } from "@app/hooks/api/integrations/queries"; +import { useDeleteIntegration, useSyncIntegration } from "@app/hooks/api/integrations/queries"; +import { ProjectType } from "@app/hooks/api/workspace/types"; import { IntegrationAuditLogsSection } from "./components/IntegrationAuditLogsSection"; import { IntegrationConnectionSection } from "./components/IntegrationConnectionSection"; @@ -38,9 +43,44 @@ export const IntegrationDetailsByIDPage = () => { refetchInterval: 4000 }); + const [shouldDeleteSecrets, setShouldDeleteSecrets] = useToggle(false); + const { currentWorkspace } = useWorkspace(); const projectId = currentWorkspace.id; const { mutateAsync: syncIntegration } = useSyncIntegration(); + const { mutateAsync: deleteIntegration } = useDeleteIntegration(); + + const navigate = useNavigate(); + + const handleIntegrationDelete = async (shouldDeleteIntegrationSecrets: boolean) => { + try { + await deleteIntegration({ + id: integrationId, + workspaceId: currentWorkspace.id, + shouldDeleteIntegrationSecrets + }); + + createNotification({ + type: "success", + text: "Deleted integration" + }); + + await navigate({ + to: `/${ProjectType.SecretManager}/${projectId}/integrations` + }); + } catch (err) { + console.log(err); + createNotification({ + type: "error", + text: "Failed to delete integration" + }); + } + }; + + const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ + "deleteConfirmation", + "deleteSecretsConfirmation" + ] as const); return ( <> @@ -90,7 +130,10 @@ export const IntegrationDetailsByIDPage = () => { ? "hover:!bg-red-500 hover:!text-white" : "pointer-events-none cursor-not-allowed opacity-50" )} - onClick={() => {}} + onClick={() => { + setShouldDeleteSecrets.off(); + handlePopUpOpen("deleteConfirmation", integration); + }} disabled={!isAllowed} >
@@ -120,6 +163,57 @@ export const IntegrationDetailsByIDPage = () => {
)} + + handlePopUpToggle("deleteConfirmation", isOpen)} + deleteKey={ + (integration?.integration === "azure-app-configuration" && + integration?.app?.split("//")[1]?.split(".")[0]) || + integration?.app || + integration?.owner || + integration?.path || + integration?.integration || + "" + } + onDeleteApproved={async () => { + if (shouldDeleteSecrets) { + handlePopUpOpen("deleteSecretsConfirmation"); + return; + } + + await handleIntegrationDelete(false); + + handlePopUpClose("deleteConfirmation"); + }} + > + {integration?.integration === "github" && ( +
+ setShouldDeleteSecrets.toggle()} + > + Delete previously synced secrets from the destination + +
+ )} +
+ handlePopUpToggle("deleteSecretsConfirmation", isOpen)} + deleteKey="confirm" + onDeleteApproved={async () => { + await handleIntegrationDelete(true); + handlePopUpClose("deleteSecretsConfirmation"); + handlePopUpClose("deleteConfirmation"); + }} + /> ); };