/* Copyright 2020 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import * as React from "react"; import { _t } from '../../../languageHandler'; import { IDialogProps } from "./IDialogProps"; import { useRef, useState } from "react"; import Field from "../elements/Field"; import CountlyAnalytics from "../../../CountlyAnalytics"; import withValidation from "../elements/Validation"; import * as Email from "../../../email"; import BaseDialog from "./BaseDialog"; import DialogButtons from "../elements/DialogButtons"; interface IProps extends IDialogProps { onFinished(continued: boolean, email?: string): void; } const validation = withValidation({ rules: [ { key: "email", test: ({ value }) => !value || Email.looksValid(value), invalid: () => _t("Doesn't look like a valid email address"), }, ], }); const RegistrationEmailPromptDialog: React.FC = ({ onFinished }) => { const [email, setEmail] = useState(""); const fieldRef = useRef(); const onSubmit = async (e) => { e.preventDefault(); if (email) { const valid = await fieldRef.current.validate({ allowEmpty: false }); if (!valid) { fieldRef.current.focus(); fieldRef.current.validate({ allowEmpty: false, focused: true }); return; } } onFinished(true, email); }; return onFinished(false)} fixedWidth={false} >

{_t("Just a heads up, if you don't add an email and forget your password, you could " + "permanently lose access to your account.", {}, { b: sub => {sub}, })}

{ setEmail(ev.target.value); }} onValidate={async fieldState => await validation(fieldState)} onFocus={() => CountlyAnalytics.instance.track("onboarding_registration_email2_focus")} onBlur={() => CountlyAnalytics.instance.track("onboarding_registration_email2_blur")} />
; }; export default RegistrationEmailPromptDialog;