refactor: streamline modal close handlers and completion callbacks across various components

This commit is contained in:
Victor Santos
2025-10-31 18:43:34 -03:00
parent 7d8b28367e
commit b26fb73053
116 changed files with 1865 additions and 2949 deletions
@@ -35,7 +35,6 @@ export const WishForm = () => {
const [isOpen, setIsOpen] = useToggle(false);
const createWish = async (data: TFormData) => {
try {
await mutateAsync({
text: data.text
});
@@ -46,12 +45,6 @@ export const WishForm = () => {
});
setIsOpen.off();
} catch {
createNotification({
text: "An error occured while sending your wish to the Infisical team.",
type: "error"
});
}
};
return (
@@ -43,7 +43,6 @@ export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose }) =>
const { mutateAsync: selectOrg } = useSelectOrganization();
const onFormSubmit = async ({ name }: FormData) => {
try {
const organization = await createOrg({
name
});
@@ -65,13 +64,6 @@ export const CreateOrgModal: FC<CreateOrgModalProps> = ({ isOpen, onClose }) =>
reset();
onClose();
} catch (err) {
console.error(err);
createNotification({
text: "Failed to created organization",
type: "error"
});
}
};
return (
@@ -20,7 +20,6 @@ export const DeletePkiSyncModal = ({ isOpen, onOpenChange, pkiSync, onComplete }
const handleDeletePkiSync = async () => {
const destinationName = PKI_SYNC_MAP[destination].name;
try {
await deleteSync.mutateAsync({
syncId,
projectId,
@@ -34,14 +33,6 @@ export const DeletePkiSyncModal = ({ isOpen, onOpenChange, pkiSync, onComplete }
if (onComplete) onComplete();
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: `Failed to delete ${destinationName} PKI Sync`,
type: "error"
});
}
};
return (
@@ -21,7 +21,6 @@ const Content = ({ pkiSync, onComplete }: ContentProps) => {
const triggerImportCertificates = useTriggerPkiSyncImportCertificates();
const handleTriggerImportCertificates = async () => {
try {
await triggerImportCertificates.mutateAsync({
syncId,
destination,
@@ -34,14 +33,6 @@ const Content = ({ pkiSync, onComplete }: ContentProps) => {
});
onComplete();
} catch (err) {
console.error(err);
createNotification({
text: `Failed to trigger certificate import for ${destinationName} Sync`,
type: "error"
});
}
};
return (
@@ -21,7 +21,6 @@ const Content = ({ pkiSync, onComplete }: ContentProps) => {
const triggerRemoveCertificates = useTriggerPkiSyncRemoveCertificates();
const handleTriggerRemoveCertificates = async () => {
try {
await triggerRemoveCertificates.mutateAsync({
syncId,
destination,
@@ -34,14 +33,6 @@ const Content = ({ pkiSync, onComplete }: ContentProps) => {
});
onComplete();
} catch (err) {
console.error(err);
createNotification({
text: `Failed to trigger certificate removal for ${destinationName} Sync`,
type: "error"
});
}
};
return (
@@ -72,14 +72,8 @@ export const CreatePkiSyncForm = ({ destination, onComplete, onCancel }: Props)
type: "success"
});
onComplete(pkiSync);
} catch (err: Error | unknown) {
console.error(err);
} catch {
setShowConfirmation(false);
createNotification({
title: `Failed to add ${destinationName} Certificate Sync`,
text: err instanceof Error ? err.message : "An unknown error occurred",
type: "error"
});
}
};
@@ -38,7 +38,6 @@ export const EditPkiSyncForm = ({ pkiSync, fields, onComplete }: Props) => {
});
const onSubmit = async ({ connection, ...formData }: TUpdatePkiSyncForm) => {
try {
const updatedPkiSync = await updatePkiSync.mutateAsync({
syncId: pkiSync.id,
...formData,
@@ -52,14 +51,6 @@ export const EditPkiSyncForm = ({ pkiSync, fields, onComplete }: Props) => {
type: "success"
});
onComplete(updatedPkiSync);
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to update ${destinationName} PKI Sync`,
text: err.message,
type: "error"
});
}
};
let Component: ReactNode;
@@ -56,7 +56,6 @@ export const ProjectOverviewChangeSection = ({ showSlugField = false }: Props) =
}, [currentProject, showSlugField]);
const onFormSubmit = async (data: BaseFormData | FormDataWithSlug) => {
try {
if (!currentProject?.id) return;
await mutateAsync({
@@ -73,13 +72,6 @@ export const ProjectOverviewChangeSection = ({ showSlugField = false }: Props) =
text: "Successfully updated project overview",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update project overview",
type: "error"
});
}
};
return (
@@ -141,7 +141,6 @@ const NewProjectForm = ({ onOpenChange }: NewProjectFormProps) => {
// type check
if (!currentOrg) return;
if (!user) return;
try {
const {
data: { project }
} = await createWs.mutateAsync({
@@ -160,10 +159,6 @@ const NewProjectForm = ({ onOpenChange }: NewProjectFormProps) => {
to: getProjectHomePage(project.type, project.environments),
params: { projectId: project.id }
});
} catch (err) {
console.error(err);
createNotification({ text: "Failed to create project", type: "error" });
}
};
const onSubmit = handleSubmit((data) => {
return onCreateProject(data);
@@ -37,7 +37,6 @@ export const DeleteSecretRotationV2Modal = ({
const handleDeleteSecretRotation = async () => {
const rotationType = SECRET_ROTATION_MAP[type].name;
try {
await deleteSecretRotation.mutateAsync({
rotationId,
type,
@@ -54,12 +53,6 @@ export const DeleteSecretRotationV2Modal = ({
if (onComplete) onComplete();
onOpenChange(false);
} catch {
createNotification({
text: `Failed to delete ${rotationType} Rotation`,
type: "error"
});
}
};
return (
@@ -22,7 +22,6 @@ const Content = ({ secretRotation, onComplete }: ContentProps) => {
const rotationType = SECRET_ROTATION_MAP[type].name;
const handleRotateSecrets = async () => {
try {
await rotateSecrets.mutateAsync({
rotationId,
type,
@@ -36,14 +35,6 @@ const Content = ({ secretRotation, onComplete }: ContentProps) => {
});
onComplete();
} catch (err) {
console.error(err);
createNotification({
text: `Failed to rotate ${rotationType} secrets`,
type: "error"
});
}
};
return (
@@ -120,7 +120,6 @@ export const SecretRotationV2Form = ({
environment: environment.slug,
projectId: currentProject.id
});
try {
const rotation = await mutation;
createNotification({
@@ -128,13 +127,6 @@ export const SecretRotationV2Form = ({
type: "success"
});
onComplete(rotation);
} catch (err: any) {
createNotification({
title: `Failed to ${secretRotation ? "update" : "create"} ${rotationType} Rotation`,
text: err.message,
type: "error"
});
}
};
const handlePrev = () => {
@@ -28,7 +28,6 @@ export const DeleteSecretScanningDataSourceModal = ({
const handleDeleteDataSource = async () => {
const dataSourceType = SECRET_SCANNING_DATA_SOURCE_MAP[type].name;
try {
await deleteDataSource.mutateAsync({
dataSourceId,
type,
@@ -42,12 +41,6 @@ export const DeleteSecretScanningDataSourceModal = ({
if (onComplete) onComplete();
onOpenChange(false);
} catch {
createNotification({
text: `Failed to delete ${dataSourceType} Data Source`,
type: "error"
});
}
};
return (
@@ -73,7 +73,6 @@ export const SecretScanningDataSourceForm = ({
connectionId: connection?.id,
projectId: currentProject.id
});
try {
const source = await mutation;
createNotification({
@@ -81,13 +80,6 @@ export const SecretScanningDataSourceForm = ({
type: "success"
});
onComplete(source);
} catch (err: any) {
createNotification({
title: `Failed to ${dataSource ? "update" : "create"} ${sourceType} Data Source`,
text: err.message,
type: "error"
});
}
};
const handlePrev = () => {
@@ -23,7 +23,6 @@ export const DeleteSecretSyncModal = ({ isOpen, onOpenChange, secretSync, onComp
const handleDeleteSecretSync = async () => {
const destinationName = SECRET_SYNC_MAP[destination].name;
try {
await deleteSync.mutateAsync({
syncId,
destination,
@@ -38,14 +37,6 @@ export const DeleteSecretSyncModal = ({ isOpen, onOpenChange, secretSync, onComp
if (onComplete) onComplete();
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: `Failed to remove ${destinationName} Sync`,
type: "error"
});
}
};
return (
@@ -51,7 +51,6 @@ const Content = ({ secretSync, onComplete }: ContentProps) => {
const triggerImportSecrets = useTriggerSecretSyncImportSecrets();
const handleTriggerImportSecrets = async ({ importBehavior }: TFormData) => {
try {
await triggerImportSecrets.mutateAsync({
syncId,
destination,
@@ -65,14 +64,6 @@ const Content = ({ secretSync, onComplete }: ContentProps) => {
});
onComplete();
} catch (err) {
console.error(err);
createNotification({
text: `Failed to trigger secret import for ${destinationName} Sync`,
type: "error"
});
}
};
return (
@@ -21,7 +21,6 @@ const Content = ({ secretSync, onComplete }: ContentProps) => {
const triggerSyncImport = useTriggerSecretSyncRemoveSecrets();
const handleTriggerRemoveSecrets = async () => {
try {
await triggerSyncImport.mutateAsync({
syncId,
destination,
@@ -34,14 +33,6 @@ const Content = ({ secretSync, onComplete }: ContentProps) => {
});
onComplete();
} catch (err) {
console.error(err);
createNotification({
text: `Failed to trigger secret removal for ${destinationName} Sync`,
type: "error"
});
}
};
return (
@@ -88,14 +88,8 @@ export const CreateSecretSyncForm = ({
type: "success"
});
onComplete(secretSync);
} catch (err: any) {
console.error(err);
} catch {
setShowConfirmation(false);
createNotification({
title: `Failed to add ${destinationName} Sync`,
text: err.message,
type: "error"
});
}
};
@@ -58,7 +58,6 @@ export const EditSecretSyncForm = ({ secretSync, fields, onComplete }: Props) =>
const performUpdate = useCallback(
async (formData: TSecretSyncForm) => {
try {
const { environment, connection, ...updateData } = formData;
const updatedSecretSync = await updateSecretSync.mutateAsync({
syncId: secretSync.id,
@@ -73,14 +72,6 @@ export const EditSecretSyncForm = ({ secretSync, fields, onComplete }: Props) =>
type: "success"
});
onComplete(updatedSecretSync);
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to update ${destinationName} Sync`,
text: err.message,
type: "error"
});
}
},
[updateSecretSync, secretSync.id, secretSync.projectId, destinationName, onComplete]
);
@@ -130,7 +130,6 @@ export const CreateTagModal = ({ isOpen, onToggle, append, currentSecret }: Prop
}, [isOpen]);
const onFormSubmit = async ({ slug, color }: FormData) => {
try {
const data = await createWsTag({
projectId,
tagColor: color,
@@ -143,13 +142,6 @@ export const CreateTagModal = ({ isOpen, onToggle, append, currentSecret }: Prop
text: "Successfully created a tag",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to create a tag",
type: "error"
});
}
};
return (
@@ -36,7 +36,6 @@ export const NewSubOrganizationForm = ({ onClose }: ContentProps) => {
const router = useRouter();
const onSubmit = async ({ name }: FormData) => {
try {
const { organization } = await createSubOrg.mutateAsync({
name
});
@@ -52,12 +51,6 @@ export const NewSubOrganizationForm = ({ onClose }: ContentProps) => {
search: (prev) => ({ ...prev, subOrganization: organization.name })
});
await router.invalidate({ sync: true }).catch(() => null);
} catch {
createNotification({
text: "Failed to create sub organization",
type: "error"
});
}
};
return (
@@ -11,7 +11,6 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { Link, linkOptions } from "@tanstack/react-router";
import { UpgradePlanModal } from "@app/components/license/UpgradePlanModal";
import { createNotification } from "@app/components/notifications";
import { OrgPermissionCan } from "@app/components/permissions";
import { NewProjectModal } from "@app/components/projects";
import {
@@ -59,31 +58,17 @@ export const ProjectSelect = () => {
const { mutateAsync: updateUserProjectFavorites } = useUpdateUserProjectFavorites();
const addProjectToFavorites = async (projectId: string) => {
try {
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 {
await updateUserProjectFavorites({
orgId: currentOrg!.id,
projectFavorites: [...(projectFavorites || []).filter((entry) => entry !== projectId)]
});
} catch {
createNotification({
text: "Failed to remove project from favorites.",
type: "error"
});
}
};
const isAddingProjectsAllowed = subscription?.workspaceLimit
@@ -65,7 +65,6 @@ const Content = ({ onClose }: ContentProps) => {
const users = usersData.filter((user) => !user.superAdmin);
const onSubmit = async ({ user }: FormData) => {
try {
await grantAdmin.mutateAsync(user.id);
createNotification({
@@ -73,12 +72,6 @@ const Content = ({ onClose }: ContentProps) => {
text: "Successfully granted server admin status"
});
onClose();
} catch {
createNotification({
text: "Failed to grant server admin status",
type: "error"
});
}
};
return (
@@ -303,18 +303,11 @@ export const ServerAdminsTable = () => {
const handleRemoveUser = async () => {
const { id } = popUp?.removeUser?.data as { id: string; username: string };
try {
await deleteUser(id);
createNotification({
type: "success",
text: "Successfully deleted user"
});
} catch {
createNotification({
type: "error",
text: "Error deleting user"
});
}
handlePopUpClose("removeUser");
};
@@ -322,24 +315,16 @@ export const ServerAdminsTable = () => {
const handleRemoveServerAdminAccess = async () => {
const { id } = popUp?.removeServerAdmin?.data as { id: string; username: string };
try {
await removeAdminAccess(id);
createNotification({
type: "success",
text: "Successfully removed server admin access from user"
});
} catch {
createNotification({
type: "error",
text: "Error removing server admin access from user"
});
}
handlePopUpClose("removeServerAdmin");
};
const handleRemoveUsers = async () => {
try {
await deleteUsers(selectedUsers.map((user) => user.id));
createNotification({
@@ -349,12 +334,6 @@ export const ServerAdminsTable = () => {
setSelectedUsers([]);
handlePopUpClose("removeUsers");
} catch {
createNotification({
text: "Failed to remove users",
type: "error"
});
}
};
return (
@@ -54,7 +54,6 @@ export const AuthenticationPageForm = () => {
});
const onAuthFormSubmit = async (formData: TAuthForm) => {
try {
const enabledMethods: LoginMethod[] = [];
if (formData.isEmailEnabled) {
enabledMethods.push(LoginMethod.EMAIL);
@@ -100,13 +99,6 @@ export const AuthenticationPageForm = () => {
text: "Login methods have been successfully updated.",
type: "success"
});
} catch (e) {
console.error(e);
createNotification({
type: "error",
text: "Failed to update login methods."
});
}
};
return (
@@ -31,15 +31,10 @@ export const CachingPageForm = () => {
const handleInvalidateCacheSubmit = async () => {
if (!type || isInvalidating) return;
try {
await invalidateCache({ type });
createNotification({ text: `Began invalidating ${type} cache`, type: "success" });
setShouldPoll(true);
handlePopUpClose("invalidateCache");
} catch (err) {
console.error(err);
createNotification({ text: `Failed to invalidate ${type} cache`, type: "error" });
}
};
useEffect(() => {
@@ -60,19 +60,12 @@ export const EncryptionPageForm = () => {
return;
}
try {
await updateEncryptionStrategy(formData.encryptionStrategy);
createNotification({
type: "success",
text: "Encryption strategy updated successfully"
});
} catch {
createNotification({
type: "error",
text: "Failed to update encryption strategy"
});
}
}, []);
return (
@@ -176,7 +176,6 @@ export const EnvironmentPageForm = () => {
const onSubmit = useCallback(
async (formData: TForm) => {
try {
const filteredFormData = Object.fromEntries(
Object.entries(formData).filter(([, value]) => value !== "")
);
@@ -190,17 +189,6 @@ export const EnvironmentPageForm = () => {
});
reset(formData);
} catch (error) {
const errorMessage =
(error as any)?.response?.data?.message ||
(error as any)?.message ||
"An unknown error occurred";
createNotification({
type: "error",
title: "Failed to update environment overrides",
text: errorMessage
});
}
},
[reset, updateServerConfig]
);
@@ -68,7 +68,6 @@ export const GeneralPageForm = () => {
const organizations = useGetOrganizations();
const onFormSubmit = async (formData: TDashboardForm) => {
try {
const {
allowedSignUpDomain,
trustSamlEmails,
@@ -92,13 +91,6 @@ export const GeneralPageForm = () => {
text: "Successfully changed sign up setting.",
type: "success"
});
} catch (e) {
console.error(e);
createNotification({
type: "error",
text: "Failed to update sign up setting."
});
}
};
return (
@@ -10,7 +10,6 @@ export const UsageReportSection = () => {
const generateUsageReport = useGenerateUsageReport();
const handleGenerateReport = async () => {
try {
const response = await generateUsageReport.mutateAsync();
const { csvContent, filename } = response;
@@ -20,13 +19,6 @@ export const UsageReportSection = () => {
text: `Usage report downloaded: "${filename}"`,
type: "success"
});
} catch (error) {
console.error("Failed to generate usage report:", error);
createNotification({
text: "Failed to generate usage report. Please try again.",
type: "error"
});
}
};
return (
@@ -81,7 +81,6 @@ const Content = ({ onClose }: ContentProps) => {
const { users = [] } = data ?? {};
const onSubmit = async ({ name, invitees }: FormData) => {
try {
await createOrg.mutateAsync({
name,
inviteAdminEmails: invitees
@@ -94,12 +93,6 @@ const Content = ({ onClose }: ContentProps) => {
text: "Successfully created organization"
});
onClose();
} catch {
createNotification({
text: "Failed to create organization",
type: "error"
});
}
};
const { append } = useFieldArray<FormData>({ control, name: "invitees" });
@@ -185,18 +185,11 @@ export const MachineIdentitiesTable = () => {
const handleRemoveServerAdmin = async () => {
const { id } = popUp?.removeServerAdmin?.data as { id: string; name: string };
try {
await deleteIdentitySuperAdminAccess(id);
createNotification({
type: "success",
text: "Successfully removed server admin permissions"
});
} catch {
createNotification({
type: "error",
text: "Error removing server admin permissions"
});
}
handlePopUpClose("removeServerAdmin");
};
@@ -179,12 +179,6 @@ const ViewMembersModalContent = ({
text: "Successfully resent org invitation",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to resend org invitation",
type: "error"
});
} finally {
setResendInviteId(null);
}
@@ -479,7 +473,6 @@ const OrganizationsPanelTable = ({
const { mutateAsync: accessOrganization } = useServerAdminAccessOrg();
const handleAccessOrg = async (orgId: string) => {
try {
await accessOrganization(orgId);
navigate({
@@ -493,12 +486,6 @@ const OrganizationsPanelTable = ({
text: "Successfully joined organization",
type: "success"
});
} catch {
createNotification({
text: "Failed to join organization",
type: "error"
});
}
};
return (
@@ -367,18 +367,11 @@ export const UserIdentitiesTable = () => {
const handleRemoveUser = async () => {
const { id } = popUp?.removeUser?.data as { id: string; username: string };
try {
await deleteUser(id);
createNotification({
type: "success",
text: "Successfully deleted user"
});
} catch {
createNotification({
type: "error",
text: "Error deleting user"
});
}
handlePopUpClose("removeUser");
};
@@ -386,18 +379,11 @@ export const UserIdentitiesTable = () => {
const handleGrantServerAdminAccess = async () => {
const { id } = popUp?.upgradeToServerAdmin?.data as { id: string; username: string };
try {
await grantAdminAccess(id);
createNotification({
type: "success",
text: "Successfully granted server admin access to user"
});
} catch {
createNotification({
type: "error",
text: "Error granting server admin access to user"
});
}
handlePopUpClose("upgradeToServerAdmin");
};
@@ -405,24 +391,16 @@ export const UserIdentitiesTable = () => {
const handleRemoveServerAdminAccess = async () => {
const { id } = popUp?.removeServerAdmin?.data as { id: string; username: string };
try {
await removeAdminAccess(id);
createNotification({
type: "success",
text: "Successfully removed server admin access from user"
});
} catch {
createNotification({
type: "error",
text: "Error removing server admin access from user"
});
}
handlePopUpClose("removeServerAdmin");
};
const handleRemoveUsers = async () => {
try {
await deleteUsers(selectedUsers.map((user) => user.id));
createNotification({
@@ -432,12 +410,6 @@ export const UserIdentitiesTable = () => {
setSelectedUsers([]);
handlePopUpClose("removeUsers");
} catch {
createNotification({
text: "Failed to remove users",
type: "error"
});
}
};
return (
@@ -6,7 +6,6 @@ import { useNavigate } from "@tanstack/react-router";
import { AnimatePresence, motion } from "framer-motion";
import { z } from "zod";
import { createNotification } from "@app/components/notifications";
// TODO(akhilmhdh): rewrite this into module functions in lib
import SecurityClient from "@app/components/utilities/SecurityClient";
import { Button, ContentLoader, FormControl, Input } from "@app/components/v2";
@@ -46,7 +45,6 @@ export const SignUpPage = () => {
const handleFormSubmit = async ({ email, password, firstName, lastName }: TFormSchema) => {
// avoid multi submission
if (isSubmitting) return;
try {
const res = await createAdminUser({
email,
password,
@@ -62,13 +60,6 @@ export const SignUpPage = () => {
// Part of migration to nextjs 14
localStorage.setItem("orgData.id", res.organization.id);
navigate({ to: "/admin" });
} catch (err) {
console.log(err);
createNotification({
type: "error",
text: "Failed to create admin"
});
}
};
if (config?.initialized) return <ContentLoader text="Redirecting to admin page..." />;
@@ -75,11 +75,7 @@ export const PasswordSetupPage = () => {
setTimeout(() => {
window.location.href = "/login";
}, 3000);
} catch (error) {
createNotification({
type: "error",
text: (error as Error).message ?? "Error setting password"
});
} catch {
navigate({ to: "/personal-settings" });
}
}
@@ -73,7 +73,6 @@ export const EmailConfirmationStep = ({
const { mutateAsync: verifyEmailVerificationCode } = useVerifyEmailVerificationCode();
const checkCode = async () => {
try {
await verifyEmailVerificationCode({ username, code });
setCodeError(false);
@@ -102,18 +101,11 @@ export const EmailConfirmationStep = ({
break;
}
}
} catch {
createNotification({
text: "Failed to verify code",
type: "error"
});
}
setCode("");
};
const resendCode = async () => {
try {
const queryParams = new URLSearchParams(window.location.search);
const token = queryParams.get("token");
if (!token) {
@@ -128,12 +120,6 @@ export const EmailConfirmationStep = ({
text: "Successfully resent code",
type: "success"
});
} catch {
createNotification({
text: "Failed to resend code",
type: "error"
});
}
};
return (
@@ -113,7 +113,6 @@ export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {
alertUnit,
emails
}: FormData) => {
try {
if (!projectId) return;
const emailArray = emails
@@ -152,13 +151,6 @@ export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {
text: `Successfully ${alert ? "updated" : "created"} alert`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${alert ? "updated" : "created"} alert`,
type: "error"
});
}
};
return (
@@ -22,7 +22,6 @@ export const PkiAlertsSection = () => {
] as const);
const onRemoveAlertSubmit = async (alertId: string) => {
try {
if (!projectId) return;
await deletePkiAlert({
@@ -36,13 +35,6 @@ export const PkiAlertsSection = () => {
});
handlePopUpClose("deletePkiAlert");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete alert",
type: "error"
});
}
};
return (
@@ -62,7 +62,6 @@ export const PkiCollectionModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [pkiCollection]);
const onFormSubmit = async ({ name, description }: FormData) => {
try {
if (!projectId) return;
if (pkiCollection) {
@@ -98,13 +97,6 @@ export const PkiCollectionModal = ({ popUp, handlePopUpToggle }: Props) => {
text: `Successfully ${pkiCollection ? "updated" : "created"} PKI collection`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${pkiCollection ? "updated" : "created"} PKI collection`,
type: "error"
});
}
};
return (
@@ -22,7 +22,6 @@ export const PkiCollectionSection = () => {
] as const);
const onRemovePkiCollectionSubmit = async (collectionId: string) => {
try {
if (!projectId) return;
await deletePkiCollection({
@@ -36,13 +35,6 @@ export const PkiCollectionSection = () => {
});
handlePopUpClose("deletePkiCollection");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete PKI collection",
type: "error"
});
}
};
return (
@@ -57,7 +57,6 @@ const Page = () => {
] as const);
const onRemoveCaSubmit = async () => {
try {
if (!currentProject?.slug) return;
await deleteCa({
@@ -78,12 +77,6 @@ const Page = () => {
projectId
}
});
} catch {
createNotification({
text: "Failed to delete CA",
type: "error"
});
}
};
return (
@@ -84,7 +84,6 @@ export const CaRenewalModal = ({ popUp, handlePopUpToggle }: Props) => {
// }, [ca, parentCa]);
const onFormSubmit = async ({ type, notAfter }: FormData) => {
try {
if (!projectSlug || !popUpData.caId) return;
await renewCa({
@@ -102,9 +101,6 @@ export const CaRenewalModal = ({ popUp, handlePopUpToggle }: Props) => {
});
reset();
} catch (err) {
console.error(err);
}
};
return (
@@ -48,7 +48,6 @@ export const ExternalCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
}, []);
const onFormSubmit = async ({ certificate, certificateChain }: FormData) => {
try {
if (!csr || !caId || !currentProject?.slug) return;
await importCaCertificate({
@@ -65,12 +64,6 @@ export const ExternalCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
type: "success"
});
handlePopUpToggle("installCaCert", false);
} catch {
createNotification({
text: "Failed to install certificate for CA",
type: "error"
});
}
};
const downloadTxtFile = (filename: string, content: string) => {
@@ -101,7 +101,6 @@ export const InternalCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
}, [parentCa]);
const onFormSubmit = async ({ notAfter, maxPathLength }: FormData) => {
try {
if (!csr || !caId || !currentProject?.slug) return;
const { certificate, certificateChain } = await signIntermediate({
@@ -126,12 +125,6 @@ export const InternalCaInstallForm = ({ caId, handlePopUpToggle }: Props) => {
type: "success"
});
handlePopUpToggle("installCaCert", false);
} catch {
createNotification({
text: "Failed to install certificate for CA",
type: "error"
});
}
};
function generatePathLengthOpts(parentCaMaxPathLength: number): number[] {
@@ -175,7 +175,6 @@ export const CaModal = ({ popUp, handlePopUpToggle }: Props) => {
status,
configuration
}: FormData) => {
try {
if (!currentProject?.slug) return;
if (ca) {
@@ -210,13 +209,6 @@ export const CaModal = ({ popUp, handlePopUpToggle }: Props) => {
text: `Successfully ${ca ? "updated" : "created"} CA`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to create CA",
type: "error"
});
}
};
return (
@@ -29,7 +29,6 @@ export const CaSection = () => {
] as const);
const onRemoveCaSubmit = async (caName: string) => {
try {
if (!currentProject?.slug) return;
await deleteCa({ caName, projectId: currentProject.id, type: CaType.INTERNAL });
@@ -40,16 +39,9 @@ export const CaSection = () => {
});
handlePopUpClose("deleteCa");
} catch {
createNotification({
text: "Failed to delete CA",
type: "error"
});
}
};
const onUpdateCaStatus = async ({ caName, status }: { caName: string; status: CaStatus }) => {
try {
if (!currentProject?.slug) return;
await updateCa({ caName, projectId: currentProject.id, type: CaType.INTERNAL, status });
@@ -60,13 +52,6 @@ export const CaSection = () => {
});
handlePopUpClose("caStatus");
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${status === CaStatus.ACTIVE ? "enabled" : "disabled"} CA`,
type: "error"
});
}
};
return (
@@ -297,7 +297,6 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
status,
configuration: formConfiguration
}: FormData) => {
try {
if (!currentProject?.slug) return;
let configPayload: any;
@@ -347,13 +346,6 @@ export const ExternalCaModal = ({ popUp, handlePopUpToggle }: Props) => {
text: `Successfully ${ca ? "updated" : "created"} CA`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to create CA",
type: "error"
});
}
};
return (
@@ -25,7 +25,6 @@ export const ExternalCaSection = () => {
] as const);
const onRemoveCaSubmit = async (caName: string, type: CaType) => {
try {
if (!currentProject?.id) return;
await deleteCa({ caName, type, projectId: currentProject.id });
@@ -36,12 +35,6 @@ export const ExternalCaSection = () => {
});
handlePopUpClose("deleteCa");
} catch {
createNotification({
text: "Failed to delete CA",
type: "error"
});
}
};
const onUpdateCaStatus = async ({
@@ -53,7 +46,6 @@ export const ExternalCaSection = () => {
type: CaType;
status: CaStatus;
}) => {
try {
if (!currentProject?.slug) return;
await updateCa({ caName: name, type, status, projectId: currentProject.id });
@@ -64,13 +56,6 @@ export const ExternalCaSection = () => {
});
handlePopUpClose("caStatus");
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${status === CaStatus.ACTIVE ? "enable" : "disable"} CA`,
type: "error"
});
}
};
return (
@@ -71,7 +71,6 @@ export const CertificateImportModal = ({ popUp, handlePopUpToggle }: Props) => {
chainPem,
collectionId
}: FormData) => {
try {
if (!currentProject?.slug) return;
const { serialNumber, certificate, certificateChain, privateKey } = await importCertificate({
@@ -96,13 +95,6 @@ export const CertificateImportModal = ({ popUp, handlePopUpToggle }: Props) => {
text: "Successfully imported certificate",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to import certificate",
type: "error"
});
}
};
return (
@@ -242,7 +242,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }
keyUsages,
extendedKeyUsages
}: FormData) => {
try {
if (!currentProject?.slug) {
createNotification({
text: "Project not found. Please refresh and try again.",
@@ -309,17 +308,6 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }
text: "Successfully created certificate",
type: "success"
});
} catch (err) {
console.error("Certificate creation failed:", err);
const errorMessage =
err instanceof Error
? err.message
: "An unexpected error occurred while creating the certificate";
createNotification({
text: `Failed to create certificate: ${errorMessage}`,
type: "error"
});
}
},
[
currentProject?.slug,
@@ -163,7 +163,6 @@ export const CertificateManageRenewalModal = ({ popUp, handlePopUpToggle }: Prop
}, [popUp.manageRenewal.isOpen, defaultRenewalDays, reset]);
const onUpdateRenewal = async (data: FormData) => {
try {
if (!currentProject?.slug) {
createNotification({
text: "Unable to update auto-renewal: Project not found. Please refresh the page and try again.",
@@ -186,15 +185,6 @@ export const CertificateManageRenewalModal = ({ popUp, handlePopUpToggle }: Prop
});
handlePopUpToggle("manageRenewal", false);
} catch (err) {
console.error(err);
createNotification({
text: isAutoRenewalEnabled
? "Failed to update auto-renewal configuration. Please check your inputs and try again."
: "Failed to enable auto-renewal. Please check your inputs and try again.",
type: "error"
});
}
};
const getModalTitle = () => {
@@ -186,7 +186,6 @@ export const CertificateModal = ({ popUp, handlePopUpToggle }: Props) => {
keyUsages,
extendedKeyUsages
}: FormData) => {
try {
if (!currentProject?.slug) return;
const { serialNumber, certificate, certificateChain, privateKey } = await createCertificate({
@@ -218,13 +217,6 @@ export const CertificateModal = ({ popUp, handlePopUpToggle }: Props) => {
text: "Successfully created certificate",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to create certificate",
type: "error"
});
}
};
useEffect(() => {
@@ -61,7 +61,6 @@ export const CertificateRenewalConfigModal = ({ popUp, handlePopUpToggle }: Prop
const renewBeforeDays = watch("renewBeforeDays");
const onSubmit = async (data: FormData) => {
try {
if (!currentProject?.slug) {
createNotification({
text: "Project not found",
@@ -82,13 +81,6 @@ export const CertificateRenewalConfigModal = ({ popUp, handlePopUpToggle }: Prop
});
handlePopUpToggle("configureRenewal", false);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update auto-renewal configuration",
type: "error"
});
}
};
return (
@@ -19,7 +19,6 @@ export const CertificateRenewalDisableModal = ({ popUp, handlePopUpToggle }: Pro
};
const onDisableConfirm = async () => {
try {
if (!currentProject?.slug) {
createNotification({
text: "Project not found",
@@ -40,13 +39,6 @@ export const CertificateRenewalDisableModal = ({ popUp, handlePopUpToggle }: Pro
});
handlePopUpToggle("disableRenewal", false);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to disable auto-renewal",
type: "error"
});
}
};
return (
@@ -18,7 +18,6 @@ export const CertificateRenewalModal = ({ popUp, handlePopUpToggle }: Props) =>
const { mutateAsync: renewCertificate, isPending: isRenewing } = useRenewCertificate();
const onRenewConfirm = async () => {
try {
const { certificateId } = popUp.renewCertificate.data as { certificateId: string };
await renewCertificate({
@@ -31,9 +30,6 @@ export const CertificateRenewalModal = ({ popUp, handlePopUpToggle }: Props) =>
});
handlePopUpToggle("renewCertificate", false);
} catch (err) {
console.error(err);
}
};
const certificateData = popUp.renewCertificate.data as {
@@ -48,7 +48,6 @@ export const CertificateRevocationModal = ({ popUp, handlePopUpToggle }: Props)
});
const onFormSubmit = async ({ revocationReason }: FormData) => {
try {
if (!currentProject?.slug) return;
const { serialNumber } = popUp.revokeCertificate.data as { serialNumber: string };
@@ -66,13 +65,6 @@ export const CertificateRevocationModal = ({ popUp, handlePopUpToggle }: Props)
text: "Successfully revoked certificate",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to revoke certificate",
type: "error"
});
}
};
return (
@@ -159,7 +159,6 @@ export const CertificateTemplateModal = ({ popUp, handlePopUpToggle, caId }: Pro
return;
}
try {
if (certTemplate) {
await updateCertTemplate({
id: certTemplate.id,
@@ -207,13 +206,6 @@ export const CertificateTemplateModal = ({ popUp, handlePopUpToggle, caId }: Pro
reset();
handlePopUpToggle("certificateTemplate", false);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to save changes",
type: "error"
});
}
};
return (
@@ -41,7 +41,6 @@ export const CertificateTemplatesSection = ({ caId }: Props) => {
return;
}
try {
await deleteCertTemplate({
id,
projectId: currentProject.id
@@ -53,13 +52,6 @@ export const CertificateTemplatesSection = ({ caId }: Props) => {
});
handlePopUpClose("deleteCertificateTemplate");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete certificate template",
type: "error"
});
}
};
return (
@@ -41,7 +41,6 @@ export const CertificatesSection = () => {
] as const);
const onRemoveCertificateSubmit = async (serialNumber: string) => {
try {
if (!currentProject?.slug) return;
await deleteCert({ serialNumber, projectSlug: currentProject.slug });
@@ -52,13 +51,6 @@ export const CertificatesSection = () => {
});
handlePopUpClose("deleteCertificate");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete certificate",
type: "error"
});
}
};
return (
@@ -200,7 +200,6 @@ export const CertificatesTable = ({ handlePopUpOpen }: Props) => {
}, [caData]);
const handleDisableAutoRenewal = async (certificateId: string, commonName: string) => {
try {
if (!currentProject?.slug) {
createNotification({
text: "Unable to disable auto-renewal: Project not found. Please refresh the page and try again.",
@@ -219,13 +218,6 @@ export const CertificatesTable = ({ handlePopUpOpen }: Props) => {
text: `Auto-renewal disabled for ${commonName}`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to disable auto-renewal. Please try again or contact support if the issue persists.",
type: "error"
});
}
};
return (
@@ -226,7 +226,6 @@ export const PkiSyncsTable = ({ pkiSyncs }: Props) => {
const isAutoSyncEnabled = !pkiSync.isAutoSyncEnabled;
try {
await updateSync.mutateAsync({
syncId: pkiSync.id,
projectId: pkiSync.projectId,
@@ -238,18 +237,11 @@ export const PkiSyncsTable = ({ pkiSyncs }: Props) => {
text: `Successfully ${isAutoSyncEnabled ? "enabled" : "disabled"} auto-sync for ${destinationName} Sync`,
type: "success"
});
} catch {
createNotification({
text: `Failed to ${isAutoSyncEnabled ? "enable" : "disable"} auto-sync for ${destinationName} Sync`,
type: "error"
});
}
};
const handleTriggerSync = async (pkiSync: TPkiSync) => {
const destinationName = PKI_SYNC_MAP[pkiSync.destination].name;
try {
await triggerSync.mutateAsync({
syncId: pkiSync.id,
destination: pkiSync.destination,
@@ -260,12 +252,6 @@ export const PkiSyncsTable = ({ pkiSyncs }: Props) => {
text: `Successfully triggered ${destinationName} Sync`,
type: "success"
});
} catch {
createNotification({
text: `Failed to trigger ${destinationName} Sync`,
type: "error"
});
}
};
return (
@@ -45,7 +45,6 @@ export const PkiCollectionPage = () => {
] as const);
const onDeletePkiCollectionSubmit = async (collectionIdToDelete: string) => {
try {
if (!projectId) return;
await deletePkiCollection({
@@ -64,12 +63,6 @@ export const PkiCollectionPage = () => {
projectId
}
});
} catch {
createNotification({
text: "Failed to delete PKI collection",
type: "error"
});
}
};
return (
@@ -51,7 +51,6 @@ const Page = () => {
] as const);
const onRemoveSubscriberSubmit = async (subscriberNameToDelete: string) => {
try {
if (!projectId) return;
await deletePkiSubscriber({ subscriberName: subscriberNameToDelete, projectId });
@@ -68,13 +67,6 @@ const Page = () => {
projectId
}
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete subscriber",
type: "error"
});
}
};
return (
@@ -70,7 +70,6 @@ export const PkiSubscriberDetailsSection = ({ subscriberName, handlePopUpOpen }:
useOrderPkiSubscriberCert();
const onIssuePkiSubscriberCert = async () => {
try {
if (pkiSubscriber?.supportsImmediateCertIssuance) {
const response = await issuePkiSubscriberCert({ subscriberName, projectId });
@@ -95,13 +94,6 @@ export const PkiSubscriberDetailsSection = ({ subscriberName, handlePopUpOpen }:
type: "info"
});
}
} catch (err) {
console.error(err);
createNotification({
text: "Failed to issue certificate",
type: "error"
});
}
};
const canIssuePkiSubscriberCert = permission.can(
@@ -276,7 +276,6 @@ export const PkiSubscriberModal = ({ popUp, handlePopUpToggle }: Props) => {
locality,
emailAddress
}: FormData) => {
try {
if (!projectId) return;
if (!caId) {
@@ -380,13 +379,6 @@ export const PkiSubscriberModal = ({ popUp, handlePopUpToggle }: Props) => {
text: `Successfully ${pkiSubscriber ? "updated" : "added"} PKI subscriber`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${pkiSubscriber ? "update" : "add"} PKI subscriber`,
type: "error"
});
}
};
return (
@@ -33,7 +33,6 @@ export const PkiSubscriberSection = () => {
] as const);
const onRemovePkiSubscriberSubmit = async (subscriberName: string) => {
try {
const subscriber = await deletePkiSubscriber({ subscriberName, projectId });
createNotification({
@@ -42,13 +41,6 @@ export const PkiSubscriberSection = () => {
});
handlePopUpClose("deletePkiSubscriber");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete PKI subscriber",
type: "error"
});
}
};
const onUpdatePkiSubscriberStatus = async ({
@@ -58,7 +50,6 @@ export const PkiSubscriberSection = () => {
subscriberName: string;
status: PkiSubscriberStatus;
}) => {
try {
if (!currentProject?.slug) return;
await updatePkiSubscriber({ subscriberName, projectId, status });
@@ -69,13 +60,6 @@ export const PkiSubscriberSection = () => {
});
handlePopUpClose("pkiSubscriberStatus");
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${status === PkiSubscriberStatus.ACTIVE ? "enable" : "disable"} subscriber`,
type: "error"
});
}
};
const subscriberStatusData = popUp?.pkiSubscriberStatus?.data as {
@@ -86,7 +86,6 @@ export const PkiSyncActionTriggers = ({ pkiSync }: Props) => {
}, [pkiSync.id, setIsIdCopied]);
const handleTriggerSync = useCallback(async () => {
try {
await triggerSyncMutation.mutateAsync({
syncId: id,
destination,
@@ -96,17 +95,9 @@ export const PkiSyncActionTriggers = ({ pkiSync }: Props) => {
text: "PKI sync job queued successfully",
type: "success"
});
} catch (error) {
console.error("Failed to trigger sync:", error);
createNotification({
text: "Failed to trigger PKI sync",
type: "error"
});
}
}, [triggerSyncMutation, id, destination, projectId]);
const handleToggleAutoSync = useCallback(async () => {
try {
await updatePkiSyncMutation.mutateAsync({
syncId: id,
projectId,
@@ -117,13 +108,6 @@ export const PkiSyncActionTriggers = ({ pkiSync }: Props) => {
text: `Auto-sync ${pkiSync.isAutoSyncEnabled ? "disabled" : "enabled"} successfully`,
type: "success"
});
} catch (error) {
console.error("Failed to toggle auto-sync:", error);
createNotification({
text: "Failed to toggle auto-sync",
type: "error"
});
}
}, [updatePkiSyncMutation, id, projectId, pkiSync.isAutoSyncEnabled]);
const permissionSubject = subject(ProjectPermissionSub.PkiSyncs, {
@@ -78,7 +78,6 @@ export const PkiTemplateListPage = () => {
const deleteCertTemplate = useDeleteCertTemplateV2();
const onRemovePkiSubscriberSubmit = async () => {
try {
const pkiTemplate = await deleteCertTemplate.mutateAsync({
projectId: currentProject.id,
templateName: popUp?.deleteTemplate?.data?.name
@@ -90,13 +89,6 @@ export const PkiTemplateListPage = () => {
});
handlePopUpClose("deleteTemplate");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete PKI subscriber",
type: "error"
});
}
};
return (
@@ -128,7 +128,6 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => {
return;
}
try {
if (certTemplate) {
await updateCertTemplate({
templateName: certTemplate.name,
@@ -174,13 +173,6 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => {
reset();
handlePopUpToggle(false);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to save changes",
type: "error"
});
}
};
return (
@@ -51,7 +51,6 @@ export const CertificateProfilesTab = () => {
const handleDeleteConfirm = async () => {
if (!selectedProfile) return;
try {
await deleteProfile.mutateAsync({
profileId: selectedProfile.id
});
@@ -61,12 +60,6 @@ export const CertificateProfilesTab = () => {
text: `Certificate profile "${selectedProfile.slug}" deleted successfully`,
type: "success"
});
} catch (error) {
console.error(
`Failed to delete profile "${selectedProfile.slug}" (ID: ${selectedProfile.id}):`,
error
);
}
};
return (
@@ -236,7 +236,6 @@ export const CreateProfileModal = ({ isOpen, onClose, profile, mode = "create" }
}, [isEdit, profile, reset]);
const onFormSubmit = async (data: FormData) => {
try {
if (!currentProject?.id && !isEdit) return;
if (isEdit) {
@@ -287,13 +286,6 @@ export const CreateProfileModal = ({ isOpen, onClose, profile, mode = "create" }
reset();
onClose();
} catch (error) {
console.error(`Error ${isEdit ? "updating" : "creating"} profile:`, error);
createNotification({
text: `Failed to ${isEdit ? "update" : "create"} certificate profile`,
type: "error"
});
}
};
return (
@@ -48,7 +48,6 @@ export const CertificateTemplatesV2Tab = () => {
const handleDeleteConfirm = async () => {
if (!selectedTemplate) return;
try {
await deleteTemplateV2.mutateAsync({
templateId: selectedTemplate.id
});
@@ -58,13 +57,6 @@ export const CertificateTemplatesV2Tab = () => {
text: `Certificate template "${selectedTemplate.name}" deleted successfully`,
type: "success"
});
} catch (error) {
console.error("Failed to delete template:", error);
createNotification({
text: "Failed to delete certificate template",
type: "error"
});
}
};
return (
@@ -407,7 +407,6 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
};
const onFormSubmit = async (data: FormData) => {
try {
if (!currentProject?.id && !isEdit) return;
const hasEmptyAttributeValues = data.attributes?.some(
@@ -453,13 +452,6 @@ export const CreateTemplateModal = ({ isOpen, onClose, template, mode = "create"
reset();
onClose();
} catch (error) {
console.error(`Error ${isEdit ? "updating" : "creating"} template:`, error);
createNotification({
text: `Failed to ${isEdit ? "update" : "create"} certificate template`,
type: "error"
});
}
};
const addAttribute = () => {
@@ -17,7 +17,6 @@ export const DeleteKmipClientModal = ({ isOpen, onOpenChange, kmipClient }: Prop
const { id, projectId, name } = kmipClient;
const handleDeleteKmipClient = async () => {
try {
await deleteKmipClients.mutateAsync({
id,
projectId
@@ -29,16 +28,6 @@ export const DeleteKmipClientModal = ({ isOpen, onOpenChange, kmipClient }: Prop
});
onOpenChange(false);
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to delete KMIP client";
createNotification({
text,
type: "error"
});
}
};
return (
@@ -98,20 +98,12 @@ const KmipClientForm = ({ onComplete, kmipClient }: FormProps) => {
.map(([key]) => key as KmipPermission)
});
try {
await mutation;
createNotification({
text: `Successfully ${isUpdate ? "updated" : "added"} KMIP client`,
type: "success"
});
onComplete();
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${isUpdate ? "update" : "add"} KMIP client`,
type: "error"
});
}
};
return (
@@ -52,7 +52,6 @@ const DecryptForm = ({ cmek }: FormProps) => {
});
const handleDecryptData = async (formData: FormData) => {
try {
const data = await cmekDecrypt.mutateAsync({ ...formData, keyId: cmek.id });
createNotification({
text: "Successfully decrypted data",
@@ -62,13 +61,6 @@ const DecryptForm = ({ cmek }: FormProps) => {
setPlaintext(
shouldDecode ? Buffer.from(decodeBase64(data.plaintext)).toString("utf8") : data.plaintext
);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to decrypt data",
type: "error"
});
}
};
useEffect(() => {
@@ -53,19 +53,11 @@ const EncryptForm = ({ cmek }: FormProps) => {
});
const handleEncryptData = async (formData: FormData) => {
try {
await cmekEncrypt.mutateAsync({ ...formData, keyId: cmek.id });
createNotification({
text: "Successfully encrypted data",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to encrypt data",
type: "error"
});
}
};
const ciphertext = cmekEncrypt.data?.ciphertext;
@@ -86,20 +86,12 @@ const CmekForm = ({ onComplete, cmek }: FormProps) => {
encryptionAlgorithm: encryptionAlgorithm as AsymmetricKeyAlgorithm | SymmetricKeyAlgorithm
});
try {
await mutation;
createNotification({
text: `Successfully ${isUpdate ? "updated" : "added"} key`,
type: "success"
});
onComplete();
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${isUpdate ? "update" : "add"} key`,
type: "error"
});
}
};
const selectedKeyUsage = watch("keyUsage");
@@ -59,19 +59,11 @@ const SignForm = ({ cmek }: FormProps) => {
});
const handleSignData = async (formData: FormData) => {
try {
await cmekSign.mutateAsync({ ...formData, keyId: cmek.id });
createNotification({
text: "Successfully signed data",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to sign data",
type: "error"
});
}
};
const signature = cmekSign.data?.signature;
@@ -152,7 +152,6 @@ export const CmekTable = () => {
const updateCmek = useUpdateCmek();
const handleDisableCmek = async ({ id: keyId, isDisabled }: TCmek) => {
try {
await updateCmek.mutateAsync({
keyId,
projectId,
@@ -163,17 +162,6 @@ export const CmekTable = () => {
text: `Key successfully ${isDisabled ? "enabled" : "disabled"}`,
type: "success"
});
} catch (err) {
console.error(err);
const error = err as any;
const text =
error?.response?.data?.message ?? `Failed to ${isDisabled ? "enable" : "disable"} key`;
createNotification({
text,
type: "error"
});
}
};
const cannotEditKey = permission.cannot(
@@ -69,7 +69,6 @@ const VerifyForm = ({ cmek }: FormProps) => {
});
const handleVerifyData = async (formData: FormData) => {
try {
const result = await cmekVerify.mutateAsync({ ...formData, keyId: cmek.id });
if (result.signatureValid) {
@@ -84,13 +83,6 @@ const VerifyForm = ({ cmek }: FormProps) => {
type: "error"
});
}
} catch (err) {
console.error(err);
createNotification({
text: "Failed to sign data",
type: "error"
});
}
};
const signature = watch("signature");
@@ -16,7 +16,6 @@ export const DeleteCmekModal = ({ isOpen, onOpenChange, cmek }: Props) => {
const { id: keyId, projectId, name } = cmek;
const handleDeleteCmek = async () => {
try {
await deleteCmek.mutateAsync({
keyId,
projectId
@@ -28,16 +27,6 @@ export const DeleteCmekModal = ({ isOpen, onOpenChange, cmek }: Props) => {
});
onOpenChange(false);
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to delete key";
createNotification({
text,
type: "error"
});
}
};
return (
@@ -74,7 +74,6 @@ export const OrgGroupModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Pr
}, [popUp?.group?.data, roles]);
const onGroupModalSubmit = async ({ name, slug, role }: TGroupFormData) => {
try {
if (!currentOrg?.id) return;
const group = popUp?.group?.data as {
@@ -105,12 +104,6 @@ export const OrgGroupModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Pr
text: `Successfully ${popUp?.group?.data ? "updated" : "created"} group`,
type: "success"
});
} catch {
createNotification({
text: `Failed to ${popUp?.group?.data ? "updated" : "created"} group`,
type: "error"
});
}
};
return (
@@ -37,7 +37,6 @@ export const OrgGroupsSection = () => {
};
const onDeleteGroupSubmit = async ({ name, groupId }: { name: string; groupId: string }) => {
try {
await deleteMutateAsync({
id: groupId
});
@@ -45,13 +44,6 @@ export const OrgGroupsSection = () => {
text: `Successfully deleted the group named ${name}`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to delete the group named ${name}`,
type: "error"
});
}
handlePopUpClose("deleteGroup");
};
@@ -79,7 +79,6 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
const { data: roles } = useGetOrgRoles(orgId);
const handleChangeRole = async ({ id, role }: { id: string; role: string }) => {
try {
await updateMutateAsync({
id,
role
@@ -89,13 +88,6 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
text: "Successfully updated group role",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update group role",
type: "error"
});
}
};
const {
@@ -56,7 +56,6 @@ export const IdentitySection = withPermission(
const isEnterprise = subscription?.slug === "enterprise";
const onDeleteIdentitySubmit = async (identityId: string) => {
try {
await deleteMutateAsync({
identityId,
organizationId: orgId
@@ -68,20 +67,9 @@ export const IdentitySection = withPermission(
});
handlePopUpClose("deleteIdentity");
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to delete identity";
createNotification({
text,
type: "error"
});
}
};
const onDeleteTemplateSubmit = async (templateId: string) => {
try {
await deleteTemplateMutateAsync({
templateId,
organizationId: orgId
@@ -93,16 +81,6 @@ export const IdentitySection = withPermission(
});
handlePopUpClose("deleteTemplate");
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to delete template";
createNotification({
text,
type: "error"
});
}
};
return (
@@ -85,7 +85,6 @@ export const OrgMembersSection = () => {
};
const onDeactivateMemberSubmit = async (orgMembershipId: string) => {
try {
await updateOrgMembership({
organizationId: orgId,
membershipId: orgMembershipId,
@@ -96,19 +95,11 @@ export const OrgMembersSection = () => {
text: "Successfully deactivated user in organization",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to deactivate user in organization",
type: "error"
});
}
handlePopUpClose("deactivateMember");
};
const onRemoveMemberSubmit = async (orgMembershipId: string) => {
try {
await deleteMutateAsync({
orgId,
membershipId: orgMembershipId
@@ -118,13 +109,6 @@ export const OrgMembersSection = () => {
text: "Successfully removed user from org",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to remove user from the organization",
type: "error"
});
}
handlePopUpClose("removeMember");
};
@@ -132,7 +116,6 @@ export const OrgMembersSection = () => {
const { data: members = [] } = useGetOrgUsers(orgId);
const handleRemoveMembers = async (selectedMembers: OrgUser[]) => {
try {
await deleteBatchMutateAsync({
orgId,
membershipIds: selectedMembers
@@ -147,12 +130,6 @@ export const OrgMembersSection = () => {
setSelectedMemberIds([]);
handlePopUpClose("removeMembers");
} catch {
createNotification({
text: "Failed to remove users from the organization",
type: "error"
});
}
};
return (
@@ -127,14 +127,12 @@ export const OrgMembersTable = ({
const onRoleChange = async (membershipId: string, role: string) => {
if (!currentOrg?.id) return;
try {
// TODO: replace hardcoding default role
const isCustomRole = !["admin", "member", "no-access"].includes(role);
if (isCustomRole && subscription && !subscription?.rbac) {
handlePopUpOpen("upgradePlan", {
description:
"You can assign custom roles to members if you switch to Infisical's Pro plan."
description: "You can assign custom roles to members if you switch to Infisical's Pro plan."
});
return;
}
@@ -149,13 +147,6 @@ export const OrgMembersTable = ({
text: "Successfully updated user role",
type: "success"
});
} catch (error) {
console.error(error);
createNotification({
text: "Failed to update user role",
type: "error"
});
}
};
const onResendInvite = async (membershipId: string) => {
@@ -174,12 +165,6 @@ export const OrgMembersTable = ({
text: "Successfully resent org invitation",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to resend org invitation",
type: "error"
});
} finally {
setResendInviteId(null);
}
@@ -86,17 +86,12 @@ export const OrgRoleTable = () => {
const handleRoleDelete = async () => {
const { id } = popUp?.deleteRole?.data as TOrgRole;
try {
await deleteRole({
orgId,
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 handleSetRoleAsDefault = async (defaultMembershipRoleSlug: string) => {
@@ -110,17 +105,12 @@ export const OrgRoleTable = () => {
return;
}
try {
await updateOrg({
orgId,
defaultMembershipRoleSlug
});
createNotification({ type: "success", text: "Successfully updated default membership role" });
handlePopUpClose("deleteRole");
} catch (err) {
console.log(err);
createNotification({ type: "error", text: "Failed to update default membership role" });
}
};
const {
@@ -73,7 +73,6 @@ const CreateForm = ({ app, onComplete, projectId }: CreateFormProps) => {
"method" | "name" | "app" | "credentials" | "isPlatformManagedCredentials"
>
) => {
try {
const connection = await createAppConnection.mutateAsync({
...formData,
projectId
@@ -83,14 +82,6 @@ const CreateForm = ({ app, onComplete, projectId }: CreateFormProps) => {
type: "success"
});
onComplete(connection);
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to add ${appName} Connection`,
text: err.message,
type: "error"
});
}
};
switch (app) {
@@ -191,7 +182,6 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
"method" | "name" | "app" | "credentials" | "isPlatformManagedCredentials"
>
) => {
try {
const connection = await updateAppConnection.mutateAsync({
connectionId: appConnection.id,
...formData
@@ -201,14 +191,6 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
type: "success"
});
onComplete(connection);
} catch (err: any) {
console.error(err);
createNotification({
title: `Failed to update ${appName} Connection`,
text: err.message,
type: "error"
});
}
};
switch (appConnection.app) {
@@ -77,7 +77,6 @@ export const GroupCreateUpdateModal = ({ popUp, handlePopUpClose, handlePopUpTog
}, [popUp?.groupCreateUpdate?.data, roles]);
const onGroupModalSubmit = async ({ name, slug, role }: TGroupFormData) => {
try {
if (!currentOrg?.id) return;
const group = popUp?.groupCreateUpdate?.data as {
@@ -108,12 +107,6 @@ export const GroupCreateUpdateModal = ({ popUp, handlePopUpClose, handlePopUpTog
text: `Successfully ${popUp?.groupCreateUpdate?.data ? "updated" : "created"} group`,
type: "success"
});
} catch {
createNotification({
text: `Failed to ${popUp?.groupCreateUpdate?.data ? "updated" : "created"} group`,
type: "error"
});
}
};
return (
@@ -44,7 +44,6 @@ const Page = () => {
] as const);
const onDeleteIdentitySubmit = async (id: string) => {
try {
await deleteIdentity({
identityId: id,
organizationId: orgId
@@ -62,16 +61,6 @@ const Page = () => {
selectedTab: OrgAccessControlTabSections.Identities
}
});
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to delete identity";
createNotification({
text,
type: "error"
});
}
};
return (
@@ -107,7 +107,6 @@ export const RolePermissionsSection = ({ roleId }: Props) => {
const { mutateAsync: updateRole } = useUpdateOrgRole();
const onSubmit = async (el: TFormSchema) => {
try {
await updateRole({
orgId,
id: roleId,
@@ -115,10 +114,6 @@ export const RolePermissionsSection = ({ roleId }: 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 = !["admin", "member", "no-access"].includes(role?.slug ?? "");
@@ -64,7 +64,6 @@ const Page = withPermission(
] as const);
const onDeactivateMemberSubmit = async (orgMembershipId: string) => {
try {
await updateOrgMembership({
organizationId: orgId,
membershipId: orgMembershipId,
@@ -75,19 +74,11 @@ const Page = withPermission(
text: "Successfully deactivated user in organization",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to deactivate user in organization",
type: "error"
});
}
handlePopUpClose("deactivateMember");
};
const onRemoveMemberSubmit = async (orgMembershipId: string) => {
try {
await deleteOrgMembership({
orgId,
membershipId: orgMembershipId
@@ -105,15 +96,6 @@ const Page = withPermission(
selectedTab: OrgAccessControlTabSections.Member
}
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to remove user from the organization",
type: "error"
});
}
handlePopUpClose("removeMember");
};
return (
@@ -46,7 +46,6 @@ export const UserDetailsSection = ({ membershipId, handlePopUpOpen }: Props) =>
const { mutateAsync: resendOrgMemberInvitation, isPending } = useResendOrgMemberInvitation();
const onResendInvite = async () => {
try {
const signupToken = await resendOrgMemberInvitation({
membershipId
});
@@ -59,13 +58,6 @@ export const UserDetailsSection = ({ membershipId, handlePopUpOpen }: Props) =>
text: "Successfully resent org invitation",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to resend org invitation",
type: "error"
});
}
};
const getStatus = (m: OrgUser) => {
@@ -38,7 +38,6 @@ const CreateForm = ({
const onSubmit = async (
formData: DiscriminativePick<TPamAccount, "name" | "description" | "credentials">
) => {
try {
const account = await createPamAccount.mutateAsync({
...formData,
folderId,
@@ -51,14 +50,6 @@ const CreateForm = ({
type: "success"
});
onComplete(account);
} catch (err: any) {
console.error(err);
createNotification({
title: "Failed to create account",
text: err.message,
type: "error"
});
}
};
switch (resourceType) {
@@ -85,7 +76,6 @@ const UpdateForm = ({ account, onComplete }: UpdateFormProps) => {
const onSubmit = async (
formData: DiscriminativePick<TPamAccount, "name" | "description" | "credentials">
) => {
try {
const updatedAccount = await updatePamAccount.mutateAsync({
accountId: account.id,
resourceType: account.resource.resourceType,
@@ -96,14 +86,6 @@ const UpdateForm = ({ account, onComplete }: UpdateFormProps) => {
type: "success"
});
onComplete(updatedAccount);
} catch (err: any) {
console.error(err);
createNotification({
title: "Failed to update account",
text: err.message,
type: "error"
});
}
};
switch (account.resource.resourceType) {
@@ -17,7 +17,6 @@ export const PamAddFolderModal = ({ isOpen, onOpenChange, projectId, currentFold
console.log({ currentFolderId });
const onSubmit = async (formData: Pick<TPamFolder, "name" | "description">) => {
try {
await createPamFolder.mutateAsync({
...formData,
parentId: currentFolderId,
@@ -28,14 +27,6 @@ export const PamAddFolderModal = ({ isOpen, onOpenChange, projectId, currentFold
type: "success"
});
onOpenChange(false);
} catch (err: any) {
console.error(err);
createNotification({
title: "Failed to create folder",
text: err.message,
type: "error"
});
}
};
return (
@@ -20,7 +20,6 @@ export const PamDeleteAccountModal = ({ isOpen, onOpenChange, account }: Props)
} = account;
const handleDelete = async () => {
try {
await deletePamAccount.mutateAsync({
accountId,
resourceType
@@ -32,13 +31,6 @@ export const PamDeleteAccountModal = ({ isOpen, onOpenChange, account }: Props)
});
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete account",
type: "error"
});
}
};
return (
@@ -16,7 +16,6 @@ export const PamDeleteFolderModal = ({ isOpen, onOpenChange, folder }: Props) =>
const { id: folderId, name } = folder;
const handleDelete = async () => {
try {
await deletePamFolder.mutateAsync({
folderId
});
@@ -27,13 +26,6 @@ export const PamDeleteFolderModal = ({ isOpen, onOpenChange, folder }: Props) =>
});
onOpenChange(false);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete folder",
type: "error"
});
}
};
return (

Some files were not shown because too many files have changed in this diff Show More