Skip to content

Commit d4a2a2c

Browse files
author
FalkWolsky
committed
Search & Create Customer
1 parent b1f1ede commit d4a2a2c

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ export interface Customer {
1818
userName: string;
1919
type: string;
2020
companyName: string;
21-
address: CustomerAddress;
21+
address?: CustomerAddress;
2222
}
2323

2424
export type ResponseType = {
2525
response: any;
2626
};
2727

28-
const apiUrl = "http://localhost:8080/api/flow";
29-
const authHeader = "96a99c7b-3758-4c48-b4b1-a8cbf59e7d6c";
30-
3128
const currentPage = 1;
3229
const currentQuery = '';
3330
const currentData = [];
@@ -41,11 +38,10 @@ const getAxiosInstance = (clientSecret?: string) => {
4138

4239
const headers: Record<string, string> = {
4340
"Content-Type": "application/json",
44-
// "Lowcoder-Token": authHeader,
4541
}
4642

4743
const apiRequestConfig: AxiosRequestConfig = {
48-
baseURL: `${apiUrl}`,
44+
baseURL: "http://localhost:8080/api/flow",
4945
headers,
5046
};
5147

@@ -54,10 +50,8 @@ const getAxiosInstance = (clientSecret?: string) => {
5450
}
5551

5652
class SubscriptionApi extends Api {
57-
58-
static async createCustomer(body: any): Promise<any> {
59-
console.log("createCustomerCall", body);
6053

54+
static async secureRequest(body: any): Promise<any> {
6155
let response;
6256
try {
6357
response = await getAxiosInstance().request({
@@ -66,12 +60,12 @@ class SubscriptionApi extends Api {
6660
data: body,
6761
});
6862
} catch (error) {
69-
console.error("Error creating customer:", error);
70-
throw error;
63+
console.error("Error at Secure Flow Request:", error);
64+
// throw error;
7165
}
7266
return response;
7367
}
7468

7569
}
7670

77-
export default SubscriptionApi;
71+
export default SubscriptionApi;

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

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getUser } from "redux/selectors/usersSelectors";
2+
import React, { useEffect } from 'react';
23
import { useSelector } from "react-redux";
34
import styled from "styled-components";
45
import { GreyTextColor } from "constants/style";
@@ -29,6 +30,11 @@ const SubscriptionSettingContent = styled.div`
2930
3031
`;
3132

33+
const lcHeaders = {
34+
"Lowcoder-Token": "96a99c7b-3758-4c48-b4b1-a8cbf59e7d6c",
35+
"Content-Type": "application/json"
36+
};
37+
3238
interface Pricing {
3339
type: string;
3440
amount: string;
@@ -60,36 +66,51 @@ export function SubscriptionSetting() {
6066
userName: user.username,
6167
type: "org",
6268
companyName: "Example Company",
63-
address: {
69+
/* address: {
6470
line1: "123 Example Street",
6571
line2: "Suite 456",
6672
city: "Malaga",
6773
state: "Andalusia",
6874
country: "Spain",
6975
postalCode: "12345"
70-
}
76+
} */
7177
};
7278

73-
const apiBody = {
74-
path: "webhook/echo",
75-
data: subscriptionCustomer,
76-
method: "post",
77-
headers: {
78-
"Lowcoder-Token": "96a99c7b-3758-4c48-b4b1-a8cbf59e7d6c",
79-
"Content-Type": "application/json"
79+
const createCustomer = async (subscriptionCustomer : Customer) => {
80+
const apiBody = {
81+
path: "webhook/secure/create-customer",
82+
data: subscriptionCustomer,
83+
method: "post",
84+
headers: lcHeaders
85+
}
86+
try {
87+
const result = await SubscriptionApi.secureRequest(apiBody);
88+
if (result) {
89+
console.log("createCustomer", result);
90+
}
91+
} catch (error) {
92+
console.error(error);
8093
}
8194
}
8295

83-
const createCustomer = async () => {
84-
85-
console.log("createCustomerTry", subscriptionCustomer);
86-
96+
const searchCustomer = async (subscriptionCustomer : Customer) => {
97+
const apiBody = {
98+
path: "webhook/secure/search-customer",
99+
data: subscriptionCustomer,
100+
method: "post",
101+
headers: lcHeaders
102+
}
87103
try {
88-
const result = await SubscriptionApi.createCustomer(apiBody);
104+
const result = await SubscriptionApi.secureRequest(apiBody);
89105
if (result) {
90-
console.log("createCustomer", result);
106+
if (result.data.data.length === 0) {
107+
console.log("searchCustomer", "Zero results");
108+
}
109+
else {
110+
console.log("searchCustomer", result.data.data);
111+
}
91112
}
92-
} catch(error) {
113+
} catch (error) {
93114
console.error(error);
94115
}
95116
}
@@ -122,13 +143,18 @@ export function SubscriptionSetting() {
122143
}
123144
];
124145

146+
useEffect(() => {
147+
// Call searchCustomer as soon as the component mounts
148+
searchCustomer(subscriptionCustomer);
149+
}, []);
150+
125151
return (
126152
<Level1SettingPageContent>
127153
<Level1SettingPageTitle>
128154
{trans("settings.subscription")}
129155
</Level1SettingPageTitle>
130156
<SubscriptionSettingContent>
131-
<a onClick={createCustomer}>Create Customer</a>
157+
<a onClick={(event) => createCustomer(subscriptionCustomer)}>Create Customer</a>
132158
<Flex wrap='wrap' gap="large">
133159
{products.map((product, index) => (
134160
<ProductCard
@@ -146,4 +172,5 @@ export function SubscriptionSetting() {
146172
</SubscriptionSettingContent>
147173
</Level1SettingPageContent>
148174
);
149-
}
175+
}
176+

0 commit comments

Comments
 (0)