mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 14:27:30 +00:00
slack integration reinstall
This commit is contained in:
@@ -21,7 +21,7 @@ import {
|
|||||||
type TSlackServiceFactoryDep = {
|
type TSlackServiceFactoryDep = {
|
||||||
slackIntegrationDAL: Pick<
|
slackIntegrationDAL: Pick<
|
||||||
TSlackIntegrationDALFactory,
|
TSlackIntegrationDALFactory,
|
||||||
"create" | "findOne" | "findById" | "updateById" | "deleteById"
|
"create" | "findOne" | "findById" | "updateById" | "deleteById" | "transaction"
|
||||||
>;
|
>;
|
||||||
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
|
||||||
projectDAL: Pick<TProjectDALFactory, "findById">;
|
projectDAL: Pick<TProjectDALFactory, "findById">;
|
||||||
@@ -62,15 +62,43 @@ export const slackServiceFactory = ({
|
|||||||
plainText: Buffer.from(botAccessToken, "utf8")
|
plainText: Buffer.from(botAccessToken, "utf8")
|
||||||
});
|
});
|
||||||
|
|
||||||
await slackIntegrationDAL.create({
|
await slackIntegrationDAL.transaction(async (tx) => {
|
||||||
projectId,
|
const slackIntegration = await slackIntegrationDAL.findOne(
|
||||||
teamId,
|
{
|
||||||
teamName,
|
projectId
|
||||||
slackUserId,
|
},
|
||||||
slackAppId,
|
tx
|
||||||
slackBotId,
|
);
|
||||||
slackBotUserId,
|
|
||||||
encryptedBotAccessToken
|
if (slackIntegration) {
|
||||||
|
return slackIntegrationDAL.updateById(
|
||||||
|
slackIntegration.id,
|
||||||
|
{
|
||||||
|
teamId,
|
||||||
|
teamName,
|
||||||
|
slackUserId,
|
||||||
|
slackAppId,
|
||||||
|
slackBotId,
|
||||||
|
slackBotUserId,
|
||||||
|
encryptedBotAccessToken
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return slackIntegrationDAL.create(
|
||||||
|
{
|
||||||
|
projectId,
|
||||||
|
teamId,
|
||||||
|
teamName,
|
||||||
|
slackUserId,
|
||||||
|
slackAppId,
|
||||||
|
slackBotId,
|
||||||
|
slackBotUserId,
|
||||||
|
encryptedBotAccessToken
|
||||||
|
},
|
||||||
|
tx
|
||||||
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+20
-6
@@ -59,6 +59,7 @@ export const NotificationTab = () => {
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isConnectToSlackLoading, setIsConnectToSlackLoading] = useToggle(false);
|
const [isConnectToSlackLoading, setIsConnectToSlackLoading] = useToggle(false);
|
||||||
|
const [isReinstallLoading, setIsReinstallLoading] = useToggle(false);
|
||||||
const secretRequestNotifState = watch("isSecretRequestNotificationEnabled");
|
const secretRequestNotifState = watch("isSecretRequestNotificationEnabled");
|
||||||
const accessRequestNotifState = watch("isAccessRequestNotificationEnabled");
|
const accessRequestNotifState = watch("isAccessRequestNotificationEnabled");
|
||||||
|
|
||||||
@@ -95,6 +96,13 @@ export const NotificationTab = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const triggerSlackInstall = async () => {
|
||||||
|
const slackInstallUrl = await fetchSlackInstallUrl(currentWorkspace?.id);
|
||||||
|
if (slackInstallUrl) {
|
||||||
|
router.push(slackInstallUrl);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (slackIntegration) {
|
if (slackIntegration) {
|
||||||
setValue(
|
setValue(
|
||||||
@@ -131,10 +139,7 @@ export const NotificationTab = () => {
|
|||||||
isLoading={isConnectToSlackLoading}
|
isLoading={isConnectToSlackLoading}
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setIsConnectToSlackLoading.on();
|
setIsConnectToSlackLoading.on();
|
||||||
const slackInstallUrl = await fetchSlackInstallUrl(currentWorkspace?.id);
|
await triggerSlackInstall();
|
||||||
if (slackInstallUrl) {
|
|
||||||
router.push(slackInstallUrl);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Connect to Slack
|
Connect to Slack
|
||||||
@@ -144,8 +149,16 @@ export const NotificationTab = () => {
|
|||||||
<form onSubmit={handleSubmit(handleIntegrationSave)}>
|
<form onSubmit={handleSubmit(handleIntegrationSave)}>
|
||||||
<div>Connected Slack workspace: {slackIntegration.teamName}</div>
|
<div>Connected Slack workspace: {slackIntegration.teamName}</div>
|
||||||
<div className="mt-2 mb-6">
|
<div className="mt-2 mb-6">
|
||||||
<Button colorSchema="secondary" size="xs">
|
<Button
|
||||||
Reinstall integration
|
colorSchema="secondary"
|
||||||
|
size="xs"
|
||||||
|
isLoading={isReinstallLoading}
|
||||||
|
onClick={async () => {
|
||||||
|
setIsReinstallLoading.on();
|
||||||
|
await triggerSlackInstall();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Reinstall
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
colorSchema="secondary"
|
colorSchema="secondary"
|
||||||
@@ -156,6 +169,7 @@ export const NotificationTab = () => {
|
|||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
<h2 className="mb-2 flex-1 text-lg font-semibold text-mineshaft-100">Events</h2>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="isSecretRequestNotificationEnabled"
|
name="isSecretRequestNotificationEnabled"
|
||||||
|
|||||||
Reference in New Issue
Block a user