-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69d8263
commit d45ac03
Showing
10 changed files
with
153 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useEffect } from 'react' | ||
import { Button, Table } from 'react-bootstrap' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { LinkContainer } from 'react-router-bootstrap' | ||
import { getOrderList } from '../../../redux/actions/orderActions' | ||
import Loader from '../Loader' | ||
import Message from '../Message' | ||
|
||
function OrderListScreen({history}) { | ||
|
||
const dispatch = useDispatch() | ||
const { userInfo: { user } } = useSelector(state => state.userLogin) | ||
|
||
|
||
const orderList = useSelector(state => state.orderList) | ||
const { loading, error, orders } = orderList | ||
|
||
useEffect(() => { | ||
if (user && user.isAdmin) { | ||
dispatch(getOrderList()) | ||
} else { | ||
history.push("/login") | ||
} | ||
}, [dispatch,history,user]) | ||
|
||
|
||
return ( | ||
<> | ||
{loading ? <Loader /> : error ? <Message variant='danger'>{error}</Message> : ( | ||
<> | ||
<h1>All Users</h1> | ||
<Table striped bordered hover> | ||
<thead> | ||
<tr> | ||
<th>USER</th> | ||
<th>DATE</th> | ||
<th>TOTAL</th> | ||
<th>PAID</th> | ||
<th>Delivered</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{orders.map(order=>( | ||
<tr key={order._id}> | ||
<td>{order.user && order.user.name}</td> | ||
<td>{order.createdAt.substring(0, 10)}</td> | ||
<td><span style={{fontSize:'1.5rem',marginRight:'0.1rem'}}>৳</span> {order.totalPrice}</td> | ||
<td> | ||
{order.isPaid ? order.paidAt.substring(0,10) : <Button variant='light' ><i className='fas fa-times' style={{color:'red'}}></i></Button>} | ||
</td> | ||
<td> | ||
{order.isDelivered ? order.deliveredAt.substring(0,10) : <Button variant='light' ><i className='fas fa-times' style={{color:'red'}}></i></Button>} | ||
</td> | ||
<td> | ||
<LinkContainer to={`/order/${order._id}`}> | ||
<Button >Details</Button> | ||
</LinkContainer> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
</> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default OrderListScreen |
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
export const ORDER_CREATE_REQUEST = "ORDER_CREATE_REQUEST"; | ||
export const ORDER_CREATE_SUCCESS = "ORDER_CREATE_SUCCESS"; | ||
export const ORDER_CREATE_FAIL = "ORDER_CREATE_FAIL"; | ||
|
||
export const ORDER_LIST_REQUEST = "ORDER_LIST_REQUEST"; | ||
export const ORDER_LIST_SUCCESS = "ORDER_LIST_SUCCESS"; | ||
export const ORDER_LIST_FAIL = "ORDER_LIST_FAIL"; |
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
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import express from "express"; | ||
import { addOrderItems } from "../controller/orderController.js"; | ||
import { isLoggedIn } from "../middlewares/authMiddleware.js"; | ||
import { addOrderItems, getOrders } from "../controller/orderController.js"; | ||
import { isAdmin, isLoggedIn } from "../middlewares/authMiddleware.js"; | ||
const router = express.Router(); | ||
|
||
router.route("/").post(isLoggedIn, addOrderItems); | ||
router.route("/").get(isLoggedIn,isAdmin,getOrders); | ||
|
||
export default router; |
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