@@ -26,8 +26,10 @@ import { validateResponse } from "@lowcoder-ee/api/apiUtils";
26
26
import history from "util/history" ;
27
27
import LoadingOutlined from "@ant-design/icons/LoadingOutlined" ;
28
28
import Spin from "antd/es/spin" ;
29
- import { useSelector } from "react-redux" ;
29
+ import { useDispatch , useSelector } from "react-redux" ;
30
30
import { getServerSettings } from "@lowcoder-ee/redux/selectors/applicationSelector" ;
31
+ import { fetchConfigAction } from "@lowcoder-ee/redux/reduxActions/configActions" ;
32
+ import { fetchOrgPaginationByEmail } from "@lowcoder-ee/util/pagination/axios" ;
31
33
32
34
const StyledFormInput = styled ( FormInput ) `
33
35
margin-bottom: 16px;
@@ -45,6 +47,7 @@ const RegisterContent = styled(FormWrapperMobile)`
45
47
46
48
function UserRegister ( ) {
47
49
const location = useLocation ( ) ;
50
+ const dispatch = useDispatch ( ) ;
48
51
const [ submitBtnDisable , setSubmitBtnDisable ] = useState ( false ) ;
49
52
const [ account , setAccount ] = useState ( ( ) => {
50
53
const { email } = ( location . state || { } ) as any ;
@@ -53,26 +56,52 @@ function UserRegister() {
53
56
const [ password , setPassword ] = useState ( "" ) ;
54
57
const [ orgLoading , setOrgLoading ] = useState ( false ) ;
55
58
const [ lastEmailChecked , setLastEmailChecked ] = useState ( "" ) ;
59
+ const [ signupEnabled , setSignupEnabled ] = useState < boolean > ( true ) ;
60
+ const [ signinEnabled , setSigninEnabled ] = useState < boolean > ( true ) ;
56
61
const redirectUrl = useRedirectUrl ( ) ;
62
+ const serverSettings = useSelector ( getServerSettings ) ;
57
63
const { systemConfig, inviteInfo, fetchUserAfterAuthSuccess } = useContext ( AuthContext ) ;
58
64
const invitationId = inviteInfo ?. invitationId ;
59
-
65
+ const isFormLoginEnabled = systemConfig ?. form . enableLogin ;
66
+ const authId = systemConfig ?. form . id ;
60
67
const orgId = useParams < any > ( ) . orgId ;
68
+
61
69
const organizationId = useMemo ( ( ) => {
62
70
if ( inviteInfo ?. invitedOrganizationId ) {
63
71
return inviteInfo ?. invitedOrganizationId ;
64
72
}
65
73
return orgId ;
66
74
} , [ inviteInfo , orgId ] ) ;
67
75
68
- const authId = systemConfig ?. form . id ;
69
-
70
- const serverSettings = useSelector ( getServerSettings ) ;
76
+ const isEmailLoginEnabled = useMemo ( ( ) => {
77
+ return isFormLoginEnabled && signinEnabled ;
78
+ } , [ isFormLoginEnabled , signinEnabled ] ) ;
71
79
72
80
const isEnterpriseMode = useMemo ( ( ) => {
73
81
return serverSettings ?. LOWCODER_WORKSPACE_MODE === "ENTERPRISE" || serverSettings ?. LOWCODER_WORKSPACE_MODE === "SINGLEWORKSPACE" ;
74
82
} , [ serverSettings ] ) ;
75
83
84
+ useEffect ( ( ) => {
85
+ if ( isEnterpriseMode ) {
86
+ // dispatch(fetchConfigAction());
87
+ fetchOrgPaginationByEmail ( {
88
+ email : ' ' ,
89
+ pageNum : 1 ,
90
+ pageSize : 10 ,
91
+ } )
92
+ . then ( ( resp ) => {
93
+ if ( resp . success ) {
94
+ const orgList = resp . data || [ ] ;
95
+ if ( orgList . length ) {
96
+ // in Enterprise mode, we will get org data in different format
97
+ const selectedOrgId = orgList [ 0 ] ?. id || orgList [ 0 ] ?. orgId ;
98
+ dispatch ( fetchConfigAction ( selectedOrgId ) ) ;
99
+ }
100
+ }
101
+ } )
102
+ }
103
+ } , [ isEnterpriseMode ] ) ;
104
+
76
105
useEffect ( ( ) => {
77
106
const { LOWCODER_EMAIL_SIGNUP_ENABLED } = serverSettings ;
78
107
if (
@@ -143,34 +172,38 @@ function UserRegister() {
143
172
type = "large"
144
173
>
145
174
< RegisterContent >
146
- < StyledFormInput
147
- className = "form-input"
148
- label = { trans ( "userAuth.email" ) }
149
- defaultValue = { account }
150
- onChange = { ( value , valid ) => setAccount ( valid ? value : "" ) }
151
- onBlur = { checkEmailExist }
152
- placeholder = { trans ( "userAuth.inputEmail" ) }
153
- checkRule = { {
154
- check : checkEmailValid ,
155
- errorMsg : trans ( "userAuth.inputValidEmail" ) ,
156
- } }
157
- />
158
- < StyledPasswordInput
159
- className = "form-input"
160
- passInputConf = { { label :trans ( "password.label" ) , placeholder : trans ( "password.placeholder" ) } }
161
- confirmPassConf = { { label :trans ( "password.conformLabel" ) , placeholder : trans ( "password.conformPlaceholder" ) } }
162
- valueCheck = { checkPassWithMsg }
163
- onChange = { ( value , valid ) => setPassword ( valid ? value : "" ) }
164
- doubleCheck
165
- />
166
- < ConfirmButton
167
- disabled = { ! account || ! password || submitBtnDisable }
168
- onClick = { onSubmit }
169
- loading = { loading }
170
- >
171
- { trans ( "userAuth.register" ) }
172
- </ ConfirmButton >
173
- < TermsAndPrivacyInfo onCheckChange = { ( e ) => setSubmitBtnDisable ( ! e . target . checked ) } />
175
+ { isFormLoginEnabled && (
176
+ < >
177
+ < StyledFormInput
178
+ className = "form-input"
179
+ label = { trans ( "userAuth.email" ) }
180
+ defaultValue = { account }
181
+ onChange = { ( value , valid ) => setAccount ( valid ? value : "" ) }
182
+ onBlur = { checkEmailExist }
183
+ placeholder = { trans ( "userAuth.inputEmail" ) }
184
+ checkRule = { {
185
+ check : checkEmailValid ,
186
+ errorMsg : trans ( "userAuth.inputValidEmail" ) ,
187
+ } }
188
+ />
189
+ < StyledPasswordInput
190
+ className = "form-input"
191
+ passInputConf = { { label :trans ( "password.label" ) , placeholder : trans ( "password.placeholder" ) } }
192
+ confirmPassConf = { { label :trans ( "password.conformLabel" ) , placeholder : trans ( "password.conformPlaceholder" ) } }
193
+ valueCheck = { checkPassWithMsg }
194
+ onChange = { ( value , valid ) => setPassword ( valid ? value : "" ) }
195
+ doubleCheck
196
+ />
197
+ < ConfirmButton
198
+ disabled = { ! account || ! password || submitBtnDisable }
199
+ onClick = { onSubmit }
200
+ loading = { loading }
201
+ >
202
+ { trans ( "userAuth.register" ) }
203
+ </ ConfirmButton >
204
+ < TermsAndPrivacyInfo onCheckChange = { ( e ) => setSubmitBtnDisable ( ! e . target . checked ) } />
205
+ </ >
206
+ ) }
174
207
{ ( organizationId || isEnterpriseMode ) && (
175
208
< ThirdPartyAuth
176
209
invitationId = { invitationId }
@@ -179,14 +212,18 @@ function UserRegister() {
179
212
/>
180
213
) }
181
214
</ RegisterContent >
182
- < Divider />
183
- < StyledRouteLinkLogin to = { {
184
- pathname : orgId
185
- ? ORG_AUTH_LOGIN_URL . replace ( ':orgId' , orgId )
186
- : AUTH_LOGIN_URL ,
187
- state : location . state
188
- } } > { trans ( "userAuth.userLogin" ) }
189
- </ StyledRouteLinkLogin >
215
+ { isFormLoginEnabled && (
216
+ < >
217
+ < Divider />
218
+ < StyledRouteLinkLogin to = { {
219
+ pathname : orgId
220
+ ? ORG_AUTH_LOGIN_URL . replace ( ':orgId' , orgId )
221
+ : AUTH_LOGIN_URL ,
222
+ state : location . state
223
+ } } > { trans ( "userAuth.userLogin" ) }
224
+ </ StyledRouteLinkLogin >
225
+ </ >
226
+ ) }
190
227
</ AuthContainer >
191
228
</ Spin >
192
229
) ;
0 commit comments