diff --git a/src/js/Components/Sort.js b/src/js/Components/Sort.js index 6a05b59..54d20be 100644 --- a/src/js/Components/Sort.js +++ b/src/js/Components/Sort.js @@ -20,13 +20,14 @@ class Sort extends Component {
+
{this.props.lowToHigh ? "A-Z" : "Z-A"}
diff --git a/src/js/Views/Stock.js b/src/js/Views/Stock.js index e629b53..d3f21ec 100644 --- a/src/js/Views/Stock.js +++ b/src/js/Views/Stock.js @@ -17,7 +17,6 @@ import EditCategory from '../Components/EditCategory'; import Sort from '../Components/Sort'; import { Link } from 'react-router-dom'; import Selected from '../Components/Selected'; -import BarcodeReader from 'react-barcode-reader' export default class Stock extends React.Component { @@ -67,8 +66,9 @@ export default class Stock extends React.Component { sortArticles = (sortType) => { let sorted; + //TRI PAR ORDRE ALPHABETIQUE OU PRIX if (sortType === "name"){ - this.setState({orderIsVisible: false}) + this.setState({orderIsHidden: false}) //choix d'ordre possible if (this.state.lowToHigh) { //ordre alphabétique croissant sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name)) @@ -76,17 +76,31 @@ export default class Stock extends React.Component { //ordre alphabétique décroissant sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name)) } + } else if (sortType === "price") { + console.log('tri pix') + this.setState({orderIsHidden: false}) //choix d'ordre possible + if (this.state.lowToHigh) { + //ordre croissant + sorted = [...this.state.articles].sort((a, b) => a.price - b.price) + } else { + //ordre décroissant + sorted = [...this.state.articles].sort((a, b) => b.price - a.price) + } + } else { - this.setState({orderIsVisible: true}) + console.log('autre 1') + this.setState({orderIsHidden: true}) this.setState({lowToHigh: false}) sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]); } + //TRI PAR CATEGORIE if (sortType === 'category_id'){ - this.setState({articles:sorted},() => { - this.setState({onSortedCategories:true}) - }) + this.setState({articles:sorted},() => { + this.setState({onSortedCategories:true}) + }) }else{ + console.log('autre 2') this.setState({articles:sorted},() => { console.log(this.state.articles) this.setState({onSortedCategories:false}) @@ -153,23 +167,34 @@ export default class Stock extends React.Component { this.setState({onEditCategory:false}) } - handleChangeSortType = (e) => { - this.setState({sortType:e.target.value},()=>{ - if (this.state.sortType === "Ordre Alphabétique"){ - this.sortArticles("name") - } else if(this.state.sortType === "Catégorie"){ - this.sortArticles("category_id") - } else if(this.state.sortType === "Quantité"){ - this.sortArticles("quantity") - } + // handleChangeSortType = (e) => { + // console.log(e.target.value) + // this.setState({sortType:e.target.value},()=>{ + // if (this.state.sortType === "Ordre Alphabétique"){ + // this.sortArticles("name") + // } else if(this.state.sortType === "Catégorie"){ + // this.sortArticles("category_id") + // } else if(this.state.sortType === "Quantité"){ + // this.sortArticles("quantity") + // } else if(this.state.sortType === "Prix"){ + // this.sortArticles("price"); + // } + // }) + // } + + handleChangeSortType = (e) => { + console.log(e.target.value) + this.setState({sortType: e.target.value}, () => { + this.sortArticles(this.state.sortType) }) } //Gère le choix de tri par ordre croissant ou décroissant quand c'est possible avec le tri actuel handleChangeSortOrder = e => { this.setState({lowToHigh: (this.state.lowToHigh + 1) % 2},() => { - this.sortArticles("name"); + console.log(this.state.sortType) + this.sortArticles(this.state.sortType); }); } @@ -216,19 +241,12 @@ export default class Stock extends React.Component { } } - handleScan = (data) => { - this.setState({code:data},()=>{ - console.log(this.state.code) - }) - } - render() { if (!sessionStorage.getItem('token')){ return (- Scanne tes articles pour remplir le ticket de caisse ! -
-+ Scanne tes articles pour remplir le ticket de caisse ! +
+