MCPcopy Create free account
hub / github.com/dailydotdev/apps / useSlack

Function useSlack

packages/shared/src/hooks/integrations/slack/useSlack.ts:29–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27const scopes = ['channels:read', 'chat:write', 'channels:join', 'groups:read'];
28
29export const useSlack = (): UseSlack => {
30 const { user } = useAuthContext();
31 const { logEvent } = useLogContext();
32
33 const connect = useCallback<UseSlack['connect']>(
34 async ({ redirectPath }) => {
35 const url = new URL('https://slack.com/oauth/v2/authorize');
36
37 const redirectUrl = new URL(`${apiUrl}/integrations/slack/auth/callback`);
38 url.searchParams.append('redirect_uri', redirectUrl.toString());
39
40 url.searchParams.append('state', user!.id);
41 url.searchParams.append('scope', scopes.join(','));
42 url.searchParams.append(
43 'client_id',
44 process.env.NEXT_PUBLIC_SLACK_CLIENT_ID!,
45 );
46
47 setCookie('slackRedirectPath', redirectPath, {
48 path: '/',
49 maxAge: 3600,
50 secure: !isDevelopment,
51 domain: process.env.NEXT_PUBLIC_DOMAIN,
52 sameSite: 'lax',
53 });
54
55 window.location.href = url.toString();
56 },
57 [user],
58 );
59
60 const connectSource = useCallback<UseSlack['connectSource']>(
61 async ({ integrationId, channelId, sourceId }) => {
62 logEvent({
63 event_name: LogEvent.SetIntegration,
64 target_id: UserIntegrationType.Slack,
65 extra: JSON.stringify({
66 source: sourceId,
67 }),
68 });
69
70 await gqlClient.request(SLACK_CONNECT_SOURCE_MUTATION, {
71 integrationId,
72 channelId,
73 sourceId,
74 });
75 },
76 [logEvent],
77 );
78
79 return {
80 connect,
81 connectSource,
82 };
83};

Callers 4

NewSquadModalFunction · 0.90
useSlackIntegrationModalFunction · 0.90
AccountIntegrationsPageFunction · 0.90

Calls 4

useAuthContextFunction · 0.90
useLogContextFunction · 0.90
setCookieFunction · 0.90
logEventFunction · 0.85

Tested by

no test coverage detected