Skip to content

Commit f4529cc

Browse files
authored
feat(KNO-9339): enable use of branches with SlackKit (#703)
1 parent f278892 commit f4529cc

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed

.changeset/every-geese-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"slack-connect-example": patch
3+
---
4+
5+
Add `NEXT_PUBLIC_KNOCK_BRANCH` env var for specifying branch

.changeset/seven-badgers-learn.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@knocklabs/react-core": patch
3+
"@knocklabs/react": patch
4+
---
5+
6+
Enable use of SlackKit with branches
7+
8+
The `useSlackAuth` hook exported by `@knocklabs/react-core` has been updated so
9+
that it works with branches. You can now use either this hook or the
10+
`<SlackAuthButton>` component exported by `@knocklabs/react` to test connecting
11+
Slack workspaces to Knock tenants while working on a branch.

examples/slack-connect-example/.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ NEXT_PUBLIC_SLACK_CLIENT_ID=<slack client id>
2020
# the slack channel you want to use and you'll find its ID on the page
2121
NEXT_PUBLIC_KNOCK_SLACK_CHANNEL_ID=<knock slack channel id>
2222
NEXT_PUBLIC_REDIRECT_URL=http://localhost:3000/
23+
24+
NEXT_PUBLIC_KNOCK_BRANCH=<optional>

examples/slack-connect-example/pages/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default function Home() {
5050
user={{ id: user.id }}
5151
host={process.env.NEXT_PUBLIC_KNOCK_API_URL}
5252
userToken={localStorage.getItem("knock-user-token")!}
53+
branch={process.env.NEXT_PUBLIC_KNOCK_BRANCH}
5354
>
5455
<KnockSlackProvider
5556
knockSlackChannelId={process.env.NEXT_PUBLIC_KNOCK_SLACK_CHANNEL_ID!}

packages/react-core/src/modules/slack/hooks/useSlackAuth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ function useSlackAuth(
9393
channel_id: knockSlackChannelId,
9494
public_key: knock.apiKey,
9595
user_token: knock.userToken,
96+
branch_slug: knock.branch,
9697
}),
9798
client_id: slackClientId,
9899
scope: combinedScopes.join(","),
@@ -104,6 +105,7 @@ function useSlackAuth(
104105
knockSlackChannelId,
105106
knock.apiKey,
106107
knock.userToken,
108+
knock.branch,
107109
slackClientId,
108110
combinedScopes,
109111
]);

packages/react-core/test/slack/useSlackAuth.test.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
33

44
import useSlackAuth from "../../src/modules/slack/hooks/useSlackAuth";
55

6+
const TEST_BRANCH_SLUG = "lorem-ipsum-branch";
7+
68
const mockSetConnectionStatus = vi.fn();
79
const mockSetActionLabel = vi.fn();
810

@@ -24,6 +26,7 @@ vi.mock("../../src/modules/core", () => ({
2426
slack: mockSlackClient,
2527
apiKey: "test_api_key",
2628
userToken: "test_user_token",
29+
branch: TEST_BRANCH_SLUG,
2730
}),
2831
}));
2932

@@ -53,6 +56,7 @@ describe("useSlackAuth", () => {
5356
channel_id: "test_channel_id",
5457
public_key: "test_api_key",
5558
user_token: "test_user_token",
59+
branch_slug: TEST_BRANCH_SLUG,
5660
});
5761
});
5862

0 commit comments

Comments
 (0)