refactor: streamline async logic and notification handling across various settings and integration components

This commit is contained in:
Victor Santos
2025-11-03 15:43:08 -03:00
parent c005f8a0fe
commit f2f50f739e
22 changed files with 383 additions and 609 deletions

View File

@@ -108,43 +108,27 @@ export const NativeIntegrationsTab = () => {
shouldDeleteIntegrationSecrets: boolean,
cb: () => void
) => {
try {
await deleteIntegration({ id: integrationId, workspaceId, shouldDeleteIntegrationSecrets });
if (cb) cb();
createNotification({
type: "success",
text: "Deleted integration"
});
} catch (err) {
console.log(err);
createNotification({
type: "error",
text: "Failed to delete integration"
});
}
await deleteIntegration({ id: integrationId, workspaceId, shouldDeleteIntegrationSecrets });
if (cb) cb();
createNotification({
type: "success",
text: "Deleted integration"
});
};
const handleIntegrationAuthRevoke = async (provider: string, cb?: () => void) => {
const integrationAuthForProvider = integrationAuths?.[provider];
if (!integrationAuthForProvider) return;
try {
await deleteIntegrationAuths({
integration: provider,
workspaceId
});
if (cb) cb();
createNotification({
type: "success",
text: "Revoked provider authentication"
});
} catch (err) {
console.error(err);
createNotification({
type: "error",
text: "Failed to revoke provider authentication"
});
}
await deleteIntegrationAuths({
integration: provider,
workspaceId
});
if (cb) cb();
createNotification({
type: "success",
text: "Revoked provider authentication"
});
};
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([

View File

@@ -39,27 +39,19 @@ export const EnvironmentSection = () => {
] as const);
const onEnvDeleteSubmit = async (id: string) => {
try {
if (!currentProject?.id) return;
if (!currentProject?.id) return;
await deleteWsEnvironment.mutateAsync({
projectId: currentProject.id,
id
});
await deleteWsEnvironment.mutateAsync({
projectId: currentProject.id,
id
});
createNotification({
text: "Successfully deleted environment",
type: "success"
});
createNotification({
text: "Successfully deleted environment",
type: "success"
});
handlePopUpClose("deleteEnv");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete environment",
type: "error"
});
}
handlePopUpClose("deleteEnv");
};
return (

View File

@@ -46,26 +46,18 @@ export const EnvironmentTable = ({ handlePopUpOpen }: Props) => {
const updateEnvironment = useUpdateWsEnvironment();
const handleReorderEnv = async (id: string, position: number) => {
try {
if (!currentProject?.id) return;
if (!currentProject?.id) return;
await updateEnvironment.mutateAsync({
projectId: currentProject.id,
id,
position
});
await updateEnvironment.mutateAsync({
projectId: currentProject.id,
id,
position
});
createNotification({
text: "Successfully re-ordered environments",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to re-order environments",
type: "error"
});
}
createNotification({
text: "Successfully re-ordered environments",
type: "success"
});
};
const isMoreEnvironmentsAllowed =

View File

@@ -55,22 +55,15 @@ export const SecretDetectionIgnoreValuesSection = () => {
}, [currentProject?.secretDetectionIgnoreValues, reset]);
const handleIgnoreValuesSubmit = async ({ ignoreValues }: TForm) => {
try {
await updateProject({
projectId: currentProject.id,
secretDetectionIgnoreValues: ignoreValues.map((item) => item.value)
});
await updateProject({
projectId: currentProject.id,
secretDetectionIgnoreValues: ignoreValues.map((item) => item.value)
});
createNotification({
text: "Successfully updated secret detection ignore values",
type: "success"
});
} catch {
createNotification({
text: "Failed updating secret detection ignore values",
type: "error"
});
}
createNotification({
text: "Successfully updated secret detection ignore values",
type: "success"
});
};
const isAdmin = hasProjectRole(ProjectMembershipRole.Admin);

View File

@@ -30,12 +30,6 @@ export const SecretSnapshotsLegacySection = () => {
text: `Successfully ${state ? "enabled" : "disabled"} secret snapshots legacy for this project`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update secret snapshots legacy for this project",
type: "error"
});
} finally {
setIsLoading(false);
}

