Skip to content

Commit fc08749

Browse files
author
FalkWolsky
committed
Subscription System Roundup
1 parent 50b8eb9 commit fc08749

File tree

8 files changed

+218
-70
lines changed

8 files changed

+218
-70
lines changed

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ export const en = {
23002300
"billingReason.subscription_threshold": "Subscription Threshold",
23012301
"billingReason.subscription_update": "Subscription Update",
23022302
"backToSubscriptions": "Back to Subscriptions",
2303-
"manageSubscription" : "Manage Your Subscription",
2303+
"manageSubscription" : "Manage Your Subscriptions",
23042304
"subscriptionHelp" : "Subscription Help",
23052305
"subscriptionHelpDescription" : "If you have any questions, please contact us. We are happy to help you. service@lowcoder.cloud",
23062306
"success" : "Payment & Subscription Success",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export default function ApplicationHome() {
177177
dispatch(fetchHomeData({}));
178178
}, [user.currentOrgId]);
179179

180-
const supportSubscription = subscriptions.some(sub => sub.product === SubscriptionProducts.SUPPORT);
180+
const supportSubscription = subscriptions.some(sub => sub.product === SubscriptionProducts.SUPPORT && sub.status === 'active');
181181

182182
useEffect(() => {
183183
if (!org) {

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

Lines changed: 163 additions & 27 deletions
Large diffs are not rendered by default.

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import { useEffect } from "react";
12
import { useLocation } from "react-router-dom";
23
import styled from "styled-components";
34
import { GreyTextColor } from "constants/style";
45
import { trans } from "i18n";
56
import { HeaderBack } from "../permission/styledComponents";
67
import history from "util/history";
78
import { SUBSCRIPTION_SETTING } from "constants/routesURL";
8-
import { Flex } from 'antd';
9-
import { ProductCard } from "./productCard";
9+
1010

1111
const SubscriptionSuccessContent = styled.div`
1212
max-width: 840px;
@@ -41,6 +41,10 @@ const useQuery = () => {
4141
export function SubscriptionCancel() {
4242
const query = useQuery();
4343
const session_id = query.get("session_id");
44+
45+
useEffect(() => {
46+
window.location.replace(SUBSCRIPTION_SETTING);
47+
}, []);
4448

4549
return (
4650
<Wrapper>
@@ -50,7 +54,7 @@ export function SubscriptionCancel() {
5054
</span>
5155
</HeaderBack>
5256
<div>
53-
<h1>{`Canceled | Session ID: ${session_id}`}</h1>
57+
<h1>Canceled</h1>
5458
</div>
5559
</Wrapper>
5660
);

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { useParams } from "react-router-dom";
66
import { HeaderBack } from "../permission/styledComponents";
77
import history from "util/history";
88
import { SUBSCRIPTION_SETTING } from "constants/routesURL";
9-
import { getProduct, getSubscriptionDetails, getInvoices, getCustomerPortalSession } from "api/subscriptionApi";
10-
import { Skeleton, Timeline, Card, Descriptions, Table, Typography, Button, message } from "antd";
9+
import { getProduct, getSubscriptionDetails, getInvoices } from "api/subscriptionApi";
10+
import { Skeleton, Timeline, Card, Descriptions, Table, Typography, Button } from "antd";
1111

1212
const { Text } = Typography;
1313

@@ -78,29 +78,6 @@ export function SubscriptionDetail() {
7878
const usageRecords = subscription ? subscription[1]?.data || [] : [];
7979

8080
const statusColor = subscriptionDetails?.status === "active" ? "green" : "red";
81-
const customerId = subscriptionDetails?.customer; // Get the customer ID from subscription details
82-
83-
// Handle Customer Portal Session Redirect
84-
const handleCustomerPortalRedirect = async () => {
85-
try {
86-
if (!customerId) {
87-
message.error("Customer ID not available for the subscription.");
88-
return;
89-
}
90-
91-
// Get the Customer Portal session URL
92-
const portalSession = await getCustomerPortalSession(customerId);
93-
if (portalSession && portalSession.url) {
94-
// Redirect to the Stripe Customer Portal
95-
window.location.href = portalSession.url;
96-
} else {
97-
message.error("Failed to generate customer portal session link.");
98-
}
99-
} catch (error) {
100-
console.error("Error redirecting to customer portal:", error);
101-
message.error("An error occurred while redirecting to the customer portal.");
102-
}
103-
};
10481

10582
return (
10683
<Wrapper>
@@ -215,14 +192,6 @@ export function SubscriptionDetail() {
215192
</TimelineWrapper>
216193
</CardWrapper>
217194

218-
{/* Manage Subscription Button */}
219-
<CardWrapper title={trans("subscription.manageSubscription")}>
220-
<ManageSubscriptionButton type="primary" onClick={handleCustomerPortalRedirect}>
221-
{trans("subscription.manageSubscription")}
222-
</ManageSubscriptionButton>
223-
</CardWrapper>
224-
225-
{/* Manage Subscription Button */}
226195
<CardWrapper title={trans("subscription.subscriptionHelp")}>
227196
<span>{trans("subscription.subscriptionHelpDescription")}</span>
228197
</CardWrapper>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Card, Tag, List } from 'antd';
1111
import { CheckCircleOutlined } from '@ant-design/icons';
1212
import { Level1SettingPageContent } from "../styled";
1313
import { TacoMarkDown } from "lowcoder-design";
14-
import ProductDescriptions, {Translations, ProductDescription} from "./ProductDescriptions";
14+
import ProductDescriptions, {Translations} from "./ProductDescriptions";
1515

1616
const { Meta } = Card;
1717

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import styled from "styled-components";
22
import { GreyTextColor } from "constants/style";
33
import { trans } from "i18n";
44
import { Level1SettingPageContent, Level1SettingPageTitle } from "../styled";
5-
import { Flex } from 'antd';
5+
import { Flex, Card, Button, message } from 'antd';
66
import { ProductCard } from "./productCard";
77
import { InitializeSubscription } from "@lowcoder-ee/api/subscriptionApi";
8-
import { getProducts } from '@lowcoder-ee/api/subscriptionApi';
8+
import { getProducts, getCustomerPortalSession } from '@lowcoder-ee/api/subscriptionApi';
99
import { useState, useEffect } from 'react';
1010

1111
const SubscriptionSettingContent = styled.div`
@@ -27,6 +27,15 @@ const SubscriptionSettingContent = styled.div`
2727
}
2828
`;
2929

30+
const CardWrapper = styled(Card)`
31+
width: 100%;
32+
margin-bottom: 24px;
33+
`;
34+
35+
const ManageSubscriptionButton = styled(Button)`
36+
margin-top: 24px;
37+
`;
38+
3039

3140
export function SubscriptionSetting() {
3241
const {
@@ -42,6 +51,30 @@ export function SubscriptionSetting() {
4251
const [subscriptionProducts, setSubscriptionProducts] = useState<any>(null);
4352
const [loading, setLoading] = useState<boolean>(true);
4453
const [error, setError] = useState<string | null>(null);
54+
const customerId = customer?.id; // Get the customer ID from subscription details
55+
56+
57+
// Handle Customer Portal Session Redirect
58+
const handleCustomerPortalRedirect = async () => {
59+
try {
60+
if (!customerId) {
61+
message.error("Customer ID not available for the subscription.");
62+
return;
63+
}
64+
65+
// Get the Customer Portal session URL
66+
const portalSession = await getCustomerPortalSession(customerId);
67+
if (portalSession && portalSession.url) {
68+
// Redirect to the Stripe Customer Portal
69+
window.open(portalSession.url, '_blank', 'noopener,noreferrer');
70+
} else {
71+
message.error("Failed to generate customer portal session link.");
72+
}
73+
} catch (error) {
74+
console.error("Error redirecting to customer portal:", error);
75+
message.error("An error occurred while redirecting to the customer portal.");
76+
}
77+
};
4578

4679
useEffect(() => {
4780
const fetchProducts = async () => {
@@ -68,7 +101,7 @@ export function SubscriptionSetting() {
68101
{customer != null ? (
69102
<SubscriptionSettingContent>
70103
{customer && <h3>Your Customer Number: {customer?.id.substring(4)} {admin && "| you are Subscriptions-Admin of this Workspace"}</h3>}
71-
<Flex wrap='wrap' gap="large" style={{marginTop: "40px"}}>
104+
<Flex wrap='wrap' gap="large" style={{marginTop: "40px", width : "100%"}}>
72105
{products
73106
.filter((product) => {
74107
if (product.type === "org") {
@@ -96,6 +129,12 @@ export function SubscriptionSetting() {
96129
);
97130
} )}
98131
</Flex>
132+
{/* Manage Subscription Button */}
133+
<CardWrapper title={trans("subscription.manageSubscription")}>
134+
<ManageSubscriptionButton type="primary" onClick={handleCustomerPortalRedirect}>
135+
{trans("subscription.manageSubscription")}
136+
</ManageSubscriptionButton>
137+
</CardWrapper>
99138
</SubscriptionSettingContent>
100139
) : (
101140
<div>Loading...</div>

client/packages/lowcoder/src/pages/support/supportOverview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export function SupportOverview() {
337337
}>
338338
<Avatar src={assignee.avatar} alt={assignee.email} />
339339
</Tooltip>
340-
<StatusDot active={assignee.active} />
340+
<StatusDot active={assignee.active.toString()} />
341341
</SubColumnCell>
342342
),
343343
},

0 commit comments

Comments
 (0)