@@ -2,10 +2,13 @@ import React, { Component } from "react";
22import {
33 deleteProductFromCart ,
44 increaseCounter ,
5- decreaseCounter , resetCart
5+ decreaseCounter ,
66} from "../../store/actions/cart" ;
77import { connect } from "react-redux" ;
88import "../../Styles/BasketComponent.css" ;
9+ import Buttton from "../Small/ButtonComponent" ;
10+ import OrderComponent from '../OrderComponent'
11+ import axios from "axios" ;
912import {
1013 Card ,
1114 Col ,
@@ -15,21 +18,29 @@ import {
1518 Form ,
1619 ListGroup ,
1720} from "react-bootstrap" ;
18-
1921class BasketComponent extends Component {
2022 deleteClick ( index ) {
2123 this . props . deleteProductFromCart ( this . props . productBasket [ index ] ) ;
22- alert ( `${ this . props . productBasket [ index ] . name } has been deleted from your basket` )
24+ alert (
25+ `${ this . props . productBasket [ index ] . name } has been deleted from your basket`
26+ ) ;
2327 }
2428
25- increase ( product ) {
26- this . props . increaseCounter ( product )
29+ increase ( product ) {
30+ this . props . increaseCounter ( product ) ;
31+ }
32+ decrease ( product ) {
33+ this . props . decreaseCounter ( product ) ;
2734 }
28- decrease ( product ) {
29- this . props . decreaseCounter ( product )
35+ storeBasket ( e ) {
36+ console . log ( this . props . productBasket ) ;
37+ e . preventDefault ( ) ;
38+ axios . post ( "http://localhost:8080/panier" , this . props . productBasket ) ;
39+ setTimeout ( function ( ) {
40+ alert ( "Basket Validate" ) ;
41+ } , 1000 ) ;
3042 }
3143 renderProduct ( product , index ) {
32- console . log ( product ) ;
3344 return (
3445 < Container className = "basketCard" key = { index } >
3546 < Row >
@@ -55,8 +66,18 @@ class BasketComponent extends Component {
5566 </ ListGroup . Item >
5667 </ ListGroup >
5768 < Form inline >
58- < Button variant = "info" onClick = { this . increase . bind ( this , product ) } > +1</ Button >
59- < Button variant = "warning" onClick = { this . decrease . bind ( this , product ) } > -1</ Button >
69+ < Button
70+ variant = "info"
71+ onClick = { this . increase . bind ( this , product ) }
72+ >
73+ +1
74+ </ Button >
75+ < Button
76+ variant = "warning"
77+ onClick = { this . decrease . bind ( this , product ) }
78+ >
79+ -1
80+ </ Button >
6081 < Button variant = "danger" >
6182 < img
6283 className = "trashBasket"
@@ -74,32 +95,34 @@ class BasketComponent extends Component {
7495 }
7596
7697 render ( ) {
77- console . log ( this . props ) ;
78- if ( this . props . productBasket ) {
79- return (
80- < div >
81- { this . props . productBasket . map ( ( product , index ) =>
82- this . renderProduct ( product , index )
83- ) }
84- </ div >
85- ) ; } else {
86- return (
87- < div > </ div >
88- )
98+ if ( this . props . productBasket . length !== 0 ) {
99+ return (
100+ < div >
101+ { this . props . productBasket . map ( ( product , index ) =>
102+ this . renderProduct ( product , index )
103+ ) }
104+ < Buttton
105+ text = "Save Basket"
106+ link = "/paiement"
107+ click = { this . storeBasket . bind ( this ) }
108+ />
109+ < OrderComponent />
110+ </ div >
111+ ) ;
112+ } else {
113+ return < div > </ div > ;
89114 }
90-
91115 }
92116}
93117
94118const mapDispatchToProps = {
95119 deleteProductFromCart,
96120 increaseCounter,
97121 decreaseCounter,
98- resetCart
99122} ;
100123
101124const mapStateToProps = ( state ) => ( {
102125 productBasket : state . cartReducer . productBasket ,
103126} ) ;
104127
105- export default connect ( mapStateToProps , mapDispatchToProps ) ( BasketComponent ) ;
128+ export default connect ( mapStateToProps , mapDispatchToProps ) ( BasketComponent ) ;
0 commit comments