From 8791b10ca92ee26e8bac32ed0aa20b63ce7a817d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 4 Sep 2021 16:36:01 +0200 Subject: [PATCH] Convert FeedbackDialog to TS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/CountlyAnalytics.ts | 4 +++- .../{FeedbackDialog.js => FeedbackDialog.tsx} | 20 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) rename src/components/views/dialogs/{FeedbackDialog.js => FeedbackDialog.tsx} (90%) diff --git a/src/CountlyAnalytics.ts b/src/CountlyAnalytics.ts index 72b0462bcd..be35597734 100644 --- a/src/CountlyAnalytics.ts +++ b/src/CountlyAnalytics.ts @@ -30,6 +30,8 @@ const HEARTBEAT_INTERVAL = 5_000; // ms const SESSION_UPDATE_INTERVAL = 60; // seconds const MAX_PENDING_EVENTS = 1000; +export type Rating = 1 | 2 | 3 | 4 | 5; + enum Orientation { Landscape = "landscape", Portrait = "portrait", @@ -451,7 +453,7 @@ export default class CountlyAnalytics { window.removeEventListener("scroll", this.onUserActivity); } - public reportFeedback(rating: 1 | 2 | 3 | 4 | 5, comment: string) { + public reportFeedback(rating: Rating, comment: string) { this.track("[CLY]_star_rating", { rating, comment }, null, {}, true); } diff --git a/src/components/views/dialogs/FeedbackDialog.js b/src/components/views/dialogs/FeedbackDialog.tsx similarity index 90% rename from src/components/views/dialogs/FeedbackDialog.js rename to src/components/views/dialogs/FeedbackDialog.tsx index ceb8cb2175..00112ab0c7 100644 --- a/src/components/views/dialogs/FeedbackDialog.js +++ b/src/components/views/dialogs/FeedbackDialog.tsx @@ -19,7 +19,7 @@ import QuestionDialog from './QuestionDialog'; import { _t } from '../../../languageHandler'; import Field from "../elements/Field"; import AccessibleButton from "../elements/AccessibleButton"; -import CountlyAnalytics from "../../../CountlyAnalytics"; +import CountlyAnalytics, { Rating } from "../../../CountlyAnalytics"; import SdkConfig from "../../../SdkConfig"; import Modal from "../../../Modal"; import BugReportDialog from "./BugReportDialog"; @@ -30,19 +30,23 @@ const existingIssuesUrl = "https://github.com/vector-im/element-web/issues" + "?q=is%3Aopen+is%3Aissue+sort%3Areactions-%2B1-desc"; const newIssueUrl = "https://github.com/vector-im/element-web/issues/new/choose"; -export default (props) => { - const [rating, setRating] = useState(""); - const [comment, setComment] = useState(""); +interface IProps { + onFinished: () => void; +} - const onDebugLogsLinkClick = () => { +const FeedbackDialog: React.FC = (props: IProps) => { + const [rating, setRating] = useState(); + const [comment, setComment] = useState(""); + + const onDebugLogsLinkClick = (): void => { props.onFinished(); Modal.createTrackedDialog('Bug Report Dialog', '', BugReportDialog, {}); }; const hasFeedback = CountlyAnalytics.instance.canEnable(); - const onFinished = (sendFeedback) => { + const onFinished = (sendFeedback: boolean): void => { if (hasFeedback && sendFeedback) { - CountlyAnalytics.instance.reportFeedback(parseInt(rating, 10), comment); + CountlyAnalytics.instance.reportFeedback((parseInt(rating) as Rating), comment); Modal.createTrackedDialog('Feedback sent', '', InfoDialog, { title: _t('Feedback sent'), description: _t('Thank you!'), @@ -142,3 +146,5 @@ export default (props) => { onFinished={onFinished} />); }; + +export default FeedbackDialog;