import { Button, Col, Form, Input, Row } from "antd"; import { ContentLayout } from "../../Components/ContentLayout"; import { Link } from "react-router-dom"; import { NLView } from "../../types"; import { ProgressButton } from "../../Components/ProgressButton"; import { Spin } from "../../Components/Spin"; import { capFirst } from "../../utils/capFirst"; import { useActions, useAppState } from "../../overmind"; import { useEffect, useState } from "react"; import { useForm } from "antd/lib/form/Form"; import SupportBox from "../../Components/SupportBox"; const STATUS = { NONE: 0, LINK_NO_EMAIL: 1, LINK_EMAIL: 2, LINK_REQUESTED: 3, ERROR: 4, AUTHENTICATED_CANTPROCEED: 5, AUTHORIZED: 6, }; export const LegacyLogin: NLView = () => { const [form] = useForm(); const actions = useActions(); const state = useAppState(); const [status, setStatus] = useState(STATUS.NONE); const [email, setEmail] = useState(""); const [error, setError] = useState(""); // const indicators = state.indicators.specific; // const authorizing = state.auth.status > 0 && !state.auth.authorized && !state.auth.authenticated; // oobCode && // ["auth.newlifeAuthorize", "auth.refreshApiToken", "auth.firebaseSignInWithEmailLink"] // .find(n => indicators[n]); const oobCode = new URLSearchParams(window.location.search).get("oobCode"); const regexEmail = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; const signIn = async (email: string) => { try { await actions.firebase.signInWithEmailLink({ email }); } catch (ex) { setStatus(STATUS.ERROR); setError(capFirst((ex as { code: string }).code.replace(/^auth\//, "").replace(/-/g, " "))); actions.auth.logout({ noRouting: true }); } }; const tryAgain = () => { actions.routing.historyPush({ location: "/auth/newlife-members" }); setStatus(STATUS.NONE); setError(""); actions.auth.logout({ noRouting: true }); }; useEffect(() => { if (state.flows.user.create.legacyToken) actions.flows.user.create.stopLegacyImport({ noRedirect: true }); if (oobCode) { const email: string = window.localStorage.getItem("emailForSignIn") || ""; setStatus(email ? STATUS.LINK_EMAIL : STATUS.LINK_NO_EMAIL); email && signIn(email); } else if (state.auth.authenticated) { if (!state.api.auth.authorized && state.api.auth.user?.id && state.api.auth.user?.status !== "imported") { // actions.routing.historyPush({ location: "/" }); setStatus(STATUS.AUTHENTICATED_CANTPROCEED); actions.auth.logout(); } } setStatus(state.api.auth.authorized ? STATUS.AUTHORIZED : STATUS.NONE); }, []); useEffect(() => { if (!(oobCode && state.auth.status > 0) || state.indicators.specific["auth.handleAuthChange"]) { return; } const st = state.auth.authenticated && (state.api.auth.authorized ? STATUS.AUTHORIZED : STATUS.AUTHENTICATED_CANTPROCEED); if (st) { setStatus(st); } }, [state.auth.status, state.api.auth.authorized]); const onFinish = ({ email }: { email: string }) => { switch (status) { case STATUS.NONE: window.localStorage.setItem("emailForSignIn", email); setStatus(STATUS.LINK_REQUESTED); setEmail(email); actions.firebase.requestEmailLink({ email }); break; case STATUS.LINK_NO_EMAIL: signIn(email); } }; if (state.indicators.isWorking) return ; if (error) return (

Oops! {error}

actions.routing.historyPush({ location: "/", }) } > Try on mobile

); return ( <> {/* authorized status {state.auth.status} {JSON.stringify(state.api.auth.user)} local status {status} */} {state.auth.authenticated ? ( <> {state.api.auth.authorized ? ( <>

Hi {state.api.auth.user?.username || state.api.auth.user?.displayName}, we've been missing you!

Please take a few steps to access the brand new version of Newlife.

) : status == STATUS.AUTHENTICATED_CANTPROCEED ? (

Oops! Looks like you didn’t have an existing account.


  • {email ? ( <> You used the email {email}
    ) : ( "" )} Please check your email address is correct.
  • Or make sure you haven’t already connected to Newlife.IO




Still having issues? Email info@newlife.io
) : ( <> )} ) : ( <> )} {status === STATUS.LINK_REQUESTED && (

check your inbox

I don't have an account yet!

)} {status === STATUS.NONE && !state.api.auth.user?.id ? ( <>

Import account

Connect my account


I don't have an account yet!

) : ( <> )} ); }; export const LegacyImport = () => { return ; };