fix(restrict-results): add error message if user try to create an election with restricted result but without voting time.

pull/62/head
Clement G 4 years ago
parent 883af565b9
commit cef2c1fda5

@ -17,6 +17,7 @@
"Write here your question or introduce simple your election (250 characters max.)": "Schreiben Sie hier Ihre Frage oder erklären Sie kurz ihre Wahl (bis 250 Zeichen)", "Write here your question or introduce simple your election (250 characters max.)": "Schreiben Sie hier Ihre Frage oder erklären Sie kurz ihre Wahl (bis 250 Zeichen)",
"Enter the name of your candidate or proposal here (250 characters max.)": "Geben Sie hier den Namen Ihres Kandidaten oder Antrags ein (max. 250 Zeichen)", "Enter the name of your candidate or proposal here (250 characters max.)": "Geben Sie hier den Namen Ihres Kandidaten oder Antrags ein (max. 250 Zeichen)",
"Please add at least 2 candidates.": "Bitte geben Sie mindestens zwei Kandidaten vor. ", "Please add at least 2 candidates.": "Bitte geben Sie mindestens zwei Kandidaten vor. ",
"You can't limit access results without specify a voting time.": "Sie können die Zugriffsergebnisse nicht einschränken, ohne eine Abstimmungszeit anzugeben.",
"Question of the election": "Zur Wahl stehende Frage", "Question of the election": "Zur Wahl stehende Frage",
"Write here the question of your election": "Schreiben Sie hier die zur Wahl stehenden Frage", "Write here the question of your election": "Schreiben Sie hier die zur Wahl stehenden Frage",
"For example:": "Zum Beispiel", "For example:": "Zum Beispiel",

@ -17,6 +17,7 @@
"Write here your question or introduce simple your election (250 characters max.)": "Write here your question or introduce simple your election (250 characters max.)", "Write here your question or introduce simple your election (250 characters max.)": "Write here your question or introduce simple your election (250 characters max.)",
"Enter the name of your candidate or proposal here (250 characters max.)":"Enter the name of your candidate or proposal here (250 characters max.)", "Enter the name of your candidate or proposal here (250 characters max.)":"Enter the name of your candidate or proposal here (250 characters max.)",
"Please add at least 2 candidates.": "Please add at least 2 candidates.", "Please add at least 2 candidates.": "Please add at least 2 candidates.",
"You can't limit access results without specify a voting time.": "You can't limit access results without specify a voting time.",
"Question of the election": "Question of the election", "Question of the election": "Question of the election",
"Write here the question of your election": "Write here the question of your election", "Write here the question of your election": "Write here the question of your election",
"For example:": "For example:", "For example:": "For example:",

@ -17,6 +17,7 @@
"Write here your question or introduce simple your election (250 characters max.)": "Escriba aquí su pregunta o introduzca simplemente su elección (250 caracteres máx.)", "Write here your question or introduce simple your election (250 characters max.)": "Escriba aquí su pregunta o introduzca simplemente su elección (250 caracteres máx.)",
"Enter the name of your candidate or proposal here (250 characters max.)": "Escriba aquí el nombre de su candidato o propuesta (250 caracteres como máximo)", "Enter the name of your candidate or proposal here (250 characters max.)": "Escriba aquí el nombre de su candidato o propuesta (250 caracteres como máximo)",
"Please add at least 2 candidates.": "Por favor, añada al menos dos canidatos(as).", "Please add at least 2 candidates.": "Por favor, añada al menos dos canidatos(as).",
"You can't limit access results without specify a voting time." : "No se puede limitar el acceso a los resultados sin especificar un tiempo de votación.",
"Question of the election": "Pregunta de su elección", "Question of the election": "Pregunta de su elección",
"Write here the question of your election": "Escriba aquí la pregunta de su elección", "Write here the question of your election": "Escriba aquí la pregunta de su elección",
"For example:": "Por ejemplo:", "For example:": "Por ejemplo:",

