From 66d2cc894723fb94e276c6505aa1957ca49aaf62 Mon Sep 17 00:00:00 2001 From: Sheen Capadngan Date: Thu, 24 Oct 2024 02:10:55 +0800 Subject: [PATCH] misc: updated ldap edit --- .../CreateDynamicSecretForm/LdapInputForm.tsx | 3 +- .../EditDynamicSecretLdapForm.tsx | 158 ++++++++++++++---- 2 files changed, 125 insertions(+), 36 deletions(-) diff --git a/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/LdapInputForm.tsx b/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/LdapInputForm.tsx index b4720e9cf..1a7e0e8fa 100644 --- a/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/LdapInputForm.tsx +++ b/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/LdapInputForm.tsx @@ -287,7 +287,8 @@ export const LdapInputForm = ({ const ldifFields = [ "provider.creationLdif", "provider.revocationLdif", - "provider.rollbackLdif" + "provider.rollbackLdif", + "provider.rotationLdif" ] as const; ldifFields.forEach((f) => { diff --git a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretLdapForm.tsx b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretLdapForm.tsx index 5d0b5938f..0cbad664a 100644 --- a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretLdapForm.tsx +++ b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretLdapForm.tsx @@ -5,22 +5,47 @@ import { z } from "zod"; import { TtlFormLabel } from "@app/components/features"; import { createNotification } from "@app/components/notifications"; -import { Button, FormControl, Input, TextArea } from "@app/components/v2"; +import { Button, FormControl, Input, Select, SelectItem, TextArea } from "@app/components/v2"; import { useUpdateDynamicSecret } from "@app/hooks/api"; import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types"; +enum CredentialType { + Dynamic = "dynamic", + Static = "static" +} + +const credentialTypes = [ + { + label: "Dynamic", + value: CredentialType.Dynamic + }, + { + label: "Static", + value: CredentialType.Static + } +] as const; + const formSchema = z.object({ - inputs: z - .object({ + inputs: z.discriminatedUnion("credentialType", [ + z.object({ url: z.string().trim().min(1), binddn: z.string().trim().min(1), bindpass: z.string().trim().min(1), ca: z.string().optional(), + credentialType: z.literal(CredentialType.Dynamic), creationLdif: z.string().min(1), revocationLdif: z.string().min(1), rollbackLdif: z.string().optional() + }), + z.object({ + url: z.string().trim().min(1), + binddn: z.string().trim().min(1), + bindpass: z.string().trim().min(1), + ca: z.string().optional(), + credentialType: z.literal(CredentialType.Static), + rotationLdif: z.string().min(1) }) - .partial(), + ]), defaultTTL: z.string().superRefine((val, ctx) => { const valMs = ms(val); if (valMs < 60 * 1000) @@ -67,7 +92,9 @@ export const EditDynamicSecretLdapForm = ({ const { control, formState: { isSubmitting }, - handleSubmit + handleSubmit, + watch, + setValue } = useForm({ resolver: zodResolver(formSchema), values: { @@ -81,6 +108,7 @@ export const EditDynamicSecretLdapForm = ({ }); const updateDynamicSecret = useUpdateDynamicSecret(); + const selectedCredentialType = watch("inputs.credentialType"); const handleUpdateDynamicSecret = async ({ inputs, maxTTL, defaultTTL, newName }: TForm) => { // wait till previous request is finished @@ -204,43 +232,103 @@ export const EditDynamicSecretLdapForm = ({ /> ( -