Skip to content

Commit fad5a23

Browse files
Merge pull request #35 from bhagirathpaliyal/OrderStatus
fix: changeOrderStatus issue
2 parents d02cae5 + 77f4516 commit fad5a23

File tree

2 files changed

+54
-33
lines changed

2 files changed

+54
-33
lines changed

src/components/Item.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function Item(prop) {
1313
load()
1414

1515
async function load() {
16-
if(prop.data.merchantIdRef) {
17-
const merchantData = await getDoc(prop.data.merchantIdRef);
16+
if(prop.data.merchantId) {
17+
const merchantData = await getDoc(prop.data.merchantId);
1818
setMerchant(await merchantData.data());
1919
} else {
2020
setMerchant(null)

src/components/Order/OrderDetails.jsx

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1-
import React, { useState } from 'react';
2-
import { Dialog, DialogTitle, DialogContent, DialogActions, Button, Typography, Stepper, Step, StepLabel } from '@mui/material';
3-
import { CheckCircle, LocalShipping, Cancel } from '@mui/icons-material';
4-
import { useDispatch } from 'react-redux';
5-
import { ChangeOrderStatus } from '../../store/feature/orderSlice';
1+
import React, { useState } from "react";
2+
import {
3+
Dialog,
4+
DialogTitle,
5+
DialogContent,
6+
DialogActions,
7+
Button,
8+
Typography,
9+
Stepper,
10+
Step,
11+
StepLabel,
12+
} from "@mui/material";
613

7-
const OrderDetails = ({ open, onClose, order, orderStatus }) => {
8-
const steps = ['Ordered', 'Shipped', 'Delivered'];
14+
import { useDispatch, useSelector } from "react-redux";
15+
import { ChangeOrderStatus } from "../../store/feature/orderSlice";
916

17+
const OrderDetails = ({ open, onClose, order, orderStatus }) => {
18+
const steps = ["Ordered", "Shipped", "Delivered"];
1019
const dispatch = useDispatch();
11-
const [status, setStatus] = useState('delivered')
20+
const [status, setStatus] = useState(orderStatus);
21+
22+
const user = useSelector((state) => {
23+
return state.auth.user;
24+
});
25+
1226
const getActiveStep = (status) => {
1327
switch (status) {
1428
case 'Ordered':
@@ -18,36 +32,46 @@ const OrderDetails = ({ open, onClose, order, orderStatus }) => {
1832
case 'Delivered':
1933
return 2;
2034
default:
21-
return -1;
35+
return -1;
36+
}
37+
};
38+
39+
const handleChangeStatus = () => {
40+
if (status !== orderStatus) {
41+
dispatch(ChangeOrderStatus({ OrderId: order, status }));
2242
}
2343
};
2444

2545
return (
2646
<Dialog open={open} onClose={onClose} maxWidth="sm" fullWidth>
27-
<DialogTitle className="bg-blue-500 text-white">Order Details</DialogTitle>
47+
<DialogTitle className="bg-blue-500 text-white">
48+
Order Details
49+
</DialogTitle>
2850
<DialogContent>
2951
<div className="space-y-4">
3052
<Typography variant="h6" className="font-bold">
3153
Order ID: <span className="font-normal">{order}</span>
3254
</Typography>
3355
<Typography variant="body1">
34-
Status: <span className="font-bold">{status}</span>
56+
Status:
57+
{user?.isMerchant ? (
58+
<select
59+
value={status}
60+
onChange={(e) => setStatus(e.target.value)}
61+
className="border p-2 rounded"
62+
>
63+
<option value="Ordered">Ordered</option>
64+
<option value="Shipped">Shipped</option>
65+
<option value="Delivered">Delivered</option>
66+
</select>
67+
) : (
68+
<span className="font-bold">{orderStatus}</span>
69+
)}
3570
</Typography>
3671
<Stepper activeStep={getActiveStep(orderStatus)} alternativeLabel>
3772
{steps.map((label) => (
3873
<Step key={label}>
39-
<StepLabel>
40-
<div className="flex items-center space-x-4">
41-
{label === 'Delivered' ? (
42-
<CheckCircle color="success" />
43-
) : label === 'Shipped' ? (
44-
<LocalShipping color="action" />
45-
) : (
46-
<CheckCircle color="primary" />
47-
)}
48-
<Typography variant="body2">{label}</Typography>
49-
</div>
50-
</StepLabel>
74+
<StepLabel>{label}</StepLabel>
5175
</Step>
5276
))}
5377
</Stepper>
@@ -57,14 +81,11 @@ const OrderDetails = ({ open, onClose, order, orderStatus }) => {
5781
<Button onClick={onClose} color="primary">
5882
Close
5983
</Button>
60-
<Button color="primary" onClick={() => {
61-
dispatch(
62-
ChangeOrderStatus({OrderId:order,status})
63-
);
64-
}}>
65-
ChangeOrderStatus
66-
</Button>
67-
84+
{user?.isMerchant && (
85+
<Button color="primary" onClick={handleChangeStatus}>
86+
Change Order Status
87+
</Button>
88+
)}
6889
</DialogActions>
6990
</Dialog>
7091
);

0 commit comments

Comments
 (0)