@@ -28,28 +28,33 @@ const ContactLowcoderModal: React.FC<ContactLowcoderModalProps> = ({
28
28
29
29
// Fetch deployment ID when modal opens
30
30
useEffect ( ( ) => {
31
- if ( visible && environment . environmentApiServiceUrl && environment . environmentApikey ) {
31
+ const fetchDeploymentId = async ( ) => {
32
+ if ( ! visible || ! environment . environmentApiServiceUrl || ! environment . environmentApikey ) {
33
+ if ( visible ) {
34
+ setError ( 'Environment API service URL or API key not configured' ) ;
35
+ }
36
+ return ;
37
+ }
38
+
32
39
setIsLoading ( true ) ;
33
40
setError ( null ) ;
34
41
35
- getEnvironmentDeploymentId (
36
- environment . environmentApiServiceUrl ,
37
- environment . environmentApikey
38
- )
39
- . then ( ( id ) => {
40
- setDeploymentId ( id ) ;
41
- setShowHubspotModal ( true ) ;
42
- } )
43
- . catch ( ( err ) => {
44
- console . error ( 'Failed to fetch deployment ID:' , err ) ;
45
- setError ( err instanceof Error ? err . message : 'Failed to fetch deployment ID' ) ;
46
- } )
47
- . finally ( ( ) => {
48
- setIsLoading ( false ) ;
49
- } ) ;
50
- } else if ( visible ) {
51
- setError ( 'Environment API service URL or API key not configured' ) ;
52
- }
42
+ try {
43
+ const id = await getEnvironmentDeploymentId (
44
+ environment . environmentApiServiceUrl ,
45
+ environment . environmentApikey
46
+ ) ;
47
+ setDeploymentId ( id ) ;
48
+ setShowHubspotModal ( true ) ;
49
+ } catch ( err ) {
50
+ console . error ( 'Failed to fetch deployment ID:' , err ) ;
51
+ setError ( err instanceof Error ? err . message : 'Failed to fetch deployment ID' ) ;
52
+ } finally {
53
+ setIsLoading ( false ) ;
54
+ }
55
+ } ;
56
+
57
+ fetchDeploymentId ( ) ;
53
58
} , [ visible , environment . environmentApiServiceUrl , environment . environmentApikey ] ) ;
54
59
55
60
// Handle HubSpot modal close
0 commit comments