"use client"; import { Divider } from "@heroui/divider"; import { ChevronLeftIcon, ChevronRightIcon, Loader2 } from "lucide-react"; import { Control, UseFormSetValue } from "react-hook-form"; import { Button } from "@/components/shadcn"; import { Form } from "@/components/ui/form"; import { useCredentialsForm } from "@/hooks/use-credentials-form"; import { getAWSCredentialsTemplateLinks } from "@/lib"; import { ProviderCredentialFields } from "@/lib/provider-credentials/provider-credential-fields"; import { requiresBackButton } from "@/lib/provider-helpers"; import { AlibabaCloudCredentials, AlibabaCloudCredentialsRole, ApiResponse, AWSCredentials, AWSCredentialsRole, AzureCredentials, GCPDefaultCredentials, GCPServiceAccountKey, IacCredentials, KubernetesCredentials, M365CertificateCredentials, M365ClientSecretCredentials, MongoDBAtlasCredentials, OCICredentials, ProviderType, } from "@/types"; import { ProviderTitleDocs } from "../provider-title-docs"; import { AlibabaCloudRoleCredentialsForm, AlibabaCloudStaticCredentialsForm, } from "./select-credentials-type/alibabacloud/credentials-type"; import { AWSStaticCredentialsForm } from "./select-credentials-type/aws/credentials-type"; import { AWSRoleCredentialsForm } from "./select-credentials-type/aws/credentials-type/aws-role-credentials-form"; import { GCPDefaultCredentialsForm } from "./select-credentials-type/gcp/credentials-type"; import { GCPServiceAccountKeyForm } from "./select-credentials-type/gcp/credentials-type/gcp-service-account-key-form"; import { M365CertificateCredentialsForm, M365ClientSecretCredentialsForm, } from "./select-credentials-type/m365"; import { AzureCredentialsForm } from "./via-credentials/azure-credentials-form"; import { GitHubCredentialsForm } from "./via-credentials/github-credentials-form"; import { IacCredentialsForm } from "./via-credentials/iac-credentials-form"; import { KubernetesCredentialsForm } from "./via-credentials/k8s-credentials-form"; import { MongoDBAtlasCredentialsForm } from "./via-credentials/mongodbatlas-credentials-form"; import { OracleCloudCredentialsForm } from "./via-credentials/oraclecloud-credentials-form"; type BaseCredentialsFormProps = { providerType: ProviderType; providerId: string; providerUid?: string; onSubmit: (formData: FormData) => Promise; successNavigationUrl: string; submitButtonText?: string; showBackButton?: boolean; }; export const BaseCredentialsForm = ({ providerType, providerId, providerUid, onSubmit, successNavigationUrl, submitButtonText = "Next", showBackButton = true, }: BaseCredentialsFormProps) => { const { form, isLoading, handleSubmit, handleBackStep, searchParamsObj, externalId, } = useCredentialsForm({ providerType, providerId, providerUid, onSubmit, successNavigationUrl, }); const templateLinks = getAWSCredentialsTemplateLinks(externalId); return (
{providerUid && ( )} {providerType === "aws" && searchParamsObj.get("via") === "role" && ( } setValue={ form.setValue as unknown as UseFormSetValue } externalId={externalId} templateLinks={templateLinks} /> )} {providerType === "aws" && searchParamsObj.get("via") !== "role" && ( } /> )} {providerType === "azure" && ( } /> )} {providerType === "m365" && searchParamsObj.get("via") === "app_client_secret" && ( } /> )} {providerType === "m365" && searchParamsObj.get("via") === "app_certificate" && ( } /> )} {providerType === "gcp" && searchParamsObj.get("via") === "service-account" && ( } /> )} {providerType === "gcp" && searchParamsObj.get("via") !== "service-account" && ( } /> )} {providerType === "kubernetes" && ( } /> )} {providerType === "github" && ( )} {providerType === "iac" && ( } /> )} {providerType === "oraclecloud" && ( } /> )} {providerType === "mongodbatlas" && ( } /> )} {providerType === "alibabacloud" && searchParamsObj.get("via") === "role" && ( } /> )} {providerType === "alibabacloud" && searchParamsObj.get("via") !== "role" && ( } /> )}
{showBackButton && requiresBackButton(searchParamsObj.get("via")) && ( )}
); };