From 7c4f34bb6cbc3b1dd361a72c7ca90a1a75e35f12 Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Thu, 31 Oct 2024 08:08:20 +0100 Subject: [PATCH] feat: custom add credentials page --- .../add-credentials/page.tsx | 20 +++++++-- components/providers/workflow/forms/index.ts | 2 +- ...ials-form.tsx => via-credentials-form.tsx} | 41 ++++++++++++------- components/ui/custom/custom-input.tsx | 3 ++ 4 files changed, 46 insertions(+), 20 deletions(-) rename components/providers/workflow/forms/{add-credentials-form.tsx => via-credentials-form.tsx} (90%) diff --git a/app/(prowler)/providers/(set-up-provider)/add-credentials/page.tsx b/app/(prowler)/providers/(set-up-provider)/add-credentials/page.tsx index d9d8640703..83ae37a99a 100644 --- a/app/(prowler)/providers/(set-up-provider)/add-credentials/page.tsx +++ b/app/(prowler)/providers/(set-up-provider)/add-credentials/page.tsx @@ -1,16 +1,28 @@ import { redirect } from "next/navigation"; import React from "react"; -import { AddCredentialsForm } from "@/components/providers/workflow/forms"; +import { ViaCredentialsForm } from "@/components/providers/workflow/forms"; interface Props { - searchParams: { provider: string; id: string }; + searchParams: { provider: string; id: string; via?: string }; } export default function AddCredentialsPage({ searchParams }: Props) { - if (!searchParams.provider || !searchParams.id) { + if ( + !searchParams.provider || + !searchParams.id || + (searchParams.provider === "aws" && !searchParams.via) + ) { redirect("/providers/connect-account"); } - return ; + const useCredentialsForm = + (searchParams.provider === "aws" && searchParams.via === "credentials") || + (searchParams.provider !== "aws" && !searchParams.via); + + return ( + <> + {useCredentialsForm && } + + ); } diff --git a/components/providers/workflow/forms/index.ts b/components/providers/workflow/forms/index.ts index 16cd78f184..b4bb037a59 100644 --- a/components/providers/workflow/forms/index.ts +++ b/components/providers/workflow/forms/index.ts @@ -1,3 +1,3 @@ -export * from "./add-credentials-form"; export * from "./connect-account-form"; export * from "./radio-group-aws-via-credentials-form"; +export * from "./via-credentials-form"; diff --git a/components/providers/workflow/forms/add-credentials-form.tsx b/components/providers/workflow/forms/via-credentials-form.tsx similarity index 90% rename from components/providers/workflow/forms/add-credentials-form.tsx rename to components/providers/workflow/forms/via-credentials-form.tsx index e76c443215..52913beab9 100644 --- a/components/providers/workflow/forms/add-credentials-form.tsx +++ b/components/providers/workflow/forms/via-credentials-form.tsx @@ -18,17 +18,19 @@ import { CredentialsFormSchema, } from "../../../../types"; -export const AddCredentialsForm = ({ +export const ViaCredentialsForm = ({ searchParams, }: { searchParams: { provider: string; id: string }; }) => { + const router = useRouter(); + const { toast } = useToast(); + const providerType = searchParams.provider; const providerId = searchParams.id; const formSchema = addCredentialsFormSchema(providerType); - const { toast } = useToast(); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { @@ -58,8 +60,6 @@ export const AddCredentialsForm = ({ const isLoading = form.formState.isSubmitting; - const router = useRouter(); - const onSubmitClient = async (values: z.infer) => { const formData = new FormData(); @@ -117,19 +117,17 @@ export const AddCredentialsForm = ({ className="flex flex-col space-y-4" > - + {providerType === "aws" && ( <> +
+
+ Connect via Credentials +
+
+ Please provide the information for your AWS credentials. +
+
)} + Name (Optional) +
{ label?: string; labelPlacement?: "inside" | "outside"; variant?: "flat" | "bordered" | "underlined" | "faded"; + size?: "sm" | "md" | "lg"; type?: string; placeholder?: string; password?: boolean; @@ -29,6 +30,7 @@ export const CustomInput = ({ labelPlacement = "inside", placeholder, variant = "bordered", + size = "md", confirmPassword = false, password = false, isRequired = true, @@ -95,6 +97,7 @@ export const CustomInput = ({ placeholder={inputPlaceholder} type={inputType} variant={variant} + size={size} isInvalid={isInvalid} endContent={endContent} {...field}