fix: review changes

This commit is contained in:
Piyush Gupta
2025-12-05 22:17:42 +05:30
parent fd1a3d5d12
commit 1f0daf447e
2 changed files with 22 additions and 7 deletions
+4 -1
View File
@@ -186,7 +186,10 @@ export const AddExternalKmsGcpFormSchema = z.discriminatedUnion("formType", [
.merge(AddExternalKmsGcpFormSchemaStandardInputs) .merge(AddExternalKmsGcpFormSchemaStandardInputs)
.merge(AddExternalKmsSchema.pick({ name: true, description: true })), .merge(AddExternalKmsSchema.pick({ name: true, description: true })),
z z
.object({ formType: z.literal("updateGcpKms") }) .object({ formType: z.literal("updateGcpKmsDetails") })
.merge(AddExternalKmsSchema.pick({ name: true, description: true })),
z
.object({ formType: z.literal("updateGcpKmsCredentials") })
.merge(AddExternalKmsGcpFormSchemaStandardInputs) .merge(AddExternalKmsGcpFormSchemaStandardInputs)
.merge(AddExternalKmsSchema.pick({ name: true, description: true })) .merge(AddExternalKmsSchema.pick({ name: true, description: true }))
]); ]);
@@ -81,6 +81,13 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props)
const [isCredentialValid, setIsCredentialValid] = useState<boolean>(false); const [isCredentialValid, setIsCredentialValid] = useState<boolean>(false);
const [keys, setKeys] = useState<{ value: string; label: string }[]>([]); const [keys, setKeys] = useState<{ value: string; label: string }[]>([]);
const getFormType = () => {
if (kms) {
return mode === "details" ? "updateGcpKmsDetails" : "updateGcpKmsCredentials";
}
return "newGcpKms";
};
const { const {
control, control,
handleSubmit, handleSubmit,
@@ -93,7 +100,7 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props)
} = useForm<AddExternalKmsGcpFormSchemaType>({ } = useForm<AddExternalKmsGcpFormSchemaType>({
resolver: zodResolver(AddExternalKmsGcpFormSchema), resolver: zodResolver(AddExternalKmsGcpFormSchema),
defaultValues: { defaultValues: {
formType: kms ? "updateGcpKms" : "newGcpKms", formType: getFormType(),
name: kms?.name ?? "", name: kms?.name ?? "",
description: kms?.description ?? "", description: kms?.description ?? "",
gcpRegion: kms gcpRegion: kms
@@ -114,6 +121,7 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props)
currentOrg.id, currentOrg.id,
ExternalKmsProvider.Gcp ExternalKmsProvider.Gcp
); );
const { mutateAsync: fetchGcpKeys, isPending: isFetchGcpKeysLoading } = const { mutateAsync: fetchGcpKeys, isPending: isFetchGcpKeysLoading } =
useExternalKmsFetchGcpKeys(currentOrg?.id); useExternalKmsFetchGcpKeys(currentOrg?.id);
@@ -144,11 +152,11 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props)
// handles the form submission // handles the form submission
const handleGcpKmsFormSubmit = async (data: AddExternalKmsGcpFormSchemaType) => { const handleGcpKmsFormSubmit = async (data: AddExternalKmsGcpFormSchemaType) => {
const { name, description, gcpRegion: gcpRegionObject, keyObject } = data; const { name, description, formType } = data;
try { try {
if (kms) { if (kms) {
if (mode === "details") { if (formType === "updateGcpKmsDetails") {
await updateGcpExternalKms({ await updateGcpExternalKms({
kmsId: kms.id, kmsId: kms.id,
name, name,
@@ -159,7 +167,9 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props)
text: "Successfully updated GCP External KMS Details", text: "Successfully updated GCP External KMS Details",
type: "success" type: "success"
}); });
} else if (mode === "credentials") { } else if (formType === "updateGcpKmsCredentials") {
const { gcpRegion: gcpRegionObject, keyObject } = data;
const gcpRegion = gcpRegionObject?.value; const gcpRegion = gcpRegionObject?.value;
if (!gcpRegion) { if (!gcpRegion) {
setError("gcpRegion", { setError("gcpRegion", {
@@ -192,7 +202,9 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props)
type: "success" type: "success"
}); });
} }
} else { } else if (formType === "newGcpKms") {
const { gcpRegion: gcpRegionObject, keyObject } = data;
const gcpRegion = gcpRegionObject?.value; const gcpRegion = gcpRegionObject?.value;
if (!gcpRegion) { if (!gcpRegion) {
setError("gcpRegion", { setError("gcpRegion", {
@@ -220,7 +232,7 @@ export const GcpKmsForm = ({ onCompleted, onCancel, kms, mode = "full" }: Props)
type: ExternalKmsProvider.Gcp, type: ExternalKmsProvider.Gcp,
inputs: { inputs: {
gcpRegion, gcpRegion,
keyName: keyObject?.value, keyName: keyObject?.value ?? "",
credential: credentialJson credential: credentialJson
} }
} }