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

128 lines
4.1 KiB
TypeScript
Raw Normal View History

2022-05-04 17:09:48 +01:00
/*
2023-01-03 16:55:26 +00:00
Copyright 2022 New Vector Ltd
2022-05-04 17:09:48 +01:00
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.
*/
2023-09-22 18:05:13 -04:00
import { 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";
2023-09-25 18:04:34 +01:00
import { logger } from "matrix-js-sdk/src/logger";
2022-08-02 00:46:16 +02:00
2022-01-05 16:09:51 -08:00
import styles from "./RoomAuthView.module.css";
import { Button } from "../button";
import { Body, Caption, Link, Headline } from "../typography/Typography";
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";
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();
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}>
2023-11-20 13:00:43 +00:00
<Headline className={styles.headline}>
{t("lobby.join_button")}
</Headline>
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>
<Caption>
2023-11-20 13:00:43 +00:00
<Trans i18nKey="room_auth_view_eula_caption">
2022-10-10 09:19:10 -04:00
By clicking "Join call now", you agree to our{" "}
2023-07-06 08:53:57 +02:00
<Link href={Config.get().eula}>
2023-07-06 08:43:00 +02:00
End User Licensing Agreement (EULA)
</Link>
2022-10-10 09:19:10 -04:00
</Trans>
2022-01-05 16:09:51 -08:00
</Caption>
{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"
>
2023-11-20 13:00:43 +00:00
{loading ? t("common.loading") : t("room_auth_view_join_button")}
2022-01-05 16:09:51 -08:00
</Button>
<div id={recaptchaId} />
</Form>
</main>
<Body 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?{" "}
2022-10-10 09:19:10 -04:00
<Link
color="primary"
to={{ pathname: "/login", state: { from: location } }}
>
Create an account
</Link>
</Trans>
2022-01-05 16:09:51 -08:00
</Body>
</div>
</>
);
2023-09-22 18:05:13 -04:00
};