diff --git a/app/scenes/Login/AuthenticationProvider.tsx b/app/scenes/Login/AuthenticationProvider.tsx index 40140e8f1..74479a4db 100644 --- a/app/scenes/Login/AuthenticationProvider.tsx +++ b/app/scenes/Login/AuthenticationProvider.tsx @@ -1,13 +1,13 @@ import { EmailIcon } from "outline-icons"; import * as React from "react"; -import { WithTranslation, withTranslation } from "react-i18next"; +import { useTranslation } from "react-i18next"; import styled from "styled-components"; import AuthLogo from "~/components/AuthLogo"; import ButtonLarge from "~/components/ButtonLarge"; import InputLarge from "~/components/InputLarge"; import { client } from "~/utils/ApiClient"; -type Props = WithTranslation & { +type Props = { id: string; name: string; authUrl: string; @@ -15,111 +15,91 @@ type Props = WithTranslation & { onEmailSuccess: (email: string) => void; }; -type State = { - showEmailSignin: boolean; - isSubmitting: boolean; - email: string; -}; +function AuthenticationProvider(props: Props) { + const { t } = useTranslation(); + const [showEmailSignin, setShowEmailSignin] = React.useState(false); + const [isSubmitting, setSubmitting] = React.useState(false); + const [email, setEmail] = React.useState(""); + const { isCreate, id, name, authUrl } = props; -class AuthenticationProvider extends React.Component { - state = { - showEmailSignin: false, - isSubmitting: false, - email: "", + const handleChangeEmail = (event: React.ChangeEvent) => { + setEmail(event.target.value); }; - handleChangeEmail = (event: React.ChangeEvent) => { - this.setState({ - email: event.target.value, - }); - }; - - handleSubmitEmail = async (event: React.SyntheticEvent) => { + const handleSubmitEmail = async ( + event: React.SyntheticEvent + ) => { event.preventDefault(); - if (this.state.showEmailSignin && this.state.email) { - this.setState({ - isSubmitting: true, - }); + if (showEmailSignin && email) { + setSubmitting(true); try { const response = await client.post(event.currentTarget.action, { - email: this.state.email, + email, }); if (response.redirect) { window.location.href = response.redirect; } else { - this.props.onEmailSuccess(this.state.email); + props.onEmailSuccess(email); } } finally { - this.setState({ - isSubmitting: false, - }); + setSubmitting(false); } } else { - this.setState({ - showEmailSignin: true, - }); + setShowEmailSignin(true); } }; - render() { - const { isCreate, id, name, authUrl, t } = this.props; - - if (id === "email") { - if (isCreate) { - return null; - } - - return ( - -
- {this.state.showEmailSignin ? ( - <> - - - {t("Sign In")} → - - - ) : ( - } fullwidth> - {t("Continue with Email")} - - )} - -
- ); + if (id === "email") { + if (isCreate) { + return null; } return ( - - (window.location.href = authUrl)} - icon={} - fullwidth - > - {t("Continue with {{ authProviderName }}", { - authProviderName: name, - })} - + +
+ {showEmailSignin ? ( + <> + + + {t("Sign In")} → + + + ) : ( + } fullwidth> + {t("Continue with Email")} + + )} +
); } + + return ( + + (window.location.href = authUrl)} + icon={} + fullwidth + > + {t("Continue with {{ authProviderName }}", { + authProviderName: name, + })} + + + ); } const Wrapper = styled.div` @@ -132,4 +112,4 @@ const Form = styled.form` justify-content: space-between; `; -export default withTranslation()(AuthenticationProvider); +export default AuthenticationProvider; diff --git a/app/scenes/Login/index.tsx b/app/scenes/Login/index.tsx index 8f551897c..6ddf04f45 100644 --- a/app/scenes/Login/index.tsx +++ b/app/scenes/Login/index.tsx @@ -200,7 +200,7 @@ function Login() { )} )} - {config.providers.map((provider: any) => { + {config.providers.map((provider) => { if (defaultProvider && provider.id === defaultProvider.id) { return null; }