Files
ThreadNet-Web/src/components/views/dialogs/FeedbackDialog.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

155 lines
5.6 KiB
TypeScript
Raw Normal View History

2020-10-29 15:53:14 +00:00
/*
2024-09-09 14:57:16 +01:00
Copyright 2018-2024 New Vector Ltd.
2020-10-29 15:53:14 +00:00
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
2020-10-29 15:53:14 +00:00
*/
import React, { useEffect, useRef, useState } from "react";
2021-12-09 09:10:23 +00:00
2020-10-29 15:53:14 +00:00
import QuestionDialog from "./QuestionDialog";
import { _t } from "../../../languageHandler";
import Field from "../elements/Field";
import AccessibleButton from "../elements/AccessibleButton";
import SdkConfig from "../../../SdkConfig";
import Modal from "../../../Modal";
import BugReportDialog from "./BugReportDialog";
import InfoDialog from "./InfoDialog";
import { submitFeedback } from "../../../rageshake/submit-rageshake";
import { useStateToggle } from "../../../hooks/useStateToggle";
import StyledCheckbox from "../elements/StyledCheckbox";
import ExternalLink from "../elements/ExternalLink";
2020-10-29 15:53:14 +00:00
interface IProps {
feature?: string;
onFinished(): void;
}
2020-10-29 15:53:14 +00:00
2021-09-04 16:36:01 +02:00
const FeedbackDialog: React.FC<IProps> = (props: IProps) => {
const feedbackRef = useRef<Field>(null);
2021-09-04 16:36:01 +02:00
const [comment, setComment] = useState<string>("");
const [canContact, toggleCanContact] = useStateToggle(false);
useEffect(() => {
// autofocus doesn't work on textareas
feedbackRef.current?.focus();
}, []);
2021-09-04 16:36:01 +02:00
const onDebugLogsLinkClick = (): void => {
2020-10-29 15:53:14 +00:00
props.onFinished();
2022-06-14 17:51:51 +01:00
Modal.createDialog(BugReportDialog, {});
2020-10-29 15:53:14 +00:00
};
const hasFeedback = !!SdkConfig.get().bug_report_endpoint_url;
2021-09-04 16:36:01 +02:00
const onFinished = (sendFeedback: boolean): void => {
2020-10-29 15:53:14 +00:00
if (hasFeedback && sendFeedback) {
const label = props.feature ? `${props.feature}-feedback` : "feedback";
submitFeedback(label, comment, canContact);
2022-06-14 17:51:51 +01:00
Modal.createDialog(InfoDialog, {
title: _t("feedback|sent"),
description: _t("bug_reporting|thank_you"),
2020-10-29 15:53:14 +00:00
});
}
props.onFinished();
2020-10-29 15:53:14 +00:00
};
let feedbackSection: JSX.Element | undefined;
if (hasFeedback) {
feedbackSection = (
<div className="mx_FeedbackDialog_section mx_FeedbackDialog_rateApp">
<h3>{_t("feedback|comment_label")}</h3>
2020-10-29 15:53:14 +00:00
<p>{_t("feedback|platform_username")}</p>
2020-10-29 15:53:14 +00:00
<Field
id="feedbackComment"
label={_t("common|feedback")}
type="text"
autoComplete="off"
value={comment}
element="textarea"
onChange={(ev) => {
setComment(ev.target.value);
}}
ref={feedbackRef}
/>
2020-10-29 15:53:14 +00:00
<StyledCheckbox checked={canContact} onChange={toggleCanContact}>
{_t("feedback|may_contact_label")}
</StyledCheckbox>
</div>
);
2020-10-29 15:53:14 +00:00
}
let bugReports: JSX.Element | undefined;
if (hasFeedback) {
bugReports = (
<p className="mx_FeedbackDialog_section_microcopy">
{_t(
"feedback|pro_type",
{},
{
debugLogsLink: (sub) => (
<AccessibleButton kind="link_inline" onClick={onDebugLogsLinkClick}>
{sub}
</AccessibleButton>
),
},
2022-12-12 12:24:14 +01:00
)}
</p>
);
}
const existingIssuesUrl = SdkConfig.getObject("feedback").get("existing_issues_url");
const newIssueUrl = SdkConfig.getObject("feedback").get("new_issue_url");
2020-10-29 15:53:14 +00:00
return (
<QuestionDialog
className="mx_FeedbackDialog"
2023-08-15 09:43:15 +01:00
hasCancelButton={hasFeedback}
title={_t("common|feedback")}
2020-10-29 15:53:14 +00:00
description={
<React.Fragment>
<div className="mx_FeedbackDialog_section mx_FeedbackDialog_reportBug">
<h3>{_t("common|report_a_bug")}</h3>
2020-10-29 15:53:14 +00:00
<p>
{_t(
"feedback|existing_issue_link",
2020-10-29 15:53:14 +00:00
{},
{
existingIssuesLink: (sub) => {
return (
<ExternalLink
target="_blank"
rel="noreferrer noopener"
href={existingIssuesUrl}
>
2020-10-29 15:53:14 +00:00
{sub}
</ExternalLink>
2020-10-29 15:53:14 +00:00
);
},
newIssueLink: (sub) => {
return (
<ExternalLink target="_blank" rel="noreferrer noopener" href={newIssueUrl}>
2020-10-29 15:53:14 +00:00
{sub}
</ExternalLink>
2020-10-29 15:53:14 +00:00
);
},
},
2022-12-12 12:24:14 +01:00
)}
2020-10-29 15:53:14 +00:00
</p>
{bugReports}
2020-10-29 15:53:14 +00:00
</div>
{feedbackSection}
2020-10-29 15:53:14 +00:00
</React.Fragment>
}
button={hasFeedback ? _t("feedback|send_feedback_action") : _t("action|go_back")}
buttonDisabled={hasFeedback && !comment}
2020-10-29 15:53:14 +00:00
onFinished={onFinished}
/>
);
};
2021-09-04 16:36:01 +02:00
export default FeedbackDialog;