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

View File

@@ -25,27 +25,20 @@ const TotpRegistration = ({ onComplete, shouldCenterQr }: Props) => {
const handleTotpVerify = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
try {
const result = await verifyUserTotp({
totp
});
const result = await verifyUserTotp({
totp
});
createNotification({
text: "Successfully configured mobile authenticator",
type: "success"
});
createNotification({
text: "Successfully configured mobile authenticator",
type: "success"
});
if (result.recoveryCodes && result.recoveryCodes.length > 0) {
setRecoveryCodes(result.recoveryCodes);
setShowRecoveryModal(true);
} else if (onComplete) {
onComplete();
}
} catch {
createNotification({
text: "Failed to verify TOTP code",
type: "error"
});
if (result.recoveryCodes && result.recoveryCodes.length > 0) {
setRecoveryCodes(result.recoveryCodes);
setShowRecoveryModal(true);
} else if (onComplete) {
onComplete();
}
};

View File

@@ -145,27 +145,16 @@ export const IdentityTable = ({ handlePopUpOpen }: Props) => {
};
const handleChangeRole = async ({ identityId, role }: { identityId: string; role: string }) => {
try {
await updateMutateAsync({
identityId,
role,
organizationId
});
await updateMutateAsync({
identityId,
role,
organizationId
});
createNotification({
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"
});
}
createNotification({
text: "Successfully updated identity role",
type: "success"
});
};
const handleRoleToggle = useCallback(

View File

@@ -134,47 +134,40 @@ export const IdentityTlsCertAuthForm = ({
accessTokenNumUsesLimit,
accessTokenTrustedIps
}: FormData) => {
try {
if (!identityId) return;
if (!identityId) return;
if (data) {
await updateMutateAsync({
organizationId: orgId,
caCertificate,
allowedCommonNames: allowedCommonNames || null,
identityId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
caCertificate,
allowedCommonNames: allowedCommonNames || undefined,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
if (data) {
await updateMutateAsync({
organizationId: orgId,
caCertificate,
allowedCommonNames: allowedCommonNames || null,
identityId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
caCertificate,
allowedCommonNames: allowedCommonNames || undefined,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
};
return (

View File

@@ -127,43 +127,36 @@ export const IdentityTokenAuthForm = ({
accessTokenNumUsesLimit,
accessTokenTrustedIps
}: FormData) => {
try {
if (!identityId) return;
if (!identityId) return;
if (data) {
await updateMutateAsync({
organizationId: orgId,
identityId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
if (data) {
await updateMutateAsync({
organizationId: orgId,
identityId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
};
return (

View File

@@ -220,64 +220,55 @@ export const IdentityUniversalAuthForm = ({
lockoutCounterResetValue,
lockoutCounterResetUnit
}: FormData) => {
try {
if (!identityId) return;
if (!identityId) return;
const lockoutDurationSeconds = ms(`${lockoutDurationValue}${lockoutDurationUnit}`) / 1000;
const lockoutCounterResetSeconds =
ms(`${lockoutCounterResetValue}${lockoutCounterResetUnit}`) / 1000;
const lockoutDurationSeconds = ms(`${lockoutDurationValue}${lockoutDurationUnit}`) / 1000;
const lockoutCounterResetSeconds =
ms(`${lockoutCounterResetValue}${lockoutCounterResetUnit}`) / 1000;
if (data) {
// update universal auth configuration
await updateMutateAsync({
organizationId: orgId,
identityId,
clientSecretTrustedIps,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps,
accessTokenPeriod: Number(accessTokenPeriod),
lockoutEnabled,
lockoutThreshold: Number(lockoutThreshold),
lockoutDurationSeconds,
lockoutCounterResetSeconds
});
} else {
// create new universal auth configuration
await addMutateAsync({
organizationId: orgId,
identityId,
clientSecretTrustedIps,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps,
accessTokenPeriod: Number(accessTokenPeriod),
lockoutEnabled,
lockoutThreshold: Number(lockoutThreshold),
lockoutDurationSeconds: Number(lockoutDurationSeconds),
lockoutCounterResetSeconds: Number(lockoutCounterResetSeconds)
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "created"} auth method`,
type: "success"
if (data) {
// update universal auth configuration
await updateMutateAsync({
organizationId: orgId,
identityId,
clientSecretTrustedIps,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps,
accessTokenPeriod: Number(accessTokenPeriod),
lockoutEnabled,
lockoutThreshold: Number(lockoutThreshold),
lockoutDurationSeconds,
lockoutCounterResetSeconds
});
} else {
// create new universal auth configuration
reset();
} catch {
const text = `Failed to ${isUpdate ? "update" : "configure"} identity`;
createNotification({
text,
type: "error"
await addMutateAsync({
organizationId: orgId,
identityId,
clientSecretTrustedIps,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps,
accessTokenPeriod: Number(accessTokenPeriod),
lockoutEnabled,
lockoutThreshold: Number(lockoutThreshold),
lockoutDurationSeconds: Number(lockoutDurationSeconds),
lockoutCounterResetSeconds: Number(lockoutCounterResetSeconds)
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "created"} auth method`,
type: "success"
});
reset();
};
return (

View File

@@ -122,64 +122,55 @@ export const AddOrgMemberModal = ({
}
}
try {
const parsedEmails = emails
.replace(/\s/g, "")
.split(",")
.map((email) => {
if (EmailSchema.safeParse(email).success) {
return email.trim();
}
const parsedEmails = emails
.replace(/\s/g, "")
.split(",")
.map((email) => {
if (EmailSchema.safeParse(email).success) {
return email.trim();
}
return null;
});
if (parsedEmails.includes(null)) {
createNotification({
text: "Invalid email addresses provided.",
type: "error"
});
return;
}
const usernames = emails.split(",").map((email) => email.trim());
const { data } = await addUsersMutateAsync({
organizationId: currentOrg?.id,
inviteeEmails: usernames,
organizationRoleSlug: organizationRole.slug
return null;
});
await Promise.allSettled(
selectedProjects.map((el) =>
addUserToProject({
orgId: currentOrg.id,
projectId: el.id,
roleSlugs: [projectRoleSlug],
usernames
})
)
);
setCompleteInviteLinks(data?.completeInviteLinks ?? null);
// only show this notification when email is configured.
// A [completeInviteLink] will not be sent if smtp is configured
if (!data.completeInviteLinks) {
createNotification({
text: "Successfully invited user to the organization.",
type: "success"
});
}
} catch (error) {
console.error(error);
if (parsedEmails.includes(null)) {
createNotification({
text: "Failed to invite user to org",
text: "Invalid email addresses provided.",
type: "error"
});
return;
}
const usernames = emails.split(",").map((email) => email.trim());
const { data } = await addUsersMutateAsync({
organizationId: currentOrg?.id,
inviteeEmails: usernames,
organizationRoleSlug: organizationRole.slug
});
await Promise.allSettled(
selectedProjects.map((el) =>
addUserToProject({
orgId: currentOrg.id,
projectId: el.id,
roleSlugs: [projectRoleSlug],
usernames
})
)
);
setCompleteInviteLinks(data?.completeInviteLinks ?? null);
// only show this notification when email is configured.
// A [completeInviteLink] will not be sent if smtp is configured
if (!data.completeInviteLinks) {
createNotification({
text: "Successfully invited user to the organization.",
type: "success"
});
}
if (serverDetails?.emailConfigured) {
handlePopUpToggle("addMember", false);
}

View File

@@ -106,32 +106,24 @@ export const AddSubOrgMemberModal = ({ onClose }: Props) => {
}
}
try {
const usernames = users.map((el) => el.username);
await addUsersMutateAsync({
organizationId: currentOrg?.id,
inviteeEmails: usernames,
organizationRoleSlug: organizationRole.slug
});
const usernames = users.map((el) => el.username);
await addUsersMutateAsync({
organizationId: currentOrg?.id,
inviteeEmails: usernames,
organizationRoleSlug: organizationRole.slug
});
await Promise.allSettled(
selectedProjects.map((el) =>
addUserToProject({
orgId: currentOrg.id,
projectId: el.id,
roleSlugs: [projectRoleSlug],
usernames
})
)
);
onClose();
} catch (error) {
console.error(error);
createNotification({
text: "Failed to add user to suborganization",
type: "error"
});
}
await Promise.allSettled(
selectedProjects.map((el) =>
addUserToProject({
orgId: currentOrg.id,
projectId: el.id,
roleSlugs: [projectRoleSlug],
usernames
})
)
);
onClose();
};
const getGroupHeaderLabel = (type: ProjectType) => {

View File

@@ -44,21 +44,14 @@ export const UpgradePrivilegeSystemModal = ({ isOpen, onOpenChange }: Props) =>
acknowledgesPermanentChange;
const handlePrivilegeSystemUpgrade = async () => {
try {
await upgradePrivilegeSystem();
await upgradePrivilegeSystem();
createNotification({
text: "Privilege system upgrade completed",
type: "success"
});
createNotification({
text: "Privilege system upgrade completed",
type: "success"
});
onOpenChange(false);
} catch {
createNotification({
text: "Failed to upgrade privilege system",
type: "error"
});
}
onOpenChange(false);
};
const handleClose = () => {

View File

@@ -18,26 +18,17 @@ export const DeleteAppConnectionModal = ({ isOpen, onOpenChange, appConnection }
const { id: connectionId, name, app } = appConnection;
const handleDeleteAppConnection = async () => {
try {
await deleteAppConnection.mutateAsync({
connectionId,
app
});
await deleteAppConnection.mutateAsync({
connectionId,
app
});
createNotification({
text: `Successfully removed ${APP_CONNECTION_MAP[app].name} connection`,
type: "success"
});
createNotification({
text: `Successfully removed ${APP_CONNECTION_MAP[app].name} connection`,
type: "success"
});
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: `Failed to remove ${APP_CONNECTION_MAP[app].name} connection`,
type: "error"
});
}
onOpenChange(false);
};
return (

View File

@@ -43,24 +43,15 @@ const Content = ({ appConnection, onComplete }: ContentProps) => {
} = form;
const onSubmit = async (formData: FormData) => {
try {
await updateAppConnection.mutateAsync({
connectionId: appConnection.id,
...formData
});
createNotification({
text: `Successfully updated ${appName} Connection`,
type: "success"
});
onComplete();
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to update ${appName} Connection`,
text: err.message,
type: "error"
});
}
await updateAppConnection.mutateAsync({
connectionId: appConnection.id,
...formData
});
createNotification({
text: `Successfully updated ${appName} Connection`,
type: "success"
});
onComplete();
};
return (

View File

@@ -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: {

View File

@@ -35,25 +35,17 @@ export const CompanyNameSection = () => {
}, [data]);
const onFormSubmit = async ({ name }: { name: string }) => {
try {
if (!currentOrg?.id) return;
if (name === "") return;
await mutateAsync({
name,
organizationId: currentOrg.id
});
if (!currentOrg?.id) return;
if (name === "") return;
await mutateAsync({
name,
organizationId: currentOrg.id
});
createNotification({
text: "Successfully updated business name",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update business name",
type: "error"
});
}
createNotification({
text: "Successfully updated business name",
type: "success"
});
};
return (

View File

@@ -35,26 +35,18 @@ export const InvoiceEmailSection = () => {
}, [data]);
const onFormSubmit = async ({ email }: { email: string }) => {
try {
if (!currentOrg?.id) return;
if (email === "") return;
if (!currentOrg?.id) return;
if (email === "") return;
await mutateAsync({
email,
organizationId: currentOrg.id
});
await mutateAsync({
email,
organizationId: currentOrg.id
});
createNotification({
text: "Successfully updated invoice email recipient",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update invoice email recipient",
type: "error"
});
}
createNotification({
text: "Successfully updated invoice email recipient",
type: "success"
});
};
return (

View File

@@ -39,22 +39,15 @@ export const PmtMethodsTable = () => {
});
return;
}
try {
await deleteOrgPmtMethod.mutateAsync({
organizationId: currentOrg.id,
pmtMethodId: pmtMethodToRemove.id
});
createNotification({
type: "success",
text: "Successfully removed payment method"
});
handlePopUpClose("removeCard");
} catch (error: any) {
createNotification({
type: "error",
text: error.message ?? "Error removing payment method"
});
}
await deleteOrgPmtMethod.mutateAsync({
organizationId: currentOrg.id,
pmtMethodId: pmtMethodToRemove.id
});
createNotification({
type: "success",
text: "Successfully removed payment method"
});
handlePopUpClose("removeCard");
};
return (

View File

@@ -98,26 +98,18 @@ export const TaxIDModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Props
});
const onTaxIDModalSubmit = async ({ type, value }: AddTaxIDFormData) => {
try {
if (!currentOrg?.id) return;
await addOrgTaxId.mutateAsync({
organizationId: currentOrg.id,
type,
value
});
if (!currentOrg?.id) return;
await addOrgTaxId.mutateAsync({
organizationId: currentOrg.id,
type,
value
});
createNotification({
text: "Successfully added Tax ID",
type: "success"
});
handlePopUpClose("addTaxID");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to add Tax ID",
type: "error"
});
}
createNotification({
text: "Successfully added Tax ID",
type: "success"
});
handlePopUpClose("addTaxID");
};
return (

View File

@@ -56,27 +56,19 @@ const Page = () => {
] as const);
const onDeleteGroupSubmit = async ({ name, id }: { name: string; id: string }) => {
try {
await deleteMutateAsync({
id
});
createNotification({
text: `Successfully deleted the ${name} group`,
type: "success"
});
navigate({
to: "/organization/access-management" as const,
search: {
selectedTab: TabSections.Groups
}
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to delete the ${name} group`,
type: "error"
});
}
await deleteMutateAsync({
id
});
createNotification({
text: `Successfully deleted the ${name} group`,
type: "success"
});
navigate({
to: "/organization/access-management" as const,
search: {
selectedTab: TabSections.Groups
}
});
handlePopUpClose("deleteGroup");
};

View File

@@ -63,31 +63,24 @@ 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",
type: "error"
});
return;
}
await addUserToGroupMutateAsync({
groupId: popUpData.groupId,
username,
slug: popUpData.slug
});
if (!popUpData?.slug) {
createNotification({
text: "Successfully assigned user to the group",
type: "success"
});
} catch {
createNotification({
text: "Failed to assign user to the group",
text: "Some data is missing, please refresh the page and try again",
type: "error"
});
return;
}
await addUserToGroupMutateAsync({
groupId: popUpData.groupId,
username,
slug: popUpData.slug
});
createNotification({
text: "Successfully assigned user to the group",
type: "success"
});
};
return (

View File

@@ -29,25 +29,18 @@ export const GroupMembersSection = ({ groupId, groupSlug }: Props) => {
const { mutateAsync: removeUserFromGroupMutateAsync } = useRemoveUserFromGroup();
const handleRemoveUserFromGroup = async (username: string) => {
try {
await removeUserFromGroupMutateAsync({
groupId,
username,
slug: groupSlug
});
await removeUserFromGroupMutateAsync({
groupId,
username,
slug: groupSlug
});
createNotification({
text: `Successfully removed user ${username} from the group`,
type: "success"
});
createNotification({
text: `Successfully removed user ${username} from the group`,
type: "success"
});
handlePopUpToggle("removeMemberFromGroup", false);
} catch {
createNotification({
text: `Failed to remove user ${username} from the group`,
type: "error"
});
}
handlePopUpToggle("removeMemberFromGroup", false);
};
return (

View File

@@ -75,30 +75,19 @@ const Content = ({ identityId, handlePopUpToggle }: Omit<Props, "popUp">) => {
}, [workspaces, projectMemberships]);
const onFormSubmit = async ({ project: selectedProject, role }: FormData) => {
try {
await addIdentityToWorkspace({
projectId: selectedProject.id,
identityId,
role: role.slug || undefined
});
await addIdentityToWorkspace({
projectId: selectedProject.id,
identityId,
role: role.slug || undefined
});
createNotification({
text: "Successfully added identity to project",
type: "success"
});
createNotification({
text: "Successfully added identity to project",
type: "success"
});
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"
});
}
reset();
handlePopUpToggle("addIdentityToProject", false);
};
const isProjectSelected = Boolean(projectId);

View File

@@ -22,28 +22,17 @@ export const IdentityProjectsSection = ({ identityId }: Props) => {
] as const);
const onRemoveIdentitySubmit = async (id: string, projectId: string) => {
try {
await deleteMutateAsync({
identityId: id,
projectId
});
await deleteMutateAsync({
identityId: id,
projectId
});
createNotification({
text: "Successfully removed identity from project",
type: "success"
});
createNotification({
text: "Successfully removed identity from project",
type: "success"
});
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"
});
}
handlePopUpClose("removeIdentityFromProject");
};
return (

View File

@@ -72,46 +72,33 @@ export const IdentityTokenModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [popUp?.token?.data]);
const onFormSubmit = async ({ name }: FormData) => {
try {
if (tokenData?.tokenId) {
// update
if (tokenData?.tokenId) {
// update
await updateToken({
identityId: tokenData.identityId,
tokenId: tokenData.tokenId,
name
});
handlePopUpToggle("token", false);
} else {
// create
const newTokenData = await createToken({
identityId: tokenData.identityId,
name
});
setToken(newTokenData.accessToken);
}
createNotification({
text: `Successfully ${popUp?.token?.data ? "updated" : "created"} token`,
type: "success"
await updateToken({
identityId: tokenData.identityId,
tokenId: tokenData.tokenId,
name
});
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`;
handlePopUpToggle("token", false);
} else {
// create
createNotification({
text,
type: "error"
const newTokenData = await createToken({
identityId: tokenData.identityId,
name
});
setToken(newTokenData.accessToken);
}
createNotification({
text: `Successfully ${popUp?.token?.data ? "updated" : "created"} token`,
type: "success"
});
reset();
};
return (

View File

@@ -31,23 +31,15 @@ export const LockoutFields = ({
const [lockedOutState, setLockedOutState] = useState(lockedOut);
async function clearLockouts() {
try {
const deleted = await mutateAsync({ identityId });
createNotification({
text: `Successfully cleared ${deleted} lockout${deleted === 1 ? "" : "s"}`,
type: "success"
});
setLockedOutState(false);
onResetAllLockouts();
} catch (error) {
console.error(error);
createNotification({
text: "Failed to clear lockouts. Please try again.",
type: "error"
});
}
}
const clearLockouts = async () => {
const deleted = await mutateAsync({ identityId });
createNotification({
text: `Successfully cleared ${deleted} lockout${deleted === 1 ? "" : "s"}`,
type: "success"
});
setLockedOutState(false);
onResetAllLockouts();
};
return (
<>

View File

@@ -51,28 +51,17 @@ export const IdentityTokenAuthTokensTable = ({ tokens, identityId }: Props) => {
tokenId: string;
name: string;
}) => {
try {
await revokeToken({
identityId: parentIdentityId,
tokenId
});
await revokeToken({
identityId: parentIdentityId,
tokenId
});
handlePopUpClose("revokeToken");
handlePopUpClose("revokeToken");
createNotification({
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"
});
}
createNotification({
text: `Successfully revoked token ${name ?? ""}`,
type: "success"
});
};
return (

View File

@@ -43,25 +43,17 @@ export const IdentityUniversalAuthClientSecretsTable = ({ clientSecrets, identit
const { mutateAsync: revokeClientSecret } = useRevokeIdentityUniversalAuthClientSecret();
const onDeleteClientSecretSubmit = async (clientSecretId: string) => {
try {
await revokeClientSecret({
identityId,
clientSecretId
});
await revokeClientSecret({
identityId,
clientSecretId
});
handlePopUpToggle("revokeClientSecret", false);
handlePopUpToggle("revokeClientSecret", false);
createNotification({
text: "Successfully deleted client secret",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete client secret",
type: "error"
});
}
createNotification({
text: "Successfully deleted client secret",
type: "success"
});
};
return (

View File

@@ -140,25 +140,17 @@ export const Content = ({
}
const handleDeleteAuthMethod = async () => {
try {
await revokeMethod({
identityId,
organizationId: orgId
});
await revokeMethod({
identityId,
organizationId: orgId
});
createNotification({
text: "Successfully removed auth method",
type: "success"
});
handlePopUpToggle("revokeAuthMethod", false);
onDeleteAuthMethod();
} catch {
createNotification({
text: "Failed to remove auth method",
type: "error"
});
}
createNotification({
text: "Successfully removed auth method",
type: "success"
});
handlePopUpToggle("revokeAuthMethod", false);
onDeleteAuthMethod();
};
return (

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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,22 +102,15 @@ export const AllProjectView = ({
projectId: string,
environments: ProjectEnv[]
) => {
try {
await orgAdminAccessProject.mutateAsync({
await orgAdminAccessProject.mutateAsync({
projectId
});
await navigate({
to: getProjectHomePage(type, environments),
params: {
projectId
});
await navigate({
to: getProjectHomePage(type, environments),
params: {
projectId
}
});
} catch {
createNotification({
text: "Failed to access project",
type: "error"
});
}
}
});
};
useResetPageHelper({

View File

@@ -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,32 +157,18 @@ 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"
if (currentOrg?.id) {
await updateUserProjectFavorites({
orgId: currentOrg?.id,
projectFavorites: [...(projectFavorites || []), projectId]
});
}
};
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"
if (currentOrg?.id) {
await updateUserProjectFavorites({
orgId: currentOrg?.id,
projectFavorites: [...(projectFavorites || []).filter((entry) => entry !== projectId)]
});
}
};

View File

@@ -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 ?? "");

View File

@@ -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 (

View File

@@ -56,35 +56,27 @@ 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,
expiresAt
});
const { id } = await createSecretRequest({
name,
accessType,
expiresAt
});
const link = new URL(`${window.location.origin}/secret-request/secret/${id}`);
if (subOrganization) {
link.searchParams.set("subOrganization", subOrganization);
}
setSecretLink(link.toString());
reset();
navigator.clipboard.writeText(link.toString());
setCopyTextSecret("secret");
createNotification({
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 link = new URL(`${window.location.origin}/secret-request/secret/${id}`);
if (subOrganization) {
link.searchParams.set("subOrganization", subOrganization);
}
setSecretLink(link.toString());
reset();
navigator.clipboard.writeText(link.toString());
setCopyTextSecret("secret");
createNotification({
text: "Shared secret link copied to clipboard.",
type: "success"
});
};
const hasSecretLink = Boolean(secretLink);

View File

@@ -22,23 +22,15 @@ export const RequestSecretTab = () => {
const { mutateAsync: deleteSecretRequest } = useDeleteSecretRequest();
const onDeleteApproved = async () => {
try {
await deleteSecretRequest({
secretRequestId: popUp.deleteSecretRequestConfirmation.data?.id
});
createNotification({
text: "Successfully deleted secret request",
type: "success"
});
await deleteSecretRequest({
secretRequestId: popUp.deleteSecretRequestConfirmation.data?.id
});
createNotification({
text: "Successfully deleted secret request",
type: "success"
});
handlePopUpClose("deleteSecretRequestConfirmation");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete shared secret",
type: "error"
});
}
handlePopUpClose("deleteSecretRequestConfirmation");
};
return (

View File

@@ -90,28 +90,21 @@ export const OrgSecretShareLimitSection = () => {
}, [currentOrg, reset]);
const handleFormSubmit = async (formData: TForm) => {
try {
const maxSharedSecretLifetimeSeconds =
ms(`${formData.maxLifetimeValue}${formData.maxLifetimeUnit}`) / 1000;
const maxSharedSecretLifetimeSeconds =
ms(`${formData.maxLifetimeValue}${formData.maxLifetimeUnit}`) / 1000;
await mutateAsync({
orgId: currentOrg.id,
maxSharedSecretViewLimit: formData.shouldLimitView ? Number(formData.maxViewLimit) : null,
maxSharedSecretLifetime: maxSharedSecretLifetimeSeconds
});
await mutateAsync({
orgId: currentOrg.id,
maxSharedSecretViewLimit: formData.shouldLimitView ? Number(formData.maxViewLimit) : null,
maxSharedSecretLifetime: maxSharedSecretLifetimeSeconds
});
createNotification({
text: "Successfully updated secret share limits",
type: "success"
});
createNotification({
text: "Successfully updated secret share limits",
type: "success"
});
reset(formData);
} catch {
createNotification({
text: "Failed to update secret share limits",
type: "error"
});
}
reset(formData);
};
// Units for the dropdown with readable labels

View File

@@ -9,25 +9,17 @@ export const SecretSharingAllowShareToAnyone = () => {
const { mutateAsync } = useUpdateOrg();
const handleSecretSharingToggle = async (value: boolean) => {
try {
if (!currentOrg?.id) return;
if (!currentOrg?.id) return;
await mutateAsync({
orgId: currentOrg.id,
allowSecretSharingOutsideOrganization: value
});
await mutateAsync({
orgId: currentOrg.id,
allowSecretSharingOutsideOrganization: value
});
createNotification({
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"
});
}
createNotification({
text: `Successfully ${value ? "enabled" : "disabled"} secret sharing to members outside of this organization`,
type: "success"
});
};
return (

View File

@@ -20,23 +20,15 @@ export const ShareSecretTab = () => {
const deleteSecretShare = useDeleteSharedSecret();
const onDeleteApproved = async () => {
try {
deleteSecretShare.mutateAsync({
sharedSecretId: (popUp?.deleteSharedSecretConfirmation?.data as DeleteModalData)?.id
});
createNotification({
text: "Successfully deleted shared secret",
type: "success"
});
deleteSecretShare.mutateAsync({
sharedSecretId: (popUp?.deleteSharedSecretConfirmation?.data as DeleteModalData)?.id
});
createNotification({
text: "Successfully deleted shared secret",
type: "success"
});
handlePopUpClose("deleteSharedSecretConfirmation");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete shared secret",
type: "error"
});
}
handlePopUpClose("deleteSharedSecretConfirmation");
};
return (

View File

@@ -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"
});
}
const logStream = await createAuditLogStream.mutateAsync(formData);
createNotification({
text: `Successfully created ${providerName} Log Stream`,
type: "success"
});
onComplete(logStream);
};
switch (provider) {
@@ -68,24 +59,15 @@ const UpdateForm = ({ auditLogStream, onComplete }: UpdateFormProps) => {
const onSubmit = async (
formData: DiscriminativePick<TAuditLogStream, "provider" | "credentials">
) => {
try {
const connection = await updateAuditLogStream.mutateAsync({
auditLogStreamId: auditLogStream.id,
...formData
});
createNotification({
text: `Successfully updated ${providerName} Log Stream`,
type: "success"
});
onComplete(connection);
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to update ${providerName} Log Stream`,
text: err.message,
type: "error"
});
}
const connection = await updateAuditLogStream.mutateAsync({
auditLogStreamId: auditLogStream.id,
...formData
});
createNotification({
text: `Successfully updated ${providerName} Log Stream`,
type: "success"
});
onComplete(connection);
};
switch (auditLogStream.provider) {

View File

@@ -20,26 +20,17 @@ export const DeleteAuditLogStreamModal = ({ isOpen, onOpenChange, auditLogStream
const providerDetails = AUDIT_LOG_STREAM_PROVIDER_MAP[provider];
const handleDelete = async () => {
try {
await deleteAuditLogStream.mutateAsync({
auditLogStreamId,
provider
});
await deleteAuditLogStream.mutateAsync({
auditLogStreamId,
provider
});
createNotification({
text: `Successfully deleted ${providerDetails.name} stream`,
type: "success"
});
createNotification({
text: `Successfully deleted ${providerDetails.name} stream`,
type: "success"
});
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: `Failed to delete ${providerDetails.name} stream`,
type: "error"
});
}
onOpenChange(false);
};
return (

View File

@@ -54,21 +54,13 @@ export const VaultConnectionSection = () => {
const handleDeleteConfirm = async () => {
if (!configToDelete) return;
try {
await deleteConfig({ id: configToDelete.id });
createNotification({
type: "success",
text: "Namespace configuration deleted successfully"
});
setIsDeleteModalOpen(false);
setConfigToDelete(null);
} catch (error) {
console.error("Failed to delete namespace config:", error);
createNotification({
type: "error",
text: "Failed to delete namespace configuration"
});
}
await deleteConfig({ id: configToDelete.id });
createNotification({
type: "success",
text: "Namespace configuration deleted successfully"
});
setIsDeleteModalOpen(false);
setConfigToDelete(null);
};
const getConnectionName = (connectionId: string | null) => {

View File

@@ -74,36 +74,28 @@ export const VaultNamespaceConfigModal = ({ isOpen, onOpenChange, editConfig }:
}, [isOpen, editConfig, reset]);
const onFormSubmit = async (data: FormData) => {
try {
if (isEdit && editConfig) {
await updateConfig({
id: editConfig.id,
namespace: data.namespace,
connectionId: data.connectionId
});
createNotification({
type: "success",
text: "Namespace configuration updated successfully"
});
} else {
await createConfig({
namespace: data.namespace,
connectionId: data.connectionId
});
createNotification({
type: "success",
text: "Namespace configuration created successfully"
});
}
reset();
onOpenChange(false);
} catch (error) {
console.error("Failed to save namespace config:", error);
if (isEdit && editConfig) {
await updateConfig({
id: editConfig.id,
namespace: data.namespace,
connectionId: data.connectionId
});
createNotification({
type: "error",
text: `Failed to ${isEdit ? "update" : "create"} namespace configuration`
type: "success",
text: "Namespace configuration updated successfully"
});
} else {
await createConfig({
namespace: data.namespace,
connectionId: data.connectionId
});
createNotification({
type: "success",
text: "Namespace configuration created successfully"
});
}
reset();
onOpenChange(false);
};
const handleClose = () => {

View File

@@ -19,27 +19,19 @@ export const OrgDeleteSection = () => {
const { mutateAsync, isPending } = useDeleteOrgById();
const handleDeleteOrgSubmit = async () => {
try {
if (!currentOrg?.id) return;
if (!currentOrg?.id) return;
await mutateAsync({
organizationId: currentOrg?.id
});
await mutateAsync({
organizationId: currentOrg?.id
});
createNotification({
text: "Successfully deleted organization",
type: "success"
});
createNotification({
text: "Successfully deleted organization",
type: "success"
});
clearSession();
navigate({ to: "/login" });
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete organization",
type: "error"
});
}
clearSession();
navigate({ to: "/login" });
};
return (

View File

@@ -51,18 +51,14 @@ export const OrgEncryptionTab = withPermission(
kmsId: string;
};
try {
await removeExternalKms(kmsId);
await removeExternalKms(kmsId);
createNotification({
text: "Successfully deleted external KMS",
type: "success"
});
createNotification({
text: "Successfully deleted external KMS",
type: "success"
});
handlePopUpToggle("removeExternalKms", false);
} catch (err) {
console.error(err);
}
handlePopUpToggle("removeExternalKms", false);
};
return (

View File

@@ -35,31 +35,23 @@ export const AddOrgIncidentContactModal = ({
const { mutateAsync, isPending } = useAddIncidentContact();
const onFormSubmit = async ({ email }: TAddContactForm) => {
try {
if (!currentOrg?.id) return;
if (!currentOrg?.id) return;
await mutateAsync({
orgId: currentOrg.id,
email
});
await mutateAsync({
orgId: currentOrg.id,
email
});
createNotification({
text: "Successfully added incident contact",
type: "success"
});
createNotification({
text: "Successfully added incident contact",
type: "success"
});
if (serverDetails?.emailConfigured) {
handlePopUpClose("addContact");
}
reset();
} catch (err) {
console.error(err);
createNotification({
text: "Failed to add incident contact",
type: "error"
});
if (serverDetails?.emailConfigured) {
handlePopUpClose("addContact");
}
reset();
};
return (

View File

@@ -33,28 +33,20 @@ export const OrgIncidentContactsTable = () => {
const { mutateAsync } = useDeleteIncidentContact();
const onRemoveIncidentContact = async () => {
try {
const incidentContactId = (popUp?.removeContact?.data as { id: string })?.id;
const incidentContactId = (popUp?.removeContact?.data as { id: string })?.id;
if (!currentOrg?.id) return;
await mutateAsync({
orgId: currentOrg.id,
incidentContactId
});
if (!currentOrg?.id) return;
await mutateAsync({
orgId: currentOrg.id,
incidentContactId
});
createNotification({
text: "Successfully removed incident contact",
type: "success"
});
createNotification({
text: "Successfully removed incident contact",
type: "success"
});
handlePopUpClose("removeContact");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to remove incident contact",
type: "error"
});
}
handlePopUpClose("removeContact");
};
const filteredContacts = contacts

View File

@@ -56,27 +56,19 @@ export const OrgNameChangeSection = (): JSX.Element => {
}, [roles]);
const onFormSubmit = async ({ name, slug, defaultMembershipRole }: FormData) => {
try {
if (!currentOrg?.id || !roles?.length) return;
if (!currentOrg?.id || !roles?.length) return;
await mutateAsync({
orgId: currentOrg?.id,
name,
slug,
defaultMembershipRoleSlug: defaultMembershipRole
});
await mutateAsync({
orgId: currentOrg?.id,
name,
slug,
defaultMembershipRoleSlug: defaultMembershipRole
});
createNotification({
text: "Successfully updated organization details",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to update organization details",
type: "error"
});
}
createNotification({
text: "Successfully updated organization details",
type: "success"
});
};
if (!isFormInitialized) {

View File

@@ -39,26 +39,18 @@ export const SubOrgNameChangeSection = (): JSX.Element => {
const { mutateAsync, isPending } = useUpdateSubOrganization();
const onFormSubmit = async ({ name }: FormData) => {
try {
await mutateAsync({
name,
subOrgId: currentOrg.id
});
await mutateAsync({
name,
subOrgId: currentOrg.id
});
navigate({ to: "/organization/settings", search: { subOrganization: name } });
queryClient.invalidateQueries();
await router.invalidate({ sync: true });
createNotification({
text: "Successfully updated sub-organization details",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to update sub-organization details",
type: "error"
});
}
navigate({ to: "/organization/settings", search: { subOrganization: name } });
queryClient.invalidateQueries();
await router.invalidate({ sync: true });
createNotification({
text: "Successfully updated sub-organization details",
type: "success"
});
};
return (

View File

@@ -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
});
}
}
await mutateAsync({
orgId: currentOrg.id,
[key]: value
});
setIsLoading(false);
};

View File

@@ -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);
}

View File

@@ -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"
});
}
await updateMappings.mutateAsync(form);
createNotification({
text: "Group organization role mappings updated.",
type: "success"
});
};
const disableScimEdit = permission.cannot(OrgPermissionActions.Edit, OrgPermissionSubjects.Scim);

View File

@@ -122,53 +122,45 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
caCert,
shouldCloseModal = true
}: TLDAPFormData & { shouldCloseModal?: boolean }) => {
try {
if (!currentOrg) return;
if (!currentOrg) return;
if (!data) {
await createMutateAsync({
organizationId: currentOrg.id,
isActive: false,
url,
bindDN,
bindPass,
searchBase,
searchFilter,
uniqueUserAttribute,
groupSearchBase,
groupSearchFilter,
caCert
});
} else {
await updateMutateAsync({
organizationId: currentOrg.id,
url,
bindDN,
bindPass,
searchBase,
searchFilter,
uniqueUserAttribute,
groupSearchBase,
groupSearchFilter,
caCert
});
}
if (shouldCloseModal) {
handlePopUpClose("addLDAP");
}
createNotification({
text: `Successfully ${!data ? "added" : "updated"} LDAP configuration`,
type: "success"
if (!data) {
await createMutateAsync({
organizationId: currentOrg.id,
isActive: false,
url,
bindDN,
bindPass,
searchBase,
searchFilter,
uniqueUserAttribute,
groupSearchBase,
groupSearchFilter,
caCert
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${!data ? "add" : "update"} LDAP configuration`,
type: "error"
} else {
await updateMutateAsync({
organizationId: currentOrg.id,
url,
bindDN,
bindPass,
searchBase,
searchFilter,
uniqueUserAttribute,
groupSearchBase,
groupSearchFilter,
caCert
});
}
if (shouldCloseModal) {
handlePopUpClose("addLDAP");
}
createNotification({
text: `Successfully ${!data ? "added" : "updated"} LDAP configuration`,
type: "success"
});
};
const handleTestLDAPConnection = async () => {

View File

@@ -122,31 +122,24 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
if (!currentOrg) {
return;
}
try {
await updateMutateAsync({
issuer: "",
discoveryURL: "",
authorizationEndpoint: "",
allowedEmailDomains: "",
jwksUri: "",
tokenEndpoint: "",
userinfoEndpoint: "",
clientId: "",
clientSecret: "",
isActive: false,
organizationId: currentOrg.id
});
await updateMutateAsync({
issuer: "",
discoveryURL: "",
authorizationEndpoint: "",
allowedEmailDomains: "",
jwksUri: "",
tokenEndpoint: "",
userinfoEndpoint: "",
clientId: "",
clientSecret: "",
isActive: false,
organizationId: currentOrg.id
});
createNotification({
text: "Successfully deleted OIDC configuration.",
type: "success"
});
} catch {
createNotification({
text: "Failed deleting OIDC configuration.",
type: "error"
});
}
createNotification({
text: "Successfully deleted OIDC configuration.",
type: "success"
});
};
useEffect(() => {
@@ -178,58 +171,50 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
clientSecret,
jwtSignatureAlgorithm
}: OIDCFormData) => {
try {
if (!currentOrg) {
return;
}
if (!currentOrg) {
return;
}
if (!data) {
await createMutateAsync({
issuer,
configurationType,
discoveryURL,
authorizationEndpoint,
allowedEmailDomains,
jwksUri,
tokenEndpoint,
userinfoEndpoint,
clientId,
clientSecret,
isActive: true,
organizationId: currentOrg.id,
jwtSignatureAlgorithm
});
} else {
await updateMutateAsync({
issuer,
configurationType,
discoveryURL,
authorizationEndpoint,
allowedEmailDomains,
jwksUri,
tokenEndpoint,
userinfoEndpoint,
clientId,
clientSecret,
isActive: true,
organizationId: currentOrg.id,
jwtSignatureAlgorithm
});
}
handlePopUpClose("addOIDC");
createNotification({
text: `Successfully ${!data ? "added" : "updated"} OIDC SSO configuration`,
type: "success"
if (!data) {
await createMutateAsync({
issuer,
configurationType,
discoveryURL,
authorizationEndpoint,
allowedEmailDomains,
jwksUri,
tokenEndpoint,
userinfoEndpoint,
clientId,
clientSecret,
isActive: true,
organizationId: currentOrg.id,
jwtSignatureAlgorithm
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${!data ? "add" : "update"} OIDC SSO configuration`,
type: "error"
} else {
await updateMutateAsync({
issuer,
configurationType,
discoveryURL,
authorizationEndpoint,
allowedEmailDomains,
jwksUri,
tokenEndpoint,
userinfoEndpoint,
clientId,
clientSecret,
isActive: true,
organizationId: currentOrg.id,
jwtSignatureAlgorithm
});
}
handlePopUpClose("addOIDC");
createNotification({
text: `Successfully ${!data ? "added" : "updated"} OIDC SSO configuration`,
type: "success"
});
};
return (

View File

@@ -108,64 +108,49 @@ export const SSOModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDelet
if (!currentOrg) {
return;
}
try {
await updateMutateAsync({
organizationId: currentOrg.id,
isActive: false,
entryPoint: "",
issuer: "",
cert: ""
});
await updateMutateAsync({
organizationId: currentOrg.id,
isActive: false,
entryPoint: "",
issuer: "",
cert: ""
});
createNotification({
text: "Successfully deleted SAML SSO configuration.",
type: "success"
});
} catch {
createNotification({
text: "Failed deleting SAML SSO configuration.",
type: "error"
});
}
createNotification({
text: "Successfully deleted SAML SSO configuration.",
type: "success"
});
};
const onSSOModalSubmit = async ({ authProvider, entryPoint, issuer, cert }: AddSSOFormData) => {
try {
if (!currentOrg) return;
if (!currentOrg) return;
if (!data) {
await createMutateAsync({
organizationId: currentOrg.id,
authProvider,
isActive: false,
entryPoint,
issuer,
cert
});
} else {
await updateMutateAsync({
organizationId: currentOrg.id,
authProvider,
isActive: false,
entryPoint,
issuer,
cert
});
}
handlePopUpClose("addSSO");
createNotification({
text: `Successfully ${!data ? "added" : "updated"} SAML SSO configuration`,
type: "success"
if (!data) {
await createMutateAsync({
organizationId: currentOrg.id,
authProvider,
isActive: false,
entryPoint,
issuer,
cert
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${!data ? "add" : "update"} SAML SSO configuration`,
type: "error"
} else {
await updateMutateAsync({
organizationId: currentOrg.id,
authProvider,
isActive: false,
entryPoint,
issuer,
cert
});
}
handlePopUpClose("addSSO");
createNotification({
text: `Successfully ${!data ? "added" : "updated"} SAML SSO configuration`,
type: "success"
});
};
const renderLabels = (authProvider: string) => {

View File

@@ -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 (

View File

@@ -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 {

View File

@@ -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");

View File

@@ -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 (

View File

@@ -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 (

View File

@@ -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 (

View File

@@ -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");

View File

@@ -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(

View File

@@ -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" });
}
await backfillSecretReferences.mutateAsync({ projectId: currentProject.id || "" });
createNotification({ text: "Successfully re-indexed secret references", type: "success" });
};
const isAdmin = hasProjectRole(ProjectMembershipRole.Admin);