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,13 +146,22 @@ 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
158
+ const afterLoginSuccess = ( ) => {
159
+ if ( props . organizationId ) {
160
+ localStorage . setItem ( "lowcoder_login_orgId" , props . organizationId ) ;
161
+ }
162
+ fetchUserAfterAuthSuccess ?.( ) ;
163
+ }
164
+
143
165
const { onSubmit, loading } = useAuthSubmit (
144
166
( ) =>
145
167
UserApi . formLogin ( {
@@ -153,7 +175,7 @@ export default function FormLoginSteps(props: FormLoginProps) {
153
175
} ) ,
154
176
false ,
155
177
redirectUrl ,
156
- fetchUserAfterAuthSuccess ,
178
+ afterLoginSuccess ,
157
179
) ;
158
180
159
181
const fetchOrgsByEmail = ( ) => {
@@ -167,8 +189,9 @@ export default function FormLoginSteps(props: FormLoginProps) {
167
189
}
168
190
169
191
setOrgLoading ( true ) ;
192
+ // for enterprise mode, we will not ask for email in first step
170
193
fetchOrgPaginationByEmail ( {
171
- email : account ,
194
+ email : isEnterpriseMode ? ' ' : account ,
172
195
pageNum : currentPage ,
173
196
pageSize : pageSize
174
197
} )
@@ -177,15 +200,13 @@ export default function FormLoginSteps(props: FormLoginProps) {
177
200
setElements ( { elements : resp . data || [ ] , total : resp . total || 1 } )
178
201
setOrgList ( resp . data ) ;
179
202
if ( ! resp . data . length ) {
180
- history . push (
181
- AUTH_REGISTER_URL ,
182
- { ...location . state || { } , email : account } ,
183
- )
184
- return ;
203
+ throw new Error ( trans ( "userAuth.userNotFound" ) ) ;
185
204
}
186
205
if ( resp . data . length === 1 ) {
187
- setOrganizationId ( resp . data [ 0 ] . orgId ) ;
188
- dispatch ( fetchConfigAction ( resp . data [ 0 ] . orgId ) ) ;
206
+ // in Enterprise mode, we will get org data in different format
207
+ const selectedOrgId = isEnterpriseMode ? resp . data [ 0 ] . id : resp . data [ 0 ] . orgId ;
208
+ setOrganizationId ( selectedOrgId ) ;
209
+ dispatch ( fetchConfigAction ( selectedOrgId ) ) ;
189
210
setCurrentStep ( CurrentStepEnum . AUTH_PROVIDERS ) ;
190
211
return ;
191
212
}
@@ -202,6 +223,39 @@ export default function FormLoginSteps(props: FormLoginProps) {
202
223
} ) ;
203
224
}
204
225
226
+ useEffect ( ( ) => {
227
+ if ( isEnterpriseMode ) {
228
+ // dispatch(fetchConfigAction());
229
+ fetchOrgsByEmail ( ) ;
230
+ }
231
+ } , [ isEnterpriseMode ] ) ;
232
+
233
+ if ( isEnterpriseMode ) {
234
+ return (
235
+ < Spin indicator = { < LoadingOutlined style = { { fontSize : 30 } } /> } spinning = { isFetchingConfig } >
236
+ { isEmailLoginEnabled && < FormLogin /> }
237
+ < ThirdPartyAuth
238
+ invitationId = { invitationId }
239
+ invitedOrganizationId = { organizationId }
240
+ authGoal = "login"
241
+ />
242
+ { signupEnabled && (
243
+ < >
244
+ < Divider />
245
+ < AuthBottomView >
246
+ < StyledRouteLink to = { {
247
+ pathname : AUTH_REGISTER_URL ,
248
+ state : { ...location . state || { } , email : account }
249
+ } } >
250
+ { trans ( "userAuth.register" ) }
251
+ </ StyledRouteLink >
252
+ </ AuthBottomView >
253
+ </ >
254
+ ) }
255
+ </ Spin >
256
+ ) ;
257
+ }
258
+
205
259
if ( currentStep === CurrentStepEnum . EMAIL ) {
206
260
return (
207
261
< >
@@ -227,8 +281,8 @@ export default function FormLoginSteps(props: FormLoginProps) {
227
281
< Divider />
228
282
< AuthBottomView >
229
283
< StyledRouteLink to = { {
230
- pathname : AUTH_REGISTER_URL ,
231
- state : location . state
284
+ pathname : props . organizationId ? `/org/ ${ props . organizationId } /auth/register` : AUTH_REGISTER_URL ,
285
+ state : { ... location . state || { } , email : account }
232
286
} } >
233
287
{ trans ( "userAuth.register" ) }
234
288
</ StyledRouteLink >
@@ -280,10 +334,10 @@ export default function FormLoginSteps(props: FormLoginProps) {
280
334
} } />
281
335
< StepHeader
282
336
title = {
283
- isFormLoginEnabled ? trans ( "userAuth.enterPassword" ) : trans ( "userAuth.selectAuthProvider" )
337
+ isEmailLoginEnabled ? trans ( "userAuth.enterPassword" ) : trans ( "userAuth.selectAuthProvider" )
284
338
}
285
339
/>
286
- { isFormLoginEnabled && (
340
+ { isEmailLoginEnabled && (
287
341
< >
288
342
< PasswordInput
289
343
className = "form-input password-input"
@@ -315,7 +369,7 @@ export default function FormLoginSteps(props: FormLoginProps) {
315
369
/>
316
370
) }
317
371
</ AccountLoginWrapper >
318
- { isFormLoginEnabled && signupEnabled && (
372
+ { isEmailLoginEnabled && signupEnabled && (
319
373
< >
320
374
< Divider />
321
375
< AuthBottomView >
0 commit comments