import { useEffect, useState } from "react"; import { useNavigate, useSearch } from "@tanstack/react-router"; import { Button, Card, CardTitle, FormControl, Input, Select, SelectItem } from "@app/components/v2"; import { ROUTE_PATHS } from "@app/const/routes"; import { useWorkspace } from "@app/context"; import { useCreateIntegration } from "@app/hooks/api"; import { useGetIntegrationAuthApps, useGetIntegrationAuthById } from "@app/hooks/api/integrationAuth"; import { IntegrationsListPageTabs } from "@app/types/integrations"; export const DigitalOceanAppPlatformConfigurePage = () => { const navigate = useNavigate(); const { mutateAsync } = useCreateIntegration(); const { currentWorkspace } = useWorkspace(); const integrationAuthId = useSearch({ from: ROUTE_PATHS.SecretManager.Integratons.DigitalOceanAppPlatformConfigurePage.id, select: (el) => el.integrationAuthId }); const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? ""); const { data: integrationAuthApps } = useGetIntegrationAuthApps({ integrationAuthId: (integrationAuthId as string) ?? "" }); const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState( currentWorkspace.environments[0].slug ); const [targetApp, setTargetApp] = useState(""); const [secretPath, setSecretPath] = useState("/"); const [isLoading, setIsLoading] = useState(false); useEffect(() => { if (integrationAuthApps) { if (integrationAuthApps.length > 0) { setTargetApp(integrationAuthApps[0].name); } else { setTargetApp("none"); } } }, [integrationAuthApps]); const handleButtonClick = async () => { try { if (!integrationAuth?.id) return; setIsLoading(true); await mutateAsync({ integrationAuthId: integrationAuth?.id, isActive: true, app: targetApp, appId: integrationAuthApps?.find( (integrationAuthApp) => integrationAuthApp.name === targetApp )?.appId, sourceEnvironment: selectedSourceEnvironment, secretPath }); setIsLoading(false); navigate({ to: "/projects/$projectId/secret-manager/integrations", params: { projectId: currentWorkspace.id }, search: { selectedTab: IntegrationsListPageTabs.NativeIntegrations } }); } catch (err) { console.error(err); } }; return integrationAuth && selectedSourceEnvironment && integrationAuthApps && targetApp ? (
Digital Ocean App Platform Integration setSecretPath(evt.target.value)} placeholder="Provide a path, default is /" />
) : (
); };