Don't leave UnauthenticatedView if there was a room creation error

This commit is contained in:
Robin Townsend
2022-05-17 12:34:05 -04:00
parent c13040f0b0
commit 1e5539f165
6 changed files with 52 additions and 45 deletions

View File

@@ -15,6 +15,7 @@ limitations under the License.
*/
import React, { useCallback, useState } from "react";
import { useClient } from "../ClientContext";
import { Header, HeaderLogo, LeftNav, RightNav } from "../Header";
import { UserMenuContainer } from "../UserMenuContainer";
import { useHistory } from "react-router-dom";
@@ -34,12 +35,14 @@ import { generateRandomName } from "../auth/generateRandomName";
import { useShouldShowPtt } from "../useShouldShowPtt";
export function UnauthenticatedView() {
const { setClient } = useClient();
const shouldShowPtt = useShouldShowPtt();
const [loading, setLoading] = useState(false);
const [error, setError] = useState();
const [{ privacyPolicyUrl, recaptchaKey }, register] =
useInteractiveRegistration();
const { execute, reset, recaptchaId } = useRecaptcha(recaptchaKey);
const onSubmit = useCallback(
(e) => {
e.preventDefault();
@@ -53,7 +56,7 @@ export function UnauthenticatedView() {
setLoading(true);
const recaptchaResponse = await execute();
const userName = generateRandomName();
const client = await register(
const [client, session] = await register(
userName,
randomString(16),
displayName,
@@ -62,6 +65,9 @@ export function UnauthenticatedView() {
);
const roomIdOrAlias = await createRoom(client, roomName, ptt);
// Only consider the registration successful if we managed to create the room, too
setClient(client, session);
if (roomIdOrAlias) {
history.push(`/room/${roomIdOrAlias}`);
}