import { useEffect, useState } from "react"; import { useNavigate, useSearch } from "@tanstack/react-router"; import axios from "axios"; import { createNotification } from "@app/components/notifications"; import { Button, Card, CardTitle, FormControl, Select, SelectItem } from "@app/components/v2"; import { SecretPathInput } from "@app/components/v2/SecretPathInput"; 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 CloudflareWorkersConfigurePage = () => { const navigate = useNavigate(); const { mutateAsync } = useCreateIntegration(); const { currentWorkspace } = useWorkspace(); const integrationAuthId = useSearch({ from: ROUTE_PATHS.SecretManager.Integratons.CloudflareWorkersConfigurePage.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 [secretPath, setSecretPath] = useState("/"); const [targetApp, setTargetApp] = useState(""); const [targetAppId, setTargetAppId] = useState(""); const [isLoading, setIsLoading] = useState(false); useEffect(() => { if (integrationAuthApps) { if (integrationAuthApps.length > 0) { setTargetApp(integrationAuthApps[0].name); setTargetAppId(String(integrationAuthApps[0].appId)); } else { setTargetApp("none"); } } }, [integrationAuthApps]); const handleButtonClick = async () => { try { if (!integrationAuth?.id) return; setIsLoading(true); await mutateAsync({ integrationAuthId: integrationAuth?.id, isActive: true, app: targetApp, appId: targetAppId, 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); let errorMessage: string = "Something went wrong!"; if (axios.isAxiosError(err)) { const { message } = err?.response?.data as { message: string }; errorMessage = message; } createNotification({ text: errorMessage, type: "error" }); setIsLoading(false); } }; return integrationAuth && selectedSourceEnvironment && integrationAuthApps && targetApp ? (
Cloudflare Workers Integration setSecretPath(value)} environment={selectedSourceEnvironment} placeholder="Provide a path, default is /" />
) : (
); };