refactor: enhance notification handling and streamline async logic across secret management components

This commit is contained in:
Victor Santos
2025-11-03 18:24:35 -03:00
parent edd34f5561
commit a73ba232ab
65 changed files with 1159 additions and 1714 deletions
@@ -64,39 +64,32 @@ export const IPAllowlistModal = ({ popUp, handlePopUpClose, handlePopUpToggle }:
}, [popUp?.trustedIp?.data]);
const onIPAllowlistModalSubmit = async ({ ipAddress, comment }: FormData) => {
try {
if (!currentProject?.id) return;
if (!currentProject?.id) return;
if (popUp?.trustedIp?.data) {
await updateTrustedIp.mutateAsync({
projectId: currentProject.id,
trustedIpId: (popUp?.trustedIp?.data as { trustedIpId: string })?.trustedIpId,
ipAddress,
comment,
isActive: true
});
} else {
await addTrustedIp.mutateAsync({
projectId: currentProject.id,
ipAddress,
comment,
isActive: true
});
}
createNotification({
text: `Successfully ${popUp?.trustedIp?.data ? "updated" : "added"} trusted IP`,
type: "success"
if (popUp?.trustedIp?.data) {
await updateTrustedIp.mutateAsync({
projectId: currentProject.id,
trustedIpId: (popUp?.trustedIp?.data as { trustedIpId: string })?.trustedIpId,
ipAddress,
comment,
isActive: true
});
reset();
handlePopUpClose("trustedIp");
} catch {
createNotification({
text: `Failed to ${popUp?.trustedIp?.data ? "update" : "add"} trusted IP`,
type: "error"
} else {
await addTrustedIp.mutateAsync({
projectId: currentProject.id,
ipAddress,
comment,
isActive: true
});
}
createNotification({
text: `Successfully ${popUp?.trustedIp?.data ? "updated" : "added"} trusted IP`,
type: "success"
});
reset();
handlePopUpClose("trustedIp");
};
return (
@@ -29,27 +29,19 @@ export const IPAllowlistSection = () => {
] as const);
const onDeleteTrustedIpSubmit = async (trustedIpId: string) => {
try {
if (!currentProject?.id) return;
if (!currentProject?.id) return;
await mutateAsync({
projectId: currentProject.id,
trustedIpId
});
await mutateAsync({
projectId: currentProject.id,
trustedIpId
});
createNotification({
text: "Successfully deleted IP access range",
type: "success"
});
createNotification({
text: "Successfully deleted IP access range",
type: "success"
});
handlePopUpClose("deleteTrustedIp");
} catch (err) {
console.log(err);
createNotification({
text: "Failed to delete IP access range",
type: "error"
});
}
handlePopUpClose("deleteTrustedIp");
};
return (