(provider: IntegrationProvider)
| 147 | }; |
| 148 | |
| 149 | const handleConnect = async (provider: IntegrationProvider) => { |
| 150 | resetError(); |
| 151 | |
| 152 | if (!provider.isConfigured) { |
| 153 | setConfigProvider(provider); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | setConnectingProvider(provider.id); |
| 158 | try { |
| 159 | const redirectUri = `${window.location.origin}/integrations/callback/${provider.id}`; |
| 160 | const response = await api.integrations.startOAuth(provider.id, { |
| 161 | userId, |
| 162 | redirectUri, |
| 163 | scopes: buildRequestedScopes(provider), |
| 164 | }); |
| 165 | window.location.href = response.authorizationUrl; |
| 166 | } catch (err) { |
| 167 | const message = err instanceof Error ? err.message : 'Failed to start OAuth session'; |
| 168 | toast({ |
| 169 | title: 'Could not start OAuth flow', |
| 170 | description: message, |
| 171 | variant: 'destructive', |
| 172 | }); |
| 173 | } finally { |
| 174 | setConnectingProvider(null); |
| 175 | } |
| 176 | }; |
| 177 | |
| 178 | const handleConfigureProvider = (provider: IntegrationProvider) => { |
| 179 | resetError(); |
no test coverage detected