diff --git a/issue-tracker-ui/app/IssueAdd.js b/issue-tracker-ui/app/IssueAdd.js
deleted file mode 100644
index 55322cd..0000000
--- a/issue-tracker-ui/app/IssueAdd.js
+++ /dev/null
@@ -1,45 +0,0 @@
-import React, { Component } from 'react';
-import PropTypes from 'prop-types';
-import { Form, FormControl, Button } from 'react-bootstrap';
-
-export default class IssueAdd extends Component {
- constructor() {
- super();
- this.handleSubmit = this.handleSubmit.bind(this);
- }
-
- handleSubmit(e) {
- console.log('==> soumission du formulaire')
- e.preventDefault();
- var form = document.forms.issueAdd;
- this.props.createIssue(
- {
- owner: form.owner.value,
- title: form.title.value,
- status: 'NEW',
- created: new Date()
- }
- );
- // clear the form for the next input
- form.owner.value = "";
- form.title.value = "";
- }
-
- render() {
- return (
-
-
-
- )
- }
-}
-
-IssueAdd.propTypes = {
- createIssue: PropTypes.func.isRequired,
-};
diff --git a/issue-tracker-ui/app/IssueAddNavItem.js b/issue-tracker-ui/app/IssueAddNavItem.js
index 3b3266f..a667554 100644
--- a/issue-tracker-ui/app/IssueAddNavItem.js
+++ b/issue-tracker-ui/app/IssueAddNavItem.js
@@ -1,7 +1,7 @@
import React from 'react';
import { withRouter } from 'react-router';
import PropTypes from 'prop-types';
-import { NavItem, Glyphicon, Modal, Form, FormGroup, FormControl, FormSelect, ControlLabel, Button, ButtonToolbar } from 'react-bootstrap';
+import { NavItem, Glyphicon, Modal, Form, FormGroup, FormControl, ControlLabel, Button, ButtonToolbar } from 'react-bootstrap';
import Toast from './Toast.js';
class IssueAddNavItem extends React.Component {
@@ -10,6 +10,7 @@ class IssueAddNavItem extends React.Component {
this.state = {
showing: false,
toastVisible: false, toastMessage: '', toastType: 'success',
+ error: false
};
this.showModal = this.showModal.bind(this);
this.hideModal = this.hideModal.bind(this);
@@ -19,7 +20,7 @@ class IssueAddNavItem extends React.Component {
}
showModal() {
- this.setState({ showing: true });
+ this.setState({ showing: true, error : false });
}
hideModal() {
@@ -37,32 +38,45 @@ class IssueAddNavItem extends React.Component {
this.setState({ toastVisible: false });
}
+
submit(e) {
e.preventDefault();
- this.hideModal();
const form = document.forms.issueAdd;
const newIssue = {
owner: form.owner.value, title: form.title.value,
status: 'NEW', created: new Date(),
};
- fetch('/api/issues', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(newIssue),
- }).then(response => {
- if (response.ok) {
- window.location.reload(false);
- } else {
- response.json().then(error => {
- this.showError(`Failed to add issue: ${error.message}`);
- });
- }
- }).catch(err => {
- this.showError(`Error in sending data to server: ${err.message}`);
- });
+ if (form.title.value !== "") {
+ this.hideModal();
+ fetch('/api/issues', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify(newIssue),
+ }).then(response => {
+ if (response.ok) {
+ window.location.reload(false);
+ } else {
+ response.json().then(
+ this.showError(`Failed to add issue. The field Title is empty`)
+ );
+ }
+ }).catch(err => {
+ this.showError(`Error in sending data to server: ${err.message}`);
+ });
+ }
+ else {
+ this.setState({ error: true });
+ }
}
-
+
render() {
+ let button;
+ if (this.state.error) {
+ button = The field title is missing;
+ }
+ else {
+ button = null;
+ }
return (
Create Issue
@@ -72,8 +86,9 @@ class IssueAddNavItem extends React.Component {