From 6783da028cbe76e4881dad135de58e1a893ec27f Mon Sep 17 00:00:00 2001 From: Pablo Lara Date: Wed, 30 Oct 2024 09:49:11 +0100 Subject: [PATCH] WIP --- components/providers/radio-group-provider.tsx | 49 +-------------- .../workflow/forms/connect-account-form.tsx | 40 +++---------- components/providers/workflow/forms/index.ts | 1 + .../radio-group-aws-via-credentials-form.tsx | 60 +++++++++++++++++++ components/ui/custom/custom-radio.tsx | 48 +++++++++++++++ components/ui/custom/index.ts | 1 + types/formSchemas.ts | 1 + 7 files changed, 122 insertions(+), 78 deletions(-) create mode 100644 components/providers/workflow/forms/radio-group-aws-via-credentials-form.tsx create mode 100644 components/ui/custom/custom-radio.tsx diff --git a/components/providers/radio-group-provider.tsx b/components/providers/radio-group-provider.tsx index 6b5242dc52..a90aa4afcd 100644 --- a/components/providers/radio-group-provider.tsx +++ b/components/providers/radio-group-provider.tsx @@ -1,7 +1,6 @@ "use client"; -import { UseRadioProps } from "@nextui-org/radio/dist/use-radio"; -import { cn, RadioGroup, useRadio, VisuallyHidden } from "@nextui-org/react"; +import { RadioGroup } from "@nextui-org/react"; import React from "react"; import { Control, Controller } from "react-hook-form"; import { z } from "zod"; @@ -11,53 +10,9 @@ import { addProviderFormSchema } from "@/types"; import { AWSProviderBadge, AzureProviderBadge } from "../icons/providers-badge"; import { GCPProviderBadge } from "../icons/providers-badge/GCPProviderBadge"; import { KS8ProviderBadge } from "../icons/providers-badge/KS8ProviderBadge"; +import { CustomRadio } from "../ui/custom"; import { FormMessage } from "../ui/form"; -interface CustomRadioProps extends UseRadioProps { - description?: string; - children?: React.ReactNode; -} - -export const CustomRadio: React.FC = (props) => { - const { - Component, - children, - // description, - getBaseProps, - getWrapperProps, - getInputProps, - getLabelProps, - getLabelWrapperProps, - getControlProps, - } = useRadio(props); - - return ( - - - - - - - -
- {children && {children}} - {/* {description && ( - - {description} - - )} */} -
-
- ); -}; - interface RadioGroupProviderProps { control: Control>; isInvalid: boolean; diff --git a/components/providers/workflow/forms/connect-account-form.tsx b/components/providers/workflow/forms/connect-account-form.tsx index 308dc2bc6f..5b3a5ce7a9 100644 --- a/components/providers/workflow/forms/connect-account-form.tsx +++ b/components/providers/workflow/forms/connect-account-form.tsx @@ -13,6 +13,9 @@ import { Form } from "@/components/ui/form"; import { addProvider } from "../../../../actions/providers/providers"; import { addProviderFormSchema, ApiError } from "../../../../types"; import { RadioGroupProvider } from "../../radio-group-provider"; +import { RadioGroupAWSViaCredentialsForm } from "./radio-group-aws-via-credentials-form"; + +export type FormValues = z.infer; export const ConnectAccountForm = () => { const { toast } = useToast(); @@ -20,18 +23,19 @@ export const ConnectAccountForm = () => { const formSchema = addProviderFormSchema; - const form = useForm>({ + const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { providerType: "", providerId: "", providerAlias: "", + awsCredentialsType: "", }, }); const providerType = form.watch("providerType"); const isLoading = form.formState.isSubmitting; - const onSubmitClient = async (values: z.infer) => { + const onSubmitClient = async (values: FormValues) => { const formData = new FormData(); Object.entries(values).forEach( @@ -125,37 +129,11 @@ export const ConnectAccountForm = () => { {prevStep === 2 && ( <> - {/* Select a provider */} - - {/* Provider UID */} - - {/* Provider alias */} - + {/* Select AWS credentials type */} + )} +
{prevStep === 2 && ( ; +}; + +export const RadioGroupAWSViaCredentialsForm = ({ + control, +}: RadioGroupAWSViaCredentialsFormProps) => { + return ( + ( + <> + +
+ Using IAM Role + +
+ Connect via CloudFormation +
+
+ +
+ Connect via Terraform +
+
+ + Using Credentials + + +
+ Connect via Credentials +
+
+
+
+ + )} + /> + ); +}; diff --git a/components/ui/custom/custom-radio.tsx b/components/ui/custom/custom-radio.tsx new file mode 100644 index 0000000000..a1248209b1 --- /dev/null +++ b/components/ui/custom/custom-radio.tsx @@ -0,0 +1,48 @@ +import { UseRadioProps } from "@nextui-org/radio/dist/use-radio"; +import { cn, useRadio, VisuallyHidden } from "@nextui-org/react"; +import React from "react"; + +interface CustomRadioProps extends UseRadioProps { + description?: string; + children?: React.ReactNode; +} + +export const CustomRadio: React.FC = (props) => { + const { + Component, + children, + // description, + getBaseProps, + getWrapperProps, + getInputProps, + getLabelProps, + getLabelWrapperProps, + getControlProps, + } = useRadio(props); + + return ( + + + + + + + +
+ {children && {children}} + {/* {description && ( + + {description} + + )} */} +
+
+ ); +}; diff --git a/components/ui/custom/index.ts b/components/ui/custom/index.ts index 703b673471..130646a89e 100644 --- a/components/ui/custom/index.ts +++ b/components/ui/custom/index.ts @@ -4,4 +4,5 @@ export * from "./custom-button"; export * from "./custom-dropdown-filter"; export * from "./custom-input"; export * from "./custom-loader"; +export * from "./custom-radio"; export * from "./CustomButtonClientAction"; diff --git a/types/formSchemas.ts b/types/formSchemas.ts index e1df1285b8..f541ebf593 100644 --- a/types/formSchemas.ts +++ b/types/formSchemas.ts @@ -35,6 +35,7 @@ export const addProviderFormSchema = z.object({ providerType: z.string(), providerAlias: z.string(), providerId: z.string(), + awsCredentialsType: z.string().optional(), }); export const editProviderFormSchema = (currentAlias: string) =>