@ -17,6 +17,7 @@
"Write here your question or introduce simple your election (250 characters max.)": "Décrire ici votre question ou introduire simplement votre vote (250 caractères max.)", "Write here your question or introduce simple your election (250 characters max.)": "Décrire ici votre question ou introduire simplement votre vote (250 caractères max.)",
"Enter the name of your candidate or proposal here (250 characters max.)": "Saisissez ici le nom de votre candidat ou de votre proposition (250 caractères max.)", "Enter the name of your candidate or proposal here (250 characters max.)": "Saisissez ici le nom de votre candidat ou de votre proposition (250 caractères max.)",
"Please add at least 2 candidates.": "Merci d'ajouter au moins 2 candidats.", "Please add at least 2 candidates.": "Merci d'ajouter au moins 2 candidats.",
"You can't limit access results without specify a voting time." : "Vous ne pouvez pas limiter l'accès aux résultats sans spécifier une durée de vote.",
"Question of the election": "Question de votre vote", "Question of the election": "Question de votre vote",
"Write here the question of your election": "Ecrire ici la question de votre vote", "Write here the question of your election": "Ecrire ici la question de votre vote",
"For example:": "Par exemple", "For example:": "Par exemple",

@ -17,6 +17,7 @@
"Write here your question or introduce simple your election (250 characters max.)": "Напишите свой вопрос или опишите голосование (250 символов максимум.)", "Write here your question or introduce simple your election (250 characters max.)": "Напишите свой вопрос или опишите голосование (250 символов максимум.)",
"Enter the name of your candidate or proposal here (250 characters max.)": "Введите имя вашего кандидата или предложение здесь (не более 250 символов).", "Enter the name of your candidate or proposal here (250 characters max.)": "Введите имя вашего кандидата или предложение здесь (не более 250 символов).",
"Please add at least 2 candidates.": "Пожалуйста добавьте как минимум 2 кандидатов", "Please add at least 2 candidates.": "Пожалуйста добавьте как минимум 2 кандидатов",
"You can't limit access results without specify a voting time." : "Вы не можете ограничить результаты доступа без указания времени голосования.",
"Question of the election": "Суть голосования", "Question of the election": "Суть голосования",
"Write here the question of your election": "Напишите вопрос вашего голосования", "Write here the question of your election": "Напишите вопрос вашего голосования",
"For example:": "Например:", "For example:": "Например:",

@ -45,6 +45,8 @@ import i18n from "../../i18n";
// Error messages // Error messages
const AT_LEAST_2_CANDIDATES_ERROR = "Please add at least 2 candidates."; const AT_LEAST_2_CANDIDATES_ERROR = "Please add at least 2 candidates.";
const NO_TITLE_ERROR = "Please add a title."; const NO_TITLE_ERROR = "Please add a title.";
const RESTRICTED_RESULTS_NEED_LIMITED_TIME =
"You can't limit access results without specify a voting time.";
const isValidDate = (date) => date instanceof Date && !isNaN(date); const isValidDate = (date) => date instanceof Date && !isNaN(date);
const getOnlyValidDate = (date) => (isValidDate(date) ? date : new Date()); const getOnlyValidDate = (date) => (isValidDate(date) ? date : new Date());
@ -269,10 +271,13 @@ class CreateElection extends Component {
}; };
checkFields() { checkFields() {
const { candidates, title } = this.state; const { candidates, title, restrictResults, isTimeLimited } = this.state;
if (!candidates) { if (!candidates) {
return { ok: false, msg: AT_LEAST_2_CANDIDATES_ERROR }; return { ok: false, msg: AT_LEAST_2_CANDIDATES_ERROR };
} }
if (restrictResults && !isTimeLimited) {
return { ok: false, msg: RESTRICTED_RESULTS_NEED_LIMITED_TIME };
}
let numCandidates = 0; let numCandidates = 0;
candidates.forEach((c) => { candidates.forEach((c) => {
@ -359,11 +364,14 @@ class CreateElection extends Component {
.catch((error) => error); .catch((error) => error);
} }
handleSendNotReady = (msg) => { handleSendNotReady = () => {
const { t } = this.props; const { t } = this.props;
toast.error(t(msg), { const check = this.checkFields();
position: toast.POSITION.TOP_CENTER, if (!check.ok) {
}); toast.error(t(check.msg), {
position: toast.POSITION.TOP_CENTER,
});
}
}; };
render() { render() {
@ -878,7 +886,7 @@ class CreateElection extends Component {
<Button <Button
type="button" type="button"
className="btn btn-dark float-right btn-block" className="btn btn-dark float-right btn-block"
onClick={this.handleSendWithoutCandidate} onClick={this.handleSendNotReady}
> >
<FontAwesomeIcon icon={faCheck} className="mr-2" /> <FontAwesomeIcon icon={faCheck} className="mr-2" />
{t("Confirm")} {t("Confirm")}

Loading…
Cancel
Save