Complete a typo sending to the server and user informing about that

parent 040cea16
...@@ -16,8 +16,8 @@ export const i18n = new LocalizedStrings({ ...@@ -16,8 +16,8 @@ export const i18n = new LocalizedStrings({
errorTooOften: "Вы отправляете исправления слишком часто", errorTooOften: "Вы отправляете исправления слишком часто",
close: "Закрыть", close: "Закрыть",
saveChanges: "Сохранить изменения", saveChanges: "Сохранить изменения",
messageSuccess: "Благодарим за отправку. Опечатка будет исправлена", messageSuccess: "Благодарим за отправку опечатки. Мы уже работаем над её исправлением!",
messageFailture: "Не удалось отправить исправление", messageFailture: "Не удалось отправить исправление. Мы уже работаем над решением проблемы!",
}, },
en: { en: {
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Modal, Button, FormGroup, FormControl, ControlLabel, HelpBlock, Alert } from 'react-bootstrap' import { Modal, Button, FormGroup, FormControl, ControlLabel, HelpBlock, Alert } from 'react-bootstrap'
import $ from 'jquery';
import './Modal.css'; import './Modal.css';
import {i18n} from '../Localization'; import { i18n } from '../Localization';
import {config} from '../config'; import { config } from '../config';
const alertify = require("alertify.js"); const alertify = require("alertify.js");
...@@ -21,7 +22,13 @@ class TypoModal extends Component { ...@@ -21,7 +22,13 @@ class TypoModal extends Component {
error: "" error: ""
} }
// TODO: English support
i18n.setLanguage(config.language);
this.closeCallback = props.closeCallback; this.closeCallback = props.closeCallback;
// Bindings
this.submitTypo = this.submitTypo.bind(this);
} }
handleShow = () => { handleShow = () => {
...@@ -69,20 +76,73 @@ class TypoModal extends Component { ...@@ -69,20 +76,73 @@ class TypoModal extends Component {
return true; return true;
} }
// Send typo to the typos server // Send data to the server
submitTypo = (corrected, comment) => { async sendRequest() {
const serverUrl = config.serverUrl;
const url = /*window.location.href*/
"https://test.etersoft.ru/test_react_client";
const data = {
language: config.language,
// Url of the page with a typo
url: url,
// Typo text
text: this.state.text,
// Corrected variant (legacy name "comment")
comment: this.state.correct,
// TODO: context
context: "",
// This is a comment for a correction
note: this.state.comment,
}
try {
let result = await $.ajax({
method: "POST",
data: data,
url: serverUrl,
});
result = JSON.parse(result);
if (result.success === "true") {
return true;
}
console.error("sendRequest error:", result.message);
return false;
} catch (error) {
return false;
}
}
// Validate data and send request to the server
async submitTypo(corrected, comment) {
if (!this.checkData()) { if (!this.checkData()) {
alertify.error(i18n.messageFailture); alertify.error(i18n.messageFailture);
return; return;
} }
// Close window - user can continue working
this.handleClose(); this.handleClose();
alertify.success(i18n.messageSuccess);
// Send async request
this.sendRequest().then(success => {
if (success) {
alertify.success(i18n.messageSuccess);
return; return;
} }
alertify.error(i18n.messageFailture);
});
}
render() { render() {
if (!this.state.show) return null; if (!this.state.show) return null;
...@@ -113,11 +173,11 @@ class TypoModal extends Component { ...@@ -113,11 +173,11 @@ class TypoModal extends Component {
<FormControl <FormControl
type="text" type="text"
placeholder={i18n.modalCommentPlaceholder} placeholder={i18n.modalCommentPlaceholder}
onChange={this.onChangeComment}/> onChange={this.onChangeComment} />
</FormGroup> </FormGroup>
</form> </form>
{ this.state.error ? <Alert bsStyle="danger">{this.state.error}</Alert> : null } {this.state.error ? <Alert bsStyle="danger">{this.state.error}</Alert> : null}
</Modal.Body> </Modal.Body>
<Modal.Footer> <Modal.Footer>
......
...@@ -4,6 +4,10 @@ export const config = { ...@@ -4,6 +4,10 @@ export const config = {
maxCorrectLength: 100, maxCorrectLength: 100,
minCorrectLength: 1, minCorrectLength: 1,
serverUrl: "//eterfund.ru/api/typos/server.php", //serverUrl: "//eterfund.ru/api/typos/server.php",
serverUrl: "//ambulance.pubsandbox.eterhost.ru/typos.server/server.php",
requestTimeout: 10000, requestTimeout: 10000,
language: "ru",
}; };
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment