Skip to content

Commit c8b3827

Browse files
committed
add discounted price
1 parent 7ce13e1 commit c8b3827

File tree

9 files changed

+76
-29
lines changed

9 files changed

+76
-29
lines changed

src/actions/currentUserActions.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,14 @@ export const submitUpdateUser = user => dispatch => {
152152
}) => {
153153
dispatch(updateCurrentUser(data));
154154
dispatch(setUpdatingCurrentUser(false));
155+
return data;
155156
})
156-
.catch(({
157-
response
158-
}) => {
159-
const {
160-
error
161-
} = response.data;
157+
.catch((err) => {
158+
const error =
159+
err.response && err.response.data ? err.response.data.error : err;
162160
dispatch(setUserError(error));
163161
dispatch(setUpdatingCurrentUser(false));
162+
return error;
164163
});
165164
};
166165

@@ -172,11 +171,13 @@ export const submitUpdateUserAddress = address => dispatch => {
172171
data
173172
}) => {
174173
dispatch(setUpdatingCurrentUserAddress(false));
174+
return data;
175175
})
176176
.catch(err => {
177177
const error =
178178
err.response && err.response.data ? err.response.data.error : err;
179179
dispatch(setUserError(error));
180180
dispatch(setUpdatingCurrentUserAddress(false));
181+
return error
181182
});
182183
};

src/components/Header/Header.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ export class Header extends Component {
119119
</div>
120120

121121
<div className="is-flex items-center is-hidden-mobile">
122-
<Link to="/items" className="navbar-item">
122+
<Link to="#" className="navbar-item">
123123
Daily Deals
124124
</Link>
125-
<Link to="/items" className="navbar-item">
125+
<Link to="#" className="navbar-item">
126126
Sell
127127
</Link>
128-
<Link to="/items" className="navbar-item">
128+
<Link to="#" className="navbar-item">
129129
Help & Contact
130130
</Link>
131131
</div>

src/components/ItemCard/ItemCard.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,22 @@ const ItemCard = ({ item, addToCart }) => (
1212
/>
1313
<div className="item-card__name">{item.name}</div>
1414
<div className="item-card__bottom">
15+
16+
<p className="item-card__bottom__prices">
17+
<span className={`item-card__bottom__price ${item.discounted_price > 0 && 'has-discount'}`}>${item.price}</span>
18+
{ item.discounted_price > 0 ?
19+
<span className="item-card__bottom__discount">
20+
${item.discounted_price}
21+
</span>
22+
: null
23+
}
24+
</p>
1525
<button
1626
data-test="buy-btn"
1727
className={`item-card__bottom__buy-btn ${item.adding ? 'loading' : ''}`}
1828
onClick={() => addToCart(item.product_id, item)}
1929
>
20-
Add to cart
30+
Buy now
2131
</button>
2232
</div>
2333
<div className="item-card__hover">

src/components/ItemCard/ItemCard.scss

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,22 @@
4949
text-overflow: ellipsis;
5050
}
5151
&__bottom {
52-
height: 60px;
52+
height: 100px;
5353
display: flex;
5454
align-items: center;
55+
flex-direction: column;
56+
&__prices {
57+
font-size: 1.8rem;
58+
color: $color-red;
59+
margin-bottom: 10px;
60+
}
61+
&__price {
62+
&.has-discount {
63+
text-decoration: line-through;
64+
font-size: 1.5rem;
65+
margin-right: 10px;
66+
}
67+
}
5568
&__buy-btn {
5669
@include item-button;
5770
}
@@ -63,7 +76,7 @@
6376
top: 0;
6477
left: 0;
6578
right: 0;
66-
bottom: 80px;
79+
bottom: 110px;
6780
display: flex;
6881
justify-content: center;
6982
align-items: center;

src/components/MyCartModal/MyCartModal.jsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,12 @@ export class MyCartModal extends Component {
8585
</tr>
8686
))}
8787
</tbody>
88-
{
89-
cartProducts.length > 0 ?
90-
(<tfoot>
91-
<tr>
92-
<td colSpan="3"><h4 className="title is-4">Total</h4></td>
93-
<td colSpan="2"><h4 className="title is-4 color-red has-text-right">${cartTotalAmount}</h4></td>
94-
</tr>
95-
</tfoot>)
96-
: null
97-
}
98-
88+
<tfoot>
89+
<tr>
90+
<td colSpan="3"><h4 className="title is-4">Total</h4></td>
91+
<td colSpan="2"><h4 className="title is-4 color-red has-text-right">${cartProducts.length === 0 ? 0 : cartTotalAmount}</h4></td>
92+
</tr>
93+
</tfoot>
9994
</table>
10095
);
10196
};

