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

203 lines
6.2 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
Please see LICENSE in the repository root for full details.
2022-05-04 17:09:48 +01:00
*/
2023-09-22 18:05:13 -04:00
import { FC, FormEventHandler, ReactNode, useCallback, useState } from "react";
2022-08-12 16:46:53 -04:00
import { MatrixClient } from "matrix-js-sdk/src/client";
2022-10-10 09:19:10 -04:00
import { Trans, useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
import { Button } from "@vector-im/compound-web";
2022-08-02 00:46:16 +02:00
2022-01-05 15:06:51 -08:00
import styles from "./CallEndedView.module.css";
import feedbackStyle from "../input/FeedbackInput.module.css";
2022-01-05 17:27:01 -08:00
import { useProfile } from "../profile/useProfile";
import { Body, Headline } from "../typography/Typography";
2022-01-05 15:06:51 -08:00
import { Header, HeaderLogo, LeftNav, RightNav } from "../Header";
import { PosthogAnalytics } from "../analytics/PosthogAnalytics";
import { FieldRow, InputField } from "../input/Input";
import { StarRatingInput } from "../input/StarRatingInput";
import { RageshakeButton } from "../settings/RageshakeButton";
import { Link } from "../button/Link";
import { LinkButton } from "../button";
2022-01-05 15:06:51 -08:00
2023-09-18 20:47:47 -04:00
interface Props {
client: MatrixClient;
isPasswordlessUser: boolean;
2023-09-18 20:47:47 -04:00
confineToRoom: boolean;
endedCallId: string;
leaveError?: Error;
reconnect: () => void;
2023-09-18 20:47:47 -04:00
}
export const CallEndedView: FC<Props> = ({
client,
isPasswordlessUser,
confineToRoom,
endedCallId,
leaveError,
reconnect,
}) => {
2022-10-10 09:19:10 -04:00
const { t } = useTranslation();
const history = useHistory();
2022-01-05 15:06:51 -08:00
const { displayName } = useProfile(client);
2024-07-25 14:33:37 +02:00
const [surveySubmitted, setSurveySubmitted] = useState(false);
const [starRating, setStarRating] = useState(0);
const [submitting, setSubmitting] = useState(false);
const [submitDone, setSubmitDone] = useState(false);
2024-07-25 14:33:37 +02:00
const submitSurvey: FormEventHandler<HTMLFormElement> = useCallback(
(e) => {
e.preventDefault();
const data = new FormData(e.target as HTMLFormElement);
const feedbackText = data.get("feedbackText") as string;
PosthogAnalytics.instance.eventQualitySurvey.track(
endedCallId,
feedbackText,
2023-10-11 10:42:04 -04:00
starRating,
);
setSubmitting(true);
setTimeout(() => {
setSubmitDone(true);
setTimeout(() => {
if (isPasswordlessUser) {
// setting this renders the callEndedView with the invitation to create an account
2024-07-25 14:33:37 +02:00
setSurveySubmitted(true);
2023-09-18 20:47:47 -04:00
} else if (!confineToRoom) {
// if the user already has an account immediately go back to the home screen
history.push("/");
}
}, 1000);
}, 1000);
},
2023-10-11 10:42:04 -04:00
[endedCallId, history, isPasswordlessUser, confineToRoom, starRating],
);
const createAccountDialog = isPasswordlessUser && (
<div className={styles.callEndedContent}>
2023-11-20 13:00:43 +00:00
<Trans i18nKey="call_ended_view.create_account_prompt">
<p>Why not finish by setting up a password to keep your account?</p>
<p>
You'll be able to keep your name and set an avatar for use on future
calls
</p>
</Trans>
<LinkButton className={styles.callEndedButton} to="/register">
2023-11-20 13:00:43 +00:00
{t("call_ended_view.create_account_button")}
</LinkButton>
</div>
);
const qualitySurveyDialog = (
<div className={styles.callEndedContent}>
2023-11-20 13:00:43 +00:00
<Trans i18nKey="call_ended_view.feedback_prompt">
<p>
We'd love to hear your feedback so we can improve your experience.
</p>
</Trans>
2024-07-25 14:33:37 +02:00
<form onSubmit={submitSurvey}>
<FieldRow>
<StarRatingInput starCount={5} onChange={setStarRating} required />
</FieldRow>
<FieldRow>
<InputField
className={feedbackStyle.feedback}
id="feedbackText"
name="feedbackText"
2023-11-20 13:00:43 +00:00
label={t("settings.feedback_tab_description_label")}
placeholder={t("settings.feedback_tab_description_label")}
type="textarea"
/>
</FieldRow>{" "}
<FieldRow>
{submitDone ? (
2023-11-20 13:00:43 +00:00
<Trans i18nKey="call_ended_view.feedback_done">
<p>Thanks for your feedback!</p>
</Trans>
) : (
<Button
type="submit"
className={styles.submitButton}
data-testid="home_go"
>
2023-11-20 13:00:43 +00:00
{submitting ? t("submitting") : t("action.submit")}
</Button>
)}
</FieldRow>
</form>
</div>
);
2022-01-05 15:06:51 -08:00
2023-09-22 18:05:13 -04:00
const renderBody = (): ReactNode => {
if (leaveError) {
return (
<>
<main className={styles.main}>
<Headline className={styles.headline}>
2023-11-20 13:00:43 +00:00
<Trans i18nKey="call_ended_view.body">
You were disconnected from the call
</Trans>
</Headline>
<div className={styles.disconnectedButtons}>
<Button onClick={reconnect}>
2023-11-20 13:00:43 +00:00
{t("call_ended_view.reconnect_button")}
</Button>
<div className={styles.rageshakeButton}>
<RageshakeButton description="***Call disconnected***" />
</div>
</div>
</main>
2023-09-18 20:47:47 -04:00
{!confineToRoom && (
<Body className={styles.footer}>
<Link to="/"> {t("return_home_button")} </Link>
2023-09-18 20:47:47 -04:00
</Body>
)}
</>
);
} else {
return (
<>
<main className={styles.main}>
<Headline className={styles.headline}>
{surveySubmitted
2023-11-20 13:00:43 +00:00
? t("call_ended_view.headline", {
displayName,
})
2023-11-20 13:00:43 +00:00
: t("call_ended_view.headline", {
displayName,
}) +
"\n" +
2023-11-20 13:00:43 +00:00
t("call_ended_view.survey_prompt")}
</Headline>
2023-09-18 20:47:47 -04:00
{(!surveySubmitted || confineToRoom) &&
PosthogAnalytics.instance.isEnabled()
? qualitySurveyDialog
: createAccountDialog}
</main>
2023-09-18 20:47:47 -04:00
{!confineToRoom && (
<Body className={styles.footer}>
<Link to="/"> {t("call_ended_view.not_now_button")} </Link>
2023-09-18 20:47:47 -04:00
</Body>
)}
</>
);
}
};
2022-01-05 15:06:51 -08:00
return (
<>
<Header>
2023-09-18 20:47:47 -04:00
<LeftNav>{!confineToRoom && <HeaderLogo />}</LeftNav>
2022-01-05 15:06:51 -08:00
<RightNav />
</Header>
<div className={styles.container}>{renderBody()}</div>
2022-01-05 15:06:51 -08:00
</>
);
2023-09-18 20:47:47 -04:00
};