/* Copyright 2024 New Vector Ltd. Copyright 2022 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE files in the repository root for full details. */ import React, { type ReactNode, useRef } from "react"; import { EmailSolidIcon } from "@vector-im/compound-design-tokens/assets/web/icons"; import { _t, _td } from "../../../../languageHandler"; import EmailField from "../../../views/auth/EmailField"; import { ErrorMessage } from "../../ErrorMessage"; import Spinner from "../../../views/elements/Spinner"; import type Field from "../../../views/elements/Field"; import AccessibleButton, { type ButtonEvent } from "../../../views/elements/AccessibleButton"; interface EnterEmailProps { email: string; errorText: string | ReactNode | null; homeserver: string; loading: boolean; onInputChanged: (stateKey: "email", ev: React.FormEvent) => void; onLoginClick: () => void; onSubmitForm: (ev: React.FormEvent) => void; } /** * This component renders the email input view of the forgot password flow. */ export const EnterEmail: React.FC = ({ email, errorText, homeserver, loading, onInputChanged, onLoginClick, onSubmitForm, }) => { const submitButtonChild = loading ? : _t("auth|forgot_password_send_email"); const emailFieldRef = useRef(null); const onSubmit = async (event: React.FormEvent): Promise => { if (await emailFieldRef.current?.validate({ allowEmpty: false })) { onSubmitForm(event); return; } emailFieldRef.current?.focus(); emailFieldRef.current?.validate({ allowEmpty: false, focused: true }); }; return ( <>

{_t("auth|enter_email_heading")}

{_t("auth|enter_email_explainer", { homeserver }, { b: (t) => {t} })}

) => onInputChanged("email", event)} fieldRef={emailFieldRef} />
{errorText && }
{ e.preventDefault(); onLoginClick(); }} > {_t("auth|sign_in_instead")}
); };