Skip to content

Commit

Permalink
fix(providers): update the label and placeholder based on the cloud p…
Browse files Browse the repository at this point in the history
…rovider (#6581)
  • Loading branch information
paabloLC authored Jan 17, 2025
1 parent 3ac92ed commit d450746
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions ui/components/providers/workflow/forms/connect-account-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,37 @@ import { RadioGroupProvider } from "../../radio-group-provider";

export type FormValues = z.infer<typeof addProviderFormSchema>;

// Helper function for labels and placeholders
const getProviderFieldDetails = (providerType?: string) => {
switch (providerType) {
case "aws":
return {
label: "Account ID",
placeholder: "123456...",
};
case "gcp":
return {
label: "Project ID",
placeholder: "project_id...",
};
case "azure":
return {
label: "Subscription ID",
placeholder: "fc94207a-d396-4a14-a7fd-12a...",
};
case "kubernetes":
return {
label: "Kubernetes Context",
placeholder: "context_name....",
};
default:
return {
label: "Provider UID",
placeholder: "Enter the provider UID",
};
}
};

export const ConnectAccountForm = () => {
const { toast } = useToast();
const [prevStep, setPrevStep] = useState(1);
Expand All @@ -39,6 +70,8 @@ export const ConnectAccountForm = () => {
});

const providerType = form.watch("providerType");
const providerFieldDetails = getProviderFieldDetails(providerType);

const isLoading = form.formState.isSubmitting;

const onSubmitClient = async (values: FormValues) => {
Expand Down Expand Up @@ -107,7 +140,12 @@ export const ConnectAccountForm = () => {
}
};

const handleBackStep = () => setPrevStep((prev) => prev - 1);
const handleBackStep = () => {
setPrevStep((prev) => prev - 1);
// Reset the providerUid and providerAlias fields when going back
form.setValue("providerUid", "");
form.setValue("providerAlias", "");
};

useEffect(() => {
if (providerType) {
Expand Down Expand Up @@ -144,9 +182,9 @@ export const ConnectAccountForm = () => {
control={form.control}
name="providerUid"
type="text"
label="Provider UID"
label={providerFieldDetails.label}
labelPlacement="inside"
placeholder="Enter the provider UID"
placeholder={providerFieldDetails.placeholder}
variant="bordered"
isRequired
isInvalid={!!form.formState.errors.providerUid}
Expand Down

0 comments on commit d450746

Please sign in to comment.