chore: add alias by default if provider alias is empty when add a provider

This commit is contained in:
Pablo Lara
2024-11-04 07:46:44 +01:00
parent 258d18112c
commit 8ca21bb92e
3 changed files with 23 additions and 12 deletions
+2 -2
View File
@@ -114,7 +114,7 @@ export const addProvider = async (formData: FormData) => {
const keyServer = process.env.API_BASE_URL;
const providerType = formData.get("providerType");
const providerId = formData.get("providerId");
const providerUid = formData.get("providerUid");
const providerAlias = formData.get("providerAlias");
const url = new URL(`${keyServer}/providers`);
@@ -132,7 +132,7 @@ export const addProvider = async (formData: FormData) => {
type: "Provider",
attributes: {
provider: providerType,
uid: providerId,
uid: providerUid,
alias: providerAlias,
},
},
@@ -29,7 +29,7 @@ export const ConnectAccountForm = () => {
resolver: zodResolver(formSchema),
defaultValues: {
providerType: undefined,
providerId: "",
providerUid: "",
providerAlias: "",
awsCredentialsType: "",
},
@@ -38,10 +38,21 @@ export const ConnectAccountForm = () => {
const isLoading = form.formState.isSubmitting;
const onSubmitClient = async (values: FormValues) => {
console.log({ values });
const formValues = { ...values };
// If providerAlias is empty, set default value
if (!formValues.providerAlias.trim()) {
const date = new Date();
const month = (date.getMonth() + 1).toString().padStart(2, "0");
const day = date.getDate().toString().padStart(2, "0");
const year = date.getFullYear();
formValues.providerAlias = `${formValues.providerType}:${month}/${day}/${year}`;
}
console.log({ formValues });
const formData = new FormData();
Object.entries(values).forEach(
Object.entries(formValues).forEach(
([key, value]) => value !== undefined && formData.append(key, value),
);
@@ -59,7 +70,7 @@ export const ConnectAccountForm = () => {
break;
case "/data/attributes/uid":
case "/data/attributes/__all__":
form.setError("providerId", {
form.setError("providerUid", {
type: "server",
message: errorMessage,
});
@@ -118,14 +129,14 @@ export const ConnectAccountForm = () => {
{/* Provider UID */}
<CustomInput
control={form.control}
name="providerId"
name="providerUid"
type="text"
label="Provider UID"
labelPlacement="inside"
placeholder={"Enter the provider UID"}
variant="bordered"
isRequired
isInvalid={!!form.formState.errors.providerId}
isInvalid={!!form.formState.errors.providerUid}
/>
{/* Provider alias */}
<CustomInput
+4 -4
View File
@@ -42,7 +42,7 @@ export const addProviderFormSchema = z
z.object({
providerType: z.literal("aws"),
providerAlias: z.string(),
providerId: z.string(),
providerUid: z.string(),
awsCredentialsType: z.string().min(1, {
message: "Please select the type of credentials you want to use",
}),
@@ -50,19 +50,19 @@ export const addProviderFormSchema = z
z.object({
providerType: z.literal("azure"),
providerAlias: z.string(),
providerId: z.string(),
providerUid: z.string(),
awsCredentialsType: z.string().optional(),
}),
z.object({
providerType: z.literal("gcp"),
providerAlias: z.string(),
providerId: z.string(),
providerUid: z.string(),
awsCredentialsType: z.string().optional(),
}),
z.object({
providerType: z.literal("kubernetes"),
providerAlias: z.string(),
providerId: z.string(),
providerUid: z.string(),
awsCredentialsType: z.string().optional(),
}),
]),