4
4
ConfirmButton ,
5
5
StyledRouteLink ,
6
6
} from "pages/userAuth/authComponents" ;
7
- import React , { useContext , useEffect , useState } from "react" ;
7
+ import React , { useContext , useEffect , useMemo , useState } from "react" ;
8
8
import styled from "styled-components" ;
9
9
import UserApi from "api/userApi" ;
10
10
import { useRedirectUrl } from "util/hooks" ;
@@ -19,7 +19,7 @@ import { Divider } from "antd";
19
19
import Flex from "antd/es/flex" ;
20
20
import { validateResponse } from "@lowcoder-ee/api/apiUtils" ;
21
21
import OrgApi from "@lowcoder-ee/api/orgApi" ;
22
- import { AccountLoginWrapper } from "./formLoginAdmin" ;
22
+ import FormLogin , { AccountLoginWrapper } from "./formLoginAdmin" ;
23
23
import { default as Button } from "antd/es/button" ;
24
24
import LeftOutlined from "@ant-design/icons/LeftOutlined" ;
25
25
import { fetchConfigAction } from "@lowcoder-ee/redux/reduxActions/configActions" ;
@@ -28,6 +28,9 @@ import history from "util/history";
28
28
import { getServerSettings } from "@lowcoder-ee/redux/selectors/applicationSelector" ;
29
29
import { fetchOrgPaginationByEmail } from "@lowcoder-ee/util/pagination/axios" ;
30
30
import PaginationComp from "@lowcoder-ee/util/pagination/Pagination" ;
31
+ import { getSystemConfigFetching } from "@lowcoder-ee/redux/selectors/configSelectors" ;
32
+ import Spin from "antd/es/spin" ;
33
+ import LoadingOutlined from "@ant-design/icons/LoadingOutlined" ;
31
34
32
35
const StyledCard = styled . div < { $selected : boolean } > `
33
36
display: flex;
@@ -107,18 +110,28 @@ export default function FormLoginSteps(props: FormLoginProps) {
107
110
const { systemConfig, inviteInfo, fetchUserAfterAuthSuccess } = useContext ( AuthContext ) ;
108
111
const invitationId = inviteInfo ?. invitationId ;
109
112
const authId = systemConfig ?. form . id ;
110
- const isFormLoginEnabled = systemConfig ?. form . enableLogin ;
113
+ const isFormLoginEnabled = systemConfig ?. form . enableLogin ; // check from configs
111
114
const [ orgLoading , setOrgLoading ] = useState ( false ) ;
112
115
const [ orgList , setOrgList ] = useState < OrgItem [ ] > ( [ ] ) ;
113
116
const [ currentStep , setCurrentStep ] = useState < CurrentStepEnum > ( CurrentStepEnum . EMAIL ) ;
114
117
const [ organizationId , setOrganizationId ] = useState < string | undefined > ( props . organizationId ) ;
115
118
const [ skipWorkspaceStep , setSkipWorkspaceStep ] = useState < boolean > ( false ) ;
116
119
const [ signupEnabled , setSignupEnabled ] = useState < boolean > ( true ) ;
120
+ const [ signinEnabled , setSigninEnabled ] = useState < boolean > ( true ) ; // check from server settings
117
121
const serverSettings = useSelector ( getServerSettings ) ;
122
+ const isFetchingConfig = useSelector ( getSystemConfigFetching ) ;
118
123
const [ elements , setElements ] = useState < ElementsState > ( { elements : [ ] , total : 0 } ) ;
119
124
const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
120
125
const [ pageSize , setPageSize ] = useState ( 10 ) ;
121
126
127
+ const isEmailLoginEnabled = useMemo ( ( ) => {
128
+ return isFormLoginEnabled && signinEnabled ;
129
+ } , [ isFormLoginEnabled , signinEnabled ] ) ;
130
+
131
+ const isEnterpriseMode = useMemo ( ( ) => {
132
+ return serverSettings ?. LOWCODER_WORKSPACE_MODE === "ENTERPRISE" || serverSettings ?. LOWCODER_WORKSPACE_MODE === "SINGLEWORKSPACE" ;
133
+ } , [ serverSettings ] ) ;
134
+
122
135
useEffect ( ( ) => {
123
136
if ( account )
124
137
fetchOrgPaginationByEmail ( {
@@ -133,11 +146,13 @@ export default function FormLoginSteps(props: FormLoginProps) {
133
146
} , [ pageSize , currentPage ] )
134
147
135
148
useEffect ( ( ) => {
136
- const { LOWCODER_EMAIL_SIGNUP_ENABLED } = serverSettings ;
137
- if ( ! LOWCODER_EMAIL_SIGNUP_ENABLED ) {
138
- return setSignupEnabled ( true ) ;
139
- }
149
+ const {
150
+ LOWCODER_EMAIL_SIGNUP_ENABLED ,
151
+ LOWCODER_EMAIL_AUTH_ENABLED ,
152
+ } = serverSettings ;
153
+
140
154
setSignupEnabled ( LOWCODER_EMAIL_SIGNUP_ENABLED === 'true' ) ;
155
+ setSigninEnabled ( LOWCODER_EMAIL_AUTH_ENABLED === 'true' ) ;
141
156
} , [ serverSettings ] ) ;
142
157
143
158
const { onSubmit, loading } = useAuthSubmit (
@@ -167,8 +182,9 @@ export default function FormLoginSteps(props: FormLoginProps) {
167
182
}
168
183
169
184
setOrgLoading ( true ) ;
185
+ // for enterprise mode, we will not ask for email in first step
170
186
fetchOrgPaginationByEmail ( {
171
- email : account ,
187
+ email : isEnterpriseMode ? ' ' : account ,
172
188
pageNum : currentPage ,
173
189
pageSize : pageSize
174
190
} )
@@ -177,16 +193,13 @@ export default function FormLoginSteps(props: FormLoginProps) {
177
193
setElements ( { elements : resp . data || [ ] , total : resp . total || 1 } )
178
194
setOrgList ( resp . data ) ;
179
195
if ( ! resp . data . length ) {
180
- // history.push(
181
- // AUTH_REGISTER_URL,
182
- // {...location.state || {}, email: account },
183
- // )
184
- // return;
185
196
throw new Error ( trans ( "userAuth.userNotFound" ) ) ;
186
197
}
187
198
if ( resp . data . length === 1 ) {
188
- setOrganizationId ( resp . data [ 0 ] . orgId ) ;
189
- dispatch ( fetchConfigAction ( resp . data [ 0 ] . orgId ) ) ;
199
+ // in Enterprise mode, we will get org data in different format
200
+ const selectedOrgId = isEnterpriseMode ? resp . data [ 0 ] . id : resp . data [ 0 ] . orgId ;
201
+ setOrganizationId ( selectedOrgId ) ;
202
+ dispatch ( fetchConfigAction ( selectedOrgId ) ) ;
190
203
setCurrentStep ( CurrentStepEnum . AUTH_PROVIDERS ) ;
191
204
return ;
192
205
}
@@ -203,6 +216,39 @@ export default function FormLoginSteps(props: FormLoginProps) {
203
216
} ) ;
204
217
}
205
218
219
+ useEffect ( ( ) => {
220
+ if ( isEnterpriseMode ) {
221
+ // dispatch(fetchConfigAction());
222
+ fetchOrgsByEmail ( ) ;
223
+ }
224
+ } , [ isEnterpriseMode ] ) ;
225
+
226
+ if ( isEnterpriseMode ) {
227
+ return (
228
+ < Spin indicator = { < LoadingOutlined style = { { fontSize : 30 } } /> } spinning = { isFetchingConfig } >
229
+ { isEmailLoginEnabled && < FormLogin /> }
230
+ < ThirdPartyAuth
231
+ invitationId = { invitationId }
232
+ invitedOrganizationId = { organizationId }
233
+ authGoal = "login"
234
+ />
235
+ { signupEnabled && (
236
+ < >
237
+ < Divider />
238
+ < AuthBottomView >
239
+ < StyledRouteLink to = { {
240
+ pathname : AUTH_REGISTER_URL ,
241
+ state : { ...location . state || { } , email : account }
242
+ } } >
243
+ { trans ( "userAuth.register" ) }
244
+ </ StyledRouteLink >
245
+ </ AuthBottomView >
246
+ </ >
247
+ ) }
248
+ </ Spin >
249
+ ) ;
250
+ }
251
+
206
252
if ( currentStep === CurrentStepEnum . EMAIL ) {
207
253
return (
208
254
< >
@@ -281,10 +327,10 @@ export default function FormLoginSteps(props: FormLoginProps) {
281
327
} } />
282
328
< StepHeader
283
329
title = {
284
- isFormLoginEnabled ? trans ( "userAuth.enterPassword" ) : trans ( "userAuth.selectAuthProvider" )
330
+ isEmailLoginEnabled ? trans ( "userAuth.enterPassword" ) : trans ( "userAuth.selectAuthProvider" )
285
331
}
286
332
/>
287
- { isFormLoginEnabled && (
333
+ { isEmailLoginEnabled && (
288
334
< >
289
335
< PasswordInput
290
336
className = "form-input password-input"
@@ -316,7 +362,7 @@ export default function FormLoginSteps(props: FormLoginProps) {
316
362
/>
317
363
) }
318
364
</ AccountLoginWrapper >
319
- { isFormLoginEnabled && signupEnabled && (
365
+ { isEmailLoginEnabled && signupEnabled && (
320
366
< >
321
367
< Divider />
322
368
< AuthBottomView >
0 commit comments