From 32ecbd2d6da957ed99c97ea42da645630c59a0b6 Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Fri, 5 Dec 2025 23:46:37 +0530 Subject: [PATCH] fix: edge cases --- frontend/src/hooks/api/kms/types.ts | 5 +- .../OrgEncryptionTab/GcpKmsForm.tsx | 58 ++++++------------- 2 files changed, 20 insertions(+), 43 deletions(-) diff --git a/frontend/src/hooks/api/kms/types.ts b/frontend/src/hooks/api/kms/types.ts index d75fb571c..32c2fa32a 100644 --- a/frontend/src/hooks/api/kms/types.ts +++ b/frontend/src/hooks/api/kms/types.ts @@ -186,10 +186,7 @@ export const AddExternalKmsGcpFormSchema = z.discriminatedUnion("formType", [ .merge(AddExternalKmsGcpFormSchemaStandardInputs) .merge(AddExternalKmsSchema.pick({ name: true, description: true })), z - .object({ formType: z.literal("updateGcpKmsDetails") }) - .merge(AddExternalKmsSchema.pick({ name: true, description: true })), - z - .object({ formType: z.literal("updateGcpKmsCredentials") }) + .object({ formType: z.literal("updateGcpKms") }) .merge(AddExternalKmsGcpFormSchemaStandardInputs) .merge(AddExternalKmsSchema.pick({ name: true, description: true })) ]); diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgEncryptionTab/GcpKmsForm.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgEncryptionTab/GcpKmsForm.tsx index 5311936d8..2ac44483e 100644 --- a/frontend/src/pages/organization/SettingsPage/components/OrgEncryptionTab/GcpKmsForm.tsx +++ b/frontend/src/pages/organization/SettingsPage/components/OrgEncryptionTab/GcpKmsForm.tsx @@ -81,13 +81,6 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props) const [isCredentialValid, setIsCredentialValid] = useState(false); const [keys, setKeys] = useState<{ value: string; label: string }[]>([]); - const getFormType = () => { - if (kms) { - return mode === "details" ? "updateGcpKmsDetails" : "updateGcpKmsCredentials"; - } - return "newGcpKms"; - }; - const { control, handleSubmit, @@ -96,11 +89,11 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props) getValues, resetField, setValue, - formState: { isSubmitting } + formState: { isSubmitting, isDirty, isValid } } = useForm({ resolver: zodResolver(AddExternalKmsGcpFormSchema), defaultValues: { - formType: getFormType(), + formType: kms ? "updateGcpKms" : "newGcpKms", name: kms?.name ?? "", description: kms?.description ?? "", gcpRegion: kms @@ -152,24 +145,11 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props) // handles the form submission const handleGcpKmsFormSubmit = async (data: AddExternalKmsGcpFormSchemaType) => { - const { name, description, formType } = data; + const { name, description, formType, gcpRegion: gcpRegionObject, keyObject } = data; try { if (kms) { - if (formType === "updateGcpKmsDetails") { - await updateGcpExternalKms({ - kmsId: kms.id, - name, - description - }); - - createNotification({ - text: "Successfully updated GCP External KMS Details", - type: "success" - }); - } else if (formType === "updateGcpKmsCredentials") { - const { gcpRegion: gcpRegionObject, keyObject } = data; - + if (formType === "updateGcpKms") { const gcpRegion = gcpRegionObject?.value; if (!gcpRegion) { setError("gcpRegion", { @@ -188,6 +168,8 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props) await updateGcpExternalKms({ kmsId: kms.id, + name, + description, configuration: { type: ExternalKmsProvider.Gcp, inputs: { @@ -198,13 +180,11 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props) }); createNotification({ - text: "Successfully updated GCP External KMS configuration", + text: "Successfully updated GCP External KMS Details", type: "success" }); } } else if (formType === "newGcpKms") { - const { gcpRegion: gcpRegionObject, keyObject } = data; - const gcpRegion = gcpRegionObject?.value; if (!gcpRegion) { setError("gcpRegion", { @@ -334,10 +314,6 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props) )} /> - - )} - {(mode === "full" || mode === "credentials") && ( - <> )} /> - {kms && ( - - To change your GCP credentials, create a new external KMS and assign it to project you - want to use it with. - - )} )} + {kms && mode === "credentials" && ( + + To change your GCP credentials, create a new external KMS and assign it to project you + want to use it with. + + )}
-