Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] #157 Implemented 'Buy Now' & 'Add to Cart' Buttons #166

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"react": "^18.2.0",
"react-bootstrap": "^2.10.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-hook-form": "^7.51.4",
"react-icons": "^5.2.1",
"react-image-zoom": "^1.3.1",
"react-inner-image-zoom": "^3.0.2",
"react-lazy-load-image-component": "^1.6.0",
Expand Down
8 changes: 6 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function App() {

const is_Login = localStorage.getItem('isLogin');
setIsLogin(is_Login);

setTimeout(() => {
setProductData(data[1]);
setIsloading(false);
Expand Down Expand Up @@ -280,7 +280,11 @@ function App() {
/>
<Route exact={true} path="/cart" element={<Cart />} />
<Route exact={true} path="/wishlist" element={<Wishlist />} />
<Route exact={true} path="/compare" element={<Compare data={data} />} />
<Route
exact={true}
path="/compare"
element={<Compare data={data} />}
/>
<Route exact={true} path="/account" element={<Account />} />

{/* sign in , signup Protection */}
Expand Down
40 changes: 40 additions & 0 deletions src/components/Buttons/buttons.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.button-container {
display: flex;
gap: 10px;
}

.buy-now-button,
.add-to-cart-button {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}

.buy-now-button {
background-color: #ff5722;
color: white;
}

.buy-now-button:hover {
background-color: #e64a19;
}

.add-to-cart-button {
background-color: #009688;
color: white;
display: flex;
align-items: center;
gap: 5px;
}

.add-to-cart-button:hover {
background-color: #00796b;
}

.cart-icon {
font-size: 18px;
}

16 changes: 16 additions & 0 deletions src/components/Buttons/buttons.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { FaShoppingCart } from 'react-icons/fa';
import './buttons.css';

const Buttons = () => {
return (
<div className="button-container">
<button className="buy-now-button">Buy Now</button>
<button className="add-to-cart-button">
<FaShoppingCart className="cart-icon" /> Add to Cart
</button>
</div>
);
};

export default Buttons;
2 changes: 1 addition & 1 deletion src/components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Header = (props) => {
const [isOpenNav, setIsOpenNav] = useState(false);
const { cartCount, setCartCount } = useContext(MyContext);
const { wishlistCount, setWishlistCount } = useContext(MyContext);
const { compareCount } = useContext(MyContext)
const { compareCount } = useContext(MyContext);
const headerRef = useRef();
const searchInput = useRef();
const [profile, setProfile] = useState('');
Expand Down
127 changes: 59 additions & 68 deletions src/pages/Compare/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
getDocs,
onSnapshot
} from 'firebase/firestore';
const Compare = ({data}) => {
const Compare = ({ data }) => {
const [compareItems, setCompareItems] = useState([]);
const [error, setError] = useState(null);
const context = useContext(MyContext);
Expand Down Expand Up @@ -65,13 +65,7 @@ const Compare = ({data}) => {
}
};
const deleteCompareItem = async (uid, compareItemId) => {
const compareItemRef = doc(
db,
'compare',
uid,
'products',
compareItemId
);
const compareItemRef = doc(db, 'compare', uid, 'products', compareItemId);

try {
await deleteDoc(compareItemRef);
Expand Down Expand Up @@ -159,71 +153,69 @@ const Compare = ({data}) => {
compareItems.map((item, index) => {
return (
<>
<tr>
<td width={'50%'}>
<div className="d-flex align-items-center">
<div className="img">
<Link to={`/product/${item.id}`}>
<img
src={
item.catImg +
'?im=Resize=(100,100)'
}
className="w-100"
/>
</Link>
</div>
<tr>
<td width={'50%'}>
<div className="d-flex align-items-center">
<div className="img">
<Link to={`/product/${item.id}`}>
<img
src={
item.catImg +
'?im=Resize=(100,100)'
}
className="w-100"
/>
</Link>
</div>

<div className="info pl-4">
<Link to={`/product/${item.id}`}>
<h4>{item.productName}</h4>
</Link>
<Rating
name="half-rating-read"
value={parseFloat(item.rating)}
precision={0.5}
readOnly
/>{' '}
<span className="text-light">
({parseFloat(item.rating)})
</span>
<div className="info pl-4">
<Link to={`/product/${item.id}`}>
<h4>{item.productName}</h4>
</Link>
<Rating
name="half-rating-read"
value={parseFloat(item.rating)}
precision={0.5}
readOnly
/>{' '}
<span className="text-light">
({parseFloat(item.rating)})
</span>
</div>
</div>
</div>
</td>

<td width="20%">
<span>
Rs:{' '}
{parseInt(item.price.split(',').join(''))}
</span>
</td>
</td>

<td width="20%">
<span>{item.brand}</span>
</td>
<td width="20%">
<span>
Rs:{' '}
{parseInt(
item.price.split(',').join('')
)}
</span>
</td>

<td>
<span width="20%">
{item.shop_name}
</span>
</td>
<td width="20%">
<span>{item.brand}</span>
</td>

<td align="center">
<span
className="cursor"
onClick={() =>
deleteCompareItem(uid, `${item?.id}`)
}
>
<DeleteOutlineOutlinedIcon />
</span>
</td>
</tr>
<tr>
<div style={{display:"flex"}}>
<td>
<span width="20%">{item.shop_name}</span>
</td>

</div>
</tr>
<td align="center">
<span
className="cursor"
onClick={() =>
deleteCompareItem(uid, `${item?.id}`)
}
>
<DeleteOutlineOutlinedIcon />
</span>
</td>
</tr>
<tr>
<div style={{ display: 'flex' }}></div>
</tr>
</>
);
})}
Expand All @@ -244,7 +236,6 @@ const Compare = ({data}) => {
<RefreshIcon /> Update Cart</Button> */}
</div>
</div>

</div>
</div>
</section>{' '}
Expand Down
Loading