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
@@ -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([
@@ -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 (
@@ -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 =
@@ -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);
@@ -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);
}
@@ -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 (
@@ -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");