1
1
import { getUser } from "redux/selectors/usersSelectors" ;
2
+ import React , { useEffect } from 'react' ;
2
3
import { useSelector } from "react-redux" ;
3
4
import styled from "styled-components" ;
4
5
import { GreyTextColor } from "constants/style" ;
@@ -29,6 +30,11 @@ const SubscriptionSettingContent = styled.div`
29
30
30
31
` ;
31
32
33
+ const lcHeaders = {
34
+ "Lowcoder-Token" : "96a99c7b-3758-4c48-b4b1-a8cbf59e7d6c" ,
35
+ "Content-Type" : "application/json"
36
+ } ;
37
+
32
38
interface Pricing {
33
39
type : string ;
34
40
amount : string ;
@@ -60,36 +66,51 @@ export function SubscriptionSetting() {
60
66
userName : user . username ,
61
67
type : "org" ,
62
68
companyName : "Example Company" ,
63
- address : {
69
+ /* address: {
64
70
line1: "123 Example Street",
65
71
line2: "Suite 456",
66
72
city: "Malaga",
67
73
state: "Andalusia",
68
74
country: "Spain",
69
75
postalCode: "12345"
70
- }
76
+ } */
71
77
} ;
72
78
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 ) ;
80
93
}
81
94
}
82
95
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
+ }
87
103
try {
88
- const result = await SubscriptionApi . createCustomer ( apiBody ) ;
104
+ const result = await SubscriptionApi . secureRequest ( apiBody ) ;
89
105
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
+ }
91
112
}
92
- } catch ( error ) {
113
+ } catch ( error ) {
93
114
console . error ( error ) ;
94
115
}
95
116
}
@@ -122,13 +143,18 @@ export function SubscriptionSetting() {
122
143
}
123
144
] ;
124
145
146
+ useEffect ( ( ) => {
147
+ // Call searchCustomer as soon as the component mounts
148
+ searchCustomer ( subscriptionCustomer ) ;
149
+ } , [ ] ) ;
150
+
125
151
return (
126
152
< Level1SettingPageContent >
127
153
< Level1SettingPageTitle >
128
154
{ trans ( "settings.subscription" ) }
129
155
</ Level1SettingPageTitle >
130
156
< SubscriptionSettingContent >
131
- < a onClick = { createCustomer } > Create Customer</ a >
157
+ < a onClick = { ( event ) => createCustomer ( subscriptionCustomer ) } > Create Customer</ a >
132
158
< Flex wrap = 'wrap' gap = "large" >
133
159
{ products . map ( ( product , index ) => (
134
160
< ProductCard
@@ -146,4 +172,5 @@ export function SubscriptionSetting() {
146
172
</ SubscriptionSettingContent >
147
173
</ Level1SettingPageContent >
148
174
) ;
149
- }
175
+ }
176
+
0 commit comments