1919import { Button , Form , Input } from 'antd' ;
2020import { AuthForm } from 'app/components' ;
2121import usePrefixI18N from 'app/hooks/useI18NPrefix' ;
22- import {
23- selectLoggedInUser ,
24- selectLoginLoading ,
25- selectOauth2Clients ,
26- } from 'app/slice/selectors' ;
27- import { getOauth2Clients } from 'app/slice/thunks' ;
28- import React , { useCallback , useEffect , useState } from 'react' ;
29- import { useDispatch , useSelector } from 'react-redux' ;
22+ import { User } from 'app/slice/types' ;
23+ import React , { useCallback , useState } from 'react' ;
3024import { Link , useHistory } from 'react-router-dom' ;
3125import styled from 'styled-components/macro' ;
3226import {
3327 BORDER_RADIUS ,
3428 LINE_HEIGHT_ICON_LG ,
29+ LINE_HEIGHT_ICON_XXL ,
3530 SPACE_MD ,
31+ SPACE_XS ,
3632} from 'styles/StyleConstants' ;
3733import { getToken } from 'utils/auth' ;
34+ import { AUTH_CLIENT_ICON_MAPPING } from './constants' ;
35+
36+ interface LoginFormProps {
37+ loading : boolean ;
38+ loggedInUser ?: User | null ;
39+ oauth2Clients : Array < { name : string ; value : string } > ;
40+ registerEnable ?: boolean ;
41+ modal ?: boolean ;
42+ onLogin ?: ( value ) => void ;
43+ }
3844
3945export function LoginForm ( {
46+ loading,
47+ loggedInUser,
48+ oauth2Clients,
4049 registerEnable = true ,
4150 modal = false ,
4251 onLogin,
43- } : {
44- registerEnable ?: boolean ;
45- modal ?: boolean ;
46- onLogin ?: ( value ) => void ;
47- } ) {
52+ } : LoginFormProps ) {
4853 const [ switchUser , setSwitchUser ] = useState ( false ) ;
49- const dispatch = useDispatch ( ) ;
5054 const history = useHistory ( ) ;
51- const loading = useSelector ( selectLoginLoading ) ;
52- const loggedInUser = useSelector ( selectLoggedInUser ) ;
5355 const [ form ] = Form . useForm ( ) ;
5456 const logged = ! ! getToken ( ) ;
5557 const t = usePrefixI18N ( 'login' ) ;
5658 const tg = usePrefixI18N ( 'global' ) ;
57- const oauth2Clients = useSelector ( selectOauth2Clients ) ;
5859
5960 const toApp = useCallback ( ( ) => {
6061 history . replace ( '/' ) ;
6162 } , [ history ] ) ;
6263
63- useEffect ( ( ) => {
64- dispatch ( getOauth2Clients ( ) ) ;
65- } , [ dispatch ] ) ;
66-
6764 const onSwitch = useCallback ( ( ) => {
6865 setSwitchUser ( true ) ;
6966 } , [ ] ) ;
7067
71- let Oauth2BtnList = oauth2Clients . map ( client => {
72- return (
73- < Oauth2Button key = { client . value } href = { client . value } >
74- { client . name }
75- </ Oauth2Button >
76- ) ;
77- } ) ;
78-
7968 return (
8069 < AuthForm >
8170 { logged && ! switchUser && ! modal ? (
@@ -142,8 +131,22 @@ export function LoginForm({
142131 ) }
143132 </ Links >
144133 ) }
145-
146- { Oauth2BtnList }
134+ { oauth2Clients . length > 0 && (
135+ < >
136+ < AuthTitle > { t ( 'authTitle' ) } </ AuthTitle >
137+ { oauth2Clients . map ( ( { name, value } ) => (
138+ < AuthButton
139+ key = { value }
140+ size = "large"
141+ icon = { AUTH_CLIENT_ICON_MAPPING [ name . toLowerCase ( ) ] }
142+ href = { value }
143+ block
144+ >
145+ { name }
146+ </ AuthButton >
147+ ) ) }
148+ </ >
149+ ) }
147150 </ Form >
148151 ) }
149152 </ AuthForm >
@@ -154,16 +157,6 @@ const Links = styled.div`
154157 display: flex;
155158` ;
156159
157- const Oauth2Button = styled . a `
158- display: block;
159- height: 36px;
160- font-weight: bold;
161- line-height: 36px;
162- color: #fff;
163- text-align: center;
164- background-color: blue;
165- ` ;
166-
167160const LinkButton = styled ( Link ) `
168161 flex: 1;
169162 line-height: ${ LINE_HEIGHT_ICON_LG } ;
@@ -173,6 +166,20 @@ const LinkButton = styled(Link)`
173166 }
174167` ;
175168
169+ const AuthTitle = styled . p `
170+ line-height: ${ LINE_HEIGHT_ICON_XXL } ;
171+ color: ${ p => p . theme . textColorLight } ;
172+ text-align: center;
173+ ` ;
174+
175+ const AuthButton = styled ( Button ) `
176+ margin-bottom: ${ SPACE_XS } ;
177+
178+ &:last-child {
179+ margin-bottom: 0;
180+ }
181+ ` ;
182+
176183const UserPanel = styled . div `
177184 display: flex;
178185 padding: ${ SPACE_MD } ;
0 commit comments