Skip to content

Commit 236b357

Browse files
authored
Merge pull request #2528 from trycompai/fix/gcp-reconnect-flow
fix(app): repair GCP reconnect flow from integration detail
2 parents 27a006f + fd9e041 commit 236b357

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

apps/app/src/app/(app)/[orgId]/integrations/[slug]/components/ProviderDetailView.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use client';
22

3+
import { ConnectIntegrationDialog } from '@/components/integrations/ConnectIntegrationDialog';
34
import {
45
useConnectionServices,
56
useIntegrationConnections,
@@ -35,10 +36,11 @@ interface ProviderDetailViewProps {
3536

3637
export function ProviderDetailView({ provider, initialConnections }: ProviderDetailViewProps) {
3738
const { orgId } = useParams<{ orgId: string }>();
38-
const { connections: allConnections } = useIntegrationConnections();
39+
const { connections: allConnections, refresh: refreshConnections } = useIntegrationConnections();
3940
const { startOAuth } = useIntegrationMutations();
4041
const [showAddAccount, setShowAddAccount] = useState(false);
4142
const [settingsOpen, setSettingsOpen] = useState(false);
43+
const [reconnectDialogOpen, setReconnectDialogOpen] = useState(false);
4244

4345
const connections = useMemo(() => {
4446
const live = allConnections.filter((c) => c.providerSlug === provider.id);
@@ -158,12 +160,15 @@ export function ProviderDetailView({ provider, initialConnections }: ProviderDet
158160
}, [isCloudProvider, isConnected, selectedConnection?.id, refreshServices]);
159161

160162
const handleConnect = useCallback(async () => {
161-
if (provider.authType === 'oauth2' && provider.oauthConfigured) {
163+
if (provider.authType === 'oauth2') {
162164
const redirectUrl = `${window.location.origin}/${orgId}/integrations/${provider.id}?success=true`;
163165
const result = await startOAuth(provider.id, redirectUrl);
164166
if (result?.authorizationUrl) {
165167
window.location.href = result.authorizationUrl;
168+
} else {
169+
toast.error(result.error || 'Failed to start connection');
166170
}
171+
return;
167172
} else {
168173
// For non-OAuth, show the inline add-account form
169174
setShowAddAccount(true);
@@ -202,7 +207,7 @@ export function ProviderDetailView({ provider, initialConnections }: ProviderDet
202207
This connection was created before {CLOUD_RECONNECT_CUTOFF_LABEL}. Reconnect it to keep scans and remediation fully reliable.
203208
</p>
204209
</div>
205-
<Button size="sm" variant="outline" onClick={() => void handleConnect()}>
210+
<Button size="sm" variant="outline" onClick={() => setReconnectDialogOpen(true)}>
206211
Reconnect
207212
</Button>
208213
</div>
@@ -276,6 +281,22 @@ export function ProviderDetailView({ provider, initialConnections }: ProviderDet
276281
onOAuthConnect={handleConnect}
277282
/>
278283
)}
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+
)}
279300
</>
280301
);
281302
}

0 commit comments

Comments
 (0)