// @flow import { EmailIcon } from "outline-icons"; import * as React from "react"; 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 = { id: string, name: string, authUrl: string, isCreate: boolean, onEmailSuccess: (email: string) => void, }; type State = { showEmailSignin: boolean, isSubmitting: boolean, email: string, }; class Provider extends React.Component { state = { showEmailSignin: false, isSubmitting: false, email: "", }; handleChangeEmail = (event: SyntheticInputEvent) => { this.setState({ email: event.target.value }); }; handleSubmitEmail = async (event: SyntheticEvent) => { event.preventDefault(); if (this.state.showEmailSignin && this.state.email) { this.setState({ isSubmitting: true }); try { const response = await client.post(event.currentTarget.action, { email: this.state.email, }); if (response.redirect) { window.location.href = response.redirect; } else { this.props.onEmailSuccess(this.state.email); } } finally { this.setState({ isSubmitting: false }); } } else { this.setState({ showEmailSignin: true }); } }; render() { const { isCreate, id, name, authUrl } = this.props; if (id === "email") { if (isCreate) { return null; } return (
{this.state.showEmailSignin ? ( <> Sign In → ) : ( } fullwidth> Continue with Email )}
); } const icon = ; return ( (window.location.href = authUrl)} icon={icon ? {icon} : null} fullwidth > {isCreate ? "Sign up" : "Continue"} with {name} ); } } const Logo = styled.div` display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; `; const Wrapper = styled.div` margin-bottom: 1em; width: 100%; `; const Form = styled.form` width: 100%; display: flex; justify-content: space-between; `; export default Provider;