|
@@ -4,16 +4,67 @@ import { Icon} from '@iconify/react';
|
4
|
4
|
import minusIcon from '@iconify/icons-fa-solid/minus';
|
5
|
5
|
import plusIcon from '@iconify/icons-fa-solid/plus';
|
6
|
6
|
import { Tooltip, Zoom } from '@material-ui/core';
|
|
7
|
+import axios from 'axios';
|
7
|
8
|
|
8
|
9
|
class Selected extends Component {
|
9
|
10
|
|
10
|
11
|
constructor(props){
|
11
|
12
|
super(props)
|
12
|
13
|
this.state = {
|
|
14
|
+ redirect:false
|
|
15
|
+ }
|
|
16
|
+ }
|
|
17
|
+
|
|
18
|
+ minusQuantitySelected = () => {
|
|
19
|
+ this.updateArticle(-1)
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+ plusQuantitySelected = () => {
|
|
23
|
+ this.updateArticle(1)
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ updateArticle = (value) => {
|
|
27
|
+
|
|
28
|
+ for (let i = 0 ; i < this.props.selectedArticles.length ; i++) {
|
|
29
|
+
|
|
30
|
+ axios.put(`https://etud.insa-toulouse.fr/~proximo/v2/api/articles/${this.props.selectedArticles[i].id}`,
|
|
31
|
+ {
|
|
32
|
+ 'name':this.props.selectedArticles[i].name,
|
|
33
|
+ 'description':this.props.selectedArticles[i].description,
|
|
34
|
+ 'quantity':this.props.selectedArticles[i].quantity+value,
|
|
35
|
+ 'price':this.props.selectedArticles[i].price,
|
|
36
|
+ 'code':this.props.selectedArticles[i].code,
|
|
37
|
+ 'category_id':this.props.selectedArticles[i].category.id
|
|
38
|
+ }
|
|
39
|
+ )
|
|
40
|
+ .then(res => {
|
|
41
|
+ console.log(res.data)
|
|
42
|
+ })
|
|
43
|
+ .catch(error => {
|
|
44
|
+ console.log(error.response)
|
|
45
|
+ })
|
|
46
|
+
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ deleteSelectedArticles = () => {
|
|
53
|
+
|
|
54
|
+ for (let i = 0 ; i < this.props.selectedArticles.length ; i++) {
|
|
55
|
+
|
|
56
|
+ axios.delete(`https://etud.insa-toulouse.fr/~proximo/v2/api/articles/${this.props.selectedArticles[i].id}`)
|
|
57
|
+ .then(res => {
|
|
58
|
+ console.log(res.data)
|
|
59
|
+ })
|
|
60
|
+ .catch(error => {
|
|
61
|
+ console.log(error.response)
|
|
62
|
+ })
|
13
|
63
|
|
14
|
64
|
}
|
15
|
65
|
}
|
16
|
66
|
|
|
67
|
+
|
17
|
68
|
render() {
|
18
|
69
|
return (
|
19
|
70
|
<div id="selectedBox">
|
|
@@ -33,7 +84,7 @@ class Selected extends Component {
|
33
|
84
|
</Tooltip>
|
34
|
85
|
<Tooltip title="Supprimer" TransitionComponent={Zoom} aria-label="Supprimer">
|
35
|
86
|
<div>
|
36
|
|
- <Icon icon={plusIcon} style={{transform : 'rotate(-45deg)', color: '#ffffff', fontSize: '2vw',cursor:'pointer',margin:'0 1vw 0 1vw'}} />
|
|
87
|
+ <Icon onClick={this.deleteSelectedArticles} icon={plusIcon} style={{transform : 'rotate(-45deg)', color: '#ffffff', fontSize: '2vw',cursor:'pointer',margin:'0 1vw 0 1vw'}} />
|
37
|
88
|
</div>
|
38
|
89
|
</Tooltip>
|
39
|
90
|
</div>
|