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
@@ -25,7 +25,6 @@ const TotpRegistration = ({ onComplete, shouldCenterQr }: Props) => {
const handleTotpVerify = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
try {
const result = await verifyUserTotp({
totp
});
@@ -41,12 +40,6 @@ const TotpRegistration = ({ onComplete, shouldCenterQr }: Props) => {
} else if (onComplete) {
onComplete();
}
} catch {
createNotification({
text: "Failed to verify TOTP code",
type: "error"
});
}
};
const handleRecoveryDownloadComplete = async () => {
@@ -145,7 +145,6 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
};
const handleChangeRole = async ({ identityId, role }: { identityId: string; role: string }) => {
try {
await updateMutateAsync({
identityId,
role,
@@ -156,16 +155,6 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
text: "Successfully updated identity role",
type: "success"
});
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to update identity role";
createNotification({
text,
type: "error"
});
}
};
const handleRoleToggle = useCallback(
@@ -134,7 +134,6 @@ export const IdentityTlsCertAuthForm = ({
accessTokenNumUsesLimit,
accessTokenTrustedIps
}: FormData) => {
try {
if (!identityId) return;
if (data) {
@@ -169,12 +168,6 @@ export const IdentityTlsCertAuthForm = ({
});
reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
};
return (
@@ -127,7 +127,6 @@ export const IdentityTokenAuthForm = ({
accessTokenNumUsesLimit,
accessTokenTrustedIps
}: FormData) => {
try {
if (!identityId) return;
if (data) {
@@ -158,12 +157,6 @@ export const IdentityTokenAuthForm = ({
});
reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
}
};
return (
@@ -220,7 +220,6 @@ export const IdentityUniversalAuthForm = ({
lockoutCounterResetValue,
lockoutCounterResetUnit
}: FormData) => {
try {
if (!identityId) return;
const lockoutDurationSeconds = ms(`${lockoutDurationValue}${lockoutDurationUnit}`) / 1000;
@@ -270,14 +269,6 @@ export const IdentityUniversalAuthForm = ({
});
reset();
} catch {
const text = `Failed to ${isUpdate ? "update" : "configure"} identity`;
createNotification({
text,
type: "error"
});
}
};
return (
@@ -122,7 +122,6 @@ export const AddOrgMemberModal = ({
}
}
try {
const parsedEmails = emails
.replace(/\s/g, "")
.split(",")
@@ -171,14 +170,6 @@ export const AddOrgMemberModal = ({
type: "success"
});
}
} catch (error) {
console.error(error);
createNotification({
text: "Failed to invite user to org",
type: "error"
});
return;
}
if (serverDetails?.emailConfigured) {
handlePopUpToggle("addMember", false);
@@ -106,7 +106,6 @@ export const AddSubOrgMemberModal = ({ onClose }: Props) => {
}
}
try {
const usernames = users.map((el) => el.username);
await addUsersMutateAsync({
organizationId: currentOrg?.id,
@@ -125,13 +124,6 @@ export const AddSubOrgMemberModal = ({ onClose }: Props) => {
)
);
onClose();
} catch (error) {
console.error(error);
createNotification({
text: "Failed to add user to suborganization",
type: "error"
});
}
};
const getGroupHeaderLabel = (type: ProjectType) => {
@@ -44,7 +44,6 @@ export const UpgradePrivilegeSystemModal = ({ isOpen, onOpenChange }: Props) =>
acknowledgesPermanentChange;
const handlePrivilegeSystemUpgrade = async () => {
try {
await upgradePrivilegeSystem();
createNotification({
@@ -53,12 +52,6 @@ export const UpgradePrivilegeSystemModal = ({ isOpen, onOpenChange }: Props) =>
});
onOpenChange(false);
} catch {
createNotification({
text: "Failed to upgrade privilege system",
type: "error"
});
}
};
const handleClose = () => {
@@ -18,7 +18,6 @@ export const DeleteAppConnectionModal = ({ isOpen, onOpenChange, appConnection }
const { id: connectionId, name, app } = appConnection;
const handleDeleteAppConnection = async () => {
try {
await deleteAppConnection.mutateAsync({
connectionId,
app
@@ -30,14 +29,6 @@ export const DeleteAppConnectionModal = ({ isOpen, onOpenChange, appConnection }
});
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: `Failed to remove ${APP_CONNECTION_MAP[app].name} connection`,
type: "error"
});
}
};
return (
@@ -43,7 +43,6 @@ const Content = ({ appConnection, onComplete }: ContentProps) => {
} = form;
const onSubmit = async (formData: FormData) => {
try {
await updateAppConnection.mutateAsync({
connectionId: appConnection.id,
...formData
@@ -53,14 +52,6 @@ const Content = ({ appConnection, onComplete }: ContentProps) => {
type: "success"
});
onComplete();
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to update ${appName} Connection`,
text: err.message,
type: "error"
});
}
};
return (
@@ -127,12 +127,7 @@ export const OAuthCallbackPage = () => {
projectId,
connection
};
} catch (err: any) {
createNotification({
title: `Failed to ${connectionId ? "update" : "add"} GitLab Connection`,
text: err?.message,
type: "error"
});
} catch {
navigate({
to: returnUrl,
params: {
@@ -176,12 +171,7 @@ export const OAuthCallbackPage = () => {
}
});
}
} catch (err: any) {
createNotification({
title: `Failed to ${connectionId ? "update" : "add"} Azure Key Vault Connection`,
text: err?.message,
type: "error"
});
} catch {
navigate({
to: returnUrl,
params: {
@@ -233,12 +223,7 @@ export const OAuthCallbackPage = () => {
}
});
}
} catch (err: any) {
createNotification({
title: `Failed to ${connectionId ? "update" : "add"} Azure App Configuration Connection`,
text: err?.message,
type: "error"
});
} catch {
navigate({
to: returnUrl,
params: {
@@ -290,12 +275,7 @@ export const OAuthCallbackPage = () => {
}
});
}
} catch (err: any) {
createNotification({
title: `Failed to ${connectionId ? "update" : "add"} Azure Client Secrets Connection`,
text: err?.message,
type: "error"
});
} catch {
navigate({
to: returnUrl,
params: {
@@ -353,12 +333,7 @@ export const OAuthCallbackPage = () => {
}
});
}
} catch (err: any) {
createNotification({
title: `Failed to ${connectionId ? "update" : "add"} Azure DevOps Connection`,
text: err?.message,
type: "error"
});
} catch {
navigate({
to: returnUrl,
params: {
@@ -441,12 +416,7 @@ export const OAuthCallbackPage = () => {
})
});
}
} catch (e: any) {
createNotification({
title: `Failed to ${connectionId ? "update" : "add"} GitHub Connection`,
text: e.message,
type: "error"
});
} catch {
navigate({
to: returnUrl,
params: {
@@ -498,12 +468,7 @@ export const OAuthCallbackPage = () => {
}
});
}
} catch (e: any) {
createNotification({
title: `Failed to ${connectionId ? "update" : "add"} GitHub Radar Connection`,
text: e.message,
type: "error"
});
} catch {
navigate({
to: returnUrl,
params: {
@@ -553,12 +518,7 @@ export const OAuthCallbackPage = () => {
}
});
}
} catch (e: any) {
createNotification({
title: `Failed to ${connectionId ? "update" : "add"} Heroku Connection`,
text: e.message,
type: "error"
});
} catch {
navigate({
to: returnUrl,
params: {
@@ -35,7 +35,6 @@ export const CompanyNameSection = () => {
}, [data]);
const onFormSubmit = async ({ name }: { name: string }) => {
try {
if (!currentOrg?.id) return;
if (name === "") return;
await mutateAsync({
@@ -47,13 +46,6 @@ export const CompanyNameSection = () => {
text: "Successfully updated business name",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update business name",
type: "error"
});
}
};
return (
@@ -35,7 +35,6 @@ export const InvoiceEmailSection = () => {
}, [data]);
const onFormSubmit = async ({ email }: { email: string }) => {
try {
if (!currentOrg?.id) return;
if (email === "") return;
@@ -48,13 +47,6 @@ export const InvoiceEmailSection = () => {
text: "Successfully updated invoice email recipient",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update invoice email recipient",
type: "error"
});
}
};
return (
@@ -39,7 +39,6 @@ export const PmtMethodsTable = () => {
});
return;
}
try {
await deleteOrgPmtMethod.mutateAsync({
organizationId: currentOrg.id,
pmtMethodId: pmtMethodToRemove.id
@@ -49,12 +48,6 @@ export const PmtMethodsTable = () => {
text: "Successfully removed payment method"
});
handlePopUpClose("removeCard");
} catch (error: any) {
createNotification({
type: "error",
text: error.message ?? "Error removing payment method"
});
}
};
return (
@@ -98,7 +98,6 @@ export const TaxIDModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Props
});
const onTaxIDModalSubmit = async ({ type, value }: AddTaxIDFormData) => {
try {
if (!currentOrg?.id) return;
await addOrgTaxId.mutateAsync({
organizationId: currentOrg.id,
@@ -111,13 +110,6 @@ export const TaxIDModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Props
type: "success"
});
handlePopUpClose("addTaxID");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to add Tax ID",
type: "error"
});
}
};
return (
@@ -56,7 +56,6 @@ const Page = () => {
] as const);
const onDeleteGroupSubmit = async ({ name, id }: { name: string; id: string }) => {
try {
await deleteMutateAsync({
id
});
@@ -70,13 +69,6 @@ const Page = () => {
selectedTab: TabSections.Groups
}
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to delete the ${name} group`,
type: "error"
});
}
handlePopUpClose("deleteGroup");
};
@@ -63,7 +63,6 @@ export const AddGroupMembersModal = ({ popUp, handlePopUpToggle }: Props) => {
const { mutateAsync: addUserToGroupMutateAsync } = useAddUserToGroup();
const handleAddMember = async (username: string) => {
try {
if (!popUpData?.slug) {
createNotification({
text: "Some data is missing, please refresh the page and try again",
@@ -82,12 +81,6 @@ export const AddGroupMembersModal = ({ popUp, handlePopUpToggle }: Props) => {
text: "Successfully assigned user to the group",
type: "success"
});
} catch {
createNotification({
text: "Failed to assign user to the group",
type: "error"
});
}
};
return (
@@ -29,7 +29,6 @@ export const GroupMembersSection = ({ groupId, groupSlug }: Props) => {
const { mutateAsync: removeUserFromGroupMutateAsync } = useRemoveUserFromGroup();
const handleRemoveUserFromGroup = async (username: string) => {
try {
await removeUserFromGroupMutateAsync({
groupId,
username,
@@ -42,12 +41,6 @@ export const GroupMembersSection = ({ groupId, groupSlug }: Props) => {
});
handlePopUpToggle("removeMemberFromGroup", false);
} catch {
createNotification({
text: `Failed to remove user ${username} from the group`,
type: "error"
});
}
};
return (
@@ -75,7 +75,6 @@ const Content = ({ identityId, handlePopUpToggle }: Omit<Props, "popUp">) => {
}, [workspaces, projectMemberships]);
const onFormSubmit = async ({ project: selectedProject, role }: FormData) => {
try {
await addIdentityToWorkspace({
projectId: selectedProject.id,
identityId,
@@ -89,16 +88,6 @@ const Content = ({ identityId, handlePopUpToggle }: Omit<Props, "popUp">) => {
reset();
handlePopUpToggle("addIdentityToProject", false);
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to add identity to project";
createNotification({
text,
type: "error"
});
}
};
const isProjectSelected = Boolean(projectId);
@@ -22,7 +22,6 @@ export const IdentityProjectsSection = ({ identityId }: Props) => {
] as const);
const onRemoveIdentitySubmit = async (id: string, projectId: string) => {
try {
await deleteMutateAsync({
identityId: id,
projectId
@@ -34,16 +33,6 @@ export const IdentityProjectsSection = ({ identityId }: Props) => {
});
handlePopUpClose("removeIdentityFromProject");
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to remove identity from project";
createNotification({
text,
type: "error"
});
}
};
return (
@@ -72,7 +72,6 @@ export const IdentityTokenModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [popUp?.token?.data]);
const onFormSubmit = async ({ name }: FormData) => {
try {
if (tokenData?.tokenId) {
// update
@@ -100,18 +99,6 @@ export const IdentityTokenModal = ({ popUp, handlePopUpToggle }: Props) => {
});
reset();
} catch (err) {
console.error(err);
const error = err as any;
const text =
error?.response?.data?.message ??
`Failed to ${popUp?.token?.data ? "update" : "create"} token`;
createNotification({
text,
type: "error"
});
}
};
return (
@@ -31,8 +31,7 @@ export const LockoutFields = ({
const [lockedOutState, setLockedOutState] = useState(lockedOut);
async function clearLockouts() {
try {
const clearLockouts = async () => {
const deleted = await mutateAsync({ identityId });
createNotification({
text: `Successfully cleared ${deleted} lockout${deleted === 1 ? "" : "s"}`,
@@ -40,14 +39,7 @@ export const LockoutFields = ({
});
setLockedOutState(false);
onResetAllLockouts();
} catch (error) {
console.error(error);
createNotification({
text: "Failed to clear lockouts. Please try again.",
type: "error"
});
}
}
};
return (
<>
@@ -51,7 +51,6 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
tokenId: string;
name: string;
}) => {
try {
await revokeToken({
identityId: parentIdentityId,
tokenId
@@ -63,16 +62,6 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
text: `Successfully revoked token ${name ?? ""}`,
type: "success"
});
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to revoke token";
createNotification({
text,
type: "error"
});
}
};
return (
@@ -43,7 +43,6 @@ export const IdentityUniversalAuthClientSecretsTable = ({ clientSecrets, identit
const { mutateAsync: revokeClientSecret } = useRevokeIdentityUniversalAuthClientSecret();
const onDeleteClientSecretSubmit = async (clientSecretId: string) => {
try {
await revokeClientSecret({
identityId,
clientSecretId
@@ -55,13 +54,6 @@ export const IdentityUniversalAuthClientSecretsTable = ({ clientSecrets, identit
text: "Successfully deleted client secret",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete client secret",
type: "error"
});
}
};
return (
@@ -140,7 +140,6 @@ export const Content = ({
}
const handleDeleteAuthMethod = async () => {
try {
await revokeMethod({
identityId,
organizationId: orgId
@@ -150,15 +149,8 @@ export const Content = ({
text: "Successfully removed auth method",
type: "success"
});
handlePopUpToggle("revokeAuthMethod", false);
onDeleteAuthMethod();
} catch {
createNotification({
text: "Failed to remove auth method",
type: "error"
});
}
};
return (
@@ -168,12 +168,7 @@ export const GatewayCliDeploymentMethod = () => {
type: "info"
});
setStep("command");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to generate token for the selected identity",
type: "error"
});
} catch {
setIdentityToken("");
}
} else {
@@ -141,12 +141,7 @@ export const RelayCliDeploymentMethod = () => {
type: "info"
});
setStep("command");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to generate token for the selected identity",
type: "error"
});
} catch {
setIdentityToken("");
}
} else {
@@ -13,7 +13,6 @@ import { useNavigate } from "@tanstack/react-router";
import { CheckIcon } from "lucide-react";
import { twMerge } from "tailwind-merge";
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
import { RequestProjectAccessModal } from "@app/components/projects/RequestProjectAccessModal";
import {
@@ -103,7 +102,6 @@ export const AllProjectView = ({
projectId: string,
environments: ProjectEnv[]
) => {
try {
await orgAdminAccessProject.mutateAsync({
projectId
});
@@ -113,12 +111,6 @@ export const AllProjectView = ({
projectId
}
});
} catch {
createNotification({
text: "Failed to access project",
type: "error"
});
}
};
useResetPageHelper({
@@ -15,7 +15,6 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useNavigate } from "@tanstack/react-router";
import { twMerge } from "tailwind-merge";
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
import {
Button,
@@ -158,34 +157,20 @@ export const MyProjectView = ({
};
const addProjectToFavorites = async (projectId: string) => {
try {
if (currentOrg?.id) {
await updateUserProjectFavorites({
orgId: currentOrg?.id,
projectFavorites: [...(projectFavorites || []), projectId]
});
}
} catch {
createNotification({
text: "Failed to add project to favorites.",
type: "error"
});
}
};
const removeProjectFromFavorites = async (projectId: string) => {
try {
if (currentOrg?.id) {
await updateUserProjectFavorites({
orgId: currentOrg?.id,
projectFavorites: [...(projectFavorites || []).filter((entry) => entry !== projectId)]
});
}
} catch {
createNotification({
text: "Failed to remove project from favorites.",
type: "error"
});
}
};
const renderProjectGridItem = (workspace: Project, isFavorite: boolean) => (
@@ -42,7 +42,6 @@ export const Page = () => {
] as const);
const onDeleteOrgRoleSubmit = async () => {
try {
if (!orgId || !roleId) return;
await deleteOrgRole({
@@ -62,16 +61,6 @@ export const Page = () => {
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"
});
}
};
const isCustomRole = !["admin", "member", "no-access"].includes(data?.slug ?? "");
@@ -70,7 +70,6 @@ export const RoleModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [role]);
const onFormSubmit = async ({ name, description, slug }: FormData) => {
try {
if (!orgId) return;
if (role) {
@@ -111,14 +110,6 @@ export const RoleModal = ({ popUp, handlePopUpToggle }: Props) => {
});
reset();
} catch {
const text = `Failed to ${popUp?.role?.data ? "update" : "create"} role`;
createNotification({
text,
type: "error"
});
}
};
return (
@@ -56,7 +56,6 @@ export const RequestSecretForm = () => {
const onFormSubmit = async ({ name, accessType, expiresIn }: FormData) => {
const expiresAt = new Date(new Date().getTime() + Number(expiresIn));
try {
const { id } = await createSecretRequest({
name,
accessType,
@@ -78,13 +77,6 @@ export const RequestSecretForm = () => {
text: "Shared secret link copied to clipboard.",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to create a shared secret.",
type: "error"
});
}
};
const hasSecretLink = Boolean(secretLink);
@@ -22,7 +22,6 @@ export const RequestSecretTab = () => {
const { mutateAsync: deleteSecretRequest } = useDeleteSecretRequest();
const onDeleteApproved = async () => {
try {
await deleteSecretRequest({
secretRequestId: popUp.deleteSecretRequestConfirmation.data?.id
});
@@ -32,13 +31,6 @@ export const RequestSecretTab = () => {
});
handlePopUpClose("deleteSecretRequestConfirmation");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete shared secret",
type: "error"
});
}
};
return (
@@ -90,7 +90,6 @@ export const OrgSecretShareLimitSection = () => {
}, [currentOrg, reset]);
const handleFormSubmit = async (formData: TForm) => {
try {
const maxSharedSecretLifetimeSeconds =
ms(`${formData.maxLifetimeValue}${formData.maxLifetimeUnit}`) / 1000;
@@ -106,12 +105,6 @@ export const OrgSecretShareLimitSection = () => {
});
reset(formData);
} catch {
createNotification({
text: "Failed to update secret share limits",
type: "error"
});
}
};
// Units for the dropdown with readable labels
@@ -9,7 +9,6 @@ export const SecretSharingAllowShareToAnyone = () => {
const { mutateAsync } = useUpdateOrg();
const handleSecretSharingToggle = async (value: boolean) => {
try {
if (!currentOrg?.id) return;
await mutateAsync({
@@ -21,13 +20,6 @@ export const SecretSharingAllowShareToAnyone = () => {
text: `Successfully ${value ? "enabled" : "disabled"} secret sharing to members outside of this organization`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: (err as { response: { data: { message: string } } }).response.data.message,
type: "error"
});
}
};
return (
@@ -20,7 +20,6 @@ export const ShareSecretTab = () => {
const deleteSecretShare = useDeleteSharedSecret();
const onDeleteApproved = async () => {
try {
deleteSecretShare.mutateAsync({
sharedSecretId: (popUp?.deleteSharedSecretConfirmation?.data as DeleteModalData)?.id
});
@@ -30,13 +29,6 @@ export const ShareSecretTab = () => {
});
handlePopUpClose("deleteSharedSecretConfirmation");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete shared secret",
type: "error"
});
}
};
return (
@@ -28,21 +28,12 @@ const CreateForm = ({ provider, onComplete }: CreateFormProps) => {
const onSubmit = async (
formData: DiscriminativePick<TAuditLogStream, "provider" | "credentials">
) => {
try {
const logStream = await createAuditLogStream.mutateAsync(formData);
createNotification({
text: `Successfully created ${providerName} Log Stream`,
type: "success"
});
onComplete(logStream);
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to create ${providerName} Log Stream`,
text: err.message,
type: "error"
});
}
};
switch (provider) {
@@ -68,7 +59,6 @@ const UpdateForm = ({ auditLogStream, onComplete }: UpdateFormProps) => {
const onSubmit = async (
formData: DiscriminativePick<TAuditLogStream, "provider" | "credentials">
) => {
try {
const connection = await updateAuditLogStream.mutateAsync({
auditLogStreamId: auditLogStream.id,
...formData
@@ -78,14 +68,6 @@ const UpdateForm = ({ auditLogStream, onComplete }: UpdateFormProps) => {
type: "success"
});
onComplete(connection);
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to update ${providerName} Log Stream`,
text: err.message,
type: "error"
});
}
};
switch (auditLogStream.provider) {
@@ -20,7 +20,6 @@ export const DeleteAuditLogStreamModal = ({ isOpen, onOpenChange, auditLogStream
const providerDetails = AUDIT_LOG_STREAM_PROVIDER_MAP[provider];
const handleDelete = async () => {
try {
await deleteAuditLogStream.mutateAsync({
auditLogStreamId,
provider
@@ -32,14 +31,6 @@ export const DeleteAuditLogStreamModal = ({ isOpen, onOpenChange, auditLogStream
});
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: `Failed to delete ${providerDetails.name} stream`,
type: "error"
});
}
};
return (
@@ -54,7 +54,6 @@ export const VaultConnectionSection = () => {
const handleDeleteConfirm = async () => {
if (!configToDelete) return;
try {
await deleteConfig({ id: configToDelete.id });
createNotification({
type: "success",
@@ -62,13 +61,6 @@ export const VaultConnectionSection = () => {
});
setIsDeleteModalOpen(false);
setConfigToDelete(null);
} catch (error) {
console.error("Failed to delete namespace config:", error);
createNotification({
type: "error",
text: "Failed to delete namespace configuration"
});
}
};
const getConnectionName = (connectionId: string | null) => {
@@ -74,7 +74,6 @@ export const VaultNamespaceConfigModal = ({ isOpen, onOpenChange, editConfig }:
}, [isOpen, editConfig, reset]);
const onFormSubmit = async (data: FormData) => {
try {
if (isEdit && editConfig) {
await updateConfig({
id: editConfig.id,
@@ -97,13 +96,6 @@ export const VaultNamespaceConfigModal = ({ isOpen, onOpenChange, editConfig }:
}
reset();
onOpenChange(false);
} catch (error) {
console.error("Failed to save namespace config:", error);
createNotification({
type: "error",
text: `Failed to ${isEdit ? "update" : "create"} namespace configuration`
});
}
};
const handleClose = () => {
@@ -19,7 +19,6 @@ export const OrgDeleteSection = () => {
const { mutateAsync, isPending } = useDeleteOrgById();
const handleDeleteOrgSubmit = async () => {
try {
if (!currentOrg?.id) return;
await mutateAsync({
@@ -33,13 +32,6 @@ export const OrgDeleteSection = () => {
clearSession();
navigate({ to: "/login" });
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete organization",
type: "error"
});
}
};
return (
@@ -51,7 +51,6 @@ export const OrgEncryptionTab = withPermission(
kmsId: string;
};
try {
await removeExternalKms(kmsId);
createNotification({
@@ -60,9 +59,6 @@ export const OrgEncryptionTab = withPermission(
});
handlePopUpToggle("removeExternalKms", false);
} catch (err) {
console.error(err);
}
};
return (
@@ -35,7 +35,6 @@ export const AddOrgIncidentContactModal = ({
const { mutateAsync, isPending } = useAddIncidentContact();
const onFormSubmit = async ({ email }: TAddContactForm) => {
try {
if (!currentOrg?.id) return;
await mutateAsync({
@@ -53,13 +52,6 @@ export const AddOrgIncidentContactModal = ({
}
reset();
} catch (err) {
console.error(err);
createNotification({
text: "Failed to add incident contact",
type: "error"
});
}
};
return (
@@ -33,7 +33,6 @@ export const OrgIncidentContactsTable = () => {
const { mutateAsync } = useDeleteIncidentContact();
const onRemoveIncidentContact = async () => {
try {
const incidentContactId = (popUp?.removeContact?.data as { id: string })?.id;
if (!currentOrg?.id) return;
@@ -48,13 +47,6 @@ export const OrgIncidentContactsTable = () => {
});
handlePopUpClose("removeContact");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to remove incident contact",
type: "error"
});
}
};
const filteredContacts = contacts
@@ -56,7 +56,6 @@ export const OrgNameChangeSection = (): JSX.Element => {
}, [roles]);
const onFormSubmit = async ({ name, slug, defaultMembershipRole }: FormData) => {
try {
if (!currentOrg?.id || !roles?.length) return;
await mutateAsync({
@@ -70,13 +69,6 @@ export const OrgNameChangeSection = (): JSX.Element => {
text: "Successfully updated organization details",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to update organization details",
type: "error"
});
}
};
if (!isFormInitialized) {
@@ -39,7 +39,6 @@ export const SubOrgNameChangeSection = (): JSX.Element => {
const { mutateAsync, isPending } = useUpdateSubOrganization();
const onFormSubmit = async ({ name }: FormData) => {
try {
await mutateAsync({
name,
subOrgId: currentOrg.id
@@ -52,13 +51,6 @@ export const SubOrgNameChangeSection = (): JSX.Element => {
text: "Successfully updated sub-organization details",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to update sub-organization details",
type: "error"
});
}
};
return (
@@ -1,7 +1,5 @@
import { useEffect, useState } from "react";
import axios from "axios";
import { createNotification } from "@app/components/notifications";
import { Switch } from "@app/components/v2";
import { useOrganization } from "@app/context";
import { useUpdateOrg } from "@app/hooks/api";
@@ -60,20 +58,10 @@ export const OrgProductSelectSection = () => {
[key]: { ...products[key], enabled: value }
}));
try {
await mutateAsync({
orgId: currentOrg.id,
[key]: value
});
} catch (e) {
if (axios.isAxiosError(e)) {
const { message = "Something went wrong" } = e.response?.data as { message: string };
createNotification({
type: "error",
text: message
});
}
}
setIsLoading(false);
};
@@ -30,12 +30,6 @@ export const OrgProductSettingsTab = () => {
text: `Successfully ${state ? "enabled" : "disabled"} blocking duplicate secret sync destinations for this organization`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update blocking duplicate secret sync destinations setting for this organization",
type: "error"
});
} finally {
setIsLoading(false);
}
@@ -75,19 +75,11 @@ export const ExternalGroupOrgRoleMappings = () => {
const mappingField = useFieldArray({ control, name: "mappings" });
const handleUpdateMappings = async (form: TForm) => {
try {
await updateMappings.mutateAsync(form);
createNotification({
text: "Group organization role mappings updated.",
type: "success"
});
} catch (e) {
console.error(e);
createNotification({
text: "Failed to update group organization role mappings.",
type: "error"
});
}
};
const disableScimEdit = permission.cannot(OrgPermissionActions.Edit, OrgPermissionSubjects.Scim);
@@ -122,7 +122,6 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
caCert,
shouldCloseModal = true
}: TLDAPFormData & { shouldCloseModal?: boolean }) => {
try {
if (!currentOrg) return;
if (!data) {
@@ -162,13 +161,6 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
text: `Successfully ${!data ? "added" : "updated"} LDAP configuration`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${!data ? "add" : "update"} LDAP configuration`,
type: "error"
});
}
};
const handleTestLDAPConnection = async () => {
@@ -122,7 +122,6 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
if (!currentOrg) {
return;
}
try {
await updateMutateAsync({
issuer: "",
discoveryURL: "",
@@ -141,12 +140,6 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
text: "Successfully deleted OIDC configuration.",
type: "success"
});
} catch {
createNotification({
text: "Failed deleting OIDC configuration.",
type: "error"
});
}
};
useEffect(() => {
@@ -178,7 +171,6 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
clientSecret,
jwtSignatureAlgorithm
}: OIDCFormData) => {
try {
if (!currentOrg) {
return;
}
@@ -223,13 +215,6 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
text: `Successfully ${!data ? "added" : "updated"} OIDC SSO configuration`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${!data ? "add" : "update"} OIDC SSO configuration`,
type: "error"
});
}
};
return (
@@ -108,7 +108,6 @@ export const SSOModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDelet
if (!currentOrg) {
return;
}
try {
await updateMutateAsync({
organizationId: currentOrg.id,
isActive: false,
@@ -121,16 +120,9 @@ export const SSOModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDelet
text: "Successfully deleted SAML SSO configuration.",
type: "success"
});
} catch {
createNotification({
text: "Failed deleting SAML SSO configuration.",
type: "error"
});
}
};
const onSSOModalSubmit = async ({ authProvider, entryPoint, issuer, cert }: AddSSOFormData) => {
try {
if (!currentOrg) return;
if (!data) {
@@ -159,13 +151,6 @@ export const SSOModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDelet
text: `Successfully ${!data ? "added" : "updated"} SAML SSO configuration`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${!data ? "add" : "update"} SAML SSO configuration`,
type: "error"
});
}
};
const renderLabels = (authProvider: string) => {
@@ -253,7 +253,6 @@ const GroupRolesForm = ({ projectRoles, roles, groupId, onClose }: FormProps) =>
};
});
try {
await updateGroupWorkspaceRole.mutateAsync({
projectId: currentProject?.id || "",
groupId,
@@ -262,9 +261,6 @@ const GroupRolesForm = ({ projectRoles, roles, groupId, onClose }: FormProps) =>
createNotification({ text: "Successfully updated group role", type: "success" });
onClose();
setSearchRoles("");
} catch {
createNotification({ text: "Failed to update group role", type: "error" });
}
};
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" });
}
};
const {
@@ -131,7 +131,6 @@ export const IdentityProjectAdditionalPrivilegeModifySection = ({
temporaryAccessStartTime: el.temporaryAccess.temporaryAccessStartTime
};
try {
if (isCreate) {
await createIdentityProjectAdditionalPrivilege({
permissions: formRolePermission2API(el.permissions),
@@ -154,10 +153,6 @@ export const IdentityProjectAdditionalPrivilegeModifySection = ({
createNotification({ type: "success", text: "Successfully updated privilege" });
}
onGoBack();
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to update privilege" });
}
};
const privilegeTemporaryAccess = form.watch("temporaryAccess");
@@ -57,7 +57,6 @@ export const IdentityProjectAdditionalPrivilegeSection = ({ identityMembershipDe
const handlePrivilegeDelete = async () => {
const { id } = popUp?.deletePrivilege?.data as { id: string };
try {
await deletePrivilege({
privilegeId: id,
projectId,
@@ -65,10 +64,6 @@ export const IdentityProjectAdditionalPrivilegeSection = ({ identityMembershipDe
});
createNotification({ type: "success", text: "Successfully removed the privilege" });
handlePopUpClose("deletePrivilege");
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to delete privilege" });
}
};
return (
@@ -50,7 +50,6 @@ 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 || "",
@@ -82,10 +81,6 @@ export const IdentityRoleDetailsSection = ({
});
createNotification({ type: "success", text: "Successfully removed role" });
handlePopUpClose("deleteRole");
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to delete role" });
}
};
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" });
}
};
return (
@@ -129,7 +129,6 @@ export const MembershipProjectAdditionalPrivilegeModifySection = ({
temporaryAccessStartTime: el.temporaryAccess.temporaryAccessStartTime
};
try {
if (isCreate) {
await createUserProjectAdditionalPrivilege({
permissions: formRolePermission2API(el.permissions),
@@ -150,10 +149,6 @@ export const MembershipProjectAdditionalPrivilegeModifySection = ({
createNotification({ type: "success", text: "Successfully updated privilege" });
}
onGoBack();
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to update privilege" });
}
};
const privilegeTemporaryAccess = form.watch("temporaryAccess");
@@ -122,7 +122,6 @@ 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,
@@ -131,10 +130,6 @@ export const RolePermissionsSection = ({ roleSlug, isDisabled }: Props) => {
permissions: formRolePermission2API(el.permissions)
});
createNotification({ type: "success", text: "Successfully updated role" });
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to update role" });
}
};
const isCustomRole = !Object.values(ProjectMembershipRole).includes(
@@ -13,12 +13,8 @@ export const BackfillSecretReferenceSecretion = () => {
const handleBackfill = async () => {
if (backfillSecretReferences.isPending) return;
try {
await backfillSecretReferences.mutateAsync({ projectId: currentProject.id || "" });
createNotification({ text: "Successfully re-indexed secret references", type: "success" });
} catch {
createNotification({ text: "Failed to re-index secret references", type: "error" });
}
};
const isAdmin = hasProjectRole(ProjectMembershipRole.Admin);