14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { useEffect , useState } from 'react'
17
+ import { useEffect , useState } from 'react'
18
18
import { Switch , Redirect , Route , useLocation , useHistory } from 'react-router-dom'
19
19
import {
20
20
getCookie ,
21
- ServerErrors ,
22
21
Host ,
23
- showError ,
24
- CustomInput ,
25
22
URLS as CommonURL ,
26
23
ToastVariantType ,
27
24
ToastManager ,
@@ -30,8 +27,6 @@ import {
30
27
ButtonComponentType ,
31
28
ButtonVariantType ,
32
29
ButtonStyleType ,
33
- useUserEmail ,
34
- PasswordField ,
35
30
useSearchString ,
36
31
getComponentSpecificThemeClass ,
37
32
AppThemeType ,
@@ -40,15 +35,13 @@ import {
40
35
Icon ,
41
36
} from '@devtron-labs/devtron-fe-common-lib'
42
37
import { importComponentFromFELibrary } from '@Components/common'
43
- import { ReactComponent as Help } from '@Icons/ic-help-outline.svg'
44
- import { REQUIRED_FIELD_MSG } from '@Config/constantMessaging'
45
- import { URLS , DOCUMENTATION , TOKEN_COOKIE_NAME } from '../../config'
46
- import { loginAsAdmin } from './login.service'
38
+ import { URLS , TOKEN_COOKIE_NAME } from '../../config'
47
39
import { dashboardAccessed } from '../../services/service'
48
40
import './login.scss'
49
41
import { getSSOConfigList } from '../../Pages/GlobalConfigurations/Authorization/SSOLoginServices/service'
50
42
import { SSOConfigLoginList } from './login.types'
51
43
import { SSOProvider } from './constants'
44
+ import { LoginForm } from './LoginForm'
52
45
53
46
const NetworkStatusInterface = ! importComponentFromFELibrary ( 'NetworkStatusInterface' , null , 'function' )
54
47
@@ -57,26 +50,10 @@ const getTermsAndConditions = importComponentFromFELibrary('getTermsAndCondition
57
50
const Login = ( ) => {
58
51
const [ continueUrl , setContinueUrl ] = useState ( '' )
59
52
const [ loginList , setLoginList ] = useState < SSOConfigLoginList [ ] > ( [ ] )
60
- const [ loading , setLoading ] = useState ( false )
61
- const [ form , setForm ] = useState ( {
62
- username : 'admin' ,
63
- password : '' ,
64
- } )
65
- const [ errorMessage , setErrorMessage ] = useState ( {
66
- username : {
67
- message : '' ,
68
- isValid : true ,
69
- } ,
70
- password : {
71
- message : '' ,
72
- isValid : true ,
73
- } ,
74
- } )
75
53
76
54
const { searchParams } = useSearchString ( )
77
55
const location = useLocation ( )
78
56
const history = useHistory ( )
79
- const { setEmail } = useUserEmail ( )
80
57
81
58
const [ initLoading , initResult ] = useAsync ( ( ) => Promise . allSettled ( [ getSSOConfigList ( ) , dashboardAccessed ( ) ] ) , [ ] )
82
59
@@ -134,58 +111,6 @@ const Login = () => {
134
111
}
135
112
} , [ initLoading , initResult ] )
136
113
137
- const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
138
- e . persist ( )
139
-
140
- const { name, value } = e . target
141
- setErrorMessage ( ( prevState ) => ( {
142
- ...prevState ,
143
- [ name ] : {
144
- message : value ? '' : REQUIRED_FIELD_MSG ,
145
- isValid : ! ! value ,
146
- } ,
147
- } ) )
148
-
149
- setForm ( {
150
- ...form ,
151
- [ name ] : value ,
152
- } )
153
- }
154
-
155
- const getDefaultRedirectionURL = ( ) => {
156
- const queryString = location . search . split ( 'continue=' ) [ 1 ]
157
- if ( queryString ) {
158
- return queryString
159
- }
160
-
161
- if ( ! window . _env_ . HIDE_NETWORK_STATUS_INTERFACE && ! ! NetworkStatusInterface ) {
162
- return CommonURL . NETWORK_STATUS_INTERFACE
163
- }
164
-
165
- // NOTE: we don't have serverMode therefore defaulting to flag value
166
- return window . _env_ . FEATURE_DEFAULT_LANDING_RB_ENABLE ? URLS . RESOURCE_BROWSER : URLS . APP
167
- }
168
-
169
- const onSubmitLogin = ( e ) : void => {
170
- e . preventDefault ( )
171
- const data = form
172
- setLoading ( true )
173
- loginAsAdmin ( data )
174
- . then ( ( response ) => {
175
- if ( response . result . token ) {
176
- setLoading ( false )
177
- const url = getDefaultRedirectionURL ( )
178
- setEmail ( data . username )
179
- history . push ( url )
180
- localStorage . setItem ( 'isAdminLogin' , 'true' )
181
- }
182
- } )
183
- . catch ( ( errors : ServerErrors ) => {
184
- showError ( errors )
185
- setLoading ( false )
186
- } )
187
- }
188
-
189
114
const onClickSSO = ( ) => {
190
115
if ( typeof Storage !== 'undefined' ) {
191
116
localStorage . setItem ( 'isSSOLogin' , 'true' )
@@ -228,76 +153,7 @@ const Login = () => {
228
153
</ div >
229
154
)
230
155
231
- const renderAdminLoginPage = ( ) => {
232
- const { search } = location
233
-
234
- return (
235
- < form className = "flexbox-col dc__gap-32" autoComplete = "on" onSubmit = { onSubmitLogin } noValidate >
236
- < div className = "flexbox-col dc__gap-16" >
237
- < CustomInput
238
- placeholder = "Enter username"
239
- value = { form . username }
240
- name = "username"
241
- onChange = { handleChange }
242
- label = "User ID"
243
- required
244
- error = { errorMessage . username . message }
245
- />
246
- < div className = "flexbox-col dc__gap-4" >
247
- < PasswordField
248
- placeholder = "Enter password"
249
- value = { form . password }
250
- name = "password"
251
- onChange = { handleChange }
252
- label = "Password"
253
- required
254
- shouldShowDefaultPlaceholderOnBlur = { false }
255
- autoFocus
256
- error = { errorMessage . password . message }
257
- />
258
-
259
- < div className = "flex left dc__gap-4" >
260
- < Help className = "fcb-5 icon-dim-16" />
261
-
262
- < a
263
- className = "anchor fs-11 cb-5 lh-20"
264
- rel = "noreferrer noopener"
265
- target = "_blank"
266
- href = { DOCUMENTATION . ADMIN_PASSWORD }
267
- >
268
- What is my admin password?
269
- </ a >
270
- </ div >
271
- </ div >
272
- </ div >
273
- < div className = "flexbox-col dc__gap-12" >
274
- < Button
275
- disabled = { loading }
276
- isLoading = { loading }
277
- dataTestId = "login-button"
278
- text = "Login"
279
- fullWidth
280
- size = { ComponentSizeType . xl }
281
- buttonProps = { {
282
- type : 'submit' ,
283
- } }
284
- />
285
-
286
- { loginList . length > 0 && (
287
- < Button
288
- dataTestId = "sso-login"
289
- text = "Login using SSO service"
290
- component = { ButtonComponentType . link }
291
- linkProps = { {
292
- to : `${ URLS . LOGIN_SSO } ${ search } ` ,
293
- } }
294
- variant = { ButtonVariantType . text }
295
- />
296
- ) }
297
- </ div >
298
- </ form >
299
- )
300
- }
156
+ const renderAdminLoginPage = ( ) => < LoginForm loginList = { loginList } />
301
157
302
158
const renderDevtronLogo = ( ) => (
303
159
< div className = "flex column dc__gap-16 dc__text-center" >
0 commit comments