Skip to content

Commit

Permalink
Installed react modal image to aid display images on the cart
Browse files Browse the repository at this point in the history
  • Loading branch information
fkiptooh-r committed Feb 22, 2023
1 parent ef5e693 commit 4dc82d1
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-image-file-resizer": "^0.4.8",
"react-modal-image": "^2.6.0",
"react-redux": "^8.0.5",
"react-responsive-carousel": "^3.2.23",
"react-router-dom": "^6.6.2",
Expand Down
31 changes: 31 additions & 0 deletions src/components/cards/ProductCardInCheckout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import ModalImage from 'react-modal-image';
import laptop from '../../images/laptop.png'

const ProductCardInCheckout = ({p})=> {
return(
<tbody>
<tr>
<td>
<div style={{width: '100px', height: 'auto'}}>
{p.images.length ? (
<ModalImage small={p.images[0].url} large={p.images[0].url}/>
):(
<ModalImage small={laptop} large={laptop}/>
)}
</div>
</td>
<td>{p.title}</td>
<td>Ksh {p.price}</td>
<td>{p.brand}</td>
<td>{p.color}</td>
<td>{p.count}</td>
<td>Shipping Icon</td>
<td>Remove icon</td>
</tr>
</tbody>
)

}

export default ProductCardInCheckout
21 changes: 20 additions & 1 deletion src/pages/Cart.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import {useSelector, useDispatch} from 'react-redux'
import { Link, useNavigate } from "react-router-dom";
import ProductCardInCheckout from "../components/cards/ProductCardInCheckout";

const Cart =()=>{
const user = useSelector((state)=> ({...state}));
Expand All @@ -9,6 +10,24 @@ const Cart =()=>{
const dispatch = useDispatch();
const navigate = useNavigate();

const showCartItems=()=> {
return ( <table className="table table-borded">
<thead className="thead-light">
<tr>
<th scope="col">Image</th>
<th scope="col">Title</th>
<th scope="col">Price</th>
<th scope="col">Brand</th>
<th scope="col">Color</th>
<th scope="col">Count</th>
<th scope="col">Shipping</th>
<th scope="col">Remove</th>
</tr>
</thead>
{cart.map((p)=>(<ProductCardInCheckout key={p._id} p={p}/>))}
</table>);
}

const getTotal=()=> {
return cart.reduce((currentValue, nextValue)=>{
return currentValue + nextValue.count * nextValue.price
Expand Down Expand Up @@ -38,7 +57,7 @@ const Cart =()=>{
&nbsp;<Link to="/shop">Continue Shopping</Link>
</p>
):(
"Show products"
showCartItems()
)}
</div>
<div className="col-md-4">
Expand Down

0 comments on commit 4dc82d1

Please sign in to comment.