|
1 | 1 | 'use client'; |
2 | 2 |
|
| 3 | +import { ConnectIntegrationDialog } from '@/components/integrations/ConnectIntegrationDialog'; |
3 | 4 | import { |
4 | 5 | useConnectionServices, |
5 | 6 | useIntegrationConnections, |
@@ -35,10 +36,11 @@ interface ProviderDetailViewProps { |
35 | 36 |
|
36 | 37 | export function ProviderDetailView({ provider, initialConnections }: ProviderDetailViewProps) { |
37 | 38 | const { orgId } = useParams<{ orgId: string }>(); |
38 | | - const { connections: allConnections } = useIntegrationConnections(); |
| 39 | + const { connections: allConnections, refresh: refreshConnections } = useIntegrationConnections(); |
39 | 40 | const { startOAuth } = useIntegrationMutations(); |
40 | 41 | const [showAddAccount, setShowAddAccount] = useState(false); |
41 | 42 | const [settingsOpen, setSettingsOpen] = useState(false); |
| 43 | + const [reconnectDialogOpen, setReconnectDialogOpen] = useState(false); |
42 | 44 |
|
43 | 45 | const connections = useMemo(() => { |
44 | 46 | const live = allConnections.filter((c) => c.providerSlug === provider.id); |
@@ -158,12 +160,15 @@ export function ProviderDetailView({ provider, initialConnections }: ProviderDet |
158 | 160 | }, [isCloudProvider, isConnected, selectedConnection?.id, refreshServices]); |
159 | 161 |
|
160 | 162 | const handleConnect = useCallback(async () => { |
161 | | - if (provider.authType === 'oauth2' && provider.oauthConfigured) { |
| 163 | + if (provider.authType === 'oauth2') { |
162 | 164 | const redirectUrl = `${window.location.origin}/${orgId}/integrations/${provider.id}?success=true`; |
163 | 165 | const result = await startOAuth(provider.id, redirectUrl); |
164 | 166 | if (result?.authorizationUrl) { |
165 | 167 | window.location.href = result.authorizationUrl; |
| 168 | + } else { |
| 169 | + toast.error(result.error || 'Failed to start connection'); |
166 | 170 | } |
| 171 | + return; |
167 | 172 | } else { |
168 | 173 | // For non-OAuth, show the inline add-account form |
169 | 174 | setShowAddAccount(true); |
@@ -202,7 +207,7 @@ export function ProviderDetailView({ provider, initialConnections }: ProviderDet |
202 | 207 | This connection was created before {CLOUD_RECONNECT_CUTOFF_LABEL}. Reconnect it to keep scans and remediation fully reliable. |
203 | 208 | </p> |
204 | 209 | </div> |
205 | | - <Button size="sm" variant="outline" onClick={() => void handleConnect()}> |
| 210 | + <Button size="sm" variant="outline" onClick={() => setReconnectDialogOpen(true)}> |
206 | 211 | Reconnect |
207 | 212 | </Button> |
208 | 213 | </div> |
@@ -276,6 +281,22 @@ export function ProviderDetailView({ provider, initialConnections }: ProviderDet |
276 | 281 | onOAuthConnect={handleConnect} |
277 | 282 | /> |
278 | 283 | )} |
| 284 | + |
| 285 | + {selectedConnectionRequiresReconnect && ( |
| 286 | + <ConnectIntegrationDialog |
| 287 | + open={reconnectDialogOpen} |
| 288 | + onOpenChange={setReconnectDialogOpen} |
| 289 | + integrationId={provider.id} |
| 290 | + integrationName={provider.name} |
| 291 | + integrationLogoUrl={provider.logoUrl} |
| 292 | + initialView="list" |
| 293 | + onConnected={() => { |
| 294 | + setReconnectDialogOpen(false); |
| 295 | + setShowAddAccount(false); |
| 296 | + refreshConnections(); |
| 297 | + }} |
| 298 | + /> |
| 299 | + )} |
279 | 300 | </> |
280 | 301 | ); |
281 | 302 | } |
0 commit comments