Skip to content

Commit 19ebdc8

Browse files
author
FalkWolsky
committed
Reorganizing and cleaning up
1 parent 45b37cd commit 19ebdc8

File tree

12 files changed

+153
-58
lines changed

12 files changed

+153
-58
lines changed

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

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface CustomerAddress {
1515
postalCode: string;
1616
}
1717

18-
export interface LowcoderCustomer {
18+
export interface LowcoderNewCustomer {
1919
hostname: string;
2020
email: string;
2121
orgId: string;
@@ -26,6 +26,13 @@ export interface LowcoderCustomer {
2626
address?: CustomerAddress;
2727
}
2828

29+
export interface LowcoderSearchCustomer {
30+
hostname: string;
31+
email: string;
32+
orgId: string;
33+
userId: string;
34+
}
35+
2936
interface LowcoderMetadata {
3037
lowcoder_host: string;
3138
lowcoder_orgId: string;
@@ -135,7 +142,7 @@ class SubscriptionApi extends Api {
135142

136143
// API Functions
137144

138-
export const searchCustomer = async (subscriptionCustomer: LowcoderCustomer) => {
145+
export const searchCustomer = async (subscriptionCustomer: LowcoderSearchCustomer) => {
139146
const apiBody = {
140147
path: "webhook/secure/search-customer",
141148
data: subscriptionCustomer,
@@ -167,7 +174,29 @@ export const searchSubscriptions = async (customerId: string) => {
167174
}
168175
};
169176

170-
export const createCustomer = async (subscriptionCustomer: LowcoderCustomer) => {
177+
export const searchCustomersSubscriptions = async (Customer: LowcoderSearchCustomer) => {
178+
const apiBody = {
179+
path: "webhook/secure/search-customersubscriptions",
180+
data: Customer,
181+
method: "post",
182+
headers: lcHeaders
183+
};
184+
try {
185+
const result = await SubscriptionApi.secureRequest(apiBody);
186+
187+
if (result?.data?.data?.length > 0) {
188+
return result?.data?.data;
189+
}
190+
else if (result.data.success == "false" && result.data.reason == "customerNotFound") {
191+
return [];
192+
}
193+
} catch (error) {
194+
console.error("Error searching customer:", error);
195+
throw error;
196+
}
197+
};
198+
199+
export const createCustomer = async (subscriptionCustomer: LowcoderNewCustomer) => {
171200
const apiBody = {
172201
path: "webhook/secure/create-customer",
173202
data: subscriptionCustomer,
@@ -263,7 +292,14 @@ export const InitializeSubscription = () => {
263292
const domain = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
264293
const admin = user.orgRoleMap.get(orgID) === "admin" ? "admin" : "member";
265294

266-
const subscriptionCustomer: LowcoderCustomer = {
295+
const subscriptionSearchCustomer: LowcoderSearchCustomer = {
296+
hostname: domain,
297+
email: currentUser.email,
298+
orgId: orgID,
299+
userId: user.id,
300+
};
301+
302+
const subscriptionNewCustomer: LowcoderNewCustomer = {
267303
hostname: domain,
268304
email: currentUser.email,
269305
orgId: orgID,
@@ -277,11 +313,11 @@ export const InitializeSubscription = () => {
277313
const initializeCustomer = async () => {
278314
try {
279315
setIsCreatingCustomer(true);
280-
const existingCustomer = await searchCustomer(subscriptionCustomer);
281-
if (existingCustomer) {
316+
const existingCustomer = await searchCustomer(subscriptionSearchCustomer);
317+
if (existingCustomer != null) {
282318
setCustomer(existingCustomer);
283319
} else {
284-
const newCustomer = await createCustomer(subscriptionCustomer);
320+
const newCustomer = await createCustomer(subscriptionNewCustomer);
285321
setCustomer(newCustomer);
286322
}
287323
} catch (error) {
@@ -377,42 +413,29 @@ export const CheckSubscriptions = () => {
377413
const orgID = user.currentOrgId;
378414
const domain = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port : '');
379415

380-
const subscriptionCustomer: LowcoderCustomer = {
416+
const subscriptionSearchCustomer: LowcoderSearchCustomer = {
381417
hostname: domain,
382418
email: currentUser.email,
383419
orgId: orgID,
384420
userId: user.id,
385-
userName: user.username,
386-
type: user.orgRoleMap.get(orgID) === "admin" ? "admin" : "user",
387-
companyName: user.currentOrgId,
388421
};
389422

390423
useEffect(() => {
391424
const fetchCustomerAndSubscriptions = async () => {
392425
try {
393-
const existingCustomer = await searchCustomer(subscriptionCustomer);
394-
if (existingCustomer) {
395-
setCustomer(existingCustomer);
396-
const subs = await searchSubscriptions(existingCustomer.id);
397-
setSubscriptions(subs);
398-
setSubscriptionDataLoaded(true);
399-
} else {
400-
setCustomer(null);
401-
}
426+
const subs = await searchCustomersSubscriptions(subscriptionSearchCustomer);
427+
setSubscriptions(subs);
428+
setSubscriptionDataLoaded(true);
402429
} catch (error) {
403-
setCustomerDataError(true);
404430
setSubscriptionDataError(true);
405431
} finally {
406432
setLoading(false);
407433
}
408434
};
409-
410435
fetchCustomerAndSubscriptions();
411436
}, []);
412437

413438
return {
414-
customer,
415-
customerDataError,
416439
subscriptions,
417440
subscriptionDataLoaded,
418441
subscriptionDataError,

client/packages/lowcoder/src/constants/configConstants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface BrandingConfig {
2424
export type ConfigBaseInfo = {
2525
selfDomain: boolean;
2626
cloudHosting: boolean;
27-
workspaceMode: "SAAS" | "ENTERPRISE";
27+
workspaceMode: "SAAS" | "ENTERPRISE" | "MULTIWORSPACE" | "SINGLEWORKSPACE";
2828
warning?: string;
2929
featureFlag: FeatureFlag;
3030
branding?: BrandingConfig;

client/packages/lowcoder/src/constants/routesURL.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ export const OAUTH_PROVIDER_DETAIL = "/setting/oauth-provider/detail";
2323

2424
export const PERMISSION_SETTING_DETAIL = `${PERMISSION_SETTING}/:groupId`;
2525
export const ORGANIZATION_SETTING_DETAIL = `${ORGANIZATION_SETTING}/:orgId`;
26-
export const SUBSCRIPTION_DETAIL = `${SUBSCRIPTION_SETTING}/:subscriptionId`;
27-
export const SUBSCRIPTION_SUCCESS = `${SUBSCRIPTION_SETTING}/success/:checkoutSessionId`;
28-
export const SUBSCRIPTION_ERROR = `${SUBSCRIPTION_SETTING}/error/:checkoutSessionId`;
26+
export const SUBSCRIPTION_SUCCESS = `${SUBSCRIPTION_SETTING}/success`;
27+
export const SUBSCRIPTION_ERROR = `${SUBSCRIPTION_SETTING}/error`;
28+
export const SUBSCRIPTION_DETAIL = `${SUBSCRIPTION_SETTING}/details/:subscriptionId`;
29+
export const SUBSCRIPTION_INFO = `${SUBSCRIPTION_SETTING}/info/:productId`;
2930

3031
export const ALL_APPLICATIONS_URL = "/apps";
3132
export const ADMIN_APP_URL = "/ee/:applicationId/:viewMode";
@@ -104,4 +105,5 @@ export const buildGroupId = (groupId: string) => `${PERMISSION_SETTING}/${groupI
104105

105106
export const buildOrgId = (orgId: string) => `${ORGANIZATION_SETTING}/${orgId}`;
106107

107-
export const buildSubscriptionId = (subscriptionId: string) => `${SUBSCRIPTION_SETTING}/${subscriptionId}`;
108+
export const buildSubscriptionSettingsLink = (subscriptionId: string) => `${SUBSCRIPTION_SETTING}/details/${subscriptionId}`;
109+
export const buildSubscriptionInfoLink = (productId: string) => `${SUBSCRIPTION_SETTING}/info/${productId}`;

client/packages/lowcoder/src/pages/setting/settingHome.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
SubscriptionIcon,
1919
} from "lowcoder-design";
2020
import { useSelector } from "react-redux";
21+
import { useEffect } from "react";
2122
import { getUser } from "redux/selectors/usersSelectors";
2223
import history from "util/history";
2324
import { useParams } from "react-router-dom";
@@ -29,6 +30,7 @@ import FreeLimitTag from "pages/common/freeLimitTag";
2930
import { Helmet } from "react-helmet";
3031
import { Card } from "antd";
3132
import { Subscription } from "./subscriptions";
33+
import { CheckSubscriptions } from "@lowcoder-ee/api/subscriptionApi";
3234

3335
enum SettingPageEnum {
3436
UserGroups = "permission",
@@ -48,6 +50,14 @@ export function SettingHome() {
4850
const config = useSelector(selectSystemConfig);
4951
const selectKey = useParams<{ setting: string }>().setting || SettingPageEnum.UserGroups;
5052

53+
const subscriptions = CheckSubscriptions();
54+
55+
useEffect(() => {
56+
if (subscriptions.subscriptionDataLoaded == true) {
57+
console.log("subscriptions", subscriptions);
58+
}
59+
}, [subscriptions]);
60+
5161
const items = [
5262
{
5363
key: SettingPageEnum.Organization,
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
// index.tsx for routes
22
import { Route, Switch, useLocation } from 'react-router-dom';
3-
import { SUBSCRIPTION_SETTING, SUBSCRIPTION_DETAIL, SUBSCRIPTION_SUCCESS, SUBSCRIPTION_ERROR } from 'constants/routesURL';
3+
import { SUBSCRIPTION_SETTING, SUBSCRIPTION_DETAIL, SUBSCRIPTION_INFO, SUBSCRIPTION_SUCCESS, SUBSCRIPTION_ERROR } from 'constants/routesURL';
44
import { SubscriptionSetting } from './subscriptionSetting';
5-
import { SubscriptionSuccess } from './subscriptionSuccess';
6-
import { SubscriptionError} from './subscriptionError';
7-
import SubscriptionContent from './subscriptionContent';
5+
import SubscriptionSuccess from './subscriptionSuccess';
6+
import SubscriptionError from './subscriptionError';
7+
import SubscriptionDetail from './subscriptionDetail';
8+
import SubscriptionInfo from './subscriptionInfo';
89

910
export const Subscription = () => {
1011

11-
const location = useLocation();
12-
1312
return (
1413
<Switch>
15-
<Route path={SUBSCRIPTION_SETTING} component={SubscriptionSetting} exact />
16-
<Route path={SUBSCRIPTION_DETAIL} component={SubscriptionContent} exact />
14+
<Route path={SUBSCRIPTION_DETAIL} component={SubscriptionDetail} exact />
15+
<Route path={SUBSCRIPTION_INFO} component={SubscriptionInfo} exact />
1716
<Route path={SUBSCRIPTION_SUCCESS} component={SubscriptionSuccess} exact />
1817
<Route path={SUBSCRIPTION_ERROR} component={SubscriptionError} exact />
18+
<Route path={SUBSCRIPTION_SETTING} component={SubscriptionSetting} exact />
1919
</Switch>
2020
);
2121
};

client/packages/lowcoder/src/pages/setting/subscriptions/productCard.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styled from 'styled-components';
33
import { GreyTextColor } from 'constants/style';
44
import { Card } from 'antd';
55
import { SettingOutlined, CheckCircleOutlined, PlusSquareOutlined, LoadingOutlined, InfoCircleOutlined } from '@ant-design/icons';
6-
import { buildSubscriptionId } from "constants/routesURL";
6+
import { buildSubscriptionSettingsLink, buildSubscriptionInfoLink } from "constants/routesURL";
77
import history from "util/history";
88

99
const ProductCardContainer = styled(Card)`
@@ -55,6 +55,7 @@ interface ProductCardProps {
5555
checkoutLink: string;
5656
checkoutLinkDataLoaded?: boolean;
5757
subscriptionId: string;
58+
productId: string;
5859
}
5960

6061
export const ProductCard: React.FC<ProductCardProps> = ({
@@ -66,7 +67,8 @@ export const ProductCard: React.FC<ProductCardProps> = ({
6667
activeSubscription,
6768
checkoutLink,
6869
checkoutLinkDataLoaded,
69-
subscriptionId
70+
subscriptionId,
71+
productId,
7072
}) => {
7173

7274
const goToCheckout = () => {
@@ -76,11 +78,11 @@ export const ProductCard: React.FC<ProductCardProps> = ({
7678
};
7779

7880
const goToSubscriptionSettings = () => {
79-
history.push(buildSubscriptionId(subscriptionId));
81+
history.push(buildSubscriptionSettingsLink(subscriptionId));
8082
};
8183

8284
const goToSubscriptionInformation = () => {
83-
// history.push(buildSubscriptionId(subscriptionId));
85+
history.push(buildSubscriptionInfoLink(productId));
8486
};
8587

8688
return (

client/packages/lowcoder/src/pages/setting/subscriptions/subscriptionContent.tsx renamed to client/packages/lowcoder/src/pages/setting/subscriptions/subscriptionDetail.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ const Wrapper = styled.div`
1616
padding: 32px 24px;
1717
`;
1818

19-
export function SubscriptionContent() {
19+
export function SubscriptionDetail() {
2020
const { subscriptionId } = useParams<{ subscriptionId: string }>();
2121

22-
console.log("Rendering SubscriptionSettingContent with subscriptionId:", subscriptionId);
23-
2422
return (
2523
<Wrapper>
2624
<HeaderBack>
@@ -36,4 +34,4 @@ export function SubscriptionContent() {
3634
);
3735
}
3836

39-
export default SubscriptionContent;
37+
export default SubscriptionDetail;

client/packages/lowcoder/src/pages/setting/subscriptions/subscriptionError.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ export function SubscriptionError() {
3636
</Level1SettingPageContent>
3737
);
3838
}
39+
40+
export default SubscriptionError;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { ArrowIcon } from "lowcoder-design";
2+
import styled from "styled-components";
3+
import { trans } from "i18n";
4+
import { useParams } from "react-router-dom";
5+
import { HeaderBack } from "../permission/styledComponents";
6+
import history from "util/history";
7+
import { SUBSCRIPTION_SETTING } from "constants/routesURL";
8+
9+
const FieldWrapper = styled.div`
10+
margin-bottom: 32px;
11+
width: 408px;
12+
margin-top: 40px;
13+
`;
14+
15+
const Wrapper = styled.div`
16+
padding: 32px 24px;
17+
`;
18+
19+
export function SubscriptionInfo() {
20+
const { productId } = useParams<{ productId: string }>();
21+
22+
return (
23+
<Wrapper>
24+
<HeaderBack>
25+
<span onClick={() => history.push(SUBSCRIPTION_SETTING)}>
26+
{trans("settings.subscription")}
27+
</span>
28+
<ArrowIcon />
29+
</HeaderBack>
30+
<div>
31+
<h1>{`Subscription ID: ${productId}`}</h1>
32+
</div>
33+
</Wrapper>
34+
);
35+
}
36+
37+
export default SubscriptionInfo;

client/packages/lowcoder/src/pages/setting/subscriptions/subscriptionSetting.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ export function SubscriptionSetting() {
5757
checkoutLink={product.checkoutLink}
5858
checkoutLinkDataLoaded={product.checkoutLinkDataLoaded}
5959
subscriptionId={product.subscriptionId}
60+
productId={product.accessLink}
6061
/>
6162
))}
6263
</Flex>
6364
</SubscriptionSettingContent>
6465
) : (
6566
<div>Loading...</div>
6667
)}
67-
{isCreatingCustomer && <div><br/>Creating your customer account, please wait...</div>}
68+
{isCreatingCustomer && <div><br/>Checking your customer account, please wait...</div>}
6869
{customerDataError &&
6970
<h3>There was an error retrieving your customer data.</h3>
7071
}

0 commit comments

Comments
 (0)