Skip to content

Commit

Permalink
Finishes user pay cart functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
ndahimana154 committed Aug 4, 2024
1 parent 41c539c commit 4a37fa5
Show file tree
Hide file tree
Showing 9 changed files with 439 additions and 80 deletions.
23 changes: 12 additions & 11 deletions src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
@import './assets/styles/ImageSlider.scss';
@import './assets/styles/Queries.scss';
@import './assets/styles/ViewCart.scss';
@import "./assets/styles/Notifications.scss";
@import "./assets/styles/Search.scss";
@import "./assets/styles/CustomSelect.scss";
@import "./assets/styles/SellerProduct.scss";
@import "./assets/styles/SellerCollection.scss";
@import "./assets/styles/SellerLayout.scss";
@import "./assets/styles/tables.scss";
@import "./assets/styles/adminDashboard.scss";
@import "./assets/styles/users.scss";
@import './assets/styles/Notifications.scss';
@import './assets/styles/Search.scss';
@import './assets/styles/CustomSelect.scss';
@import './assets/styles/SellerProduct.scss';
@import './assets/styles/SellerCollection.scss';
@import './assets/styles/SellerLayout.scss';
@import './assets/styles/tables.scss';
@import './assets/styles/adminDashboard.scss';
@import './assets/styles/users.scss';
@import "./assets/styles/liveChat.scss";
@import "./assets//styles/UserProfile.scss";
@import "./assets/styles/SellerSideProduct.scss";
@import './assets//styles/UserProfile.scss';
@import './assets/styles/SellerSideProduct.scss';
@import './assets/styles/myOrders.scss';
1 change: 1 addition & 0 deletions src/assets/styles/Colors.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import url('https://fonts.googleapis.com/css2?family=Averia+Serif+Libre:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700&display=swap');
$primary-color: #ff6d18;
$primary-color-opacity: #ff6d184d;
$primary-color-light: #ffe2d1;
$primary-color-dark: #ff8a46;
$secondary-color: #777777;
Expand Down
102 changes: 102 additions & 0 deletions src/assets/styles/myOrders.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
.my-orders-section {
h1 {
color: $primary-color;
text-align: center;
font-size: 22px;
padding: 10px;
}
.order {
width: 90%;
margin: auto;
font-size: 14px;
margin-top: 20px;
margin-bottom: 20px;
.head {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 10px 0;
background: $border-color;
text-transform: uppercase;
font-size: 12px;
div {
flex: 1;
color: $black;
font-weight: bold;
font-size: 12px;
padding-left: 5px;
}
.or {
flex: 2;
}
}
.order-body {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
background: $white;
div {
width: 25%;
color: $black;
padding: 5px;
border: 1px solid $border-color;
min-height: 100px;
}
.order-product {
display: flex;
flex-direction: row;
font-size: 12px;
img {
width: 48%;
height: 80px;
object-fit: cover;
}
p {
padding-left: 10px;
h3 {
margin-top: 5px;
font-size: 12px;
}
span {
font-weight: bold;
}
.o-price {
margin-left: 20px;
}
}
}
.order-details {
a {
top: 20px;
position: relative;
text-transform: uppercase;
text-decoration: underline;
font-size: 12px;
}
}
.date-placed {
span {
top: 20px;
position: relative;
}
}
.track {
button {
padding: 5px;
border: 2px solid $primary-color;
color: $primary-color;
border-radius: 5px;
margin-top: 20px;
cursor: pointer;
}
.disabled {
cursor: default;
color: $primary-color-opacity;
border: 2px solid $primary-color-opacity;
}
}
}
}
}
10 changes: 5 additions & 5 deletions src/pages/UserViewCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ const UserViewCart: React.FC = () => {
toast.error(response.message);
}
} catch (error: any) {
if (error === "Not authorized") {
localStorage.setItem("pendingCartProduct", productId);
toast.error("Please login first");
navigate("/login");
if (error === 'Not authorized') {
localStorage.setItem('pendingCartProduct', productId);
toast.error('Please login first');
navigate('/login');
} else {
toast.error("Something went wrong. Please try again later.");
toast.error('Something went wrong. Please try again later.');
}
} finally {
setIsLoading(false);
Expand Down
194 changes: 194 additions & 0 deletions src/pages/UserViewOrders.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/* eslint-disable */
import React, { useEffect, useState } from 'react';
import { Meta } from '../components/Meta';
import { useAppDispatch, useAppSelector } from '../store/store';
import { PuffLoader, PulseLoader } from 'react-spinners';
import { toast } from 'react-toastify';
import {
checkout,
getUserCarts,
clearCarts,
createCart,
clearCart,
clearCartProduct,
createProductStripe,
createSessionStripe,
updateCartStatus,
userSaveOrder,
getUserOrders,
} from '../store/features/carts/cartSlice';
import {
FaCheckSquare,
FaMinus,
FaPlus,
FaEdit,
FaTrash,
FaGift,
FaShippingFast,
} from 'react-icons/fa';
import { GiBroom } from 'react-icons/gi';
import { useNavigate } from 'react-router-dom';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import Product from '../components/product/Product';
import { Box, LinearProgress } from '@mui/material';
import Button from '@mui/material/Button';
import Dispatch from 'react';
import { fetchUserProfile } from '../store/features/user/userSlice';
import { useLocation } from 'react-router-dom';
import { Link } from 'react-router-dom';

const UserVIewOrders: React.FC = () => {
const dispatch = useAppDispatch();
const [isLoading, setIsLoading] = useState(true);
const [isError, setIsError] = useState(false);
const [cartData, setCartData] = useState<any>(null);
const [orderResponseData, setOrderResponseData] = useState(null);
const [isLoggedOut, setIsLoggedOut] = useState(false);
const [checkoutData, setCheckoutData] = useState(null);
const [isCheckoutSuccess, setCheckoutSuccess] = useState(null);
const [isPreloader, setIsPreloader] = useState(false);
const [discount, setDiscount] = useState(0);
const [totalProductPrice, setTotalProductPrice] = useState(0);
const [arrayOfProduct, setArrayOfProduct] = useState(null);
const [quantities, setQuantities] = useState<{ [key: string]: number }>({});
const [open, setOpen] = useState(false);
const [cartToPay, setCartToPay] = useState<string | null>(null);
const [amountToPay, setAmountToPay] = useState<any>(null);
const [stripePrice, setStripePrice] = useState<string>('');
const [currentEndpoint, setCurrentEndpoint] = useState('');

const navigate = useNavigate();
const location = useLocation();

const cartState = useAppSelector((state) => state.cart);

useEffect(() => {
fetchOrders();
}, [dispatch]);
const fetchOrders = async () => {
try {
setIsLoading(true);
const response = await dispatch(getUserOrders());
if (response.payload === 'orders not found') {
setIsError(true);
}
console.log('Response', response);
setOrderResponseData(response.payload.data.orders);
console.log('Response', response.payload.data);
} catch (error: any) {
if (error === 'Not authorized') {
setIsLoggedOut(true);
toast.error('Please login first');
navigate('/login');
}
console.error('Error fetching orders:', error);
setIsLoading(false);
setIsError(true);
toast.error(error.message);
} finally {
setIsLoading(false);
}
};

if (isLoading) {
return (
<div className="loader">
<PuffLoader color="#ff6d18" size={300} loading={isLoading} />
</div>
);
}

if (isError) {
return (
<div className="error-message">
<p>No orders found.</p>
</div>
);
}
if (isLoggedOut) {
return (
<div className="error-message">
<p>Please login or create account first.</p>
</div>
);
}

return (
<>
<Meta title="View Order history - E-Commerce Ninjas" />

{isPreloader && (
<div className="table__spinner">
<Box sx={{ width: '100%' }}>
<LinearProgress
sx={{
backgroundColor: '#fff',
'& .MuiLinearProgress-bar': {
backgroundColor: '#ff8a46',
},
}}
/>
</Box>
</div>
)}
<section className="my-orders-section">
<h1>Orders History</h1>
<div className="order">
{orderResponseData?.map((order) => (
<React.Fragment key={order.id}>
{JSON.parse(order.products).map((product, index) => (
<div key={index} className="order-item">
<div className="head">
<div className="">Order No: {order.id}</div>
<div className="">Details</div>
<div className="">Placed on</div>
<div className="">Status: {order.status}</div>
</div>
<div className="order-body">
<div className="order-product">
<img
src={product.image}
alt={product.name}
className="product_img"
/>
<p className="o-description">
<h3>{product.name}</h3>
<br />
<span>x{product.quantity}</span>
<span className="o-price">${product.price}</span>
</p>
</div>
<div className="order-details">
<Link to={`/track-order/${order.id}`}>
View Order Details
</Link>
</div>
<div className="date-placed">
<span>{new Date(order.createdAt).toDateString()}</span>
</div>
<div className="track">
<button
className={
order.status === 'Cancelled' ? 'disabled' : ''
}
disabled={order.status === 'Cancelled'}
>
TRACK ORDER
</button>
</div>
</div>
</div>
))}
</React.Fragment>
))}
</div>
</section>
</>
);
};

export default UserVIewOrders;
Loading

0 comments on commit 4a37fa5

Please sign in to comment.