-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finishes user pay cart functionality
- Loading branch information
1 parent
41c539c
commit 4a37fa5
Showing
9 changed files
with
439 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.