Skip to content

Commit fab539a

Browse files
committed
promotion visible in list-of-product
1 parent c91ddb9 commit fab539a

File tree

9 files changed

+83
-63
lines changed

9 files changed

+83
-63
lines changed

src/Components/Basket/BasketComponent.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ class BasketComponent extends Component {
8181
>
8282
-1
8383
</Button>
84-
<Button variant="danger">
84+
<Button
85+
variant="danger"
86+
onClick={this.deleteClick.bind(this, index)}
87+
>
8588
<img
8689
className="trashBasket"
8790
src="https://img.icons8.com/carbon-copy/100/000000/trash.png"
8891
alt="trash"
89-
onClick={this.deleteClick.bind(this, index)}
9092
/>
9193
</Button>
9294
</Form>

src/Components/Orders/OrderComponent.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
resetHistoryOrders,
99
} from "../../store/actions/orders";
1010
import { connect } from "react-redux";
11-
import TitleComponent from "../Small/TitleComponent"
11+
import TitleComponent from "../Small/TitleComponent";
1212

1313
class OrderComponent extends Component {
1414
componentDidMount() {
@@ -63,6 +63,10 @@ class OrderComponent extends Component {
6363
<p className="productNameTitle">Description:</p>
6464
{product.description}
6565
</Card.Text>
66+
<Card.Text>
67+
<p className="productNameTitle"> Qty:</p>
68+
{product.quantity}
69+
</Card.Text>
6670
</Card.Body>
6771
</Col>
6872
</Row>
@@ -71,12 +75,12 @@ class OrderComponent extends Component {
7175
}
7276

7377
render() {
74-
let a = "You have"
75-
let b = "never ordered"
76-
if (this.props.old_Orders.length>1) {
78+
let a = "You have";
79+
let b = "never ordered";
80+
if (this.props.old_Orders.length > 1) {
7781
return (
7882
<div>
79-
<TitleComponent text1="Orders" text2="&nbsp;History"/>
83+
<TitleComponent text1="Orders" text2="&nbsp;History" />
8084
{/* <h1 className="pageTitle">Orders History</h1> */}
8185
{this.props.old_Orders.map((product, index) =>
8286
this.renderProduct(product, index)
@@ -89,7 +93,7 @@ class OrderComponent extends Component {
8993
<div class="container2">
9094
<h1>
9195
<div class="animation">
92-
<span class="first">{a}</span>
96+
<span class="first">{a}</span>
9397
<span class="oh">
9498
<span class="second">&nbsp;{b}</span>
9599
</span>

src/Components/Product/ListOfProductsComponent.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ class ProductListPage extends Component {
2828
}
2929

3030
render() {
31-
//store in navCategory all te different category of products
31+
//store in navCategory all the different category of products
3232
let product = this.props.products;
3333
let navCategory = [];
3434
product.forEach((element) => {
3535
if (element.category) {
36-
// if test not contains this category add it
36+
// if array not contains this category add it
3737
if (!navCategory.includes(element.category)) {
3838
navCategory.push(element.category);
3939
}
4040
}
4141
});
4242
return (
4343
<div id="myRow">
44-
<NavDropdown
45-
title="Category"
46-
id="nav-dropdown"
47-
onSelect={this.categorySet.bind(this)}
48-
>
49-
<NavDropdown.Item eventKey="All">All</NavDropdown.Item>
50-
{navCategory.map((product) => this.renderCategory(product))}
51-
52-
</NavDropdown>
53-
5444
<TitleComponent text1="Products" text2="&nbsp;list" />
45+
<div>
46+
<NavDropdown
47+
title="Category"
48+
id="nav-dropdown"
49+
onSelect={this.categorySet.bind(this)}
50+
>
51+
<NavDropdown.Item eventKey="All">All</NavDropdown.Item>
52+
{navCategory.map((product) => this.renderCategory(product))}
53+
</NavDropdown>
54+
</div>
5555

5656
<Container className="testContainer">
5757
<Row className="justify-content-md-center">
@@ -62,7 +62,7 @@ class ProductListPage extends Component {
6262
);
6363
}
6464

65-
//use to show all the different category of products
65+
//use to show all the different category of products in NavDrop
6666
renderCategory(category) {
6767
return (
6868
<div key={category}>
@@ -72,7 +72,10 @@ class ProductListPage extends Component {
7272
}
7373

7474
renderProduct(product) {
75-
if (product.category === `${this.props.category}`|| this.props.category === "All") {
75+
if (
76+
product.category === `${this.props.category}` ||
77+
this.props.category === "All"
78+
) {
7679
return (
7780
<Col className="testCol" md="auto" key={product.id}>
7881
<Card
@@ -96,9 +99,8 @@ class ProductListPage extends Component {
9699
More Info
97100
</a>
98101
</Card.Body>
99-
<Card.Footer id="footerCard" text="light">
100-
{product.prices}
101-
</Card.Footer>
102+
<Card.Footer className={product.promotionIsActive === 1 ? "colorSalePrice" : ""} id="footerCard" text="light">{product.promotionIsActive === 1 ? product.promotion : product.prices}</Card.Footer>
103+
102104
</Card>
103105
</Col>
104106
);

src/Components/Product/ProductCardComponent2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class ProductCardComponent2 extends Component {
4949
)
5050
}
5151
}
52+
5253
renderProduct(product) {
54+
let reducPrice = `${product.promotion} $`
5355
return (
5456
<div>
5557
<div className="login-box2 smallScreen">
@@ -71,7 +73,7 @@ class ProductCardComponent2 extends Component {
7173
<p>{product.lastName} {product.firstName}</p>
7274
</div>
7375
<ButtonComponent
74-
text={"Buy " + product.prices + " $"}
76+
text={"Buy" + product.prices + " $"}
7577
click={this.addButtonIsClick.bind(this)}
7678
/>
7779
</form>
@@ -99,7 +101,7 @@ class ProductCardComponent2 extends Component {
99101
<p>{product.lastName} {product.firstName}</p>
100102
</Card.Body>
101103
<ButtonComponent
102-
text={"Buy" + product.prices + "$"}
104+
text={product.promotionIsActive === 1 ? reducPrice: product.prices}
103105
click={this.addButtonIsClick.bind(this)}
104106
className="downButton"
105107
/>

src/Components/Sign/SignInComponent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from "react";
2+
// allow to connect the component to redux store
23
import { connect } from "react-redux";
34
import "../../Styles/Sign.css";
45
import axios from "axios";

src/Styles/EditProfilComponent.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ body {
1515
.login-box-Edit {
1616
margin: auto;
1717
margin-top: 10vh;
18-
width: 70%;
18+
width: 50%;
1919
padding: 40px;
2020
background: rgba(0, 0, 0, 0.8);
2121
box-sizing: border-box;
@@ -74,6 +74,7 @@ body {
7474
left: 50%;
7575
padding: 40px;
7676
margin-bottom: 40%;
77+
width: 70%;
7778
}
7879
html {
7980
height: 150%;
@@ -132,6 +133,6 @@ body {
132133
margin-left: 40%;
133134
margin-bottom: 40px;
134135
}
135-
.editDiv {
136+
/* .editDiv {
136137
137-
}
138+
} */

src/Styles/ListOfProduct.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ body {
66
min-height: 500px;
77
max-height: 500px;
88
opacity: 0.75;
9-
109
}
11-
#footerCard{
10+
#footerCard {
1211
position: absolute;
1312
}
1413
.box:hover {
@@ -22,9 +21,14 @@ body {
2221
}
2322
.testCol {
2423
padding-bottom: 10vh;
25-
2624
}
2725
.testImg {
2826
height: 200px;
2927
object-fit: contain;
3028
}
29+
.colorSalePrice{
30+
color: rgb(38, 247, 10);
31+
font-weight: bolder;
32+
}
33+
34+

src/index.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import './index.css';
4-
import App from './App';
5-
import * as serviceWorker from './serviceWorker';
6-
import 'bootstrap/dist/css/bootstrap.min.css';
7-
import{Provider} from "react-redux"
8-
import { BrowserRouter } from 'react-router-dom'
9-
import {persistStore,persistReducer} from "redux-persist";
10-
import {PersistGate} from "redux-persist/integration/react";
11-
import { createStore } from 'redux'
12-
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import "./index.css";
4+
import App from "./App";
5+
import * as serviceWorker from "./serviceWorker";
6+
import "bootstrap/dist/css/bootstrap.min.css";
7+
import { Provider } from "react-redux";
8+
import { BrowserRouter } from "react-router-dom";
9+
import { persistStore, persistReducer } from "redux-persist";
10+
import { PersistGate } from "redux-persist/integration/react";
11+
import { createStore } from "redux";
12+
import storage from "redux-persist/lib/storage"; // defaults to localStorage for web
13+
// all th reducer
1314
import indexReducer from "./store/reducer/index";
1415

15-
16+
//PersistData
1617
const persistConfig = {
17-
key: 'root',
18+
key: "root",
1819
storage,
19-
}
20-
21-
const persistedReducer = persistReducer(persistConfig, indexReducer)
22-
23-
let store = createStore(persistedReducer,
24-
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
25-
)
20+
};
21+
const persistedReducer = persistReducer(persistConfig, indexReducer);
2622

23+
let store = createStore(
24+
persistedReducer,
25+
//window dev extension
26+
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
27+
);
2728
const persistor = persistStore(store);
2829

2930
ReactDOM.render(
30-
// we need to make the store available to our app.
31-
// To do this, we wrap our app with the <Provider />
31+
// we need to make the store available to our app.
32+
// To do this, we wrap our app with the <Provider />
3233
// API provided by React Redux. store is passed in as a prop
33-
<Provider store={store}>
34-
<PersistGate persistor={persistor}>
35-
<BrowserRouter>
34+
35+
36+
<Provider store={store}>{/* Attach the store so all the component have acces */}
37+
<PersistGate persistor={persistor}>{/* Attach persit */}
38+
<BrowserRouter> {/* Attach Router */}
3639
<App />
3740
</BrowserRouter>
3841
</PersistGate>
3942
</Provider>,
40-
document.getElementById('root')
43+
document.getElementById("root")
4144
);
4245

43-
4446
// If you want your app to work offline and load faster, you can change
4547
// unregister() to register() below. Note this comes with some pitfalls.
4648
// Learn more about service workers: https://bit.ly/CRA-PWA
47-
serviceWorker.unregister();
49+
serviceWorker.unregister();

src/store/reducer/cart.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ const initialState = {
22
productBasket: [],
33
total: 0,
44
};
5+
6+
// to handle the qty of the same product
57
let item = {};
8+
69
const cartReducer = (state = initialState, action) => {
710
switch (action.type) {
811
case "ADD_PRODUCT_TO_CART":
9-
console.log("ICI",action.productBasket); // undefined
1012
item = state.productBasket.find(
1113
(element) => element.id === action.productBasket.id
1214
);

0 commit comments

Comments
 (0)