mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-21 15:28:12 +00:00
refactor: streamline modal close handlers and completion callbacks across various components
This commit is contained in:
+9
-16
@@ -51,22 +51,15 @@ export const CertificateProfilesTab = () => {
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (!selectedProfile) return;
|
||||
|
||||
try {
|
||||
await deleteProfile.mutateAsync({
|
||||
profileId: selectedProfile.id
|
||||
});
|
||||
setIsDeleteModalOpen(false);
|
||||
setSelectedProfile(null);
|
||||
createNotification({
|
||||
text: `Certificate profile "${selectedProfile.slug}" deleted successfully`,
|
||||
type: "success"
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Failed to delete profile "${selectedProfile.slug}" (ID: ${selectedProfile.id}):`,
|
||||
error
|
||||
);
|
||||
}
|
||||
await deleteProfile.mutateAsync({
|
||||
profileId: selectedProfile.id
|
||||
});
|
||||
setIsDeleteModalOpen(false);
|
||||
setSelectedProfile(null);
|
||||
createNotification({
|
||||
text: `Certificate profile "${selectedProfile.slug}" deleted successfully`,
|
||||
type: "success"
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
+44
-52
@@ -236,64 +236,56 @@ export const CreateProfileModal = ({ isOpen, onClose, profile, mode = "create" }
|
||||
}, [isEdit, profile, reset]);
|
||||
|
||||
const onFormSubmit = async (data: FormData) => {
|
||||
try {
|
||||
if (!currentProject?.id && !isEdit) return;
|
||||
if (!currentProject?.id && !isEdit) return;
|
||||
|
||||
if (isEdit) {
|
||||
const updateData: TUpdateCertificateProfileDTO = {
|
||||
profileId: profile.id,
|
||||
slug: data.slug,
|
||||
description: data.description
|
||||
};
|
||||
if (isEdit) {
|
||||
const updateData: TUpdateCertificateProfileDTO = {
|
||||
profileId: profile.id,
|
||||
slug: data.slug,
|
||||
description: data.description
|
||||
};
|
||||
|
||||
if (data.enrollmentType === "est" && data.estConfig) {
|
||||
updateData.estConfig = data.estConfig;
|
||||
} else if (data.enrollmentType === "api" && data.apiConfig) {
|
||||
updateData.apiConfig = data.apiConfig;
|
||||
}
|
||||
|
||||
await updateProfile.mutateAsync(updateData);
|
||||
} else {
|
||||
if (!currentProject?.id) {
|
||||
throw new Error("Project ID is required for creating a profile");
|
||||
}
|
||||
|
||||
const createData: TCreateCertificateProfileDTO = {
|
||||
projectId: currentProject.id,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
enrollmentType: data.enrollmentType,
|
||||
caId: data.certificateAuthorityId,
|
||||
certificateTemplateId: data.certificateTemplateId
|
||||
};
|
||||
|
||||
if (data.enrollmentType === "est" && data.estConfig) {
|
||||
createData.estConfig = {
|
||||
passphrase: data.estConfig.passphrase,
|
||||
caChain: data.estConfig.caChain || undefined,
|
||||
disableBootstrapCaValidation: data.estConfig.disableBootstrapCaValidation
|
||||
};
|
||||
} else if (data.enrollmentType === "api" && data.apiConfig) {
|
||||
createData.apiConfig = data.apiConfig;
|
||||
}
|
||||
|
||||
await createProfile.mutateAsync(createData);
|
||||
if (data.enrollmentType === "est" && data.estConfig) {
|
||||
updateData.estConfig = data.estConfig;
|
||||
} else if (data.enrollmentType === "api" && data.apiConfig) {
|
||||
updateData.apiConfig = data.apiConfig;
|
||||
}
|
||||
|
||||
createNotification({
|
||||
text: `Certificate profile ${isEdit ? "updated" : "created"} successfully`,
|
||||
type: "success"
|
||||
});
|
||||
await updateProfile.mutateAsync(updateData);
|
||||
} else {
|
||||
if (!currentProject?.id) {
|
||||
throw new Error("Project ID is required for creating a profile");
|
||||
}
|
||||
|
||||
reset();
|
||||
onClose();
|
||||
} catch (error) {
|
||||
console.error(`Error ${isEdit ? "updating" : "creating"} profile:`, error);
|
||||
createNotification({
|
||||
text: `Failed to ${isEdit ? "update" : "create"} certificate profile`,
|
||||
type: "error"
|
||||
});
|
||||
const createData: TCreateCertificateProfileDTO = {
|
||||
projectId: currentProject.id,
|
||||
slug: data.slug,
|
||||
description: data.description,
|
||||
enrollmentType: data.enrollmentType,
|
||||
caId: data.certificateAuthorityId,
|
||||
certificateTemplateId: data.certificateTemplateId
|
||||
};
|
||||
|
||||
if (data.enrollmentType === "est" && data.estConfig) {
|
||||
createData.estConfig = {
|
||||
passphrase: data.estConfig.passphrase,
|
||||
caChain: data.estConfig.caChain || undefined,
|
||||
disableBootstrapCaValidation: data.estConfig.disableBootstrapCaValidation
|
||||
};
|
||||
} else if (data.enrollmentType === "api" && data.apiConfig) {
|
||||
createData.apiConfig = data.apiConfig;
|
||||
}
|
||||
|
||||
await createProfile.mutateAsync(createData);
|
||||
}
|
||||
|
||||
createNotification({
|
||||
text: `Certificate profile ${isEdit ? "updated" : "created"} successfully`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
onClose();
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
+9
-17
@@ -48,23 +48,15 @@ export const CertificateTemplatesV2Tab = () => {
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (!selectedTemplate) return;
|
||||
|
||||
try {
|
||||
await deleteTemplateV2.mutateAsync({
|
||||
templateId: selectedTemplate.id
|
||||
});
|
||||
setIsDeleteModalOpen(false);
|
||||
setSelectedTemplate(null);
|
||||
createNotification({
|
||||
text: `Certificate template "${selectedTemplate.name}" deleted successfully`,
|
||||
type: "success"
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to delete template:", error);
|
||||
createNotification({
|
||||
text: "Failed to delete certificate template",
|
||||
type: "error"
|
||||
});
|
||||
}
|
||||
await deleteTemplateV2.mutateAsync({
|
||||
templateId: selectedTemplate.id
|
||||
});
|
||||
setIsDeleteModalOpen(false);
|
||||
setSelectedTemplate(null);
|
||||
createNotification({
|
||||
text: `Certificate template "${selectedTemplate.name}" deleted successfully`,
|
||||
type: "success"
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
+38
-46
@@ -407,59 +407,51 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
|
||||
};
|
||||
|
||||
const onFormSubmit = async (data: FormData) => {
|
||||
try {
|
||||
if (!currentProject?.id && !isEdit) return;
|
||||
if (!currentProject?.id && !isEdit) return;
|
||||
|
||||
const hasEmptyAttributeValues = data.attributes?.some(
|
||||
(attr) => !attr.value || attr.value.length === 0 || attr.value.some((v) => !v.trim())
|
||||
);
|
||||
const hasEmptyAttributeValues = data.attributes?.some(
|
||||
(attr) => !attr.value || attr.value.length === 0 || attr.value.some((v) => !v.trim())
|
||||
);
|
||||
|
||||
const hasEmptySanValues = data.subjectAlternativeNames?.some(
|
||||
(san) => !san.value || san.value.length === 0 || san.value.some((v) => !v.trim())
|
||||
);
|
||||
|
||||
if (hasEmptyAttributeValues || hasEmptySanValues) {
|
||||
createNotification({
|
||||
text: "All values must be non-empty. Use wildcards (*) if needed.",
|
||||
type: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const transformedData = transformToApiFormat(data);
|
||||
|
||||
if (isEdit) {
|
||||
const updateData = {
|
||||
templateId: template.id,
|
||||
...transformedData
|
||||
};
|
||||
await updateTemplate.mutateAsync(updateData);
|
||||
} else {
|
||||
if (!currentProject?.id) {
|
||||
throw new Error("Project ID is required for creating a template");
|
||||
}
|
||||
|
||||
const createData = {
|
||||
projectId: currentProject.id,
|
||||
...transformedData
|
||||
};
|
||||
await createTemplate.mutateAsync(createData);
|
||||
}
|
||||
const hasEmptySanValues = data.subjectAlternativeNames?.some(
|
||||
(san) => !san.value || san.value.length === 0 || san.value.some((v) => !v.trim())
|
||||
);
|
||||
|
||||
if (hasEmptyAttributeValues || hasEmptySanValues) {
|
||||
createNotification({
|
||||
text: `Certificate template ${isEdit ? "updated" : "created"} successfully`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
onClose();
|
||||
} catch (error) {
|
||||
console.error(`Error ${isEdit ? "updating" : "creating"} template:`, error);
|
||||
createNotification({
|
||||
text: `Failed to ${isEdit ? "update" : "create"} certificate template`,
|
||||
text: "All values must be non-empty. Use wildcards (*) if needed.",
|
||||
type: "error"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const transformedData = transformToApiFormat(data);
|
||||
|
||||
if (isEdit) {
|
||||
const updateData = {
|
||||
templateId: template.id,
|
||||
...transformedData
|
||||
};
|
||||
await updateTemplate.mutateAsync(updateData);
|
||||
} else {
|
||||
if (!currentProject?.id) {
|
||||
throw new Error("Project ID is required for creating a template");
|
||||
}
|
||||
|
||||
const createData = {
|
||||
projectId: currentProject.id,
|
||||
...transformedData
|
||||
};
|
||||
await createTemplate.mutateAsync(createData);
|
||||
}
|
||||
|
||||
createNotification({
|
||||
text: `Certificate template ${isEdit ? "updated" : "created"} successfully`,
|
||||
type: "success"
|
||||
});
|
||||
|
||||
reset();
|
||||
onClose();
|
||||
};
|
||||
|
||||
const addAttribute = () => {
|
||||
|
||||
Reference in New Issue
Block a user