OrderListing.js
6.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { EyeOutlined, EyeTwoTone } from "@ant-design/icons";
import { Space, Table, Tag } from "antd";
import { Fragment, useEffect, useState } from "react";
import { Button, Image, Modal } from "react-bootstrap";
import { useDispatch, useSelector } from "react-redux";
import { toast } from "react-toastify";
import { getActivitiesByVendor } from "../../redux/actions/activityAction";
import { changeEnquiryStatus, getEnquiriesByVendor } from "../../redux/actions/enquiryAction";
const OrderListing = () => {
const dispatch = useDispatch();
useEffect(() => {
dispatch(getEnquiriesByVendor());
dispatch(getActivitiesByVendor());
}, []);
const { enquiriesByVendor } = useSelector(state => state.enquiriesByVendor);
const { allActivitiesData } = useSelector(state => state.allActivitiesData);
const [data, setData] = useState();
const [activityFilters, setactivityFilters] = useState();
const [enquiryDetails, setenquiryDetails] = useState();
const [showEnquiryModal, setshowEnquiryModal] = useState(false);
console.log("enquiriesByVendor", enquiriesByVendor);
const columns = [
{
title: "Activity name",
dataIndex: "activityName",
filters: activityFilters,
// filterMode: "tree",
filterSearch: true,
onFilter: (value, record) => {
console.log("value", value, record.name.startsWith(value));
return record.activityName.startsWith(value);
},
width: "25%"
},
{
title: "Name",
dataIndex: "name",
sorter: (a, b) => a.age - b.age,
width: "25%"
},
{
title: "Status",
dataIndex: "status",
filters: [
{
text: "pending",
value: "pending"
},
{
text: "closed",
value: "closed"
}
],
onFilter: (value, record) => record.status.startsWith(value),
filterSearch: true,
width: "25%",
render: tag => (
<span>
{tag == "pending" ? (
<Tag color={"red"} key={tag}>
{tag.toUpperCase()}
</Tag>
) : (
<Tag color={"blue"} key={tag}>
{tag.toUpperCase()}
</Tag>
)}
</span>
)
},
{
title: "Quantity",
dataIndex: "quantity",
// filters: [
// {
// text: "London",
// value: "London"
// },
// {
// text: "New York",
// value: "New York"
// }
// ],
// onFilter: (value, record) => record.address.startsWith(value),
// filterSearch: true,
width: "15%"
},
{
title: "Action",
width: "25%",
render: (_, record) => (
<Space size="middle">
<EyeTwoTone
onClick={() => {
setshowEnquiryModal(true);
console.log(record);
setenquiryDetails(enquiriesByVendor.filter(item => item.id == record.key));
}}
style={{ fontSize: "22px" }}
/>
{/* <a>Delete</a> */}
</Space>
)
}
];
useEffect(() => {
let rawData =
enquiriesByVendor &&
enquiriesByVendor.map(item => {
return {
key: item.id,
name: item.attributes.end_user.data.attributes.name,
quantity: item.attributes.quantity,
status: item.attributes.status,
activityName: item?.attributes?.experience?.data?.attributes?.name
};
});
setData(rawData);
}, [enquiriesByVendor]);
useEffect(() => {
const activityFiltersRaw =
allActivitiesData &&
allActivitiesData.data.map(item => {
return {
text: item.attributes.name,
value: item.attributes.name
};
});
setactivityFilters(activityFiltersRaw);
}, [allActivitiesData]);
const onChange = (pagination, filters, sorter, extra) => {
// console.log("params", pagination, filters, sorter, extra);
};
return (
<Fragment>
{/* <div className="row">
<div className="col-12 col-lg-12">
<div className="rightContent">
<div className="d-flex align-items-center justify-content-between px-2 mb-2"> */}
<div className="mb-3 d-flex align-items-center justify-content-between">
<h2 style={{ fontSize: 28 }}>Orders</h2>
<p><a href="">View all the orders</a></p>
</div>
{/* <div>
<Button type="button" variant="" className="btnAdd m-0">
<Image alt="" width="16" height="16" src="/images/vendor/icon-filter.svg" className="me-2" /> Filter
</Button>
</div>
</div> */}
<Table columns={columns} dataSource={data} onChange={onChange} />
{/* </div>
</div>
</div> */}
<Modal
show={showEnquiryModal}
onHide={() => {
setshowEnquiryModal(false);
}}
>
{console.log("enquiryDetails", enquiryDetails)}
<Modal.Header>Enquiry Details</Modal.Header>
<Modal.Body>
{enquiryDetails && enquiryDetails.length > 0 && (
<>
<div className="p-2">Name: {enquiryDetails[0].attributes.end_user.data.attributes.name}</div>
<div className="p-2">Phone number: {enquiryDetails[0].attributes.end_user.data.attributes.phone}</div>
<div className="p-2">Email: {enquiryDetails[0].attributes.end_user.data.attributes.email}</div>
<div className="p-2">
Status: <Tag color={enquiryDetails[0].attributes.status == "pending" ? "red" : "blue"}>{enquiryDetails[0].attributes.status.toUpperCase()}</Tag>
</div>
<Button
onClick={async () => {
if (enquiryDetails[0].attributes.status == "pending") {
let res = await changeEnquiryStatus({ status: "closed", id: enquiryDetails[0].id });
console.log("res", res);
} else {
let res = await changeEnquiryStatus({ status: "pending", id: enquiryDetails[0].id });
console.log("res", res);
}
await dispatch(getEnquiriesByVendor());
toast.success("Status changed");
setshowEnquiryModal(false);
}}
>
Change Status
</Button>
</>
)}
</Modal.Body>
</Modal>
</Fragment>
);
};
export default OrderListing;