refactor: streamline modal close handlers and completion callbacks across various components

This commit is contained in:
Victor Santos
2025-10-31 18:43:34 -03:00
parent 7d8b28367e
commit b26fb73053
116 changed files with 1865 additions and 2949 deletions
@@ -48,29 +48,22 @@ export const ExternalCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
}, []);
const onFormSubmit = async ({ certificate, certificateChain }: FormData) => {
try {
if (!csr || !caId || !currentProject?.slug) return;
if (!csr || !caId || !currentProject?.slug) return;
await importCaCertificate({
caId,
projectSlug: currentProject?.slug,
certificate,
certificateChain
});
await importCaCertificate({
caId,
projectSlug: currentProject?.slug,
certificate,
certificateChain
});
reset();
reset();
createNotification({
text: "Successfully installed certificate for CA",
type: "success"
});
handlePopUpToggle("installCaCert", false);
} catch {
createNotification({
text: "Failed to install certificate for CA",
type: "error"
});
}
createNotification({
text: "Successfully installed certificate for CA",
type: "success"
});
handlePopUpToggle("installCaCert", false);
};
const downloadTxtFile = (filename: string, content: string) => {
@@ -101,37 +101,30 @@ export const InternalCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
}, [parentCa]);
const onFormSubmit = async ({ notAfter, maxPathLength }: FormData) => {
try {
if (!csr || !caId || !currentProject?.slug) return;
if (!csr || !caId || !currentProject?.slug) return;
const { certificate, certificateChain } = await signIntermediate({
caId: parentCaId,
csr,
maxPathLength: Number(maxPathLength),
notAfter,
notBefore: new Date().toISOString()
});
const { certificate, certificateChain } = await signIntermediate({
caId: parentCaId,
csr,
maxPathLength: Number(maxPathLength),
notAfter,
notBefore: new Date().toISOString()
});
await importCaCertificate({
caId,
projectSlug: currentProject?.slug,
certificate,
certificateChain
});
await importCaCertificate({
caId,
projectSlug: currentProject?.slug,
certificate,
certificateChain
});
reset();
reset();
createNotification({
text: "Successfully installed certificate for CA",
type: "success"
});
handlePopUpToggle("installCaCert", false);
} catch {
createNotification({
text: "Failed to install certificate for CA",
type: "error"
});
}
createNotification({
text: "Successfully installed certificate for CA",
type: "success"
});
handlePopUpToggle("installCaCert", false);
};
function generatePathLengthOpts(parentCaMaxPathLength: number): number[] {
@@ -175,48 +175,40 @@ export const CaModal = ({ popUp, handlePopUpToggle }: Props) => {
status,
configuration
}: FormData) => {
try {
if (!currentProject?.slug) return;
if (!currentProject?.slug) return;
if (ca) {
// update
await updateMutateAsync({
caName: ca.name,
projectId: currentProject.id,
name,
type: CaType.INTERNAL,
status,
enableDirectIssuance
});
} else {
// create
await createMutateAsync({
projectId: currentProject.id,
name,
type,
status,
enableDirectIssuance,
configuration: {
...configuration,
maxPathLength: Number(configuration.maxPathLength)
}
});
}
reset();
handlePopUpToggle("ca", false);
createNotification({
text: `Successfully ${ca ? "updated" : "created"} CA`,
type: "success"
if (ca) {
// update
await updateMutateAsync({
caName: ca.name,
projectId: currentProject.id,
name,
type: CaType.INTERNAL,
status,
enableDirectIssuance
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to create CA",
type: "error"
} else {
// create
await createMutateAsync({
projectId: currentProject.id,
name,
type,
status,
enableDirectIssuance,
configuration: {
...configuration,
maxPathLength: Number(configuration.maxPathLength)
}
});
}
reset();
handlePopUpToggle("ca", false);
createNotification({
text: `Successfully ${ca ? "updated" : "created"} CA`,
type: "success"
});
};
return (
@@ -29,44 +29,29 @@ export const CaSection = () => {
] as const);
const onRemoveCaSubmit = async (caName: string) => {
try {
if (!currentProject?.slug) return;
if (!currentProject?.slug) return;
await deleteCa({ caName, projectId: currentProject.id, type: CaType.INTERNAL });
await deleteCa({ caName, projectId: currentProject.id, type: CaType.INTERNAL });
createNotification({
text: "Successfully deleted CA",
type: "success"
});
createNotification({
text: "Successfully deleted CA",
type: "success"
});
handlePopUpClose("deleteCa");
} catch {
createNotification({
text: "Failed to delete CA",
type: "error"
});
}
handlePopUpClose("deleteCa");
};
const onUpdateCaStatus = async ({ caName, status }: { caName: string; status: CaStatus }) => {
try {
if (!currentProject?.slug) return;
if (!currentProject?.slug) return;
await updateCa({ caName, projectId: currentProject.id, type: CaType.INTERNAL, status });
await updateCa({ caName, projectId: currentProject.id, type: CaType.INTERNAL, status });
createNotification({
text: `Successfully ${status === CaStatus.ACTIVE ? "enabled" : "disabled"} CA`,
type: "success"
});
createNotification({
text: `Successfully ${status === CaStatus.ACTIVE ? "enabled" : "disabled"} CA`,
type: "success"
});
handlePopUpClose("caStatus");
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${status === CaStatus.ACTIVE ? "enabled" : "disabled"} CA`,
type: "error"
});
}
handlePopUpClose("caStatus");
};
return (
@@ -297,63 +297,55 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
status,
configuration: formConfiguration
}: FormData) => {
try {
if (!currentProject?.slug) return;
if (!currentProject?.slug) return;
let configPayload: any;
let configPayload: any;
if (type === CaType.ACME && "dnsAppConnection" in formConfiguration) {
configPayload = {
dnsProviderConfig: formConfiguration.dnsProviderConfig,
directoryUrl: formConfiguration.directoryUrl,
accountEmail: formConfiguration.accountEmail,
dnsAppConnectionId: formConfiguration.dnsAppConnection.id,
eabKid: formConfiguration.eabKid,
eabHmacKey: formConfiguration.eabHmacKey
};
} else if (type === CaType.AZURE_AD_CS && "azureAdcsConnection" in formConfiguration) {
configPayload = {
azureAdcsConnectionId: formConfiguration.azureAdcsConnection.id
};
} else {
throw new Error("Invalid certificate authority configuration");
}
if (type === CaType.ACME && "dnsAppConnection" in formConfiguration) {
configPayload = {
dnsProviderConfig: formConfiguration.dnsProviderConfig,
directoryUrl: formConfiguration.directoryUrl,
accountEmail: formConfiguration.accountEmail,
dnsAppConnectionId: formConfiguration.dnsAppConnection.id,
eabKid: formConfiguration.eabKid,
eabHmacKey: formConfiguration.eabHmacKey
};
} else if (type === CaType.AZURE_AD_CS && "azureAdcsConnection" in formConfiguration) {
configPayload = {
azureAdcsConnectionId: formConfiguration.azureAdcsConnection.id
};
} else {
throw new Error("Invalid certificate authority configuration");
}
if (ca) {
await updateMutateAsync({
caName: ca.name,
projectId: currentProject.id,
name,
type,
status,
enableDirectIssuance: type === CaType.AZURE_AD_CS ? false : enableDirectIssuance,
configuration: configPayload
});
} else {
await createMutateAsync({
projectId: currentProject.id,
name,
type,
status,
enableDirectIssuance: type === CaType.AZURE_AD_CS ? false : enableDirectIssuance,
configuration: configPayload
});
}
reset();
handlePopUpToggle("ca", false);
createNotification({
text: `Successfully ${ca ? "updated" : "created"} CA`,
type: "success"
if (ca) {
await updateMutateAsync({
caName: ca.name,
projectId: currentProject.id,
name,
type,
status,
enableDirectIssuance: type === CaType.AZURE_AD_CS ? false : enableDirectIssuance,
configuration: configPayload
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to create CA",
type: "error"
} else {
await createMutateAsync({
projectId: currentProject.id,
name,
type,
status,
enableDirectIssuance: type === CaType.AZURE_AD_CS ? false : enableDirectIssuance,
configuration: configPayload
});
}
reset();
handlePopUpToggle("ca", false);
createNotification({
text: `Successfully ${ca ? "updated" : "created"} CA`,
type: "success"
});
};
return (
@@ -25,23 +25,16 @@ export const ExternalCaSection = () => {
] as const);
const onRemoveCaSubmit = async (caName: string, type: CaType) => {
try {
if (!currentProject?.id) return;
if (!currentProject?.id) return;
await deleteCa({ caName, type, projectId: currentProject.id });
await deleteCa({ caName, type, projectId: currentProject.id });
createNotification({
text: "Successfully deleted CA",
type: "success"
});
createNotification({
text: "Successfully deleted CA",
type: "success"
});
handlePopUpClose("deleteCa");
} catch {
createNotification({
text: "Failed to delete CA",
type: "error"
});
}
handlePopUpClose("deleteCa");
};
const onUpdateCaStatus = async ({
@@ -53,24 +46,16 @@ export const ExternalCaSection = () => {
type: CaType;
status: CaStatus;
}) => {
try {
if (!currentProject?.slug) return;
if (!currentProject?.slug) return;
await updateCa({ caName: name, type, status, projectId: currentProject.id });
await updateCa({ caName: name, type, status, projectId: currentProject.id });
createNotification({
text: `Successfully ${status === CaStatus.ACTIVE ? "enabled" : "disabled"} CA`,
type: "success"
});
createNotification({
text: `Successfully ${status === CaStatus.ACTIVE ? "enabled" : "disabled"} CA`,
type: "success"
});
handlePopUpClose("caStatus");
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${status === CaStatus.ACTIVE ? "enable" : "disable"} CA`,
type: "error"
});
}
handlePopUpClose("caStatus");
};
return (