Files
element-call/src/settings/FeedbackSettingsTab.tsx
T

119 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-05-05 11:44:35 +02:00
/*
Copyright 2022-2024 New Vector Ltd.
2023-05-05 11:44:35 +02:00
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE in the repository root for full details.
2023-05-05 11:44:35 +02:00
*/
2024-12-11 09:36:59 +00:00
import { type ChangeEvent, type FC, useCallback } from "react";
2025-02-03 13:28:12 +01:00
import { secureRandomString } from "matrix-js-sdk/src/randomstring";
2024-12-11 09:36:59 +00:00
import { Trans, useTranslation } from "react-i18next";
import { Button, Text } from "@vector-im/compound-web";
import { logger } from "matrix-js-sdk/src/logger";
2023-05-05 11:44:35 +02:00
import { FieldRow, InputField, ErrorMessage } from "../input/Input";
import { useSubmitRageshake, useRageshakeRequest } from "./submit-rageshake";
import feedbackStyles from "../input/FeedbackInput.module.css";
2024-12-11 09:36:59 +00:00
import { AnalyticsNotice } from "../analytics/AnalyticsNotice";
import { useOptInAnalytics } from "./settings";
2023-05-05 11:44:35 +02:00
interface Props {
roomId?: string;
}
2023-09-22 18:05:13 -04:00
export const FeedbackSettingsTab: FC<Props> = ({ roomId }) => {
2023-05-05 11:44:35 +02:00
const { t } = useTranslation();
2023-05-05 19:36:23 +02:00
const { submitRageshake, sending, sent, error } = useSubmitRageshake();
2023-05-05 11:44:35 +02:00
const sendRageshakeRequest = useRageshakeRequest();
const onSubmitFeedback = useCallback(
2023-06-30 16:43:28 +01:00
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
2023-05-05 11:44:35 +02:00
(e) => {
e.preventDefault();
const data = new FormData(e.target);
const descriptionData = data.get("description");
const description =
typeof descriptionData === "string" ? descriptionData : "";
const sendLogs = Boolean(data.get("sendLogs"));
2025-02-03 13:28:12 +01:00
const rageshakeRequestId = secureRandomString(16);
2023-05-05 11:44:35 +02:00
submitRageshake({
description,
sendLogs,
rageshakeRequestId,
roomId,
}).catch((e) => {
logger.error("Failed to send feedback rageshake", e);
2023-05-05 11:44:35 +02:00
});
if (roomId && sendLogs) {
sendRageshakeRequest(roomId, rageshakeRequestId);
}
},
2023-10-11 10:42:04 -04:00
[submitRageshake, roomId, sendRageshakeRequest],
2023-05-05 11:44:35 +02:00
);
2024-12-11 09:36:59 +00:00
const [optInAnalytics, setOptInAnalytics] = useOptInAnalytics();
const optInDescription = (
<Text size="sm">
<Trans i18nKey="settings.opt_in_description">
<AnalyticsNotice />
<br />
You may withdraw consent by unchecking this box. If you are currently in
a call, this setting will take effect at the end of the call.
</Trans>
</Text>
);
2023-05-05 11:44:35 +02:00
return (
<div>
2024-12-11 09:36:59 +00:00
<h4>{t("common.analytics")}</h4>
<FieldRow>
<InputField
id="optInAnalytics"
type="checkbox"
checked={optInAnalytics ?? undefined}
description={optInDescription}
onChange={(event: ChangeEvent<HTMLInputElement>): void => {
setOptInAnalytics?.(event.target.checked);
}}
/>
</FieldRow>
<h4>{t("settings.feedback_tab_h4")}</h4>
<Text>{t("settings.feedback_tab_body")}</Text>
2023-05-05 11:44:35 +02:00
<form onSubmit={onSubmitFeedback}>
<FieldRow>
<InputField
className={feedbackStyles.feedback}
2023-05-05 11:44:35 +02:00
id="description"
name="description"
2023-11-20 13:00:43 +00:00
label={t("settings.feedback_tab_description_label")}
placeholder={t("settings.feedback_tab_description_label")}
2023-05-05 11:44:35 +02:00
type="textarea"
2023-05-05 19:36:23 +02:00
disabled={sending || sent}
2023-05-05 11:44:35 +02:00
/>
</FieldRow>
{!sent && (
2023-05-05 11:44:35 +02:00
<FieldRow>
2023-05-05 19:36:23 +02:00
<InputField
id="sendLogs"
name="sendLogs"
2023-11-20 13:00:43 +00:00
label={t("settings.feedback_tab_send_logs_label")}
2023-05-05 19:36:23 +02:00
type="checkbox"
defaultChecked
/>
<Button type="submit" disabled={sending}>
2023-11-30 17:31:12 +01:00
{sending ? t("submitting") : t("action.submit")}
2023-05-05 19:36:23 +02:00
</Button>
2023-05-05 11:44:35 +02:00
</FieldRow>
)}
<FieldRow>
{error && <ErrorMessage error={error} />}
{sent && <Text>{t("settings.feedback_tab_thank_you")}</Text>}
</FieldRow>
2023-05-05 11:44:35 +02:00
</form>
</div>
);
2023-09-22 18:05:13 -04:00
};