|
@@ -9,6 +9,7 @@ import BarcodeReader from 'react-barcode-reader';
|
9
|
9
|
import axios from 'axios';
|
10
|
10
|
import ArticleDetails from '../Components/ArticleDetails';
|
11
|
11
|
import { Link } from 'react-router-dom';
|
|
12
|
+import NotInBdd from '../Components/NotInBdd';
|
12
|
13
|
|
13
|
14
|
export default class Stock extends React.Component {
|
14
|
15
|
|
|
@@ -21,7 +22,8 @@ export default class Stock extends React.Component {
|
21
|
22
|
empty:true,
|
22
|
23
|
totalPrice:0,
|
23
|
24
|
totalQuantity:0,
|
24
|
|
- redirect:false
|
|
25
|
+ redirect:false,
|
|
26
|
+ onNotInBdd:false
|
25
|
27
|
}
|
26
|
28
|
|
27
|
29
|
this.handleScan = this.handleScan.bind(this);
|
|
@@ -49,14 +51,18 @@ export default class Stock extends React.Component {
|
49
|
51
|
let i=0;
|
50
|
52
|
let current = this.state.articles[i];
|
51
|
53
|
let trouve = current.code === code ? true : false;
|
52
|
|
- while(!trouve) {
|
|
54
|
+ while(!trouve && i < this.state.articles.length-1) {
|
53
|
55
|
i++;
|
54
|
56
|
current = this.state.articles[i];
|
55
|
57
|
if (current.code === code) {
|
56
|
58
|
trouve = !trouve;
|
57
|
59
|
}
|
58
|
60
|
}
|
59
|
|
- // current.quantity = 1
|
|
61
|
+
|
|
62
|
+ // Gestion d'erreur si le code n'est pas dans la BDD
|
|
63
|
+ if (!trouve){
|
|
64
|
+ this.setState({onNotInBdd:true})
|
|
65
|
+ } else {
|
60
|
66
|
|
61
|
67
|
console.log(current);
|
62
|
68
|
|
|
@@ -96,7 +102,7 @@ export default class Stock extends React.Component {
|
96
|
102
|
this.calculateTotaux()
|
97
|
103
|
})
|
98
|
104
|
|
99
|
|
-
|
|
105
|
+ }
|
100
|
106
|
}
|
101
|
107
|
|
102
|
108
|
calculateTotaux = () => {
|
|
@@ -141,6 +147,12 @@ export default class Stock extends React.Component {
|
141
|
147
|
}
|
142
|
148
|
}
|
143
|
149
|
|
|
150
|
+ closeNotInBdd = () => {
|
|
151
|
+
|
|
152
|
+ this.setState({onNotInBdd:false})
|
|
153
|
+
|
|
154
|
+ }
|
|
155
|
+
|
144
|
156
|
render() {
|
145
|
157
|
if (!sessionStorage.getItem('token')){
|
146
|
158
|
return (<div id="errorRouteBlock"><div id="errorRouteTitle">ERREUR </div><br/><div id="errorRouteTxt">Vous n'êtes pas connecté</div><br/><Link id="link" to='/'>Retourner à l'Accueil</Link></div>)
|
|
@@ -151,6 +163,9 @@ export default class Stock extends React.Component {
|
151
|
163
|
<Navbar redirect="/stock" left="Monnaie" right="Le Stock"/>
|
152
|
164
|
<BarcodeReader onScan={this.handleScan}/>
|
153
|
165
|
<SearchBar/>
|
|
166
|
+ {this.state.onNotInBdd &&
|
|
167
|
+ <NotInBdd handleCloseAbove={this.closeNotInBdd}/>
|
|
168
|
+ }
|
154
|
169
|
{!this.state.empty ?
|
155
|
170
|
<div id="articlesInline">
|
156
|
171
|
{this.state.articlesJamalette.map((article) =>
|