diff --git a/frontend/src/pages/integrations/gcp-secret-manager/create.tsx b/frontend/src/pages/integrations/gcp-secret-manager/create.tsx index c4997c2d6..3d1a7c504 100644 --- a/frontend/src/pages/integrations/gcp-secret-manager/create.tsx +++ b/frontend/src/pages/integrations/gcp-secret-manager/create.tsx @@ -1,10 +1,10 @@ import { useEffect, useState } from "react"; -import Head from "next/head"; -import Link from "next/link"; +import { Controller, useForm } from "react-hook-form"; import { useRouter } from "next/router"; -import { faArrowUpRightFromSquare, faBookOpen, faBugs } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { yupResolver } from "@hookform/resolvers/yup"; +import { motion } from "framer-motion"; import queryString from "query-string"; +import * as yup from "yup"; import { useCreateIntegration @@ -17,7 +17,12 @@ import { FormControl, Input, Select, - SelectItem + SelectItem, + Switch, + Tab, + TabList, + TabPanel, + Tabs } from "../../../components/v2"; import { useGetIntegrationAuthApps, @@ -25,41 +30,93 @@ import { } from "../../../hooks/api/integrationAuth"; import { useGetWorkspaceById } from "../../../hooks/api/workspace"; +enum TabSections { + Connection = "connection", + Options = "options" +} + +const schema = yup.object({ + selectedSourceEnvironment: yup.string().required("Source environment is required"), + secretPath: yup.string().required("Secret path is required"), + targetAppId: yup.string().required("GCP project is required"), + secretPrefix: yup.string(), + secretSuffix: yup.string(), + shouldLabel: yup.boolean(), + labelName: yup.string(), + labelValue: yup.string() +}); + +type FormData = yup.InferType; + export default function GCPSecretManagerCreateIntegrationPage() { const router = useRouter(); + const { + control, + handleSubmit, + setValue, + watch + } = useForm({ + resolver: yupResolver(schema), + defaultValues: { + secretPath: "/", + shouldLabel: false, + labelName: "managed-by", + labelValue: "infisical" + } + }); + + const shouldLabel = watch("shouldLabel"); + const selectedSourceEnvironment = watch("selectedSourceEnvironment"); + const { mutateAsync } = useCreateIntegration(); const { integrationAuthId } = queryString.parse(router.asPath.split("?")[1]); const { data: workspace } = useGetWorkspaceById(localStorage.getItem("projectData.id") ?? ""); const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? ""); - const { data: integrationAuthApps, isLoading: isintegrationAuthAppsLoading } = useGetIntegrationAuthApps({ + const { data: integrationAuthApps } = useGetIntegrationAuthApps({ integrationAuthId: (integrationAuthId as string) ?? "" }); - const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState(""); - const [targetAppId, setTargetAppId] = useState(""); - const [secretPath, setSecretPath] = useState("/"); - const [isLoading, setIsLoading] = useState(false); + + useEffect(() => { + if (shouldLabel) { + setValue("labelName", "managed-by"); + setValue("labelValue", "infisical"); + return; + } + + setValue("labelName", undefined); + setValue("labelValue", undefined); + }, [shouldLabel]); useEffect(() => { if (workspace) { - setSelectedSourceEnvironment(workspace.environments[0].slug); + setValue("selectedSourceEnvironment", workspace.environments[0].slug); } }, [workspace]); useEffect(() => { if (integrationAuthApps) { if (integrationAuthApps.length > 0) { - setTargetAppId(integrationAuthApps[0].appId as string); + setValue("targetAppId", integrationAuthApps[0].appId as string); } else { - setTargetAppId("none"); + setValue("targetAppId", "none"); } } }, [integrationAuthApps]); - - const handleButtonClick = async () => { + + const onFormSubmit = async ({ + selectedSourceEnvironment: sce, + secretPath, + targetAppId, + secretPrefix, + secretSuffix, + shouldLabel: sl, + labelName, + labelValue + }: FormData) => { try { setIsLoading(true); @@ -70,118 +127,235 @@ export default function GCPSecretManagerCreateIntegrationPage() { isActive: true, app: integrationAuthApps?.find((integrationAuthApp) => integrationAuthApp.appId === targetAppId)?.name, appId: targetAppId, - sourceEnvironment: selectedSourceEnvironment, - secretPath + sourceEnvironment: sce, + secretPath, + metadata: { + secretPrefix, + secretSuffix, + ...(sl ? { + secretGCPLabel: { + labelName, + labelValue + } + } : {}) + } }); - + setIsLoading(false); router.push(`/integrations/${localStorage.getItem("projectData.id")}`); } catch (err) { console.error(err); + setIsLoading(false); } - }; + } return integrationAuth && workspace && selectedSourceEnvironment && - integrationAuthApps && - targetAppId ? ( -
- - - Set Up GCP Secret Manager Integration - - - - GCP Secret Manager Integration - - -
- - Docs - -
-
- -
- - - - - setSecretPath(evt.target.value)} - placeholder="Provide a path, default is /" - /> - - - onChange(e)} + className="w-full" + > + {workspace?.environments.map((sourceEnvironment) => ( + + {sourceEnvironment.name} + + ))} + + + )} + /> + ( + + + + )} + /> + { + return ( + + + + ) + }} + /> + +
+ + + + ( + + + + )} + /> + ( + + + + )} + /> +
+ ( + onChange(isChecked)} + isChecked={value} + > + Label in GCP Secret Manager + + )} + /> +
+ {shouldLabel && ( +
+ ( + + + + )} + /> + ( + + + + )} + /> +
)} - - - +
+ - + ) : ( -
- {isintegrationAuthAppsLoading ? infisical loading indicator :
- -

- Something went wrong. Please contact - support@infisical.com - if the issue persists. -

-
} -
+
); } -GCPSecretManagerCreateIntegrationPage.requireAuth = true; +GCPSecretManagerCreateIntegrationPage.requireAuth = true; \ No newline at end of file