2022-12-14 21:46:49 +08:00
|
|
|
import React, { Component, createRef } from 'react';
|
2018-10-16 03:58:07 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2022-04-29 04:18:35 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2018-10-18 22:31:17 +08:00
|
|
|
import { Session } from 'meteor/session';
|
2022-02-15 03:26:19 +08:00
|
|
|
import Checkbox from '/imports/ui/components/common/checkbox/component';
|
2022-04-29 04:18:35 +08:00
|
|
|
import DraggableTextArea from '/imports/ui/components/poll/dragAndDrop/component';
|
|
|
|
import LiveResult from '/imports/ui/components/poll/live-result/component';
|
2021-11-04 22:19:38 +08:00
|
|
|
import Styled from './styles';
|
2022-04-29 04:18:35 +08:00
|
|
|
import Toggle from '/imports/ui/components/common/switch/component';
|
2021-05-18 04:25:07 +08:00
|
|
|
import { PANELS, ACTIONS } from '../layout/enums';
|
2022-05-24 01:09:50 +08:00
|
|
|
import { addNewAlert } from '../screenreader-alert/service';
|
|
|
|
import Header from '/imports/ui/components/common/control-header/component';
|
2018-09-15 01:50:18 +08:00
|
|
|
|
2018-09-24 06:57:03 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
pollPaneTitle: {
|
|
|
|
id: 'app.poll.pollPaneTitle',
|
|
|
|
description: 'heading label for the poll menu',
|
|
|
|
},
|
2018-10-30 23:57:10 +08:00
|
|
|
closeLabel: {
|
|
|
|
id: 'app.poll.closeLabel',
|
|
|
|
description: 'label for poll pane close button',
|
|
|
|
},
|
2018-09-24 06:57:03 +08:00
|
|
|
hidePollDesc: {
|
|
|
|
id: 'app.poll.hidePollDesc',
|
|
|
|
description: 'aria label description for hide poll button',
|
|
|
|
},
|
|
|
|
quickPollInstruction: {
|
|
|
|
id: 'app.poll.quickPollInstruction',
|
|
|
|
description: 'instructions for using pre configured polls',
|
|
|
|
},
|
2018-09-25 06:43:54 +08:00
|
|
|
activePollInstruction: {
|
|
|
|
id: 'app.poll.activePollInstruction',
|
|
|
|
description: 'instructions displayed when a poll is active',
|
|
|
|
},
|
2021-02-08 20:06:15 +08:00
|
|
|
dragDropPollInstruction: {
|
|
|
|
id: 'app.poll.dragDropPollInstruction',
|
|
|
|
description: 'instructions for upload poll options via drag and drop',
|
|
|
|
},
|
2019-02-02 11:56:15 +08:00
|
|
|
ariaInputCount: {
|
|
|
|
id: 'app.poll.ariaInputCount',
|
|
|
|
description: 'aria label for custom poll input field',
|
|
|
|
},
|
2018-09-24 06:57:03 +08:00
|
|
|
customPlaceholder: {
|
|
|
|
id: 'app.poll.customPlaceholder',
|
|
|
|
description: 'custom poll input field placeholder text',
|
|
|
|
},
|
2019-03-09 04:46:25 +08:00
|
|
|
noPresentationSelected: {
|
|
|
|
id: 'app.poll.noPresentationSelected',
|
|
|
|
description: 'no presentation label',
|
|
|
|
},
|
|
|
|
clickHereToSelect: {
|
|
|
|
id: 'app.poll.clickHereToSelect',
|
|
|
|
description: 'open uploader modal button label',
|
|
|
|
},
|
2020-09-22 06:52:38 +08:00
|
|
|
questionErr: {
|
|
|
|
id: 'app.poll.questionErr',
|
|
|
|
description: 'question text area error label',
|
|
|
|
},
|
2022-03-22 01:58:11 +08:00
|
|
|
questionAndOptionsPlaceholder: {
|
|
|
|
id: 'app.poll.questionAndoptions.label',
|
|
|
|
description: 'poll input questions and options label',
|
|
|
|
},
|
2022-04-29 04:18:35 +08:00
|
|
|
customInputToggleLabel: {
|
|
|
|
id: 'app.poll.customInput.label',
|
|
|
|
description: 'poll custom input toogle button label',
|
2022-03-22 01:58:11 +08:00
|
|
|
},
|
2022-04-29 04:18:35 +08:00
|
|
|
customInputInstructionsLabel: {
|
|
|
|
id: 'app.poll.customInputInstructions.label',
|
|
|
|
description: 'poll custom input instructions label',
|
2022-03-22 01:58:11 +08:00
|
|
|
},
|
2022-03-22 03:44:21 +08:00
|
|
|
maxOptionsWarning: {
|
|
|
|
id: 'app.poll.maxOptionsWarning.label',
|
2022-03-22 01:58:11 +08:00
|
|
|
description: 'poll max options error',
|
|
|
|
},
|
2020-09-22 06:52:38 +08:00
|
|
|
optionErr: {
|
|
|
|
id: 'app.poll.optionErr',
|
|
|
|
description: 'poll input error label',
|
|
|
|
},
|
2018-10-03 11:24:34 +08:00
|
|
|
tf: {
|
|
|
|
id: 'app.poll.tf',
|
2018-09-24 06:57:03 +08:00
|
|
|
description: 'label for true / false poll',
|
|
|
|
},
|
2018-10-03 11:24:34 +08:00
|
|
|
a4: {
|
|
|
|
id: 'app.poll.a4',
|
2018-09-24 06:57:03 +08:00
|
|
|
description: 'label for A / B / C / D poll',
|
|
|
|
},
|
2020-09-21 20:07:36 +08:00
|
|
|
delete: {
|
|
|
|
id: 'app.poll.optionDelete.label',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
questionLabel: {
|
|
|
|
id: 'app.poll.question.label',
|
|
|
|
description: '',
|
|
|
|
},
|
2021-10-01 02:55:46 +08:00
|
|
|
optionalQuestionLabel: {
|
|
|
|
id: 'app.poll.optionalQuestion.label',
|
|
|
|
description: '',
|
|
|
|
},
|
2020-09-21 20:07:36 +08:00
|
|
|
userResponse: {
|
|
|
|
id: 'app.poll.userResponse.label',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
responseChoices: {
|
|
|
|
id: 'app.poll.responseChoices.label',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
typedResponseDesc: {
|
|
|
|
id: 'app.poll.typedResponse.desc',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
responseTypesLabel: {
|
|
|
|
id: 'app.poll.responseTypes.label',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
addOptionLabel: {
|
|
|
|
id: 'app.poll.addItem.label',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
startPollLabel: {
|
|
|
|
id: 'app.poll.start.label',
|
|
|
|
description: '',
|
|
|
|
},
|
2021-04-29 23:10:18 +08:00
|
|
|
secretPollLabel: {
|
|
|
|
id: 'app.poll.secretPoll.label',
|
|
|
|
description: '',
|
|
|
|
},
|
2021-05-26 19:34:48 +08:00
|
|
|
isSecretPollLabel: {
|
2021-06-17 21:25:03 +08:00
|
|
|
id: 'app.poll.secretPoll.isSecretLabel',
|
2021-05-26 19:34:48 +08:00
|
|
|
description: '',
|
|
|
|
},
|
2020-09-21 20:07:36 +08:00
|
|
|
true: {
|
|
|
|
id: 'app.poll.answer.true',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
false: {
|
|
|
|
id: 'app.poll.answer.false',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
a: {
|
|
|
|
id: 'app.poll.answer.a',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
b: {
|
|
|
|
id: 'app.poll.answer.b',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
c: {
|
|
|
|
id: 'app.poll.answer.c',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
d: {
|
|
|
|
id: 'app.poll.answer.d',
|
|
|
|
description: '',
|
2018-09-24 06:57:03 +08:00
|
|
|
},
|
2022-03-22 01:58:11 +08:00
|
|
|
e: {
|
|
|
|
id: 'app.poll.answer.e',
|
|
|
|
description: '',
|
|
|
|
},
|
2021-02-19 00:06:21 +08:00
|
|
|
yna: {
|
|
|
|
id: 'app.poll.yna',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
yes: {
|
|
|
|
id: 'app.poll.y',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
no: {
|
|
|
|
id: 'app.poll.n',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
abstention: {
|
|
|
|
id: 'app.poll.abstention',
|
|
|
|
description: '',
|
|
|
|
},
|
2021-02-08 17:57:39 +08:00
|
|
|
enableMultipleResponseLabel: {
|
|
|
|
id: 'app.poll.enableMultipleResponseLabel',
|
2021-02-04 21:59:16 +08:00
|
|
|
description: 'label for checkbox to enable multiple choice',
|
2021-02-08 17:57:39 +08:00
|
|
|
},
|
2021-08-11 12:10:41 +08:00
|
|
|
startPollDesc: {
|
|
|
|
id: 'app.poll.startPollDesc',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
showRespDesc: {
|
|
|
|
id: 'app.poll.showRespDesc',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
addRespDesc: {
|
|
|
|
id: 'app.poll.addRespDesc',
|
|
|
|
description: '',
|
|
|
|
},
|
|
|
|
deleteRespDesc: {
|
|
|
|
id: 'app.poll.deleteRespDesc',
|
|
|
|
description: '',
|
|
|
|
},
|
2021-08-19 04:02:46 +08:00
|
|
|
on: {
|
|
|
|
id: 'app.switch.onLabel',
|
|
|
|
description: 'label for toggle switch on state',
|
|
|
|
},
|
|
|
|
off: {
|
|
|
|
id: 'app.switch.offLabel',
|
|
|
|
description: 'label for toggle switch off state',
|
|
|
|
},
|
2021-09-13 08:03:03 +08:00
|
|
|
removePollOpt: {
|
|
|
|
id: 'app.poll.removePollOpt',
|
|
|
|
description: 'screen reader alert for removed poll option',
|
|
|
|
},
|
2021-09-13 08:11:45 +08:00
|
|
|
emptyPollOpt: {
|
|
|
|
id: 'app.poll.emptyPollOpt',
|
|
|
|
description: 'screen reader for blank poll option',
|
|
|
|
},
|
2022-04-29 04:18:35 +08:00
|
|
|
pollingQuestion: {
|
|
|
|
id: 'app.polling.pollQuestionTitle',
|
|
|
|
description: 'polling question header',
|
|
|
|
}
|
2018-09-24 06:57:03 +08:00
|
|
|
});
|
|
|
|
|
2021-04-30 00:54:39 +08:00
|
|
|
const POLL_SETTINGS = Meteor.settings.public.poll;
|
|
|
|
|
2022-04-29 04:18:35 +08:00
|
|
|
const ALLOW_CUSTOM_INPUT = POLL_SETTINGS.allowCustomResponseInput;
|
2021-06-18 22:02:09 +08:00
|
|
|
const MAX_CUSTOM_FIELDS = POLL_SETTINGS.maxCustom;
|
2021-04-30 00:54:39 +08:00
|
|
|
const MAX_INPUT_CHARS = POLL_SETTINGS.maxTypedAnswerLength;
|
2022-04-29 04:18:35 +08:00
|
|
|
const MIN_OPTIONS_LENGTH = 2;
|
2022-03-22 01:58:11 +08:00
|
|
|
const QUESTION_MAX_INPUT_CHARS = 1200;
|
|
|
|
|
2019-07-09 06:57:10 +08:00
|
|
|
class Poll extends Component {
|
2018-09-15 01:50:18 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2018-09-25 06:43:54 +08:00
|
|
|
isPolling: false,
|
2020-09-21 20:07:36 +08:00
|
|
|
question: '',
|
2022-03-22 01:58:11 +08:00
|
|
|
questionAndOptions: '',
|
2020-09-21 20:07:36 +08:00
|
|
|
optList: [],
|
2020-09-22 06:52:38 +08:00
|
|
|
error: null,
|
2021-02-08 17:57:39 +08:00
|
|
|
isMultipleResponse: false,
|
2021-04-29 23:10:18 +08:00
|
|
|
secretPoll: false,
|
2022-04-29 04:18:35 +08:00
|
|
|
customInput: false,
|
2022-03-22 01:58:11 +08:00
|
|
|
warning: null,
|
|
|
|
isPasting: false,
|
|
|
|
type: null,
|
2018-09-15 01:50:18 +08:00
|
|
|
};
|
|
|
|
|
2022-12-14 21:46:49 +08:00
|
|
|
this.textarea = createRef();
|
|
|
|
|
2018-10-30 21:17:40 +08:00
|
|
|
this.handleBackClick = this.handleBackClick.bind(this);
|
2020-09-21 20:07:36 +08:00
|
|
|
this.handleAddOption = this.handleAddOption.bind(this);
|
|
|
|
this.handleRemoveOption = this.handleRemoveOption.bind(this);
|
|
|
|
this.handleTextareaChange = this.handleTextareaChange.bind(this);
|
|
|
|
this.handleInputChange = this.handleInputChange.bind(this);
|
2021-03-07 22:12:49 +08:00
|
|
|
this.toggleIsMultipleResponse = this.toggleIsMultipleResponse.bind(this);
|
2021-08-19 04:02:46 +08:00
|
|
|
this.displayToggleStatus = this.displayToggleStatus.bind(this);
|
2022-03-22 01:58:11 +08:00
|
|
|
this.displayAutoOptionToggleStatus = this.displayAutoOptionToggleStatus.bind(this);
|
2022-04-29 04:18:35 +08:00
|
|
|
this.setQuestionAndOptions = this.setQuestionAndOptions.bind(this);
|
2018-09-24 06:57:03 +08:00
|
|
|
}
|
|
|
|
|
2019-05-07 04:18:23 +08:00
|
|
|
componentDidMount() {
|
2022-12-14 21:46:49 +08:00
|
|
|
if (this.textarea.current) {
|
|
|
|
this.textarea.current.focus();
|
|
|
|
}
|
2019-05-07 04:18:23 +08:00
|
|
|
}
|
|
|
|
|
2018-11-23 12:08:48 +08:00
|
|
|
componentDidUpdate() {
|
2022-04-18 17:06:05 +08:00
|
|
|
const { amIPresenter, layoutContextDispatch, sidebarContentPanel } = this.props;
|
2021-07-08 04:15:07 +08:00
|
|
|
|
2019-03-28 23:58:10 +08:00
|
|
|
if (Session.equals('resetPollPanel', true)) {
|
2019-03-15 03:34:53 +08:00
|
|
|
this.handleBackClick();
|
|
|
|
}
|
2021-07-08 04:15:07 +08:00
|
|
|
|
2022-04-18 17:06:05 +08:00
|
|
|
if (!amIPresenter && sidebarContentPanel === PANELS.POLL) {
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-07-08 04:15:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: false,
|
|
|
|
});
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-07-08 04:15:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.NONE,
|
|
|
|
});
|
|
|
|
}
|
2018-11-23 12:08:48 +08:00
|
|
|
}
|
|
|
|
|
2021-12-09 00:49:43 +08:00
|
|
|
componentWillUnmount() {
|
|
|
|
Session.set('secretPoll', false);
|
|
|
|
}
|
|
|
|
|
2018-12-18 23:15:51 +08:00
|
|
|
handleBackClick() {
|
|
|
|
const { stopPoll } = this.props;
|
2022-04-29 04:18:35 +08:00
|
|
|
|
2018-12-18 23:15:51 +08:00
|
|
|
this.setState({
|
|
|
|
isPolling: false,
|
2020-09-22 06:52:38 +08:00
|
|
|
error: null,
|
2020-09-21 20:07:36 +08:00
|
|
|
}, () => {
|
|
|
|
stopPoll();
|
|
|
|
Session.set('resetPollPanel', false);
|
|
|
|
document.activeElement.blur();
|
|
|
|
});
|
2018-09-24 06:57:03 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 04:18:35 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Event} e
|
|
|
|
* @param {Number} index
|
|
|
|
*/
|
2020-09-21 20:07:36 +08:00
|
|
|
handleInputChange(e, index) {
|
2022-04-29 04:18:35 +08:00
|
|
|
const { optList, type, error, questionAndOptions } = this.state;
|
|
|
|
const { pollTypes, validateInput } = this.props;
|
2020-09-21 20:07:36 +08:00
|
|
|
const list = [...optList];
|
2020-09-22 06:52:38 +08:00
|
|
|
const validatedVal = validateInput(e.target.value).replace(/\s{2,}/g, ' ');
|
2022-01-15 05:05:16 +08:00
|
|
|
const charsRemovedCount = e.target.value.length - validatedVal.length;
|
2021-05-27 01:52:55 +08:00
|
|
|
const clearError = validatedVal.length > 0 && type !== pollTypes.Response;
|
2022-01-15 05:05:16 +08:00
|
|
|
const input = e.target;
|
|
|
|
const caretStart = e.target.selectionStart;
|
|
|
|
const caretEnd = e.target.selectionEnd;
|
2022-03-22 01:58:11 +08:00
|
|
|
let questionAndOptionsList = [];
|
2022-04-29 04:18:35 +08:00
|
|
|
list[index] = { val: validatedVal };
|
|
|
|
|
2022-03-22 01:58:11 +08:00
|
|
|
if (questionAndOptions.length > 0) {
|
|
|
|
questionAndOptionsList = questionAndOptions.split('\n');
|
|
|
|
questionAndOptionsList[index + 1] = validatedVal;
|
|
|
|
}
|
2022-04-29 04:18:35 +08:00
|
|
|
|
2022-03-22 01:58:11 +08:00
|
|
|
this.setState({
|
|
|
|
optList: list,
|
|
|
|
questionAndOptions: questionAndOptionsList.length > 0
|
|
|
|
? questionAndOptionsList.join('\n') : '',
|
|
|
|
error: clearError ? null : error,
|
2022-04-29 04:18:35 +08:00
|
|
|
}, () => {
|
2022-03-22 01:58:11 +08:00
|
|
|
input.focus();
|
|
|
|
input.selectionStart = caretStart - charsRemovedCount;
|
|
|
|
input.selectionEnd = caretEnd - charsRemovedCount;
|
|
|
|
});
|
2021-02-04 21:59:16 +08:00
|
|
|
}
|
|
|
|
|
2022-04-29 04:18:35 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Event} e
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2020-09-21 20:07:36 +08:00
|
|
|
handleTextareaChange(e) {
|
2022-04-29 04:18:35 +08:00
|
|
|
const { type, error, customInput } = this.state;
|
|
|
|
const { pollTypes, validateInput } = this.props;
|
2022-03-22 01:58:11 +08:00
|
|
|
const validatedInput = validateInput(e.target.value);
|
|
|
|
const clearError = validatedInput.length > 0 && type === pollTypes.Response;
|
2022-04-29 04:18:35 +08:00
|
|
|
|
|
|
|
if (!customInput) {
|
2022-03-22 01:58:11 +08:00
|
|
|
this.setState({
|
|
|
|
question: validatedInput,
|
|
|
|
error: clearError ? null : error,
|
|
|
|
});
|
|
|
|
} else {
|
2022-04-29 04:18:35 +08:00
|
|
|
this.setQuestionAndOptions(validatedInput);
|
2022-03-22 01:58:11 +08:00
|
|
|
}
|
2022-04-29 04:18:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {String} input Validated string containing question and options.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
setQuestionAndOptions(input) {
|
|
|
|
const { intl, pollTypes, getSplittedQuestionAndOptions } = this.props;
|
|
|
|
const { warning, optList, isPasting, type, error } = this.state;
|
|
|
|
const { splittedQuestion, optionsList } = getSplittedQuestionAndOptions(input);
|
|
|
|
const optionsListLength = optionsList.length;
|
|
|
|
let maxOptionsWarning = warning;
|
|
|
|
const clearWarning = maxOptionsWarning && optionsListLength <= MAX_CUSTOM_FIELDS;
|
|
|
|
const clearError = input.length > 0 && type === pollTypes.Response;
|
|
|
|
|
|
|
|
if (optionsListLength > MAX_CUSTOM_FIELDS && optList[MAX_CUSTOM_FIELDS] === undefined) {
|
|
|
|
this.setState({ warning: intl.formatMessage(intlMessages.maxOptionsWarning) });
|
|
|
|
if (!isPasting) return null;
|
|
|
|
maxOptionsWarning = intl.formatMessage(intlMessages.maxOptionsWarning);
|
|
|
|
this.setState({ isPasting: false });
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
questionAndOptions: input,
|
|
|
|
optList: optionsList,
|
|
|
|
question: splittedQuestion,
|
|
|
|
error: clearError ? null : error,
|
|
|
|
warning: clearWarning ? null : maxOptionsWarning,
|
|
|
|
});
|
2020-09-21 20:07:36 +08:00
|
|
|
}
|
2018-09-24 06:57:03 +08:00
|
|
|
|
2021-04-27 07:04:34 +08:00
|
|
|
handlePollValuesText(text) {
|
2022-04-29 04:18:35 +08:00
|
|
|
const { validateInput } = this.props;
|
2021-04-27 07:04:34 +08:00
|
|
|
if (text && text.length > 0) {
|
2022-04-29 04:18:35 +08:00
|
|
|
const validatedInput = validateInput(text);
|
|
|
|
this.setQuestionAndOptions(validatedInput);
|
2021-04-27 07:04:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 04:18:35 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Number} index
|
|
|
|
*/
|
2021-04-27 07:04:34 +08:00
|
|
|
handleRemoveOption(index) {
|
2021-09-13 08:03:03 +08:00
|
|
|
const { intl } = this.props;
|
2022-04-29 04:18:35 +08:00
|
|
|
const { optList, questionAndOptions, customInput, warning } = this.state;
|
2021-04-27 07:04:34 +08:00
|
|
|
const list = [...optList];
|
2021-09-13 08:03:03 +08:00
|
|
|
const removed = list[index];
|
2022-03-22 01:58:11 +08:00
|
|
|
let questionAndOptionsList = [];
|
|
|
|
let clearWarning = false;
|
2022-04-29 04:18:35 +08:00
|
|
|
|
|
|
|
list.splice(index, 1);
|
|
|
|
|
|
|
|
// If customInput then removing text from input field.
|
|
|
|
if (customInput) {
|
2022-03-22 01:58:11 +08:00
|
|
|
questionAndOptionsList = questionAndOptions.split('\n');
|
|
|
|
delete questionAndOptionsList[index + 1];
|
|
|
|
questionAndOptionsList = questionAndOptionsList.filter((val) => val !== undefined);
|
|
|
|
clearWarning = warning && list.length <= MAX_CUSTOM_FIELDS;
|
|
|
|
}
|
2022-04-29 04:18:35 +08:00
|
|
|
|
2022-03-22 01:58:11 +08:00
|
|
|
this.setState({
|
|
|
|
optList: list,
|
|
|
|
questionAndOptions: questionAndOptionsList.length > 0
|
2022-04-29 04:18:35 +08:00
|
|
|
? questionAndOptionsList.join('\n')
|
|
|
|
: [],
|
2022-03-22 01:58:11 +08:00
|
|
|
warning: clearWarning ? null : warning,
|
|
|
|
}, () => {
|
2022-05-24 01:09:50 +08:00
|
|
|
addNewAlert(`${intl.formatMessage(intlMessages.removePollOpt,
|
2021-09-13 08:11:45 +08:00
|
|
|
{ 0: removed.val || intl.formatMessage(intlMessages.emptyPollOpt) })}`);
|
2021-09-13 08:03:03 +08:00
|
|
|
});
|
2021-04-27 07:04:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
handleAddOption() {
|
|
|
|
const { optList } = this.state;
|
|
|
|
this.setState({ optList: [...optList, { val: '' }] });
|
|
|
|
}
|
|
|
|
|
2021-04-29 23:10:18 +08:00
|
|
|
handleToggle() {
|
2021-07-03 03:58:33 +08:00
|
|
|
const { secretPoll } = this.state;
|
|
|
|
const toggledValue = !secretPoll;
|
|
|
|
Session.set('secretPoll', toggledValue);
|
|
|
|
this.setState({ secretPoll: toggledValue });
|
2021-04-29 23:10:18 +08:00
|
|
|
}
|
|
|
|
|
2022-03-22 01:58:11 +08:00
|
|
|
handleAutoOptionToogle() {
|
2022-04-29 04:18:35 +08:00
|
|
|
const { customInput, questionAndOptions, question } = this.state;
|
|
|
|
const { intl, removeEmptyLineSpaces, getSplittedQuestionAndOptions } = this.props;
|
|
|
|
const toggledValue = !customInput;
|
|
|
|
|
|
|
|
if (customInput === true && toggledValue === false) {
|
2022-03-22 01:58:11 +08:00
|
|
|
const questionAndOptionsList = removeEmptyLineSpaces(questionAndOptions);
|
|
|
|
this.setState({
|
|
|
|
question: questionAndOptionsList.join('\n'),
|
2022-04-29 04:18:35 +08:00
|
|
|
customInput: toggledValue,
|
2022-03-22 01:58:11 +08:00
|
|
|
optList: [],
|
|
|
|
type: null,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const inputList = removeEmptyLineSpaces(question);
|
|
|
|
const { splittedQuestion, optionsList } = getSplittedQuestionAndOptions(inputList);
|
|
|
|
const clearWarning = optionsList.length > MAX_CUSTOM_FIELDS
|
2022-03-22 03:44:21 +08:00
|
|
|
? intl.formatMessage(intlMessages.maxOptionsWarning) : null;
|
2022-04-29 04:18:35 +08:00
|
|
|
this.handlePollLetterOptions();
|
2022-03-22 01:58:11 +08:00
|
|
|
this.setState({
|
|
|
|
questionAndOptions: inputList.join('\n'),
|
|
|
|
optList: optionsList,
|
2022-04-29 04:18:35 +08:00
|
|
|
customInput: toggledValue,
|
2022-03-22 01:58:11 +08:00
|
|
|
question: splittedQuestion,
|
|
|
|
warning: clearWarning,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePollLetterOptions() {
|
|
|
|
const { pollTypes } = this.props;
|
|
|
|
const { optList } = this.state;
|
2022-04-29 04:18:35 +08:00
|
|
|
|
2022-03-22 01:58:11 +08:00
|
|
|
if (optList.length === 0) {
|
|
|
|
this.setState({
|
|
|
|
type: pollTypes.Letter,
|
|
|
|
optList: [
|
|
|
|
{ val: '' },
|
|
|
|
{ val: '' },
|
|
|
|
{ val: '' },
|
|
|
|
{ val: '' },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleIsMultipleResponse() {
|
|
|
|
const { isMultipleResponse } = this.state;
|
|
|
|
return this.setState({ isMultipleResponse: !isMultipleResponse });
|
|
|
|
}
|
|
|
|
|
2022-04-29 04:18:35 +08:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {Boolean} status
|
|
|
|
* @returns
|
|
|
|
*/
|
2021-08-19 04:02:46 +08:00
|
|
|
displayToggleStatus(status) {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
2021-11-04 22:19:38 +08:00
|
|
|
<Styled.ToggleLabel>
|
2022-04-29 04:18:35 +08:00
|
|
|
{status
|
|
|
|
? intl.formatMessage(intlMessages.on)
|
2021-08-19 04:02:46 +08:00
|
|
|
: intl.formatMessage(intlMessages.off)}
|
2021-11-04 22:19:38 +08:00
|
|
|
</Styled.ToggleLabel>
|
2021-08-19 04:02:46 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-03-22 01:58:11 +08:00
|
|
|
displayAutoOptionToggleStatus(status) {
|
|
|
|
const { intl } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Styled.ToggleLabel>
|
2022-04-29 04:18:35 +08:00
|
|
|
{status
|
|
|
|
? intl.formatMessage(intlMessages.on)
|
2022-03-22 01:58:11 +08:00
|
|
|
: intl.formatMessage(intlMessages.off)}
|
|
|
|
</Styled.ToggleLabel>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-09-21 20:07:36 +08:00
|
|
|
renderInputs() {
|
2021-05-27 01:52:55 +08:00
|
|
|
const { intl, pollTypes } = this.props;
|
2020-09-22 06:52:38 +08:00
|
|
|
const { optList, type, error } = this.state;
|
|
|
|
let hasVal = false;
|
2022-03-22 01:58:11 +08:00
|
|
|
return optList.slice(0, MAX_CUSTOM_FIELDS).map((o, i) => {
|
2020-09-21 20:07:36 +08:00
|
|
|
const pollOptionKey = `poll-option-${i}`;
|
2022-04-29 04:18:35 +08:00
|
|
|
if (o.val && o.val.length > 0) hasVal = true;
|
2018-12-18 23:15:51 +08:00
|
|
|
return (
|
2021-04-09 02:42:06 +08:00
|
|
|
<span key={pollOptionKey}>
|
2022-04-29 04:18:35 +08:00
|
|
|
<Styled.OptionWrapper>
|
2021-11-04 22:19:38 +08:00
|
|
|
<Styled.PollOptionInput
|
2020-09-22 06:52:38 +08:00
|
|
|
type="text"
|
|
|
|
value={o.val}
|
2023-05-26 22:04:35 +08:00
|
|
|
placeholder={intl.formatMessage(intlMessages.customPlaceholder)}
|
2021-03-08 07:53:58 +08:00
|
|
|
data-test="pollOptionItem"
|
2021-04-27 07:04:34 +08:00
|
|
|
onChange={(e) => this.handleInputChange(e, i)}
|
2020-09-22 06:52:38 +08:00
|
|
|
maxLength={MAX_INPUT_CHARS}
|
2022-11-04 00:06:25 +08:00
|
|
|
onPaste={(e) => { e.stopPropagation(); }}
|
2022-11-04 03:24:00 +08:00
|
|
|
onCut={(e) => { e.stopPropagation(); }}
|
|
|
|
onCopy={(e) => { e.stopPropagation(); }}
|
2020-09-22 06:52:38 +08:00
|
|
|
/>
|
2022-04-29 04:18:35 +08:00
|
|
|
{optList.length > MIN_OPTIONS_LENGTH && (
|
|
|
|
<Styled.DeletePollOptionButton
|
|
|
|
label={intl.formatMessage(intlMessages.delete)}
|
|
|
|
aria-describedby={`option-${i}`}
|
|
|
|
icon="delete"
|
|
|
|
data-test="deletePollOption"
|
|
|
|
hideLabel
|
|
|
|
circle
|
|
|
|
color="default"
|
|
|
|
onClick={() => {
|
|
|
|
this.handleRemoveOption(i);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2022-03-22 01:58:11 +08:00
|
|
|
<span className="sr-only" id={`option-${i}`}>
|
2022-04-29 04:18:35 +08:00
|
|
|
{intl.formatMessage(
|
|
|
|
intlMessages.deleteRespDesc,
|
|
|
|
{ 0: o.val || intl.formatMessage(intlMessages.emptyPollOpt) },
|
|
|
|
)}
|
2022-03-22 01:58:11 +08:00
|
|
|
</span>
|
2022-04-29 04:18:35 +08:00
|
|
|
</Styled.OptionWrapper>
|
2021-05-27 01:52:55 +08:00
|
|
|
{!hasVal && type !== pollTypes.Response && error ? (
|
2022-10-26 04:12:59 +08:00
|
|
|
<Styled.InputError data-test="errorNoValueInput">{error}</Styled.InputError>
|
2020-09-22 06:52:38 +08:00
|
|
|
) : (
|
2021-11-04 22:19:38 +08:00
|
|
|
<Styled.ErrorSpacer> </Styled.ErrorSpacer>
|
2020-09-22 06:52:38 +08:00
|
|
|
)}
|
|
|
|
</span>
|
2018-12-18 23:15:51 +08:00
|
|
|
);
|
|
|
|
});
|
2018-10-24 22:17:13 +08:00
|
|
|
}
|
|
|
|
|
2018-09-25 06:43:54 +08:00
|
|
|
renderActivePollOptions() {
|
|
|
|
const {
|
2019-05-23 02:00:44 +08:00
|
|
|
intl,
|
2019-06-28 00:46:14 +08:00
|
|
|
isMeteorConnected,
|
2019-05-23 02:00:44 +08:00
|
|
|
stopPoll,
|
|
|
|
currentPoll,
|
|
|
|
pollAnswerIds,
|
2021-04-19 21:58:33 +08:00
|
|
|
usernames,
|
2021-06-12 00:55:53 +08:00
|
|
|
isDefaultPoll,
|
2018-09-25 06:43:54 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2021-11-04 22:19:38 +08:00
|
|
|
<Styled.Instructions>
|
2018-10-11 02:25:35 +08:00
|
|
|
{intl.formatMessage(intlMessages.activePollInstruction)}
|
2021-11-04 22:19:38 +08:00
|
|
|
</Styled.Instructions>
|
2018-10-29 23:27:50 +08:00
|
|
|
<LiveResult
|
|
|
|
{...{
|
2019-06-28 00:46:14 +08:00
|
|
|
isMeteorConnected,
|
2018-10-29 23:27:50 +08:00
|
|
|
stopPoll,
|
|
|
|
currentPoll,
|
2019-05-23 02:00:44 +08:00
|
|
|
pollAnswerIds,
|
2021-04-19 21:58:33 +08:00
|
|
|
usernames,
|
2021-06-12 00:55:53 +08:00
|
|
|
isDefaultPoll,
|
2018-10-29 23:27:50 +08:00
|
|
|
}}
|
2018-10-30 21:17:40 +08:00
|
|
|
handleBackClick={this.handleBackClick}
|
2018-10-29 23:27:50 +08:00
|
|
|
/>
|
2018-09-25 06:43:54 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-29 04:18:35 +08:00
|
|
|
renderStartPollButton() {
|
2021-07-03 03:58:33 +08:00
|
|
|
const {
|
2022-04-29 04:18:35 +08:00
|
|
|
startPoll, startCustomPoll, intl, pollTypes, checkPollType,
|
2021-07-03 03:58:33 +08:00
|
|
|
} = this.props;
|
2022-04-29 04:18:35 +08:00
|
|
|
const {
|
|
|
|
type, secretPoll, optList, isMultipleResponse, question,
|
|
|
|
} = this.state;
|
|
|
|
return (
|
|
|
|
<Styled.StartPollBtn
|
|
|
|
data-test="startPoll"
|
|
|
|
label={intl.formatMessage(intlMessages.startPollLabel)}
|
|
|
|
color="primary"
|
|
|
|
onClick={() => {
|
|
|
|
const optionsList = optList.slice(0, MAX_CUSTOM_FIELDS);
|
|
|
|
let hasVal = false;
|
|
|
|
optionsList.forEach((o) => {
|
|
|
|
if (o.val.trim().length > 0) hasVal = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
let err = null;
|
|
|
|
if (type === pollTypes.Response && question.length === 0) {
|
|
|
|
err = intl.formatMessage(intlMessages.questionErr);
|
|
|
|
}
|
|
|
|
if (!hasVal && type !== pollTypes.Response) {
|
|
|
|
err = intl.formatMessage(intlMessages.optionErr);
|
|
|
|
}
|
|
|
|
if (err) return this.setState({ error: err });
|
|
|
|
|
|
|
|
return this.setState({ isPolling: true }, () => {
|
|
|
|
const verifiedPollType = checkPollType(
|
|
|
|
type,
|
|
|
|
optionsList,
|
|
|
|
intl.formatMessage(intlMessages.yes),
|
|
|
|
intl.formatMessage(intlMessages.no),
|
|
|
|
intl.formatMessage(intlMessages.abstention),
|
|
|
|
intl.formatMessage(intlMessages.true),
|
|
|
|
intl.formatMessage(intlMessages.false),
|
|
|
|
);
|
|
|
|
const verifiedOptions = optionsList.map((o) => {
|
|
|
|
if (o.val.trim().length > 0) return o.val;
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
if (verifiedPollType === pollTypes.Custom) {
|
|
|
|
startCustomPoll(
|
|
|
|
verifiedPollType,
|
|
|
|
secretPoll,
|
|
|
|
question,
|
|
|
|
isMultipleResponse,
|
2023-02-17 21:40:21 +08:00
|
|
|
verifiedOptions.filter(Boolean),
|
2022-04-29 04:18:35 +08:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
startPoll(verifiedPollType, secretPoll, question, isMultipleResponse);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderResponseArea() {
|
|
|
|
const { intl, pollTypes, isDefaultPoll } = this.props;
|
|
|
|
const { type, secretPoll, optList, isMultipleResponse } = this.state;
|
2021-05-27 01:52:55 +08:00
|
|
|
const defaultPoll = isDefaultPoll(type);
|
2022-04-29 04:18:35 +08:00
|
|
|
if (defaultPoll || type === pollTypes.Response) return (
|
|
|
|
<Styled.ResponseArea>
|
|
|
|
{defaultPoll && (
|
|
|
|
<div>
|
2022-10-26 04:12:59 +08:00
|
|
|
<Styled.PollCheckbox data-test="allowMultiple">
|
2022-04-29 04:18:35 +08:00
|
|
|
<Checkbox
|
|
|
|
onChange={this.toggleIsMultipleResponse}
|
|
|
|
checked={isMultipleResponse}
|
|
|
|
ariaLabelledBy="multipleResponseCheckboxLabel"
|
2022-12-15 04:03:23 +08:00
|
|
|
label={intl.formatMessage(intlMessages.enableMultipleResponseLabel)}
|
2022-04-29 04:18:35 +08:00
|
|
|
/>
|
|
|
|
</Styled.PollCheckbox>
|
2022-12-15 04:03:23 +08:00
|
|
|
<div id="multipleResponseCheckboxLabel" hidden>
|
2022-04-29 04:18:35 +08:00
|
|
|
{intl.formatMessage(intlMessages.enableMultipleResponseLabel)}
|
2022-12-15 04:03:23 +08:00
|
|
|
</div>
|
2022-04-29 04:18:35 +08:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{defaultPoll && this.renderInputs()}
|
|
|
|
{defaultPoll && (
|
|
|
|
<Styled.AddItemButton
|
|
|
|
data-test="addPollItem"
|
|
|
|
label={intl.formatMessage(intlMessages.addOptionLabel)}
|
|
|
|
aria-describedby="add-item-button"
|
|
|
|
color="default"
|
|
|
|
icon="add"
|
|
|
|
disabled={optList.length >= MAX_CUSTOM_FIELDS}
|
|
|
|
onClick={() => this.handleAddOption()}
|
|
|
|
/>
|
|
|
|
)}
|
2022-11-23 22:09:38 +08:00
|
|
|
<Styled.AnonymousRow>
|
|
|
|
<Styled.AnonymousHeadingCol aria-hidden="true">
|
|
|
|
<Styled.AnonymousHeading>
|
2022-04-29 04:18:35 +08:00
|
|
|
{intl.formatMessage(intlMessages.secretPollLabel)}
|
2022-11-23 22:09:38 +08:00
|
|
|
</Styled.AnonymousHeading>
|
|
|
|
</Styled.AnonymousHeadingCol>
|
|
|
|
<Styled.AnonymousToggleCol>
|
2022-04-29 04:18:35 +08:00
|
|
|
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */}
|
|
|
|
<Styled.Toggle>
|
|
|
|
{this.displayToggleStatus(secretPoll)}
|
|
|
|
<Toggle
|
|
|
|
icons={false}
|
|
|
|
defaultChecked={secretPoll}
|
|
|
|
onChange={() => this.handleToggle()}
|
|
|
|
ariaLabel={intl.formatMessage(intlMessages.secretPollLabel)}
|
|
|
|
showToggleLabel={false}
|
|
|
|
data-test="anonymousPollBtn"
|
|
|
|
/>
|
|
|
|
</Styled.Toggle>
|
2022-11-23 22:09:38 +08:00
|
|
|
</Styled.AnonymousToggleCol>
|
|
|
|
</Styled.AnonymousRow>
|
2022-04-29 04:18:35 +08:00
|
|
|
{secretPoll && (
|
|
|
|
<Styled.PollParagraph>
|
|
|
|
{intl.formatMessage(intlMessages.isSecretPollLabel)}
|
|
|
|
</Styled.PollParagraph>
|
|
|
|
)}
|
|
|
|
{this.renderStartPollButton()}
|
|
|
|
</Styled.ResponseArea>
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderCustomInputRow() {
|
|
|
|
const { intl } = this.props;
|
|
|
|
const { customInput } = this.state;
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Styled.CustomInputRow>
|
2022-11-22 20:09:35 +08:00
|
|
|
<Styled.CustomInputHeadingCol aria-hidden="true">
|
|
|
|
<Styled.CustomInputHeading>
|
2022-04-29 04:18:35 +08:00
|
|
|
{intl.formatMessage(intlMessages.customInputToggleLabel)}
|
2022-11-22 20:09:35 +08:00
|
|
|
</Styled.CustomInputHeading>
|
|
|
|
</Styled.CustomInputHeadingCol>
|
|
|
|
<Styled.CustomInputToggleCol>
|
2022-04-29 04:18:35 +08:00
|
|
|
<Styled.Toggle>
|
|
|
|
{this.displayAutoOptionToggleStatus(customInput)}
|
|
|
|
<Toggle
|
|
|
|
icons={false}
|
|
|
|
defaultChecked={customInput}
|
|
|
|
onChange={() => this.handleAutoOptionToogle()}
|
|
|
|
ariaLabel={intl.formatMessage(intlMessages.customInputToggleLabel)}
|
|
|
|
showToggleLabel={false}
|
|
|
|
data-test="autoOptioningPollBtn"
|
|
|
|
/>
|
|
|
|
</Styled.Toggle>
|
2022-11-22 20:09:35 +08:00
|
|
|
</Styled.CustomInputToggleCol>
|
2022-04-29 04:18:35 +08:00
|
|
|
</Styled.CustomInputRow>
|
|
|
|
{customInput && (
|
|
|
|
<Styled.PollParagraph>
|
|
|
|
{intl.formatMessage(intlMessages.customInputInstructionsLabel)}
|
|
|
|
</Styled.PollParagraph>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPollQuestionArea() {
|
|
|
|
const { intl, pollTypes } = this.props;
|
|
|
|
const {
|
|
|
|
type, optList, questionAndOptions, error,
|
|
|
|
question, customInput, warning,
|
|
|
|
} = this.state;
|
|
|
|
const hasOptionError = (customInput && optList.length === 0 && error);
|
|
|
|
const hasWarning = (customInput && warning);
|
|
|
|
const hasQuestionError = (type === pollTypes.Response
|
|
|
|
&& questionAndOptions.length === 0 && error);
|
|
|
|
const questionsAndOptionsPlaceholder = intlMessages.questionAndOptionsPlaceholder;
|
2021-10-01 02:55:46 +08:00
|
|
|
const questionPlaceholder = (type === pollTypes.Response)
|
|
|
|
? intlMessages.questionLabel
|
|
|
|
: intlMessages.optionalQuestionLabel;
|
2018-09-15 01:50:18 +08:00
|
|
|
return (
|
2018-09-24 06:20:20 +08:00
|
|
|
<div>
|
2022-04-29 04:18:35 +08:00
|
|
|
<Styled.PollQuestionArea
|
|
|
|
hasError={hasQuestionError || hasOptionError}
|
|
|
|
data-test="pollQuestionArea"
|
|
|
|
value={customInput ? questionAndOptions : question}
|
|
|
|
onChange={(e) => this.handleTextareaChange(e)}
|
2022-11-04 00:06:25 +08:00
|
|
|
onPaste={(e) => { e.stopPropagation(); this.setState({ isPasting: true }); }}
|
2022-11-04 03:24:00 +08:00
|
|
|
onCut={(e) => { e.stopPropagation(); }}
|
|
|
|
onCopy={(e) => { e.stopPropagation(); }}
|
2022-04-29 04:18:35 +08:00
|
|
|
onKeyPress={(event) => {
|
|
|
|
if (event.key === 'Enter' && customInput) {
|
|
|
|
this.handlePollLetterOptions();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
rows="5"
|
|
|
|
cols="35"
|
|
|
|
maxLength={QUESTION_MAX_INPUT_CHARS}
|
|
|
|
aria-label={intl.formatMessage(customInput ? questionsAndOptionsPlaceholder
|
|
|
|
: questionPlaceholder)}
|
|
|
|
placeholder={intl.formatMessage(customInput ? questionsAndOptionsPlaceholder
|
|
|
|
: questionPlaceholder)}
|
|
|
|
{...{ MAX_INPUT_CHARS }}
|
|
|
|
handlePollValuesText={(e) => this.handlePollValuesText(e)}
|
|
|
|
as={customInput ? DraggableTextArea : 'textarea'}
|
2022-12-14 21:46:49 +08:00
|
|
|
ref={this.textarea}
|
2022-04-29 04:18:35 +08:00
|
|
|
/>
|
|
|
|
{hasQuestionError || hasOptionError ? (
|
|
|
|
<Styled.InputError>{error}</Styled.InputError>
|
|
|
|
) : (
|
|
|
|
<Styled.ErrorSpacer> </Styled.ErrorSpacer>
|
|
|
|
)}
|
|
|
|
{hasWarning ? (
|
|
|
|
<Styled.Warning>{warning}</Styled.Warning>
|
|
|
|
) : (
|
|
|
|
<Styled.ErrorSpacer> </Styled.ErrorSpacer>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-03-22 01:58:11 +08:00
|
|
|
|
2022-04-29 04:18:35 +08:00
|
|
|
renderResponseTypes() {
|
|
|
|
const { intl, pollTypes, smallSidebar } = this.props;
|
|
|
|
const { type, customInput } = this.state;
|
|
|
|
if (!customInput) return (
|
|
|
|
<div data-test="responseTypes">
|
|
|
|
<Styled.SectionHeading>
|
|
|
|
{intl.formatMessage(intlMessages.responseTypesLabel)}
|
|
|
|
</Styled.SectionHeading>
|
|
|
|
<Styled.ResponseType>
|
|
|
|
<Styled.PollConfigButton
|
|
|
|
selected={type === pollTypes.TrueFalse}
|
|
|
|
small={!smallSidebar}
|
|
|
|
label={intl.formatMessage(intlMessages.tf)}
|
|
|
|
aria-describedby="poll-config-button"
|
2023-03-03 03:57:02 +08:00
|
|
|
data-test="pollTrueFalse"
|
2022-04-29 04:18:35 +08:00
|
|
|
color="default"
|
|
|
|
onClick={() => {
|
|
|
|
this.setState({
|
|
|
|
type: pollTypes.TrueFalse,
|
|
|
|
optList: [
|
|
|
|
{ val: intl.formatMessage(intlMessages.true) },
|
|
|
|
{ val: intl.formatMessage(intlMessages.false) },
|
|
|
|
],
|
|
|
|
});
|
2022-03-22 01:58:11 +08:00
|
|
|
}}
|
2020-09-21 20:07:36 +08:00
|
|
|
/>
|
2022-04-29 04:18:35 +08:00
|
|
|
<Styled.PollConfigButton
|
|
|
|
selected={type === pollTypes.Letter}
|
|
|
|
small={!smallSidebar}
|
|
|
|
label={intl.formatMessage(intlMessages.a4)}
|
|
|
|
aria-describedby="poll-config-button"
|
|
|
|
data-test="pollLetterAlternatives"
|
|
|
|
color="default"
|
|
|
|
onClick={() => {
|
|
|
|
if (!customInput) {
|
|
|
|
this.setState({
|
|
|
|
type: pollTypes.Letter,
|
|
|
|
optList: [
|
|
|
|
{ val: intl.formatMessage(intlMessages.a) },
|
|
|
|
{ val: intl.formatMessage(intlMessages.b) },
|
|
|
|
{ val: intl.formatMessage(intlMessages.c) },
|
|
|
|
{ val: intl.formatMessage(intlMessages.d) },
|
|
|
|
],
|
|
|
|
});
|
2020-09-21 20:07:36 +08:00
|
|
|
}
|
2022-04-29 04:18:35 +08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Styled.PollConfigButton
|
|
|
|
selected={type === pollTypes.YesNoAbstention}
|
|
|
|
small={false}
|
|
|
|
full
|
|
|
|
label={intl.formatMessage(intlMessages.yna)}
|
|
|
|
aria-describedby="poll-config-button"
|
|
|
|
data-test="pollYesNoAbstentionBtn"
|
|
|
|
color="default"
|
|
|
|
onClick={() => {
|
|
|
|
this.setState({
|
|
|
|
type: pollTypes.YesNoAbstention,
|
|
|
|
optList: [
|
|
|
|
{ val: intl.formatMessage(intlMessages.yes) },
|
|
|
|
{ val: intl.formatMessage(intlMessages.no) },
|
|
|
|
{ val: intl.formatMessage(intlMessages.abstention) },
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Styled.PollConfigButton
|
|
|
|
selected={type === pollTypes.Response}
|
|
|
|
small={false}
|
|
|
|
full
|
|
|
|
label={intl.formatMessage(intlMessages.userResponse)}
|
|
|
|
aria-describedby="poll-config-button"
|
|
|
|
data-test="userResponseBtn"
|
|
|
|
color="default"
|
|
|
|
onClick={() => { this.setState({ type: pollTypes.Response }); }}
|
|
|
|
/>
|
|
|
|
</Styled.ResponseType>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderResponseChoices() {
|
|
|
|
const { intl, pollTypes } = this.props;
|
|
|
|
const { type, questionAndOptions, question, customInput } = this.state;
|
|
|
|
if ((!customInput && type) || (questionAndOptions && customInput)) return (
|
|
|
|
<div data-test="responseChoices">
|
|
|
|
{customInput && questionAndOptions && (
|
|
|
|
<Styled.Question>
|
|
|
|
<Styled.SectionHeading>
|
|
|
|
{intl.formatMessage(intlMessages.pollingQuestion)}
|
|
|
|
</Styled.SectionHeading>
|
|
|
|
<Styled.PollParagraph>
|
|
|
|
<span>{question}</span>
|
|
|
|
</Styled.PollParagraph>
|
|
|
|
</Styled.Question>
|
|
|
|
)}
|
|
|
|
<Styled.SectionHeading>
|
|
|
|
{intl.formatMessage(intlMessages.responseChoices)}
|
|
|
|
</Styled.SectionHeading>
|
|
|
|
{type === pollTypes.Response && (
|
|
|
|
<Styled.PollParagraph>
|
|
|
|
<span>{intl.formatMessage(intlMessages.typedResponseDesc)}</span>
|
|
|
|
</Styled.PollParagraph>
|
|
|
|
)}
|
|
|
|
{this.renderResponseArea()}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPollOptions() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{ALLOW_CUSTOM_INPUT && this.renderCustomInputRow()}
|
|
|
|
{this.renderPollQuestionArea()}
|
|
|
|
{this.renderResponseTypes()}
|
|
|
|
{this.renderResponseChoices()}
|
2018-09-15 01:50:18 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-09-25 06:43:54 +08:00
|
|
|
|
2019-03-15 03:34:53 +08:00
|
|
|
renderNoSlidePanel() {
|
2021-05-11 01:34:23 +08:00
|
|
|
const { intl } = this.props;
|
2019-03-09 04:46:25 +08:00
|
|
|
return (
|
2021-11-04 22:19:38 +08:00
|
|
|
<Styled.NoSlidePanelContainer>
|
2022-10-26 04:12:59 +08:00
|
|
|
<Styled.SectionHeading data-test="noPresentation">
|
2021-11-04 22:19:38 +08:00
|
|
|
{intl.formatMessage(intlMessages.noPresentationSelected)}
|
|
|
|
</Styled.SectionHeading>
|
|
|
|
<Styled.PollButton
|
2019-03-09 04:46:25 +08:00
|
|
|
label={intl.formatMessage(intlMessages.clickHereToSelect)}
|
|
|
|
color="primary"
|
2021-05-11 01:34:23 +08:00
|
|
|
onClick={() => Session.set('showUploadPresentationView', true)}
|
2019-03-09 04:46:25 +08:00
|
|
|
/>
|
2021-11-04 22:19:38 +08:00
|
|
|
</Styled.NoSlidePanelContainer>
|
2019-03-09 04:46:25 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:34:53 +08:00
|
|
|
renderPollPanel() {
|
2019-03-09 04:46:25 +08:00
|
|
|
const { isPolling } = this.state;
|
2018-09-25 06:43:54 +08:00
|
|
|
const {
|
2019-03-09 04:46:25 +08:00
|
|
|
currentPoll,
|
|
|
|
currentSlide,
|
2018-09-25 06:43:54 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2021-05-11 01:34:23 +08:00
|
|
|
if (!currentSlide) return this.renderNoSlidePanel();
|
2021-08-27 21:47:58 +08:00
|
|
|
if (isPolling || currentPoll) {
|
2019-03-09 04:46:25 +08:00
|
|
|
return this.renderActivePollOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.renderPollOptions();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
stopPoll,
|
|
|
|
currentPoll,
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch,
|
2019-03-09 04:46:25 +08:00
|
|
|
} = this.props;
|
2018-12-18 23:15:51 +08:00
|
|
|
|
2018-09-25 06:43:54 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2022-05-24 01:09:50 +08:00
|
|
|
<Header
|
|
|
|
leftButtonProps={{
|
|
|
|
'aria-label': intl.formatMessage(intlMessages.hidePollDesc),
|
|
|
|
'data-test': "hidePollDesc",
|
|
|
|
label: intl.formatMessage(intlMessages.pollPaneTitle),
|
|
|
|
onClick: () => {
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-05-18 04:25:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: false,
|
|
|
|
});
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-05-18 04:25:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.NONE,
|
|
|
|
});
|
2022-05-24 01:09:50 +08:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
rightButtonProps={{
|
|
|
|
'aria-label': `${intl.formatMessage(intlMessages.closeLabel)} ${intl.formatMessage(intlMessages.pollPaneTitle)}`,
|
|
|
|
'data-test': "closePolling",
|
|
|
|
icon: "close",
|
|
|
|
label: intl.formatMessage(intlMessages.closeLabel),
|
|
|
|
onClick: () => {
|
2020-09-21 20:07:36 +08:00
|
|
|
if (currentPoll) stopPoll();
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-05-18 04:25:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: false,
|
|
|
|
});
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-05-18 04:25:07 +08:00
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.NONE,
|
|
|
|
});
|
2018-12-18 23:15:51 +08:00
|
|
|
Session.set('forcePollOpen', false);
|
2020-01-30 02:36:17 +08:00
|
|
|
Session.set('pollInitiated', false);
|
2022-05-24 01:09:50 +08:00
|
|
|
},
|
|
|
|
}}
|
|
|
|
/>
|
2020-09-21 20:07:36 +08:00
|
|
|
{this.renderPollPanel()}
|
2021-08-11 12:10:41 +08:00
|
|
|
<span className="sr-only" id="poll-config-button">{intl.formatMessage(intlMessages.showRespDesc)}</span>
|
|
|
|
<span className="sr-only" id="add-item-button">{intl.formatMessage(intlMessages.addRespDesc)}</span>
|
|
|
|
<span className="sr-only" id="start-poll-button">{intl.formatMessage(intlMessages.startPollDesc)}</span>
|
2018-09-25 06:43:54 +08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-09-15 01:50:18 +08:00
|
|
|
}
|
|
|
|
|
2023-03-27 23:36:25 +08:00
|
|
|
export default injectIntl(Poll);
|
2018-10-16 03:58:07 +08:00
|
|
|
|
|
|
|
Poll.propTypes = {
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2019-08-30 00:26:07 +08:00
|
|
|
amIPresenter: PropTypes.bool.isRequired,
|
2021-05-27 01:52:55 +08:00
|
|
|
pollTypes: PropTypes.instanceOf(Object).isRequired,
|
2018-10-16 03:58:07 +08:00
|
|
|
startPoll: PropTypes.func.isRequired,
|
|
|
|
startCustomPoll: PropTypes.func.isRequired,
|
|
|
|
stopPoll: PropTypes.func.isRequired,
|
|
|
|
};
|