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.
|
|
|
|
*/
|
|
|
|
|
2022-01-05 16:09:51 -08:00
|
|
|
import React, { 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";
|
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";
|
2022-07-13 14:34:15 +01:00
|
|
|
import { useRegisterPasswordlessUser } from "../auth/useRegisterPasswordlessUser";
|
2022-01-05 15:35:12 -08:00
|
|
|
|
|
|
|
export function RoomAuthView() {
|
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>();
|
2022-07-13 14:34:15 +01:00
|
|
|
|
|
|
|
const { registerPasswordlessUser, recaptchaId, privacyPolicyUrl } =
|
|
|
|
useRegisterPasswordlessUser();
|
2022-05-17 12:34:05 -04:00
|
|
|
|
2022-01-05 16:09:51 -08:00
|
|
|
const onSubmit = useCallback(
|
|
|
|
(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
|
|
|
|
2022-07-13 14:34:15 +01:00
|
|
|
registerPasswordlessUser(displayName).catch((error) => {
|
|
|
|
console.error("Failed to register passwordless user", e);
|
2022-01-05 16:09:51 -08:00
|
|
|
setLoading(false);
|
|
|
|
setError(error);
|
|
|
|
});
|
|
|
|
},
|
2022-07-13 14:34:15 +01: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>
|
2022-02-02 15:09:16 -08:00
|
|
|
<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}>
|
2022-10-10 09:19:10 -04:00
|
|
|
<Headline className={styles.headline}>{t("Join call")}</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"
|
2022-10-10 09:19:10 -04:00
|
|
|
label={t("Display name")}
|
|
|
|
placeholder={t("Display name")}
|
2022-01-05 16:09:51 -08:00
|
|
|
type="text"
|
|
|
|
required
|
|
|
|
autoComplete="off"
|
|
|
|
/>
|
|
|
|
</FieldRow>
|
|
|
|
<Caption>
|
2022-10-10 09:19:10 -04:00
|
|
|
<Trans>
|
|
|
|
By clicking "Join call now", you agree to our{" "}
|
|
|
|
<Link href={privacyPolicyUrl}>Terms and conditions</Link>
|
|
|
|
</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>
|
|
|
|
)}
|
|
|
|
<Button type="submit" size="lg" disabled={loading}>
|
2022-10-10 09:19:10 -04:00
|
|
|
{loading ? t("Loading…") : t("Join call now")}
|
2022-01-05 16:09:51 -08:00
|
|
|
</Button>
|
|
|
|
<div id={recaptchaId} />
|
|
|
|
</Form>
|
|
|
|
</main>
|
|
|
|
<Body className={styles.footer}>
|
2022-10-10 09:19:10 -04:00
|
|
|
<Trans>
|
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>
|
|
|
|
</>
|
|
|
|
);
|
2022-01-05 15:35:12 -08:00
|
|
|
}
|