Content-Length: 530605 | pFad | http://github.com/lowcoder-org/lowcoder/pull/1275/commits/3bee7f177d4a74ba307eb4eb09d56eb65c367221

88 Refactoring - subscription handling by raheeliftikhar5 · Pull Request #1275 · lowcoder-org/lowcoder · GitHub
Skip to content

Refactoring - subscription handling #1275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove polling for deploymentId in fetching user subscription
  • Loading branch information
raheeliftikhar5 committed Oct 31, 2024
commit 3bee7f177d4a74ba307eb4eb09d56eb65c367221
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ export function HomeLayout(props: HomeLayoutProps) {

const { breadcrumb = [], elements = [], localMarketplaceApps = [], globalMarketplaceApps = [], mode } = props;

console.log("HomeLayout props: ", props);

const categoryOptions = [
{ label: <FilterMenuItem>{trans("home.allCategories")}</FilterMenuItem>, value: 'All' },
...Object.entries(ApplicationCategoriesEnum).map(([key, value]) => ({
Expand Down
19 changes: 15 additions & 4 deletions client/packages/lowcoder/src/pages/ApplicationV2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
EnterpriseIcon,
UserIcon,
} from "lowcoder-design";
import React, { useCallback, useEffect, useState } from "react";
import React, { useCallback, useEffect, useState, useMemo } from "react";
import { fetchAllApplications, fetchHomeData } from "redux/reduxActions/applicationActions";
import { fetchSubscriptionsAction } from "redux/reduxActions/subscriptionActions";
import { getHomeOrg, normalAppListSelector } from "redux/selectors/applicationSelector";
Expand Down Expand Up @@ -66,13 +66,14 @@ import { Support } from "pages/support";
// import { messageInstance } from "lowcoder-design/src/components/GlobalInstances";
import { isEE } from "util/envUtils";
import { getSubscriptions } from 'redux/selectors/subscriptionSelectors';
import { SubscriptionProducts } from '@lowcoder-ee/api/subscriptionApi';
import { SubscriptionProductsEnum } from '@lowcoder-ee/constants/subscriptionConstants';
import { ReduxActionTypes } from '@lowcoder-ee/constants/reduxActionConstants';

// adding App Editor, so we can show Apps inside the Admin Area
import AppEditor from "../editor/AppEditor";
import { set } from "lodash";
import { fetchDeploymentIdAction } from "@lowcoder-ee/redux/reduxActions/configActions";
import { getDeploymentId } from "@lowcoder-ee/redux/selectors/configSelectors";

const TabLabel = styled.div`
font-weight: 500;
Expand Down Expand Up @@ -166,18 +167,28 @@ export default function ApplicationHome() {
const orgHomeId = "root";
const isSelfHost = window.location.host !== 'app.lowcoder.cloud';
const subscriptions = useSelector(getSubscriptions);
const deploymentId = useSelector(getDeploymentId);

const isOrgAdmin = org?.createdBy == user.id ? true : false;

useEffect(() => {
if (user.currentOrgId) {
dispatch(fetchSubscriptionsAction());
dispatch(fetchDeploymentIdAction());
}
dispatch(fetchHomeData({}));
}, [user.currentOrgId]);

const supportSubscription = subscriptions.some(sub => sub.product === SubscriptionProducts.SUPPORT && sub.status === 'active');
useEffect(() => {
if(Boolean(deploymentId)) {
dispatch(fetchSubscriptionsAction())
}
}, [deploymentId]);

const supportSubscription = useMemo(() => {
return subscriptions.some(
sub => sub.product === SubscriptionProductsEnum.SUPPORT && sub.status === 'active'
);
}, [subscriptions])

useEffect(() => {
if (!org) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CheckCircleOutlined } from '@ant-design/icons';
import { Level1SettingPageContent } from "../styled";
import { TacoMarkDown } from "lowcoder-design";
import ProductDescriptions, {Translations} from "./ProductDescriptions";
import { SubscriptionProductsEnum } from "@lowcoder-ee/constants/subscriptionConstants";

const { Meta } = Card;

Expand Down Expand Up @@ -66,10 +67,10 @@ const useMarkdown = (productId: string | null, userLanguage: string) => {
let descriptionContent : Translations | false;

switch (productId) {
case "QW8L3WPMiNjQjI":
case SubscriptionProductsEnum.SUPPORT:
descriptionContent = ProductDescriptions["SupportProduct"];
break;
case "QW8MpIBHxieKXd":
case SubscriptionProductsEnum.MEDIAPACKAGE:
descriptionContent = ProductDescriptions["MediaPackageProduct"];
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const initialState: SubscriptionsReduxState = {
fetchingSubscriptions: false,
fetchSubscriptionsFinished: false,
},
error: "",
error: undefined,
};

const subscriptionReducer = createReducer(initialState, {
Expand All @@ -22,6 +22,7 @@ const subscriptionReducer = createReducer(initialState, {
...state.loadingStates,
fetchingSubscriptions: true,
},
error: undefined,
}),

[ReduxActionTypes.FETCH_SUBSCRIPTIONS_SUCCESS]: (
Expand All @@ -35,6 +36,7 @@ const subscriptionReducer = createReducer(initialState, {
fetchingSubscriptions: false,
fetchSubscriptionsFinished: true,
},
error: undefined,
}),

[ReduxActionErrorTypes.FETCH_SUBSCRIPTIONS_ERROR]: (
Expand All @@ -57,7 +59,7 @@ export interface SubscriptionsReduxState {
fetchingSubscriptions: boolean;
fetchSubscriptionsFinished: boolean;
};
error: string;
error?: string;
}

export default subscriptionReducer;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReduxActionTypes } from "constants/reduxActionConstants";
import { ReduxActionErrorTypes, ReduxActionTypes } from "constants/reduxActionConstants";
import { Subscription } from 'api/subscriptionApi';

// Action Creators
Expand All @@ -12,6 +12,6 @@ export const fetchSubscriptionsSuccess = (subscriptions: Subscription[]) => ({
});

export const fetchSubscriptionsError = (error: string) => ({
type: ReduxActionTypes.FETCH_SUBSCRIPTIONS_FAILURE,
type: ReduxActionErrorTypes.FETCH_SUBSCRIPTIONS_ERROR,
payload: { error },
});
14 changes: 1 addition & 13 deletions client/packages/lowcoder/src/redux/sagas/subscriptionSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,12 @@ import { CurrentUser, User } from '@lowcoder-ee/constants/userConstants';
import { ReduxActionTypes } from '@lowcoder-ee/constants/reduxActionConstants';

function* fetchSubscriptionsSaga(action: ReturnType<typeof fetchSubscriptionsAction>) {

try {

// wait for deploymentId to be available
yield take(ReduxActionTypes.FETCH_DEPLOYMENT_ID_SUCCESS);

const user: User = yield select(getUser);
const currentUser: CurrentUser = yield select(getCurrentUser);
const orgID = user.currentOrgId;
const domain = `${window.location.protocol}//${window.location.hostname}${window.location.port ? `:${window.location.port}` : ''}`;

let hostIdenticator : string = yield select(getDeploymentId);

// Poll until deploymentId is available
while (!hostIdenticator) {
yield delay(100); // wait for 100ms
hostIdenticator = yield select(getDeploymentId);
}
const hostIdenticator: string = yield select(getDeploymentId);

const subscriptionSearchCustomer: LowcoderSearchCustomer = {
hostname: domain,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const checkSubscriptionsLoading = (state: AppState) : boolean => {
return state.ui.subscriptions.loadingStates.fetchingSubscriptions;
};

export const checkSubscriptionsError = (state: AppState) : string | null => {
export const getFetchSubscriptionsFinished = (state: AppState) : boolean => {
return state.ui.subscriptions.loadingStates.fetchSubscriptionsFinished;
};

export const getSubscriptionsError = (state: AppState) : string | undefined => {
return state.ui.subscriptions.error;
};
};








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/lowcoder-org/lowcoder/pull/1275/commits/3bee7f177d4a74ba307eb4eb09d56eb65c367221

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy