mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-20 21:18:18 +00:00
refactor: streamline modal close handlers and completion callbacks across various components
This commit is contained in:
@@ -17,28 +17,17 @@ export const DeleteKmipClientModal = ({ isOpen, onOpenChange, kmipClient }: Prop
|
||||
const { id, projectId, name } = kmipClient;
|
||||
|
||||
const handleDeleteKmipClient = async () => {
|
||||
try {
|
||||
await deleteKmipClients.mutateAsync({
|
||||
id,
|
||||
projectId
|
||||
});
|
||||
await deleteKmipClients.mutateAsync({
|
||||
id,
|
||||
projectId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: "KMIP client successfully deleted",
|
||||
type: "success"
|
||||
});
|
||||
createNotification({
|
||||
text: "KMIP client successfully deleted",
|
||||
type: "success"
|
||||
});
|
||||
|
||||
onOpenChange(false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
const error = err as any;
|
||||
const text = error?.response?.data?.message ?? "Failed to delete KMIP client";
|
||||
|
||||
createNotification({
|
||||
text,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -98,20 +98,12 @@ const KmipClientForm = ({ onComplete, kmipClient }: FormProps) => {
|
||||
.map(([key]) => key as KmipPermission)
|
||||
});
|
||||
|
||||
try {
|
||||
await mutation;
|
||||
createNotification({
|
||||
text: `Successfully ${isUpdate ? "updated" : "added"} KMIP client`,
|
||||
type: "success"
|
||||
});
|
||||
onComplete();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
text: `Failed to ${isUpdate ? "update" : "add"} KMIP client`,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
await mutation;
|
||||
createNotification({
|
||||
text: `Successfully ${isUpdate ? "updated" : "added"} KMIP client`,
|
||||
type: "success"
|
||||
});
|
||||
onComplete();
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -52,23 +52,15 @@ const DecryptForm = ({ cmek }: FormProps) => {
|
||||
});
|
||||
|
||||
const handleDecryptData = async (formData: FormData) => {
|
||||
try {
|
||||
const data = await cmekDecrypt.mutateAsync({ ...formData, keyId: cmek.id });
|
||||
createNotification({
|
||||
text: "Successfully decrypted data",
|
||||
type: "success"
|
||||
});
|
||||
const data = await cmekDecrypt.mutateAsync({ ...formData, keyId: cmek.id });
|
||||
createNotification({
|
||||
text: "Successfully decrypted data",
|
||||
type: "success"
|
||||
});
|
||||
|
||||
setPlaintext(
|
||||
shouldDecode ? Buffer.from(decodeBase64(data.plaintext)).toString("utf8") : data.plaintext
|
||||
);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
text: "Failed to decrypt data",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
setPlaintext(
|
||||
shouldDecode ? Buffer.from(decodeBase64(data.plaintext)).toString("utf8") : data.plaintext
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -53,19 +53,11 @@ const EncryptForm = ({ cmek }: FormProps) => {
|
||||
});
|
||||
|
||||
const handleEncryptData = async (formData: FormData) => {
|
||||
try {
|
||||
await cmekEncrypt.mutateAsync({ ...formData, keyId: cmek.id });
|
||||
createNotification({
|
||||
text: "Successfully encrypted data",
|
||||
type: "success"
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
text: "Failed to encrypt data",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
await cmekEncrypt.mutateAsync({ ...formData, keyId: cmek.id });
|
||||
createNotification({
|
||||
text: "Successfully encrypted data",
|
||||
type: "success"
|
||||
});
|
||||
};
|
||||
|
||||
const ciphertext = cmekEncrypt.data?.ciphertext;
|
||||
|
||||
@@ -86,20 +86,12 @@ const CmekForm = ({ onComplete, cmek }: FormProps) => {
|
||||
encryptionAlgorithm: encryptionAlgorithm as AsymmetricKeyAlgorithm | SymmetricKeyAlgorithm
|
||||
});
|
||||
|
||||
try {
|
||||
await mutation;
|
||||
createNotification({
|
||||
text: `Successfully ${isUpdate ? "updated" : "added"} key`,
|
||||
type: "success"
|
||||
});
|
||||
onComplete();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
text: `Failed to ${isUpdate ? "update" : "add"} key`,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
await mutation;
|
||||
createNotification({
|
||||
text: `Successfully ${isUpdate ? "updated" : "added"} key`,
|
||||
type: "success"
|
||||
});
|
||||
onComplete();
|
||||
};
|
||||
|
||||
const selectedKeyUsage = watch("keyUsage");
|
||||
|
||||
@@ -59,19 +59,11 @@ const SignForm = ({ cmek }: FormProps) => {
|
||||
});
|
||||
|
||||
const handleSignData = async (formData: FormData) => {
|
||||
try {
|
||||
await cmekSign.mutateAsync({ ...formData, keyId: cmek.id });
|
||||
createNotification({
|
||||
text: "Successfully signed data",
|
||||
type: "success"
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
createNotification({
|
||||
text: "Failed to sign data",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
await cmekSign.mutateAsync({ ...formData, keyId: cmek.id });
|
||||
createNotification({
|
||||
text: "Successfully signed data",
|
||||
type: "success"
|
||||
});
|
||||
};
|
||||
|
||||
const signature = cmekSign.data?.signature;
|
||||
|
||||
@@ -152,28 +152,16 @@ export const CmekTable = () => {
|
||||
const updateCmek = useUpdateCmek();
|
||||
|
||||
const handleDisableCmek = async ({ id: keyId, isDisabled }: TCmek) => {
|
||||
try {
|
||||
await updateCmek.mutateAsync({
|
||||
keyId,
|
||||
projectId,
|
||||
isDisabled: !isDisabled
|
||||
});
|
||||
await updateCmek.mutateAsync({
|
||||
keyId,
|
||||
projectId,
|
||||
isDisabled: !isDisabled
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: `Key successfully ${isDisabled ? "enabled" : "disabled"}`,
|
||||
type: "success"
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
const error = err as any;
|
||||
const text =
|
||||
error?.response?.data?.message ?? `Failed to ${isDisabled ? "enable" : "disable"} key`;
|
||||
|
||||
createNotification({
|
||||
text,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
createNotification({
|
||||
text: `Key successfully ${isDisabled ? "enabled" : "disabled"}`,
|
||||
type: "success"
|
||||
});
|
||||
};
|
||||
|
||||
const cannotEditKey = permission.cannot(
|
||||
|
||||
@@ -69,25 +69,17 @@ const VerifyForm = ({ cmek }: FormProps) => {
|
||||
});
|
||||
|
||||
const handleVerifyData = async (formData: FormData) => {
|
||||
try {
|
||||
const result = await cmekVerify.mutateAsync({ ...formData, keyId: cmek.id });
|
||||
const result = await cmekVerify.mutateAsync({ ...formData, keyId: cmek.id });
|
||||
|
||||
if (result.signatureValid) {
|
||||
createNotification({
|
||||
text: "Successfully verified signature",
|
||||
type: "success"
|
||||
});
|
||||
} else {
|
||||
createNotification({
|
||||
title: "Signature Verification Failed",
|
||||
text: "The signature is invalid. The signature was not created using the same signing algorithm and key as the one used to sign the data. The data and signature may have been tampered with.",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
if (result.signatureValid) {
|
||||
createNotification({
|
||||
text: "Failed to sign data",
|
||||
text: "Successfully verified signature",
|
||||
type: "success"
|
||||
});
|
||||
} else {
|
||||
createNotification({
|
||||
title: "Signature Verification Failed",
|
||||
text: "The signature is invalid. The signature was not created using the same signing algorithm and key as the one used to sign the data. The data and signature may have been tampered with.",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,28 +16,17 @@ export const DeleteCmekModal = ({ isOpen, onOpenChange, cmek }: Props) => {
|
||||
const { id: keyId, projectId, name } = cmek;
|
||||
|
||||
const handleDeleteCmek = async () => {
|
||||
try {
|
||||
await deleteCmek.mutateAsync({
|
||||
keyId,
|
||||
projectId
|
||||
});
|
||||
await deleteCmek.mutateAsync({
|
||||
keyId,
|
||||
projectId
|
||||
});
|
||||
|
||||
createNotification({
|
||||
text: "Key successfully deleted",
|
||||
type: "success"
|
||||
});
|
||||
createNotification({
|
||||
text: "Key successfully deleted",
|
||||
type: "success"
|
||||
});
|
||||
|
||||
onOpenChange(false);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
const error = err as any;
|
||||
const text = error?.response?.data?.message ?? "Failed to delete key";
|
||||
|
||||
createNotification({
|
||||
text,
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
onOpenChange(false);
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user