// @flow import * as React from "react"; import styled from "styled-components"; import { BackIcon, EmailIcon } from "outline-icons"; import { observer, inject } from "mobx-react"; import { Redirect } from "react-router-dom"; import { find } from "lodash"; import Flex from "components/Flex"; import TeamLogo from "components/TeamLogo"; import OutlineLogo from "components/OutlineLogo"; import Heading from "components/Heading"; import PageTitle from "components/PageTitle"; import ButtonLarge from "components/ButtonLarge"; import HelpText from "components/HelpText"; import Fade from "components/Fade"; import Service from "./Service"; import Notices from "./Notices"; import AuthStore from "stores/AuthStore"; import getQueryVariable from "shared/utils/getQueryVariable"; import env from "env"; type Props = { auth: AuthStore, location: Object, }; type State = { emailLinkSentTo: string, }; @observer class Login extends React.Component { state = { emailLinkSentTo: "", }; handleReset = () => { this.setState({ emailLinkSentTo: "" }); }; handleEmailSuccess = email => { this.setState({ emailLinkSentTo: email }); }; render() { const { auth, location } = this.props; const { config } = auth; const isCreate = location.pathname === "/create"; if (auth.authenticated) { return ; } // we're counting on the config request being fast if (!config) { return null; } const hasMultipleServices = config.services.length > 1; const defaultService = find( config.services, service => service.id === auth.lastSignedIn ); const header = env.DEPLOYMENT === "hosted" && (config.hostname ? ( Back to home ) : ( Back to website )); if (this.state.emailLinkSentTo) { return ( {header} Check your email A magic sign-in link has been sent to the email{" "} {this.state.emailLinkSentTo}, no password needed.
Back to login
); } return ( {header} {env.TEAM_LOGO && env.DEPLOYMENT !== "hosted" ? ( ) : ( )} {isCreate ? ( Create an account ) : ( Login to {config.name || "Outline"} )} {defaultService && ( {hasMultipleServices && ( You signed in with {defaultService.name} last time. )} )} {config.services.map(service => { if (service.id === auth.lastSignedIn) { return null; } return ( ); })} ); } } const CheckEmailIcon = styled(EmailIcon)` margin-bottom: -1.5em; `; const Background = styled(Fade)` width: 100vw; height: 100vh; background: ${props => props.theme.background}; display: flex; `; const Logo = styled.div` margin-bottom: -1.5em; height: 38px; `; const Note = styled(HelpText)` text-align: center; font-size: 14px; em { font-style: normal; font-weight: 500; } `; const Back = styled.a` display: flex; align-items: center; color: inherit; padding: 32px; font-weight: 500; position: absolute; svg { transition: transform 100ms ease-in-out; } &:hover { svg { transform: translateX(-4px); } } `; const Or = styled.hr` margin: 1em 0; position: relative; width: 100%; &:after { content: "Or"; display: block; position: absolute; left: 50%; transform: translate3d(-50%, -50%, 0); text-transform: uppercase; font-size: 11px; color: ${props => props.theme.textSecondary}; background: ${props => props.theme.background}; border-radius: 2px; padding: 0 4px; } `; const Centered = styled(Flex)` user-select: none; width: 90vw; height: 100%; max-width: 320px; margin: 0 auto; `; export default inject("auth")(Login);