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
@@ -253,18 +253,14 @@ const GroupRolesForm = ({ projectRoles, roles, groupId, onClose }: FormProps) =>
};
});
try {
await updateGroupWorkspaceRole.mutateAsync({
projectId: currentProject?.id || "",
groupId,
roles: selectedRoles
});
createNotification({ text: "Successfully updated group role", type: "success" });
onClose();
setSearchRoles("");
} catch {
createNotification({ text: "Failed to update group role", type: "error" });
}
await updateGroupWorkspaceRole.mutateAsync({
projectId: currentProject?.id || "",
groupId,
roles: selectedRoles
});
createNotification({ text: "Successfully updated group role", type: "success" });
onClose();
setSearchRoles("");
};
return (
@@ -77,17 +77,12 @@ export const ProjectRoleList = () => {
const handleRoleDelete = async () => {
const { id } = popUp?.deleteRole?.data as TProjectRole;
try {
await deleteRole({
projectId,
id
});
createNotification({ type: "success", text: "Successfully removed the role" });
handlePopUpClose("deleteRole");
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to delete role" });
}
await deleteRole({
projectId,
id
});
createNotification({ type: "success", text: "Successfully removed the role" });
handlePopUpClose("deleteRole");
};
const {
@@ -131,33 +131,28 @@ export const IdentityProjectAdditionalPrivilegeModifySection = ({
temporaryAccessStartTime: el.temporaryAccess.temporaryAccessStartTime
};
try {
if (isCreate) {
await createIdentityProjectAdditionalPrivilege({
permissions: formRolePermission2API(el.permissions),
identityId,
projectId,
slug: el.slug || undefined,
type: accessType
});
createNotification({ type: "success", text: "Successfully created privilege" });
} else {
if (!projectId || !privilegeDetails?.id) return;
await updateIdentityProjectAdditionalPrivilege({
privilegeId: privilegeDetails.id,
permissions: formRolePermission2API(el.permissions),
projectId,
identityId,
slug: el.slug || undefined,
type: accessType
});
createNotification({ type: "success", text: "Successfully updated privilege" });
}
onGoBack();
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to update privilege" });
if (isCreate) {
await createIdentityProjectAdditionalPrivilege({
permissions: formRolePermission2API(el.permissions),
identityId,
projectId,
slug: el.slug || undefined,
type: accessType
});
createNotification({ type: "success", text: "Successfully created privilege" });
} else {
if (!projectId || !privilegeDetails?.id) return;
await updateIdentityProjectAdditionalPrivilege({
privilegeId: privilegeDetails.id,
permissions: formRolePermission2API(el.permissions),
projectId,
identityId,
slug: el.slug || undefined,
type: accessType
});
createNotification({ type: "success", text: "Successfully updated privilege" });
}
onGoBack();
};
const privilegeTemporaryAccess = form.watch("temporaryAccess");
@@ -57,18 +57,13 @@ export const IdentityProjectAdditionalPrivilegeSection = ({ identityMembershipDe
const handlePrivilegeDelete = async () => {
const { id } = popUp?.deletePrivilege?.data as { id: string };
try {
await deletePrivilege({
privilegeId: id,
projectId,
identityId
});
createNotification({ type: "success", text: "Successfully removed the privilege" });
handlePopUpClose("deletePrivilege");
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to delete privilege" });
}
await deletePrivilege({
privilegeId: id,
projectId,
identityId
});
createNotification({ type: "success", text: "Successfully removed the privilege" });
handlePopUpClose("deletePrivilege");
};
return (
@@ -50,42 +50,37 @@ export const IdentityRoleDetailsSection = ({
const handleRoleDelete = async () => {
const { id } = popUp?.deleteRole?.data as TProjectRole;
try {
const updatedRoles = identityMembershipDetails?.roles?.filter((el) => el.id !== id);
await updateIdentityWorkspaceRole({
projectId: currentProject?.id || "",
identityId: identityMembershipDetails.identity.id,
roles: updatedRoles.map(
({
role,
customRoleSlug,
isTemporary,
temporaryMode,
temporaryRange,
temporaryAccessStartTime,
temporaryAccessEndTime
}) => ({
role: role === "custom" ? customRoleSlug : role,
...(isTemporary
? {
isTemporary,
temporaryMode,
temporaryRange,
temporaryAccessStartTime,
temporaryAccessEndTime
}
: {
isTemporary
})
})
)
});
createNotification({ type: "success", text: "Successfully removed role" });
handlePopUpClose("deleteRole");
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to delete role" });
}
const updatedRoles = identityMembershipDetails?.roles?.filter((el) => el.id !== id);
await updateIdentityWorkspaceRole({
projectId: currentProject?.id || "",
identityId: identityMembershipDetails.identity.id,
roles: updatedRoles.map(
({
role,
customRoleSlug,
isTemporary,
temporaryMode,
temporaryRange,
temporaryAccessStartTime,
temporaryAccessEndTime
}) => ({
role: role === "custom" ? customRoleSlug : role,
...(isTemporary
? {
isTemporary,
temporaryMode,
temporaryRange,
temporaryAccessStartTime,
temporaryAccessEndTime
}
: {
isTemporary
})
})
)
});
createNotification({ type: "success", text: "Successfully removed role" });
handlePopUpClose("deleteRole");
};
return (
@@ -60,17 +60,12 @@ export const MemberProjectAdditionalPrivilegeSection = ({ membershipDetails }: P
const handlePrivilegeDelete = async () => {
const { id } = popUp?.deletePrivilege?.data as { id: string };
try {
await deletePrivilege({
privilegeId: id,
projectMembershipId: membershipDetails.id
});
createNotification({ type: "success", text: "Successfully removed the privilege" });
handlePopUpClose("deletePrivilege");
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to delete privilege" });
}
await deletePrivilege({
privilegeId: id,
projectMembershipId: membershipDetails.id
});
createNotification({ type: "success", text: "Successfully removed the privilege" });
handlePopUpClose("deletePrivilege");
};
return (
@@ -129,31 +129,26 @@ export const MembershipProjectAdditionalPrivilegeModifySection = ({
temporaryAccessStartTime: el.temporaryAccess.temporaryAccessStartTime
};
try {
if (isCreate) {
await createUserProjectAdditionalPrivilege({
permissions: formRolePermission2API(el.permissions),
projectMembershipId,
slug: el.slug || undefined,
type: accessType
});
createNotification({ type: "success", text: "Successfully created privilege" });
} else {
if (!projectId || !privilegeDetails?.id) return;
await updateUserProjectAdditionalPrivilege({
privilegeId: privilegeDetails.id,
permissions: formRolePermission2API(el.permissions),
projectMembershipId,
slug: el.slug || undefined,
type: accessType
});
createNotification({ type: "success", text: "Successfully updated privilege" });
}
onGoBack();
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to update privilege" });
if (isCreate) {
await createUserProjectAdditionalPrivilege({
permissions: formRolePermission2API(el.permissions),
projectMembershipId,
slug: el.slug || undefined,
type: accessType
});
createNotification({ type: "success", text: "Successfully created privilege" });
} else {
if (!projectId || !privilegeDetails?.id) return;
await updateUserProjectAdditionalPrivilege({
privilegeId: privilegeDetails.id,
permissions: formRolePermission2API(el.permissions),
projectMembershipId,
slug: el.slug || undefined,
type: accessType
});
createNotification({ type: "success", text: "Successfully updated privilege" });
}
onGoBack();
};
const privilegeTemporaryAccess = form.watch("temporaryAccess");
@@ -122,19 +122,14 @@ export const RolePermissionsSection = ({ roleSlug, isDisabled }: Props) => {
const { mutateAsync: updateRole } = useUpdateProjectRole();
const onSubmit = async (el: TFormSchema) => {
try {
if (!projectId || !role?.id) return;
await updateRole({
id: role?.id as string,
projectId,
...el,
permissions: formRolePermission2API(el.permissions)
});
createNotification({ type: "success", text: "Successfully updated role" });
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to update role" });
}
if (!projectId || !role?.id) return;
await updateRole({
id: role?.id as string,
projectId,
...el,
permissions: formRolePermission2API(el.permissions)
});
createNotification({ type: "success", text: "Successfully updated role" });
};
const isCustomRole = !Object.values(ProjectMembershipRole).includes(