refactor: streamline error handling and notification logic across various components

This commit is contained in:
Victor Santos
2025-11-03 11:12:38 -03:00
parent eba04e4278
commit 1ed59a7304
61 changed files with 843 additions and 1375 deletions
@@ -42,36 +42,25 @@ export const Page = () => {
] as const);
const onDeleteOrgRoleSubmit = async () => {
try {
if (!orgId || !roleId) return;
if (!orgId || !roleId) return;
await deleteOrgRole({
orgId,
id: roleId
});
await deleteOrgRole({
orgId,
id: roleId
});
createNotification({
text: "Successfully deleted organization role",
type: "success"
});
createNotification({
text: "Successfully deleted organization role",
type: "success"
});
handlePopUpClose("deleteOrgRole");
navigate({
to: "/organization/access-management" as const,
search: {
selectedTab: OrgAccessControlTabSections.Roles
}
});
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to delete organization role";
createNotification({
text,
type: "error"
});
}
handlePopUpClose("deleteOrgRole");
navigate({
to: "/organization/access-management" as const,
search: {
selectedTab: OrgAccessControlTabSections.Roles
}
});
};
const isCustomRole = !["admin", "member", "no-access"].includes(data?.slug ?? "");
@@ -70,55 +70,46 @@ export const RoleModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [role]);
const onFormSubmit = async ({ name, description, slug }: FormData) => {
try {
if (!orgId) return;
if (!orgId) return;
if (role) {
// update
if (role) {
// update
await updateOrgRole({
orgId,
id: role.id,
name,
description,
slug
});
handlePopUpToggle("role", false);
} else {
// create
const newRole = await createOrgRole({
orgId,
name,
description,
slug,
permissions: []
});
handlePopUpToggle("role", false);
navigate({
to: "/organization/roles/$roleId",
params: {
roleId: newRole.id
}
});
}
createNotification({
text: `Successfully ${popUp?.role?.data ? "updated" : "created"} role`,
type: "success"
await updateOrgRole({
orgId,
id: role.id,
name,
description,
slug
});
reset();
} catch {
const text = `Failed to ${popUp?.role?.data ? "update" : "create"} role`;
handlePopUpToggle("role", false);
} else {
// create
createNotification({
text,
type: "error"
const newRole = await createOrgRole({
orgId,
name,
description,
slug,
permissions: []
});
handlePopUpToggle("role", false);
navigate({
to: "/organization/roles/$roleId",
params: {
roleId: newRole.id
}
});
}
createNotification({
text: `Successfully ${popUp?.role?.data ? "updated" : "created"} role`,
type: "success"
});
reset();
};
return (