View File

@@ -59,83 +59,51 @@ export const WebhooksTab = withProjectPermission(
const { mutateAsync: deleteWebhook } = useDeleteWebhook();
const handleWebhookCreate = async (data: TFormSchema) => {
try {
await createWebhook({
...data,
projectId
});
handlePopUpClose("addWebhook");
createNotification({
type: "success",
text: "Successfully created webhook"
});
} catch (err) {
console.log(err);
createNotification({
type: "error",
text: "Failed to create webhook"
});
}
await createWebhook({
...data,
projectId
});
handlePopUpClose("addWebhook");
createNotification({
type: "success",
text: "Successfully created webhook"
});
};
const handleWebhookDisable = async (webhookId: string, isDisabled: boolean) => {
try {
await updateWebhook({
webhookId,
projectId,
isDisabled
});
createNotification({
type: "success",
text: "Successfully updated webhook"
});
} catch (err) {
console.log(err);
createNotification({
type: "error",
text: "Failed to update webhook"
});
}
await updateWebhook({
webhookId,
projectId,
isDisabled
});
createNotification({
type: "success",
text: "Successfully updated webhook"
});
};
const handleWebhookDelete = async () => {
try {
const webhookId = popUp?.deleteWebhook?.data as string;
await deleteWebhook({
webhookId,
projectId
});
handlePopUpClose("deleteWebhook");
createNotification({
type: "success",
text: "Successfully deleted webhook"
});
} catch (err) {
console.log(err);
createNotification({
type: "error",
text: "Failed to delete webhook"
});
}
const webhookId = popUp?.deleteWebhook?.data as string;
await deleteWebhook({
webhookId,
projectId
});
handlePopUpClose("deleteWebhook");
createNotification({
type: "success",
text: "Successfully deleted webhook"
});
};
const handleWebhookTest = async (webhookId: string) => {
try {
await testWebhook({
webhookId,
projectId
});
createNotification({
type: "success",
text: "Successfully triggered webhook"
});
} catch (err) {
console.log(err);
createNotification({
type: "error",
text: "Failed to trigger webhook"
});
}
await testWebhook({
webhookId,
projectId
});
createNotification({
type: "success",
text: "Successfully triggered webhook"
});
};
return (

View File

@@ -130,37 +130,30 @@ export const MicrosoftTeamsIntegrationForm = ({ onClose }: Props) => {
});
const handleIntegrationSave = async (data: TMicrosoftTeamsConfigForm) => {
try {
if (!currentProject) {
return;
}
await updateProjectMicrosoftTeamsConfig({
projectId: currentProject.id,
isAccessRequestNotificationEnabled: data.isAccessRequestNotificationEnabled,
isSecretRequestNotificationEnabled: data.isSecretRequestNotificationEnabled,
...(data.isAccessRequestNotificationEnabled && {
accessRequestChannels: data.accessRequestChannels
}),
...(data.isSecretRequestNotificationEnabled && {
secretRequestChannels: data.secretRequestChannels
}),
integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS,
integrationId: data.microsoftTeamsIntegrationId
});
createNotification({
type: "success",
text: "Successfully created microsoft teams integration"
});
onClose();
} catch {
createNotification({
type: "error",
text: "Failed to create microsoft teams integration"
});
if (!currentProject) {
return;
}
await updateProjectMicrosoftTeamsConfig({
projectId: currentProject.id,
isAccessRequestNotificationEnabled: data.isAccessRequestNotificationEnabled,
isSecretRequestNotificationEnabled: data.isSecretRequestNotificationEnabled,
...(data.isAccessRequestNotificationEnabled && {
accessRequestChannels: data.accessRequestChannels
}),
...(data.isSecretRequestNotificationEnabled && {
secretRequestChannels: data.secretRequestChannels
}),
integration: WorkflowIntegrationPlatform.MICROSOFT_TEAMS,
integrationId: data.microsoftTeamsIntegrationId
});
createNotification({
type: "success",
text: "Successfully created microsoft teams integration"
});
onClose();
};
const selectedAccessRequestTeamId = watch("accessRequestChannels.teamId");

View File

@@ -22,23 +22,16 @@ export const SecretScanningResourceSection = ({ dataSource }: Props) => {
const triggerDataSourceScan = useTriggerSecretScanningDataSource();
const handleTriggerScan = async () => {
try {
await triggerDataSourceScan.mutateAsync({
dataSourceId: dataSource.id,
type: dataSource.type,
projectId: dataSource.projectId
});
await triggerDataSourceScan.mutateAsync({
dataSourceId: dataSource.id,
type: dataSource.type,
projectId: dataSource.projectId
});
createNotification({
text: `Successfully triggered scan for ${dataSource.name}`,
type: "success"
});
} catch {
createNotification({
text: `Failed to trigger scan for ${dataSource.name}`,
type: "error"
});
}
createNotification({
text: `Successfully triggered scan for ${dataSource.name}`,
type: "success"
});
};
const resourceDetails = RESOURCE_DESCRIPTION_HELPER[dataSource.type];

View File

@@ -184,44 +184,30 @@ export const SecretScanningDataSourcesTable = ({ dataSources }: Props) => {
const isAutoScanEnabled = !dataSource.isAutoScanEnabled;
try {
await updateDataSource.mutateAsync({
dataSourceId: dataSource.id,
type: dataSource.type,
isAutoScanEnabled,
projectId: dataSource.projectId
});
await updateDataSource.mutateAsync({
dataSourceId: dataSource.id,
type: dataSource.type,
isAutoScanEnabled,
projectId: dataSource.projectId
});
createNotification({
text: `Successfully ${isAutoScanEnabled ? "enabled" : "disabled"} auto-scan for ${destinationName} Data Source`,
type: "success"
});
} catch {
createNotification({
text: `Failed to ${isAutoScanEnabled ? "enable" : "disable"} auto-scan for ${destinationName} Data Source`,
type: "error"
});
}
createNotification({
text: `Successfully ${isAutoScanEnabled ? "enabled" : "disabled"} auto-scan for ${destinationName} Data Source`,
type: "success"
});
};
const handleTriggerScan = async (dataSource: TSecretScanningDataSource) => {
try {
await triggerDataSourceScan.mutateAsync({
dataSourceId: dataSource.id,
type: dataSource.type,
projectId: dataSource.projectId
});
await triggerDataSourceScan.mutateAsync({
dataSourceId: dataSource.id,
type: dataSource.type,
projectId: dataSource.projectId
});
createNotification({
text: "Successfully triggered scan",
type: "success"
});
} catch {
createNotification({
text: "Failed to trigger scan",
type: "error"
});
}
createNotification({
text: "Successfully triggered scan",
type: "success"
});
};
return (

View File

@@ -47,24 +47,16 @@ export const ProjectSshConfigCasSection = () => {
}, [sshConfig]);
const onFormSubmit = async ({ defaultUserSshCaId, defaultHostSshCaId }: FormData) => {
try {
await updateProjectSshConfig({
projectId: currentProject.id,
defaultUserSshCaId: defaultUserSshCaId || undefined,
defaultHostSshCaId: defaultHostSshCaId || undefined
});
await updateProjectSshConfig({
projectId: currentProject.id,
defaultUserSshCaId: defaultUserSshCaId || undefined,
defaultHostSshCaId: defaultHostSshCaId || undefined
});
createNotification({
text: "Successfully updated SSH project settings",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to update SSH project settings",
type: "error"
});
}
createNotification({
text: "Successfully updated SSH project settings",
type: "success"
});
};
return (

View File

@@ -43,30 +43,22 @@ const Page = () => {
] as const);
const onRemoveCaSubmit = async (caIdToDelete: string) => {
try {
if (!projectId) return;
if (!projectId) return;
await deleteSshCa({ caId: caIdToDelete });
await deleteSshCa({ caId: caIdToDelete });
createNotification({
text: "Successfully deleted SSH CA",
type: "success"
});
createNotification({
text: "Successfully deleted SSH CA",
type: "success"
});
handlePopUpClose("deleteSshCa");
navigate({
to: "/projects/ssh/$projectId/overview",
params: {
projectId
}
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete SSH CA",
type: "error"
});
}
handlePopUpClose("deleteSshCa");
navigate({
to: "/projects/ssh/$projectId/overview",
params: {
projectId
}
});
};
return (

View File

@@ -122,65 +122,57 @@ export const SshCertificateModal = ({ popUp, handlePopUpToggle }: Props) => {
ttl,
keyId
}: FormData) => {
try {
if (!templateData) return;
if (!projectId) return;
if (!templateData) return;
if (!projectId) return;
switch (operation) {
case SshCertificateOperation.SIGN_SSH_KEY: {
const { serialNumber, signedKey } = await signSshKey({
projectId,
certificateTemplateId: templateData.id,
publicKey: existingPublicKey,
certType,
principals: principals.split(",").map((user) => user.trim()),
ttl,
keyId
});
switch (operation) {
case SshCertificateOperation.SIGN_SSH_KEY: {
const { serialNumber, signedKey } = await signSshKey({
projectId,
certificateTemplateId: templateData.id,
publicKey: existingPublicKey,
certType,
principals: principals.split(",").map((user) => user.trim()),
ttl,
keyId
});
setCertificateDetails({
serialNumber,
signedKey
});
break;
}
case SshCertificateOperation.ISSUE_SSH_CREDS: {
const { serialNumber, publicKey, privateKey, signedKey } = await issueSshCreds({
projectId,
certificateTemplateId: templateData.id,
keyAlgorithm,
certType,
principals: principals.split(",").map((user) => user.trim()),
ttl,
keyId
});
setCertificateDetails({
serialNumber,
privateKey,
publicKey,
signedKey
});
break;
}
default: {
break;
}
setCertificateDetails({
serialNumber,
signedKey
});
break;
}
case SshCertificateOperation.ISSUE_SSH_CREDS: {
const { serialNumber, publicKey, privateKey, signedKey } = await issueSshCreds({
projectId,
certificateTemplateId: templateData.id,
keyAlgorithm,
certType,
principals: principals.split(",").map((user) => user.trim()),
ttl,
keyId
});
reset();
createNotification({
text: "Successfully created SSH certificate",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to create SSH certificate",
type: "error"
});
setCertificateDetails({
serialNumber,
privateKey,
publicKey,
signedKey
});
break;
}
default: {
break;
}
}
reset();
createNotification({
text: "Successfully created SSH certificate",
type: "success"
});
};
return (

View File

@@ -138,52 +138,44 @@ export const SshCertificateTemplateModal = ({ popUp, handlePopUpToggle, sshCaId
allowedHosts,
allowCustomKeyIds
}: FormData) => {
try {
if (certTemplate) {
await updateSshCertTemplate({
id: certTemplate.id,
name,
ttl,
maxTTL,
allowedUsers: allowedUsers ? allowedUsers.split(",").map((user) => user.trim()) : [],
allowedHosts: allowedHosts ? allowedHosts.split(",").map((host) => host.trim()) : [],
allowUserCertificates,
allowHostCertificates,
allowCustomKeyIds
});
if (certTemplate) {
await updateSshCertTemplate({
id: certTemplate.id,
name,
ttl,
maxTTL,
allowedUsers: allowedUsers ? allowedUsers.split(",").map((user) => user.trim()) : [],
allowedHosts: allowedHosts ? allowedHosts.split(",").map((host) => host.trim()) : [],
allowUserCertificates,
allowHostCertificates,
allowCustomKeyIds
});
createNotification({
text: "Successfully updated SSH certificate template",
type: "success"
});
} else {
await createSshCertTemplate({
sshCaId,
name,
ttl,
maxTTL,
allowedUsers: allowedUsers ? allowedUsers.split(",").map((user) => user.trim()) : [],
allowedHosts: allowedHosts ? allowedHosts.split(",").map((host) => host.trim()) : [],
allowUserCertificates,
allowHostCertificates,
allowCustomKeyIds
});
createNotification({
text: "Successfully created SSH certificate template",
type: "success"
});
}
reset();
handlePopUpToggle("sshCertificateTemplate", false);
} catch (err) {
console.error(err);
createNotification({
text: "Failed to save changes",
type: "error"
text: "Successfully updated SSH certificate template",
type: "success"
});
} else {
await createSshCertTemplate({
sshCaId,
name,
ttl,
maxTTL,
allowedUsers: allowedUsers ? allowedUsers.split(",").map((user) => user.trim()) : [],
allowedHosts: allowedHosts ? allowedHosts.split(",").map((host) => host.trim()) : [],
allowUserCertificates,
allowHostCertificates,
allowCustomKeyIds
});
createNotification({
text: "Successfully created SSH certificate template",
type: "success"
});
}
reset();
handlePopUpToggle("sshCertificateTemplate", false);
};
return (

View File

@@ -33,24 +33,16 @@ export const SshCertificateTemplatesSection = ({ caId }: Props) => {
const { mutateAsync: updateSshCertTemplate } = useUpdateSshCertTemplate();
const onRemoveSshCertificateTemplateSubmit = async (id: string) => {
try {
await deleteSshCertTemplate({
id
});
await deleteSshCertTemplate({
id
});
await createNotification({
text: "Successfully deleted SSH certificate template",
type: "success"
});
createNotification({
text: "Successfully deleted SSH certificate template",
type: "success"
});
handlePopUpClose("deleteSshCertificateTemplate");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete SSH certificate template",
type: "error"
});
}
handlePopUpClose("deleteSshCertificateTemplate");
};
const onUpdateSshCaStatus = async ({
@@ -60,26 +52,16 @@ export const SshCertificateTemplatesSection = ({ caId }: Props) => {
templateId: string;
status: SshCertTemplateStatus;
}) => {
try {
await updateSshCertTemplate({ id: templateId, status });
await updateSshCertTemplate({ id: templateId, status });
await createNotification({
text: `Successfully ${
status === SshCertTemplateStatus.ACTIVE ? "enabled" : "disabled"
} SSH certificate template`,
type: "success"
});
createNotification({
text: `Successfully ${
status === SshCertTemplateStatus.ACTIVE ? "enabled" : "disabled"
} SSH certificate template`,
type: "success"
});
handlePopUpClose("sshCertificateTemplateStatus");
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${
status === SshCertTemplateStatus.ACTIVE ? "enabled" : "disabled"
} SSH certificate template`,
type: "error"
});
}
handlePopUpClose("sshCertificateTemplateStatus");
};
return (

View File

@@ -106,47 +106,39 @@ export const SshCaModal = ({ popUp, handlePopUpToggle }: Props) => {
publicKey,
privateKey
}: FormData) => {
try {
if (!projectId) return;
if (!projectId) return;
if (ca) {
await updateMutateAsync({
caId: ca.id,
friendlyName
});
} else {
const { id: newCaId } = await createMutateAsync({
projectId,
friendlyName,
keySource,
keyAlgorithm,
publicKey,
privateKey
});
navigate({
to: "/projects/ssh/$projectId/ca/$caId",
params: {
projectId,
caId: newCaId
}
});
}
reset();
handlePopUpToggle("sshCa", false);
createNotification({
text: `Successfully ${ca ? "updated" : "created"} SSH CA`,
type: "success"
if (ca) {
await updateMutateAsync({
caId: ca.id,
friendlyName
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${ca ? "update" : "create"} SSH CA`,
type: "error"
} else {
const { id: newCaId } = await createMutateAsync({
projectId,
friendlyName,
keySource,
keyAlgorithm,
publicKey,
privateKey
});
navigate({
to: "/projects/ssh/$projectId/ca/$caId",
params: {
projectId,
caId: newCaId
}
});
}
reset();
handlePopUpToggle("sshCa", false);
createNotification({
text: `Successfully ${ca ? "updated" : "created"} SSH CA`,
type: "success"
});
};
return (

View File

@@ -23,41 +23,25 @@ export const SshCaSection = () => {
] as const);
const onRemoveSshCaSubmit = async (caId: string) => {
try {
await deleteSshCa({ caId });
await deleteSshCa({ caId });
createNotification({
text: "Successfully deleted SSH CA",
type: "success"
});
createNotification({
text: "Successfully deleted SSH CA",
type: "success"
});
handlePopUpClose("deleteSshCa");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete SSH CA",
type: "error"
});
}
handlePopUpClose("deleteSshCa");
};
const onUpdateSshCaStatus = async ({ caId, status }: { caId: string; status: SshCaStatus }) => {
try {
await updateSshCa({ caId, status });
await updateSshCa({ caId, status });
createNotification({
text: `Successfully ${status === SshCaStatus.ACTIVE ? "enabled" : "disabled"} SSH CA`,
type: "success"
});
createNotification({
text: `Successfully ${status === SshCaStatus.ACTIVE ? "enabled" : "disabled"} SSH CA`,
type: "success"
});
handlePopUpClose("sshCaStatus");
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${status === SshCaStatus.ACTIVE ? "enabled" : "disabled"} SSH CA`,
type: "error"
});
}
handlePopUpClose("sshCaStatus");
};
return (

View File

@@ -44,30 +44,22 @@ const Page = () => {
] as const);
const onRemoveSshGroupSubmit = async (groupIdToDelete: string) => {
try {
if (!projectId) return;
if (!projectId) return;
await deleteSshHostGroup({ sshHostGroupId: groupIdToDelete });
await deleteSshHostGroup({ sshHostGroupId: groupIdToDelete });
createNotification({
text: "Successfully deleted SSH group",
type: "success"
});
createNotification({
text: "Successfully deleted SSH group",
type: "success"
});
handlePopUpClose("deleteSshHostGroup");
navigate({
to: "/projects/ssh/$projectId/overview",
params: {
projectId
}
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete SSH group",
type: "error"
});
}
handlePopUpClose("deleteSshHostGroup");
navigate({
to: "/projects/ssh/$projectId/overview",
params: {
projectId
}
});
};
return (

View File

@@ -42,30 +42,23 @@ export const AddHostGroupMemberModal = ({ popUp, handlePopUpToggle }: Props) =>
useAddHostToSshHostGroup();
const handleAddHost = async (sshHostId: string) => {
try {
if (!popUpData?.sshHostGroupId) {
createNotification({
text: "Some data is missing, please refresh the page and try again",
type: "error"
});
return;
}
await addHostToSshHostGroup({
sshHostGroupId: popUpData.sshHostGroupId,
sshHostId
});
if (!popUpData?.sshHostGroupId) {
createNotification({
text: "Successfully added host to the group",
type: "success"
});
} catch {
createNotification({
text: "Failed to add host to the group",
text: "Some data is missing, please refresh the page and try again",
type: "error"
});
return;
}
await addHostToSshHostGroup({
sshHostGroupId: popUpData.sshHostGroupId,
sshHostId
});
createNotification({
text: "Successfully added host to the group",
type: "success"
});
};
return (

View File

@@ -121,67 +121,59 @@ export const SshHostGroupModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [sshHostGroup]);
const onFormSubmit = async ({ name, loginMappings }: FormData) => {
try {
if (!projectId) return;
if (!projectId) return;
// check if there is already a different host group with the same name
const existingNames =
sshHostGroups?.filter((h) => h.id !== sshHostGroup?.id).map((h) => h.name) || [];
if (existingNames.includes(name.trim())) {
createNotification({
text: "A host group with this name already exists.",
type: "error"
});
return;
}
const transformedLoginMappings = loginMappings.map(({ loginUser, allowedPrincipals }) => {
const usernames = allowedPrincipals
.filter((p) => p.type === "user" && p.value)
.map((p) => p.value);
const groupNames = allowedPrincipals
.filter((p) => p.type === "group" && p.value)
.map((p) => p.value);
return {
loginUser,
allowedPrincipals: {
usernames,
groups: groupNames
}
};
});
if (sshHostGroup) {
await updateMutateAsync({
sshHostGroupId: sshHostGroup.id,
name,
loginMappings: transformedLoginMappings
});
} else {
await createMutateAsync({
projectId,
name,
loginMappings: transformedLoginMappings
});
}
reset();
handlePopUpToggle("sshHostGroup", false);
// check if there is already a different host group with the same name
const existingNames =
sshHostGroups?.filter((h) => h.id !== sshHostGroup?.id).map((h) => h.name) || [];
if (existingNames.includes(name.trim())) {
createNotification({
text: `Successfully ${sshHostGroup ? "updated" : "created"} SSH host group`,
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: `Failed to ${sshHostGroup ? "update" : "create"} SSH host group`,
text: "A host group with this name already exists.",
type: "error"
});
return;
}
const transformedLoginMappings = loginMappings.map(({ loginUser, allowedPrincipals }) => {
const usernames = allowedPrincipals
.filter((p) => p.type === "user" && p.value)
.map((p) => p.value);
const groupNames = allowedPrincipals
.filter((p) => p.type === "group" && p.value)
.map((p) => p.value);
return {
loginUser,
allowedPrincipals: {
usernames,
groups: groupNames
}
};
});
if (sshHostGroup) {
await updateMutateAsync({
sshHostGroupId: sshHostGroup.id,
name,
loginMappings: transformedLoginMappings
});
} else {
await createMutateAsync({
projectId,
name,
loginMappings: transformedLoginMappings
});
}
reset();
handlePopUpToggle("sshHostGroup", false);
createNotification({
text: `Successfully ${sshHostGroup ? "updated" : "created"} SSH host group`,
type: "success"
});
};
const toggleMapping = (index: number) => {

View File

@@ -20,22 +20,14 @@ export const SshHostsSection = () => {
] as const);
const onRemoveSshHostSubmit = async (sshHostId: string) => {
try {
const host = await deleteSshHost({ sshHostId });
const host = await deleteSshHost({ sshHostId });
createNotification({
text: `Successfully deleted SSH host: ${host.hostname}`,
type: "success"
});
createNotification({
text: `Successfully deleted SSH host: ${host.hostname}`,
type: "success"
});
handlePopUpClose("deleteSshHost");
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete SSH host",
type: "error"
});
}
handlePopUpClose("deleteSshHost");
};
return (

View File

@@ -22,19 +22,11 @@ export const APIKeyTable = () => {
const { mutateAsync } = useDeleteAPIKey();
const handleDeleteAPIKeyDataClick = async (apiKeyDataId: string) => {
try {
await mutateAsync(apiKeyDataId);
createNotification({
text: "Successfully deleted API key",
type: "success"
});
} catch (err) {
console.error(err);
createNotification({
text: "Failed to delete API key",
type: "error"
});
}
await mutateAsync(apiKeyDataId);
createNotification({
text: "Successfully deleted API key",
type: "success"
});
};
return (

View File

@@ -76,27 +76,19 @@ export const AddAPIKeyModal = ({ popUp, handlePopUpToggle }: Props) => {
};
const onFormSubmit = async ({ name, expiresIn }: FormData) => {
try {
const { apiKey } = await mutateAsync({
name,
expiresIn: expirationMapping[expiresIn]
});
const { apiKey } = await mutateAsync({
name,
expiresIn: expirationMapping[expiresIn]
});
setNewAPIKey(apiKey);
setNewAPIKey(apiKey);
createNotification({
text: "Successfully created API key",
type: "success"
});
createNotification({
text: "Successfully created API key",
type: "success"
});
reset();
} catch (err) {
console.error(err);
createNotification({
text: "Failed to create API key",
type: "error"
});
}
reset();
};
const hasAPIKey = Boolean(newAPIKey);