import React, { useState } from 'react'; import { connect } from 'react-redux'; import { bindActionCreators, Dispatch } from 'redux'; import CardMedia from '@material-ui/core/CardMedia'; import { Google } from '@styled-icons/bootstrap/Google'; import { Facebook } from '@styled-icons/bootstrap/Facebook'; import Fab from '@material-ui/core/Fab'; // @ts-ignore import styles from './Login.module.scss'; import { Config } from '../../../helper'; import Typography from '@material-ui/core/Typography'; import Button from '@material-ui/core/Button'; import ArrowBackIosIcon from '@material-ui/icons/ArrowBackIos'; import ForgotPassword from '../../../user/components/Auth/ForgotPassword'; import PasswordLoginApp from '../../../user/components/Auth/PasswordLoginApp'; import RegisterApp from '../../../user/components/Auth/RegisterApp'; import ResetPassword from '../../../user/components/Auth/ResetPassword'; import { loginUserByOAuth, resetPassword, registerUserByEmail } from '../../../user/reducers/auth/service'; import { useTranslation } from 'react-i18next'; const mapStateToProps = (state: any): any => { return {}; }; const mapDispatchToProps = (dispatch: Dispatch): any => ({ loginUserByOAuth: bindActionCreators(loginUserByOAuth, dispatch), resetPassword: bindActionCreators(resetPassword, dispatch), registerUserByEmail: bindActionCreators(registerUserByEmail, dispatch), }); interface Props { auth?: any; enableFacebookSocial?: boolean; enableGithubSocial?: boolean; enableGoogleSocial?: boolean; loginUserByOAuth?: typeof loginUserByOAuth; logo: string; isAddConnection?: boolean; resetPassword?: typeof resetPassword; registerUserByEmail?: typeof registerUserByEmail; } const FlatSignIn = (props: Props) => { const [view, setView] = useState('login'); const enableUserPassword = Config.publicRuntimeConfig?.auth ? Config.publicRuntimeConfig.auth.enableUserPassword : false; const enableGoogleSocial = Config.publicRuntimeConfig?.auth ? Config.publicRuntimeConfig.auth.enableGoogleSocial : false; const enableFacebookSocial = Config.publicRuntimeConfig?.auth ? Config.publicRuntimeConfig.auth.enableFacebookSocial : false; const { t } = useTranslation(); const socials = [ enableGoogleSocial, enableFacebookSocial ]; const socialCount = socials.filter(v => v).length; const userTabPanel = enableUserPassword && ; const handleGoogleLogin = (e: any): void => { e.preventDefault(); loginUserByOAuth('google'); }; const handleFacebookLogin = (e: any): void => { e.preventDefault(); loginUserByOAuth('facebook'); }; let component = null; let footer = null; switch (view) { case 'sign-up': component = ; footer = <>{!props.isAddConnection && (

{t('social:login.account')} setView('login')}>{t('social:login.login')}

)} ; break; case 'forget-password': component = <>setView('reset-password')}>{t('social:login.resetPassword')}; footer = <>{!props.isAddConnection && (

{t('social:login.notHavingAccount')} setView('sign-up')}>{t('social:login.signUp')}

)}; break; // completeAction={()=>setView('login')} removed from ResetPassword since it failed lintsub case 'reset-password': component = <>; footer = <>{!props.isAddConnection && (

)} ;break; //login by default default: component = <>{userTabPanel} setView('forget-password')}>{t('social:login.forgotPassword')} ; footer = <>{!props.isAddConnection && (

{t('social:login.notHavingAccount')} setView('sign-up')}>{t('social:login.signUp')}

)}; break; } return
{view !== 'login' && } {component} {enableUserPassword && socialCount > 0 &&
{t('social:login.or')}
} {socialCount > 0 &&
{enableGoogleSocial && handleGoogleLogin(e)}/>} {enableFacebookSocial && handleFacebookLogin(e)}/>}
}
{footer}
; }; export default connect(mapStateToProps, mapDispatchToProps)(FlatSignIn);