()
| 22 | }; |
| 23 | |
| 24 | export const useSlack = (): UseSlack => { |
| 25 | const { logEvent } = useLogContext(); |
| 26 | |
| 27 | const connect = useCallback<UseSlack['connect']>(({ redirectPath }) => { |
| 28 | // apiUrl is a relative proxy path on localhost, hence the base |
| 29 | const url = new URL( |
| 30 | `${apiUrl}/integrations/slack/auth/authorize`, |
| 31 | globalThis.location?.origin, |
| 32 | ); |
| 33 | url.searchParams.set('redirectPath', redirectPath); |
| 34 | |
| 35 | window.location.href = url.toString(); |
| 36 | }, []); |
| 37 | |
| 38 | const connectSource = useCallback<UseSlack['connectSource']>( |
| 39 | async ({ integrationId, channelId, sourceId }) => { |
| 40 | logEvent({ |
| 41 | event_name: LogEvent.SetIntegration, |
| 42 | target_id: UserIntegrationType.Slack, |
| 43 | extra: JSON.stringify({ |
| 44 | source: sourceId, |
| 45 | }), |
| 46 | }); |
| 47 | |
| 48 | await gqlClient.request(SLACK_CONNECT_SOURCE_MUTATION, { |
| 49 | integrationId, |
| 50 | channelId, |
| 51 | sourceId, |
| 52 | }); |
| 53 | }, |
| 54 | [logEvent], |
| 55 | ); |
| 56 | |
| 57 | return { |
| 58 | connect, |
| 59 | connectSource, |
| 60 | }; |
| 61 | }; |
no test coverage detected