From 965539da2d2c16e6bb830bff88f5d5d2e853c6cb Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Thu, 25 Nov 2021 17:00:13 +0000 Subject: [PATCH] Show an error dialog if poll creation or voting fails (#7201) Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- .../views/elements/PollCreateDialog.tsx | 32 ++++++++++++++++--- src/components/views/messages/MPollBody.tsx | 13 ++++++++ .../views/rooms/MessageComposer.tsx | 14 ++++++-- src/i18n/strings/en_EN.json | 4 +++ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/components/views/elements/PollCreateDialog.tsx b/src/components/views/elements/PollCreateDialog.tsx index 11a1e72b83..d015347d66 100644 --- a/src/components/views/elements/PollCreateDialog.tsx +++ b/src/components/views/elements/PollCreateDialog.tsx @@ -16,7 +16,9 @@ limitations under the License. import ScrollableBaseModal, { IScrollableBaseState } from "../dialogs/ScrollableBaseModal"; import { IDialogProps } from "../dialogs/IDialogProps"; +import QuestionDialog from "../dialogs/QuestionDialog"; import React, { ChangeEvent, createRef } from "react"; +import Modal from '../../../Modal'; import { _t } from "../../../languageHandler"; import { Room } from "matrix-js-sdk/src/models/room"; import { arrayFastClone, arraySeed } from "../../../utils/arrays"; @@ -98,10 +100,32 @@ export default class PollCreateDialog extends ScrollableBaseModal this.props.onFinished(true)).catch(e => { - console.error("Failed to submit poll event:", e); - this.setState({ busy: false, canSubmit: true }); + makePollContent( + this.state.question, this.state.options, POLL_KIND_DISCLOSED.name, + ), + ).then( + () => this.props.onFinished(true), + ).catch(e => { + console.error("Failed to post poll:", e); + Modal.createTrackedDialog( + 'Failed to post poll', + '', + QuestionDialog, + { + title: _t("Failed to post poll"), + description: _t( + "Sorry, the poll you tried to create was not posted."), + button: _t('Try again'), + cancelButton: _t('Cancel'), + onFinished: (tryAgain: boolean) => { + if (!tryAgain) { + this.cancel(); + } else { + this.setState({ busy: false, canSubmit: true }); + } + }, + }, + ); }); } diff --git a/src/components/views/messages/MPollBody.tsx b/src/components/views/messages/MPollBody.tsx index e9eede77fc..b93c27eaa5 100644 --- a/src/components/views/messages/MPollBody.tsx +++ b/src/components/views/messages/MPollBody.tsx @@ -17,6 +17,7 @@ limitations under the License. import React from 'react'; import { _t } from '../../../languageHandler'; import { replaceableComponent } from "../../../utils/replaceableComponent"; +import Modal from '../../../Modal'; import { IBodyProps } from "./IBodyProps"; import { IPollAnswer, @@ -29,6 +30,7 @@ import StyledRadioButton from '../elements/StyledRadioButton'; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { Relations } from 'matrix-js-sdk/src/models/relations'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; +import ErrorDialog from '../dialogs/ErrorDialog'; // TODO: [andyb] Use extensible events library when ready const TEXT_NODE_TYPE = "org.matrix.msc1767.text"; @@ -123,6 +125,17 @@ export default class MPollBody extends React.Component { responseContent, ).catch(e => { console.error("Failed to submit poll response event:", e); + + Modal.createTrackedDialog( + 'Vote not registered', + '', + ErrorDialog, + { + title: _t("Vote not registered"), + description: _t( + "Sorry, your vote was not registered. Please try again."), + }, + ); }); this.setState({ selected: answerId }); diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index 98c2bc3f28..f625389da5 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -216,9 +216,17 @@ class PollButton extends React.PureComponent { description: _t("You do not have permission to start polls in this room."), }); } else { - Modal.createTrackedDialog('Polls', 'create', PollCreateDialog, { - room: this.props.room, - }, 'mx_CompoundDialog'); + Modal.createTrackedDialog( + 'Polls', + 'create', + PollCreateDialog, + { + room: this.props.room, + }, + 'mx_CompoundDialog', + false, // isPriorityModal + true, // isStaticModal + ); } }; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index b5e7f5166c..1bacfa9e6c 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2051,6 +2051,8 @@ "Declining …": "Declining …", "%(name)s wants to verify": "%(name)s wants to verify", "You sent a verification request": "You sent a verification request", + "Vote not registered": "Vote not registered", + "Sorry, your vote was not registered. Please try again.": "Sorry, your vote was not registered. Please try again.", "%(count)s votes|other": "%(count)s votes", "%(count)s votes|one": "%(count)s vote", "Based on %(count)s votes|other": "Based on %(count)s votes", @@ -2207,6 +2209,8 @@ "%(severalUsers)schanged the pinned messages for the room %(count)s times.|other": "%(severalUsers)schanged the pinned messages for the room %(count)s times.", "%(oneUser)schanged the pinned messages for the room %(count)s times.|other": "%(oneUser)schanged the pinned messages for the room %(count)s times.", "Create Poll": "Create Poll", + "Failed to post poll": "Failed to post poll", + "Sorry, the poll you tried to create was not posted.": "Sorry, the poll you tried to create was not posted.", "What is your poll question or topic?": "What is your poll question or topic?", "Question or topic": "Question or topic", "Write something...": "Write something...",