@@ -12,7 +12,7 @@ import {
1212 XCircle ,
1313 Zap ,
1414} from "lucide-react" ;
15- import { useEffect , useMemo , useState } from "react" ;
15+ import { useCallback , useEffect , useMemo , useState } from "react" ;
1616import { toast } from "sonner" ;
1717import {
1818 AlertDialog ,
@@ -42,7 +42,7 @@ import {
4242 aiGatewayStatusAtom ,
4343 aiGatewayTeamsAtom ,
4444 aiGatewayTeamsLoadingAtom ,
45- showAiGatewayConsentModalAtom ,
45+ openAiGatewayConsentModalAtom ,
4646} from "@/lib/ai-gateway/state" ;
4747import { api , type Integration } from "@/lib/api-client" ;
4848import type { IntegrationType } from "@/lib/types/integration" ;
@@ -555,7 +555,7 @@ export function IntegrationFormDialog({
555555
556556 // AI Gateway managed keys state
557557 const aiGatewayStatus = useAtomValue ( aiGatewayStatusAtom ) ;
558- const setShowConsentModal = useSetAtom ( showAiGatewayConsentModalAtom ) ;
558+ const openConsentModal = useSetAtom ( openAiGatewayConsentModalAtom ) ;
559559
560560 // Check if AI Gateway managed keys should be offered
561561 const shouldUseManagedKeys =
@@ -590,6 +590,16 @@ export function IntegrationFormDialog({
590590 const setTeams = useSetAtom ( aiGatewayTeamsAtom ) ;
591591 const setTeamsLoading = useSetAtom ( aiGatewayTeamsLoadingAtom ) ;
592592
593+ // Helper to open consent modal with callbacks
594+ const showConsentModalWithCallbacks = useCallback ( ( ) => {
595+ onClose ( ) ;
596+ openConsentModal ( {
597+ onConsent : ( integrationId : string ) => {
598+ onSuccess ?.( integrationId ) ;
599+ } ,
600+ } ) ;
601+ } , [ onClose , openConsentModal , onSuccess ] ) ;
602+
593603 // Handle preselected AI Gateway - fetch status/teams and show consent modal if managed keys available
594604 useEffect ( ( ) => {
595605 if ( ! open || preselectedType !== "ai-gateway" || mode !== "create" ) {
@@ -598,8 +608,7 @@ export function IntegrationFormDialog({
598608
599609 // If we already have status and managed keys are available, show consent modal
600610 if ( shouldUseManagedKeys ) {
601- onClose ( ) ;
602- setShowConsentModal ( true ) ;
611+ showConsentModalWithCallbacks ( ) ;
603612 return ;
604613 }
605614
@@ -618,8 +627,7 @@ export function IntegrationFormDialog({
618627 } )
619628 . finally ( ( ) => {
620629 setTeamsLoading ( false ) ;
621- onClose ( ) ;
622- setShowConsentModal ( true ) ;
630+ showConsentModalWithCallbacks ( ) ;
623631 } ) ;
624632 }
625633 } ) ;
@@ -630,8 +638,7 @@ export function IntegrationFormDialog({
630638 mode ,
631639 aiGatewayStatus ,
632640 shouldUseManagedKeys ,
633- onClose ,
634- setShowConsentModal ,
641+ showConsentModalWithCallbacks ,
635642 setAiGatewayStatus ,
636643 setTeams ,
637644 setTeamsLoading ,
@@ -640,8 +647,7 @@ export function IntegrationFormDialog({
640647 const handleSelectType = ( type : IntegrationType ) => {
641648 // If selecting AI Gateway and managed keys are available, show consent modal
642649 if ( type === "ai-gateway" && shouldUseManagedKeys ) {
643- onClose ( ) ;
644- setShowConsentModal ( true ) ;
650+ showConsentModalWithCallbacks ( ) ;
645651 return ;
646652 }
647653
0 commit comments