Skip to content

Commit f9616aa

Browse files
actions and selectors for deploymentId
1 parent e1ca7dc commit f9616aa

File tree

5 files changed

+38
-13
lines changed

5 files changed

+38
-13
lines changed

client/packages/lowcoder/src/api/subscriptionApi.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useSelector } from "react-redux";
44
import { getUser, getCurrentUser } from "redux/selectors/usersSelectors";
55
import { useEffect, useState } from "react";
66
import { calculateFlowCode } from "./apiUtils";
7+
import { getDeploymentId } from "@lowcoder-ee/redux/selectors/configSelectors";
78

89
// Interfaces
910
export 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

client/packages/lowcoder/src/pages/ApplicationV2/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import { ReduxActionTypes } from '@lowcoder-ee/constants/reduxActionConstants';
7272
// adding App Editor, so we can show Apps inside the Admin Area
7373
import AppEditor from "../editor/AppEditor";
7474
import { set } from "lodash";
75+
import { fetchDeploymentIdAction } from "@lowcoder-ee/redux/reduxActions/configActions";
7576

7677
const TabLabel = styled.div`
7778
font-weight: 500;
@@ -172,6 +173,7 @@ export default function ApplicationHome() {
172173
if (user.currentOrgId) {
173174
dispatch(fetchHomeData({}));
174175
dispatch(fetchSubscriptionsAction());
176+
dispatch(fetchDeploymentIdAction());
175177
}
176178
}, [user.currentOrgId]);
177179

client/packages/lowcoder/src/redux/reducers/uiReducers/configReducer.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ExternalEditorContextState } from "util/context/ExternalEditorContext";
1010
const initialState: ConfigState = {
1111
fetchingConfig: false,
1212
editorExternalState: {},
13+
deploymentId: '',
1314
};
1415

1516
const configReducer = createReducer(initialState, {
@@ -40,12 +41,22 @@ const configReducer = createReducer(initialState, {
4041
editorExternalState: action.payload,
4142
};
4243
},
44+
[ReduxActionTypes.FETCH_DEPLOYMENT_ID_SUCCESS]: (
45+
state: ConfigState,
46+
action: ReduxAction<string>
47+
): ConfigState => {
48+
return {
49+
...state,
50+
deploymentId: action.payload,
51+
};
52+
},
4353
});
4454

4555
export interface ConfigState {
4656
fetchingConfig: boolean;
4757
systemConfig?: SystemConfig;
4858
editorExternalState: Partial<ExternalEditorContextState>;
59+
deploymentId: string;
4960
}
5061

5162
export default configReducer;

client/packages/lowcoder/src/redux/sagas/configSagas.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ export function* fetchDeploymentIdSaga(action: ReduxAction<undefined>) {
3737
const response: AxiosResponse<ConfigResponse> = yield call(
3838
ConfigApi.fetchDeploymentId,
3939
);
40-
const isValidResponse: boolean = validateResponse(response);
41-
if (isValidResponse) {
40+
if (Boolean(response.data)) {
4241
yield put({
4342
type: ReduxActionTypes.FETCH_DEPLOYMENT_ID_SUCCESS,
4443
payload: response.data,

client/packages/lowcoder/src/redux/selectors/configSelectors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ export const getBrandingConfig = (state: AppState) => {
1616
export const getExternalEditorState = (state: AppState) => {
1717
return state.ui.config.editorExternalState;
1818
};
19+
20+
export const getDeploymentId = (state: AppState) => {
21+
return state.ui.config.deploymentId;
22+
};

0 commit comments

Comments
 (0)