@@ -4,6 +4,7 @@ import { useSelector } from "react-redux";
44import { getUser , getCurrentUser } from "redux/selectors/usersSelectors" ;
55import { useEffect , useState } from "react" ;
66import { calculateFlowCode } from "./apiUtils" ;
7+ import { getDeploymentId } from "@lowcoder-ee/redux/selectors/configSelectors" ;
78
89// Interfaces
910export interface CustomerAddress {
@@ -213,10 +214,7 @@ export const searchCustomersSubscriptions = async (Customer: LowcoderSearchCusto
213214 if ( result ?. data ?. data ?. length > 0 ) {
214215 return result ?. data ?. data ;
215216 }
216- else if ( result . data . success == "false" && (
217- result . data . reason == "customerNotFound"
218- || result . data . reason === "userSubscriptionNotFound"
219- ) ) {
217+ else if ( result . data . success == "false" && result . data . reason == "customerNotFound" ) {
220218 return [ ] ;
221219 }
222220 else if ( result . data . success == "false" && result . data . reason == "userSubscriptionNotFound" ) {
@@ -225,6 +223,7 @@ export const searchCustomersSubscriptions = async (Customer: LowcoderSearchCusto
225223 else if ( result . data . success == "false" && result . data . reason == "orgSubscriptionNotFound" ) {
226224 return [ ] ;
227225 }
226+ return [ ] ;
228227 } catch ( error ) {
229228 console . error ( "Error searching customer:" , error ) ;
230229 throw error ;
@@ -404,23 +403,24 @@ export const InitializeSubscription = () => {
404403
405404 const user = useSelector ( getUser ) ;
406405 const currentUser = useSelector ( getCurrentUser ) ;
406+ const deploymentId = useSelector ( getDeploymentId ) ;
407407 const currentOrg = user . orgs . find ( org => org . id === user . currentOrgId ) ;
408408 const orgID = user . currentOrgId ;
409409 const domain = window . location . protocol + "//" + window . location . hostname + ( window . location . port ? ':' + window . location . port : '' ) ;
410- const hostIdenticator = "lowcoder-test" ;
410+ // const hostIdenticator = "lowcoder-test";
411411 const admin = user . orgRoleMap . get ( orgID ) === "admin" ? "admin" : "member" ;
412412
413413 const subscriptionSearchCustomer : LowcoderSearchCustomer = {
414414 hostname : domain ,
415- hostId : hostIdenticator ,
415+ hostId : deploymentId ,
416416 email : currentUser . email ,
417417 orgId : orgID ,
418418 userId : user . id ,
419419 } ;
420420
421421 const subscriptionNewCustomer : LowcoderNewCustomer = {
422422 hostname : domain ,
423- hostId : hostIdenticator ,
423+ hostId : deploymentId ,
424424 email : currentUser . email ,
425425 orgId : orgID ,
426426 userId : user . id ,
@@ -447,8 +447,10 @@ export const InitializeSubscription = () => {
447447 }
448448 } ;
449449
450- initializeCustomer ( ) ;
451- } , [ ] ) ;
450+ if ( Boolean ( deploymentId ) ) {
451+ initializeCustomer ( ) ;
452+ }
453+ } , [ deploymentId ] ) ;
452454
453455 useEffect ( ( ) => {
454456 const fetchSubscriptions = async ( ) => {
@@ -547,13 +549,14 @@ export const CheckSubscriptions = () => {
547549
548550 const user = useSelector ( getUser ) ;
549551 const currentUser = useSelector ( getCurrentUser ) ;
552+ const deploymentId = useSelector ( getDeploymentId ) ;
550553 const orgID = user . currentOrgId ;
551554 const domain = window . location . protocol + "//" + window . location . hostname + ( window . location . port ? ':' + window . location . port : '' ) ;
552- const hostIdenticator = "lowcoder-test" ;
555+ // const hostIdenticator = "lowcoder-test";
553556
554557 const subscriptionSearchCustomer : LowcoderSearchCustomer = {
555558 hostname : domain ,
556- hostId : hostIdenticator ,
559+ hostId : deploymentId ,
557560 email : currentUser . email ,
558561 orgId : orgID ,
559562 userId : user . id ,
@@ -571,6 +574,12 @@ export const CheckSubscriptions = () => {
571574 setLoading ( false ) ;
572575 }
573576 } ;
577+ if (
578+ Boolean ( currentUser . email )
579+ && Boolean ( orgID )
580+ && Boolean ( user . id )
581+ && Boolean ( deploymentId )
582+ )
574583 fetchCustomerAndSubscriptions ( ) ;
575584 } , [ subscriptionSearchCustomer ] ) ;
576585
0 commit comments