Skip to content

Commit

Permalink
Merge pull request AditiSharma00#20 from AditiSharma00/fw20_0743_day6
Browse files Browse the repository at this point in the history
d6
  • Loading branch information
waseem-1995 authored Apr 2, 2023
2 parents 0d6c60f + 3a7c95a commit 8637976
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
12 changes: 6 additions & 6 deletions pharmeasy/src/Components/AddAddressDrawer/AddressDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AddressDrawer = () => {
<>
{!address.bill?<Button
variant="solid"
// className={styles.addAddressButton}
className={styles.addAddressButton}
width="354px"
height="45px"
backgroundColor="#10847e"
Expand All @@ -58,7 +58,7 @@ const AddressDrawer = () => {
Add Delivery Address
</Button>:<Button
variant="solid"
// className={styles.addAddressButton}
className={styles.addAddressButton}
width="354px"
height="45px"
backgroundColor="#10847e"
Expand Down Expand Up @@ -206,7 +206,7 @@ const AddressDrawer = () => {
</Box>

<Box m="30px 0 0 0">
<Text
{/* <Text
mb="15px"
fontSize="14px"
color="#4f585e"
Expand All @@ -215,8 +215,8 @@ const AddressDrawer = () => {
letterSpacing="0.3px"
>
Pincode<span style={{ color: "red" }}>*</span>
</Text>
<RadioGroup fontSize="12px" name="addType" value={address.addType} onChange={handleChange}>
</Text> */}
{/* <RadioGroup fontSize="12px" name="addType" value={address.addType} onChange={handleChange}>
<Stack
spacing={5}
direction="row"
Expand All @@ -233,7 +233,7 @@ const AddressDrawer = () => {
<Radio value="work">Work</Radio>
<Radio value="others">Others</Radio>
</Stack>
</RadioGroup>
</RadioGroup> */}
</Box>

<Box m="30px 40px">
Expand Down
6 changes: 3 additions & 3 deletions pharmeasy/src/Components/CartItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React, { useEffect, useState } from "react";
import styles from "./CartItem.module.css";

const CartItem = ({ image, title, price }) => {
// const handleclick = (id) => {
// const handleDelete = (id) => {
// let data = JSON.parse(localStorage.getItem("cartitem"));
// let finaldata = data.filter((ele) => {
// if (ele.id != id) return ele;
// });
// localStorage.setItem("cartitem", JSON.stringify(finaldata));
// setdata(finaldata);
// };
// useEffect(() => {}, []);
useEffect(() => {}, []);

// function updateqty(id, value) {
// let data = JSON.parse(localStorage.getItem("cartitem"));
Expand Down Expand Up @@ -44,7 +44,7 @@ const CartItem = ({ image, title, price }) => {
<div className={styles.deleteButtonWrapper}>
<button
className={styles.deleteButton}
// onClick={() => handleclick()}
// onClick={() => handleDelete()}
>
<img
src="https://assets.pharmeasy.in/web-assets/dist/2fb50086.svg"
Expand Down
2 changes: 2 additions & 0 deletions pharmeasy/src/Pages/AllRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import NotFound from "./NotFound";
import { Products } from "../Pages/ProductPage/Products";
import { SingleProductPage } from "../Pages/SingleProdPage/SingleProductPage";
import Cart from "./Cart/Cart";
import Payment from "./PaymentPage/Payment";
function AllRoutes() {
return (
<Routes>
Expand All @@ -15,6 +16,7 @@ function AllRoutes() {
<Route path="/products/:id" element={<SingleProductPage />} />
<Route path="/search/:name" element={<Search />}></Route>
<Route path="/cart" element={<Cart />} />
<Route path="/payment" element={<Payment />} />
</Routes>
);
}
Expand Down
36 changes: 16 additions & 20 deletions pharmeasy/src/Pages/Cart/Cart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,28 @@ import AddressDrawer from "../../Components/AddAddressDrawer/AddressDrawer";
import axios from "axios";

const Cart = () => {
const[total_price,setTotalPrice]=useState(0)
const [cartItems, setCartItems] = useState([]);
useEffect(() => {
const items = JSON.parse(localStorage.getItem("cartItems")) || [];
setCartItems(items);
// console.log(items);
}, []);
// console.log(cartItems);

useEffect(() => {
let total = 0;
cartItems.forEach((item) => {
total += item.salePrice;
});
setTotalPrice(total);
}, [cartItems]);
// console.log(total_price)
return (
<>
<div className={styles.container}>
<div className={styles.leftContainer}>
<div className={styles.cartItemsWrapper}>
<h1 className={styles.cartItemsNumber}>Items in cart</h1>
<h1 className={styles.cartItemsNumber}>{cartItems.length}{" "}Items in cart</h1>
{/* <p className={styles.priceDes}>Prices are indicative</p> */}
</div>
{cartItems?.map((el) => {
Expand Down Expand Up @@ -141,7 +149,7 @@ const Cart = () => {
display: "flex",
justifyContent: "center",
alignItems: "center",
gap: "5px",
gap: "20px",
}}
>
<span>
Expand All @@ -161,13 +169,12 @@ const Cart = () => {
<div className={styles.cartValueWrapper}>
<p className={styles.CartValue}>Cart Value</p>
<p className={styles.CartValue}>
<span className={styles.orderStrikedPrice} />
<span className>
{total_price}
</span>
</p>
</div>
<div className={styles.deliveryChargesWrapper}>
<p className={styles.deliveryCharges}>Delivery Charges</p>
<p className={styles.deliveryCharges}>₹49.00</p>
</div>

<div className={styles.convenienceWrapper}>
<p className={styles.convenienceCharges}>Convenience charges</p>
<p className={styles.convenienceCharges}>
Expand All @@ -178,18 +185,7 @@ const Cart = () => {
<div className={styles.toBePaidWrapper}>
<p className={styles.toBePaid}>Amount to be paid</p>
<p className={styles.toBePaid}>
{/* ₹
{data.length == 0
? 0
: data.length == 1
? (Number(data[0].offprice * data[0].qty) + 49).toFixed(2)
: (
Number(
data.reduce(
(a, b) => a.offprice * a.qty + b.offprice * b.qty
)
) + 49
).toFixed(2)} */}
{total_price}
</p>
</div>
<hr className={styles.seperator} />
Expand Down
30 changes: 23 additions & 7 deletions pharmeasy/src/Pages/PaymentPage/Payment.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import styles from "./Payment.module.css";
import { MdOutlineKeyboardArrowRight } from "react-icons/md";
import {
Expand All @@ -20,6 +20,23 @@ import { GiConfirmed } from "react-icons/gi";
import { useNavigate } from "react-router-dom";

const Payment = () => {
const[total_price,setTotalPrice]=useState(0)
const [cartItems, setCartItems] = useState([]);
useEffect(() => {
const items = JSON.parse(localStorage.getItem("cartItems")) || [];
setCartItems(items);
// console.log(items);
}, []);
// console.log(cartItems);
useEffect(() => {
let total = 0;
cartItems.forEach((item) => {
total += item.salePrice;
});
setTotalPrice(total);
}, [cartItems]);
console.log(total_price)

const offersArray = [
{
id: 1,
Expand Down Expand Up @@ -65,8 +82,8 @@ const Payment = () => {
onOpen();
setTimeout(() => {
onClose();
localStorage.removeItem("cartvalue");
localStorage.removeItem("cartitem");
//localStorage.removeItem("cartvalue");
localStorage.removeItem("cartItems");
Navigate("/")
}, 5000)
}
Expand Down Expand Up @@ -358,13 +375,12 @@ const Payment = () => {
</Box>
<Flex gap="10px">
<Text
textDecoration="line-through"
fontSize="16px"
color="#8897a2"
color="#4f585e"
fontWeight="400"
fontFamily='"Open Sans", sans-serif'
>
{/* ₹{prices.sprice} */}
{total_price}
</Text>
<Text
fontSize="16px"
Expand Down Expand Up @@ -454,7 +470,7 @@ const Payment = () => {
fontWeight="500"
fontFamily='"Open Sans", sans-serif'
>
{/* ₹{Number(prices.price) + 49} */}
{Number(total_price) + 49}
</Text>
</Flex>
</Flex>
Expand Down

0 comments on commit 8637976

Please sign in to comment.