Show an error dialog if poll creation or voting fails (#7201)
Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
c8765821b5
commit
965539da2d
4 changed files with 56 additions and 7 deletions
|
@ -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<IProps, IState
|
|||
this.matrixClient.sendEvent(
|
||||
this.props.room.roomId,
|
||||
POLL_START_EVENT_TYPE.name,
|
||||
makePollContent(this.state.question, this.state.options, POLL_KIND_DISCLOSED.name),
|
||||
).then(() => 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 });
|
||||
}
|
||||
},
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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<IBodyProps, IState> {
|
|||
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 });
|
||||
|
|
|
@ -216,9 +216,17 @@ class PollButton extends React.PureComponent<IPollButtonProps> {
|
|||
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
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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 <a>pinned messages</a> for the room %(count)s times.|other": "%(severalUsers)schanged the <a>pinned messages</a> for the room %(count)s times.",
|
||||
"%(oneUser)schanged the <a>pinned messages</a> for the room %(count)s times.|other": "%(oneUser)schanged the <a>pinned messages</a> 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...",
|
||||
|
|
Loading…
Reference in a new issue