Files
ThreadNet-Web/src/components/structures/auth/forgot-password/EnterEmail.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
3.7 KiB
TypeScript
Raw Normal View History

2022-11-22 07:58:37 +01:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
2022-11-22 07:58:37 +01:00
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
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
2022-11-22 07:58:37 +01:00
*/
import React, { ReactNode, useRef } from "react";
import { EmailSolidIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
2022-11-22 07:58:37 +01:00
import { _t, _td } from "../../../../languageHandler";
import EmailField from "../../../views/auth/EmailField";
import { ErrorMessage } from "../../ErrorMessage";
import Spinner from "../../../views/elements/Spinner";
import Field from "../../../views/elements/Field";
2022-12-23 13:36:09 +01:00
import AccessibleButton, { ButtonEvent } from "../../../views/elements/AccessibleButton";
2022-11-22 07:58:37 +01:00
interface EnterEmailProps {
email: string;
errorText: string | ReactNode | null;
homeserver: string;
loading: boolean;
2023-07-12 15:56:51 +01:00
onInputChanged: (stateKey: "email", ev: React.FormEvent<HTMLInputElement>) => void;
onLoginClick: () => void;
2022-11-22 07:58:37 +01:00
onSubmitForm: (ev: React.FormEvent) => void;
}
/**
* This component renders the email input view of the forgot password flow.
*/
export const EnterEmail: React.FC<EnterEmailProps> = ({
email,
errorText,
homeserver,
loading,
onInputChanged,
onLoginClick,
2022-11-22 07:58:37 +01:00
onSubmitForm,
}) => {
2023-09-28 12:51:30 +05:30
const submitButtonChild = loading ? <Spinner w={16} h={16} /> : _t("auth|forgot_password_send_email");
2022-11-22 07:58:37 +01:00
const emailFieldRef = useRef<Field>(null);
const onSubmit = async (event: React.FormEvent): Promise<void> => {
2022-11-22 07:58:37 +01:00
if (await emailFieldRef.current?.validate({ allowEmpty: false })) {
onSubmitForm(event);
return;
}
emailFieldRef.current?.focus();
emailFieldRef.current?.validate({ allowEmpty: false, focused: true });
};
return (
<>
<EmailSolidIcon className="mx_AuthBody_icon" />
<h1>{_t("auth|enter_email_heading")}</h1>
2022-11-22 07:58:37 +01:00
<p className="mx_AuthBody_text">
{_t("auth|enter_email_explainer", { homeserver }, { b: (t) => <strong>{t}</strong> })}
2022-11-22 07:58:37 +01:00
</p>
<form onSubmit={onSubmit}>
<fieldset disabled={loading}>
<div className="mx_AuthBody_fieldRow">
<EmailField
name="reset_email" // define a name so browser's password autofill gets less confused
label={_td("common|email_address")}
labelRequired={_td("auth|forgot_password_email_required")}
labelInvalid={_td("auth|forgot_password_email_invalid")}
2022-11-22 07:58:37 +01:00
value={email}
autoFocus={true}
onChange={(event: React.FormEvent<HTMLInputElement>) => onInputChanged("email", event)}
fieldRef={emailFieldRef}
/>
</div>
{errorText && <ErrorMessage message={errorText} />}
<button type="submit" className="mx_Login_submit">
{submitButtonChild}
</button>
<div className="mx_AuthBody_button-container">
<AccessibleButton
className="mx_AuthBody_sign-in-instead-button"
element="button"
kind="link"
2022-12-23 13:36:09 +01:00
onClick={(e: ButtonEvent) => {
e.preventDefault();
onLoginClick();
}}
>
{_t("auth|sign_in_instead")}
</AccessibleButton>
</div>
2022-11-22 07:58:37 +01:00
</fieldset>
</form>
</>
);
};