Files
element-call/src/room/RoomAuthView.tsx
T

120 lines
3.8 KiB
TypeScript
Raw Normal View History

2022-05-04 17:09:48 +01:00
/*
Copyright 2022-2024 New Vector Ltd.
2022-05-04 17:09:48 +01:00
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
2022-05-04 17:09:48 +01:00
*/
import { type FC, useCallback, useState } from "react";
2022-08-02 00:46:16 +02:00
import { useLocation } from "react-router-dom";
2022-10-10 09:19:10 -04:00
import { Trans, useTranslation } from "react-i18next";
2025-03-13 13:58:43 +01:00
import { logger } from "matrix-js-sdk/lib/logger";
import { Button, Heading, Text } from "@vector-im/compound-web";
2022-08-02 00:46:16 +02:00
2022-01-05 16:09:51 -08:00
import styles from "./RoomAuthView.module.css";
import { Header, HeaderLogo, LeftNav, RightNav } from "../Header";
2022-01-05 17:27:01 -08:00
import { FieldRow, InputField, ErrorMessage } from "../input/Input";
2022-01-05 16:09:51 -08:00
import { Form } from "../form/Form";
2022-01-06 14:10:33 -08:00
import { UserMenuContainer } from "../UserMenuContainer";
import { useRegisterPasswordlessUser } from "../auth/useRegisterPasswordlessUser";
2023-07-06 08:53:57 +02:00
import { Config } from "../config/Config";
import { ExternalLink, Link } from "../button/Link";
2022-01-05 15:35:12 -08:00
2023-09-22 18:05:13 -04:00
export const RoomAuthView: FC = () => {
2022-01-05 16:09:51 -08:00
const [loading, setLoading] = useState(false);
2022-08-02 00:46:16 +02:00
const [error, setError] = useState<Error>();
2023-07-06 08:53:57 +02:00
const { registerPasswordlessUser, recaptchaId } =
useRegisterPasswordlessUser();
2022-01-05 16:09:51 -08:00
const onSubmit = useCallback(
2023-06-30 16:43:28 +01:00
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
2022-01-05 16:09:51 -08:00
(e) => {
e.preventDefault();
setLoading(true);
2022-01-05 16:09:51 -08:00
const data = new FormData(e.target);
2022-08-02 00:46:16 +02:00
const dataForDisplayName = data.get("displayName");
const displayName =
typeof dataForDisplayName === "string" ? dataForDisplayName : "";
2022-01-05 16:09:51 -08:00
registerPasswordlessUser(displayName).catch((error) => {
2023-09-25 18:04:34 +01:00
logger.error("Failed to register passwordless user", e);
2022-01-05 16:09:51 -08:00
setLoading(false);
setError(error);
});
},
2023-10-11 10:42:04 -04:00
[registerPasswordlessUser],
2022-01-05 16:09:51 -08:00
);
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
2022-01-05 16:09:51 -08:00
const location = useLocation();
return (
<>
<Header>
<LeftNav>
<HeaderLogo />
</LeftNav>
2022-01-06 14:10:33 -08:00
<RightNav>
<UserMenuContainer preventNavigation />
2022-01-06 14:10:33 -08:00
</RightNav>
2022-01-05 16:09:51 -08:00
</Header>
<div className={styles.container}>
<main className={styles.main}>
<Heading size="xl" weight="semibold" className={styles.headline}>
{t("lobby.join_as_guest")}
</Heading>
2022-01-05 16:09:51 -08:00
<Form className={styles.form} onSubmit={onSubmit}>
<FieldRow>
<InputField
2022-02-15 12:46:58 -08:00
id="displayName"
name="displayName"
label={t("common.display_name")}
placeholder={t("common.display_name")}
data-testid="joincall_displayName"
2022-01-05 16:09:51 -08:00
type="text"
required
autoComplete="off"
/>
</FieldRow>
<Text size="sm">
2025-03-31 14:18:45 +02:00
<Trans i18nKey="room_auth_view_ssla_caption">
2022-10-10 09:19:10 -04:00
By clicking "Join call now", you agree to our{" "}
2025-03-31 14:18:45 +02:00
<ExternalLink href={Config.get().ssla}>
Software and Services License Agreement (SSLA)
</ExternalLink>
2022-10-10 09:19:10 -04:00
</Trans>
</Text>
2022-01-05 16:09:51 -08:00
{error && (
<FieldRow>
2022-10-10 09:19:10 -04:00
<ErrorMessage error={error} />
2022-01-05 16:09:51 -08:00
</FieldRow>
)}
2023-05-11 15:16:17 +01:00
<Button
type="submit"
size="lg"
disabled={loading}
data-testid="joincall_joincall"
>
{loading
? t("common.loading")
: t("room_auth_view_continue_button")}
2022-01-05 16:09:51 -08:00
</Button>
<div id={recaptchaId} />
</Form>
</main>
<Text className={styles.footer}>
2023-11-20 13:00:43 +00:00
<Trans i18nKey="unauthenticated_view_body">
2022-10-14 18:38:33 -04:00
Not registered yet?{" "}
<Link to="/register" state={{ from: location }}>
2022-10-10 09:19:10 -04:00
Create an account
</Link>
</Trans>
</Text>
2022-01-05 16:09:51 -08:00
</div>
</>
);
2023-09-22 18:05:13 -04:00
};