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
@@ -113,52 +113,44 @@ export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {
alertUnit,
emails
}: FormData) => {
try {
if (!projectId) return;
if (!projectId) return;
const emailArray = emails
.split(",")
.map((email) => email.trim())
.filter((email) => email.length > 0);
const emailArray = emails
.split(",")
.map((email) => email.trim())
.filter((email) => email.length > 0);
const alertBeforeDays = convertToDays(alertUnit, Number(alertBefore));
const alertBeforeDays = convertToDays(alertUnit, Number(alertBefore));
if (alert) {
// update
await updatePkiAlert({
alertId: alert.id,
pkiCollectionId,
name,
projectId,
alertBeforeDays,
emails: emailArray
});
} else {
// create
await createPkiAlert({
name,
projectId,
pkiCollectionId,
alertBeforeDays,
emails: emailArray
});
}
handlePopUpToggle("pkiAlert", false);
reset();
createNotification({
text: `Successfully ${alert ? "updated" : "created"} alert`,
type: "success"
if (alert) {
// update
await updatePkiAlert({
alertId: alert.id,
pkiCollectionId,
name,
projectId,
alertBeforeDays,
emails: emailArray
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${alert ? "updated" : "created"} alert`,
type: "error"
} else {
// create
await createPkiAlert({
name,
projectId,
pkiCollectionId,
alertBeforeDays,
emails: emailArray
});
}
handlePopUpToggle("pkiAlert", false);
reset();
createNotification({
text: `Successfully ${alert ? "updated" : "created"} alert`,
type: "success"
});
};
return (
@@ -22,27 +22,19 @@ export const PkiAlertsSection = () => {
] as const);
const onRemoveAlertSubmit = async (alertId: string) => {
try {
if (!projectId) return;
if (!projectId) return;
await deletePkiAlert({
alertId,
projectId
});
await deletePkiAlert({
alertId,
projectId
});
createNotification({
text: "Successfully deleted alert",
type: "success"
});
createNotification({
text: "Successfully deleted alert",
type: "success"
});
handlePopUpClose("deletePkiAlert");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete alert",
type: "error"
});
}
handlePopUpClose("deletePkiAlert");
};
return (
@@ -62,49 +62,41 @@ export const PkiCollectionModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [pkiCollection]);
const onFormSubmit = async ({ name, description }: FormData) => {
try {
if (!projectId) return;
if (!projectId) return;
if (pkiCollection) {
// update
await updatePkiCollection({
collectionId: pkiCollection.id,
name,
description,
projectId
});
} else {
// create
const { id: collectionId } = await createPkiCollection({
name,
description,
projectId
});
navigate({
to: "/projects/cert-management/$projectId/pki-collections/$collectionId",
params: {
projectId,
collectionId
}
});
}
handlePopUpToggle("pkiCollection", false);
reset();
createNotification({
text: `Successfully ${pkiCollection ? "updated" : "created"} PKI collection`,
type: "success"
if (pkiCollection) {
// update
await updatePkiCollection({
collectionId: pkiCollection.id,
name,
description,
projectId
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${pkiCollection ? "updated" : "created"} PKI collection`,
type: "error"
} else {
// create
const { id: collectionId } = await createPkiCollection({
name,
description,
projectId
});
navigate({
to: "/projects/cert-management/$projectId/pki-collections/$collectionId",
params: {
projectId,
collectionId
}
});
}
handlePopUpToggle("pkiCollection", false);
reset();
createNotification({
text: `Successfully ${pkiCollection ? "updated" : "created"} PKI collection`,
type: "success"
});
};
return (
@@ -22,27 +22,19 @@ export const PkiCollectionSection = () => {
] as const);
const onRemovePkiCollectionSubmit = async (collectionId: string) => {
try {
if (!projectId) return;
if (!projectId) return;
await deletePkiCollection({
collectionId,
projectId
});
await deletePkiCollection({
collectionId,
projectId
});
createNotification({
text: "Successfully deleted PKI collection",
type: "success"
});
createNotification({
text: "Successfully deleted PKI collection",
type: "success"
});
handlePopUpClose("deletePkiCollection");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete PKI collection",
type: "error"
});
}
handlePopUpClose("deletePkiCollection");
};
return (