44 ConfirmButton ,
55 StyledRouteLink ,
66} from "pages/userAuth/authComponents" ;
7- import React , { useContext , useEffect , useState } from "react" ;
7+ import React , { useContext , useEffect , useMemo , useState } from "react" ;
88import styled from "styled-components" ;
99import UserApi from "api/userApi" ;
1010import { useRedirectUrl } from "util/hooks" ;
@@ -19,7 +19,7 @@ import { Divider } from "antd";
1919import Flex from "antd/es/flex" ;
2020import { validateResponse } from "@lowcoder-ee/api/apiUtils" ;
2121import OrgApi from "@lowcoder-ee/api/orgApi" ;
22- import { AccountLoginWrapper } from "./formLoginAdmin" ;
22+ import FormLogin , { AccountLoginWrapper } from "./formLoginAdmin" ;
2323import { default as Button } from "antd/es/button" ;
2424import LeftOutlined from "@ant-design/icons/LeftOutlined" ;
2525import { fetchConfigAction } from "@lowcoder-ee/redux/reduxActions/configActions" ;
@@ -28,6 +28,9 @@ import history from "util/history";
2828import { getServerSettings } from "@lowcoder-ee/redux/selectors/applicationSelector" ;
2929import { fetchOrgPaginationByEmail } from "@lowcoder-ee/util/pagination/axios" ;
3030import 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" ;
3134
3235const StyledCard = styled . div < { $selected : boolean } > `
3336 display: flex;
@@ -107,18 +110,28 @@ export default function FormLoginSteps(props: FormLoginProps) {
107110 const { systemConfig, inviteInfo, fetchUserAfterAuthSuccess } = useContext ( AuthContext ) ;
108111 const invitationId = inviteInfo ?. invitationId ;
109112 const authId = systemConfig ?. form . id ;
110- const isFormLoginEnabled = systemConfig ?. form . enableLogin ;
113+ const isFormLoginEnabled = systemConfig ?. form . enableLogin ; // check from configs
111114 const [ orgLoading , setOrgLoading ] = useState ( false ) ;
112115 const [ orgList , setOrgList ] = useState < OrgItem [ ] > ( [ ] ) ;
113116 const [ currentStep , setCurrentStep ] = useState < CurrentStepEnum > ( CurrentStepEnum . EMAIL ) ;
114117 const [ organizationId , setOrganizationId ] = useState < string | undefined > ( props . organizationId ) ;
115118 const [ skipWorkspaceStep , setSkipWorkspaceStep ] = useState < boolean > ( false ) ;
116119 const [ signupEnabled , setSignupEnabled ] = useState < boolean > ( true ) ;
120+ const [ signinEnabled , setSigninEnabled ] = useState < boolean > ( true ) ; // check from server settings
117121 const serverSettings = useSelector ( getServerSettings ) ;
122+ const isFetchingConfig = useSelector ( getSystemConfigFetching ) ;
118123 const [ elements , setElements ] = useState < ElementsState > ( { elements : [ ] , total : 0 } ) ;
119124 const [ currentPage , setCurrentPage ] = useState ( 1 ) ;
120125 const [ pageSize , setPageSize ] = useState ( 10 ) ;
121126
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+
122135 useEffect ( ( ) => {
123136 if ( account )
124137 fetchOrgPaginationByEmail ( {
@@ -133,11 +146,13 @@ export default function FormLoginSteps(props: FormLoginProps) {
133146 } , [ pageSize , currentPage ] )
134147
135148 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+
140154 setSignupEnabled ( LOWCODER_EMAIL_SIGNUP_ENABLED === 'true' ) ;
155+ setSigninEnabled ( LOWCODER_EMAIL_AUTH_ENABLED === 'true' ) ;
141156 } , [ serverSettings ] ) ;
142157
143158 const { onSubmit, loading } = useAuthSubmit (
@@ -167,8 +182,9 @@ export default function FormLoginSteps(props: FormLoginProps) {
167182 }
168183
169184 setOrgLoading ( true ) ;
185+ // for enterprise mode, we will not ask for email in first step
170186 fetchOrgPaginationByEmail ( {
171- email : account ,
187+ email : isEnterpriseMode ? ' ' : account ,
172188 pageNum : currentPage ,
173189 pageSize : pageSize
174190 } )
@@ -177,16 +193,13 @@ export default function FormLoginSteps(props: FormLoginProps) {
177193 setElements ( { elements : resp . data || [ ] , total : resp . total || 1 } )
178194 setOrgList ( resp . data ) ;
179195 if ( ! resp . data . length ) {
180- // history.push(
181- // AUTH_REGISTER_URL,
182- // {...location.state || {}, email: account },
183- // )
184- // return;
185196 throw new Error ( trans ( "userAuth.userNotFound" ) ) ;
186197 }
187198 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 ) ) ;
190203 setCurrentStep ( CurrentStepEnum . AUTH_PROVIDERS ) ;
191204 return ;
192205 }
@@ -203,6 +216,39 @@ export default function FormLoginSteps(props: FormLoginProps) {
203216 } ) ;
204217 }
205218
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+
206252 if ( currentStep === CurrentStepEnum . EMAIL ) {
207253 return (
208254 < >
@@ -281,10 +327,10 @@ export default function FormLoginSteps(props: FormLoginProps) {
281327 } } />
282328 < StepHeader
283329 title = {
284- isFormLoginEnabled ? trans ( "userAuth.enterPassword" ) : trans ( "userAuth.selectAuthProvider" )
330+ isEmailLoginEnabled ? trans ( "userAuth.enterPassword" ) : trans ( "userAuth.selectAuthProvider" )
285331 }
286332 />
287- { isFormLoginEnabled && (
333+ { isEmailLoginEnabled && (
288334 < >
289335 < PasswordInput
290336 className = "form-input password-input"
@@ -316,7 +362,7 @@ export default function FormLoginSteps(props: FormLoginProps) {
316362 />
317363 ) }
318364 </ AccountLoginWrapper >
319- { isFormLoginEnabled && signupEnabled && (
365+ { isEmailLoginEnabled && signupEnabled && (
320366 < >
321367 < Divider />
322368 < AuthBottomView >
0 commit comments