src/components/OrderModal/OrderSummary.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class OrderDelivery extends Component {
1818
};
1919

2020
render = () => {
21-
const { cartProducts, user } = this.props;
21+
const { cartProducts, user, cartTotalAmount } = this.props;
2222
return (
2323
<div className="columns">
2424
<div className="column is-8">
@@ -44,6 +44,14 @@ export class OrderDelivery extends Component {
4444
</tr>
4545
))}
4646
</tbody>
47+
<tfoot>
48+
<tr>
49+
<td><h5 className="title is-5">Total</h5></td>
50+
<td colSpan="2">
51+
<h5 className="title is-5 has-text-right color-red">${cartTotalAmount}</h5>
52+
</td>
53+
</tr>
54+
</tfoot>
4755
</table>
4856
</div>
4957
<div className="column is-4">
@@ -74,7 +82,7 @@ export const mapStateToProps = ({
7482
submittingOrder,
7583
},
7684
shipping: { regions, region },
77-
cart: { cartProducts },
85+
cart: { cartProducts, cartTotalAmount },
7886
}) => ({
7987
orders,
8088
cartId,
@@ -86,6 +94,7 @@ export const mapStateToProps = ({
8694
regions,
8795
region,
8896
cartProducts,
97+
cartTotalAmount
8998
});
9099

91100
export const mapDispatchToProps = dispatch => ({

src/pages/Settings/Settings.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { Component } from 'react';
22
import propTypes from 'prop-types';
33
import { connect } from 'react-redux';
4+
import Notification from 'react-bulma-notification';
45
import './Settings.scss';
56
import Layout from '../../containers/Layout/Layout';
6-
77
import {
88
setCurrentUserField,
99
submitUpdateUser,
@@ -37,7 +37,11 @@ export class Settings extends Component {
3737
eve_phone: user.eve_phone,
3838
mob_phone: user.mob_phone,
3939
password: user.password || undefined,
40-
});
40+
}).then((res) => {
41+
if (res && res.email) {
42+
Notification.success('Information updated', { duration: 3 })
43+
}
44+
})
4145
};
4246

4347
_submitAddress = e => {
@@ -60,7 +64,11 @@ export class Settings extends Component {
6064
postal_code: user.postal_code,
6165
country: user.country,
6266
shipping_region_id: user.shipping_region_id,
63-
});
67+
}).then((res) => {
68+
if (res && res.email) {
69+
Notification.success('Address updated', { duration: 3 })
70+
}
71+
})
6472
};
6573

6674
_renderProfile = () => {

src/pages/SingleItem/SingleItem.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@ export class SingleItem extends Component {
170170
return (
171171
<div className="product">
172172
<h3 className="product__name">{item.name}</h3>
173-
<h3 className="product__price">$ {item.price}</h3>
173+
<h3 className={`product__price ${item.discounted_price > 0 && 'has-discount'}`}>$ {item.price}</h3>
174+
{
175+
item.discounted_price > 0 ?
176+
<h3 className="product__price">
177+
$ {item.discounted_price}
178+
</h3>
179+
: null
180+
}
174181

175182
{this._renderColors()}
176183

src/pages/SingleItem/SingleItem.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
&__price {
4848
color: $color-red;
4949
font-size: 2rem;
50+
&.has-discount {
51+
text-decoration: line-through;
52+
font-size: 1.5rem;
53+
}
5054
}
5155
&__info {
5256
font-size: 1.3rem;

0 commit comments

Comments
 (0)