import React, { Fragment, useState } from 'react'; import EmailIcon from '@material-ui/icons/Email'; import SocialIcon from '@material-ui/icons/Public'; import UserIcon from '@material-ui/icons/Person'; import { Config } from '../../../helper'; import MagicLinkEmail from './MagicLinkEmail'; import Tabs from '@material-ui/core/Tabs'; import Tab from '@material-ui/core/Tab'; import SocialLogin from './SocialLogin'; import PasswordLogin from './PasswordLogin'; import { useTranslation } from "react-i18next"; const TabPanel = (props: any): any => { const { children, value, index } = props; return ( {value === index && children} ); }; const SignIn = (): any => { let enableSmsMagicLink = true; let enableEmailMagicLink = true; let enableUserPassword = false; let enableGithubSocial = false; let enableGoogleSocial = false; let enableFacebookSocial = false; let enableLinkedInSocial = false; let enableTwitterSocial = false; const [tabIndex, setTabIndex] = useState(0); const { t } = useTranslation(); const handleChange = (event: any, newValue: number): void => { event.preventDefault(); setTabIndex(newValue); }; if (Config.publicRuntimeConfig?.auth) { enableSmsMagicLink = Config.publicRuntimeConfig.auth.enableSmsMagicLink; enableEmailMagicLink = Config.publicRuntimeConfig.auth.enableEmailMagicLink; enableUserPassword = Config.publicRuntimeConfig.auth.enableUserPassword; enableGithubSocial = Config.publicRuntimeConfig.auth.enableGithubSocial; enableGoogleSocial = Config.publicRuntimeConfig.auth.enableGoogleSocial; enableFacebookSocial = Config.publicRuntimeConfig.auth.enableFacebookSocial; enableLinkedInSocial = Config.publicRuntimeConfig.auth.enableLinkedInSocial; enableTwitterSocial = Config.publicRuntimeConfig.auth.enableTwitterSocial; } const socials = [ enableGithubSocial, enableGoogleSocial, enableFacebookSocial, enableLinkedInSocial, enableTwitterSocial ]; const enabled = [ enableSmsMagicLink, enableEmailMagicLink, enableUserPassword, enableGithubSocial, enableGoogleSocial, enableFacebookSocial, enableLinkedInSocial, enableTwitterSocial ]; const enabledCount = enabled.filter(v => v).length; const socialCount = socials.filter(v => v).length; let component = ; if (enabledCount === 1) { if (enableSmsMagicLink) { component = ; } else if (enableEmailMagicLink) { component = ; } else if (enableUserPassword) { component = ; } else if (socialCount > 0) { component = ; } } else { let index = 0; const emailTab = (enableEmailMagicLink || enableSmsMagicLink) && } label={t('user:auth.login.email')} />; const emailTabPanel = (enableEmailMagicLink || enableSmsMagicLink) && ; (enableEmailMagicLink || enableSmsMagicLink) && ++index; const userTab = enableUserPassword && } label={t('user:auth.login.username')} />; const userTabPanel = enableUserPassword && ; enableUserPassword && ++index; const socialTab = socialCount > 0 && } label={t('user:auth.login.social')} />; const socialTabPanel = socialCount > 0 && ; socialCount > 0 && ++index; component = ( {(enableUserPassword || socialCount > 0) && {emailTab} {userTab} {socialTab} } {emailTabPanel} {userTabPanel} {socialTabPanel} ); } return component; }; export default SignIn;