Skip to content

Commit 38cda3b

Browse files
Merge pull request #77 from atlp-rwanda/ft-seller-export-stats
Ft seller export stats
2 parents 94d23fd + 20bf105 commit 38cda3b

File tree

6 files changed

+266
-19
lines changed

6 files changed

+266
-19
lines changed

Diff for: package-lock.json

+122
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"html-webpack-plugin": "^5.6.0",
2828
"jwt-decode": "^4.0.0",
2929
"mini-css-extract-plugin": "^2.9.0",
30+
"papaparse": "^5.4.1",
3031
"react": "^18.3.1",
3132
"react-dom": "^18.3.1",
3233
"react-helmet": "^6.1.0",
@@ -40,6 +41,7 @@
4041
"recharts": "^2.12.7",
4142
"save-dev": "0.0.1-security",
4243
"socket.io-client": "^4.7.5",
44+
"xlsx": "^0.18.5",
4345
"yup": "^1.4.0"
4446
},
4547
"devDependencies": {
@@ -67,6 +69,7 @@
6769
"@types/jest": "^29.5.12",
6870
"@types/mini-css-extract-plugin": "^2.5.1",
6971
"@types/node": "^20.14.9",
72+
"@types/papaparse": "^5.3.14",
7073
"@types/react": "^18.3.3",
7174
"@types/react-dom": "^18.3.0",
7275
"@types/react-helmet": "^6.1.11",

Diff for: src/assets/styles/SellerLayout.scss

+28-12
Original file line numberDiff line numberDiff line change
@@ -341,21 +341,37 @@
341341
}
342342
}
343343

344-
.monthDropDown {
345-
.dropdown-button {
346-
background-color: #ff7300;
347-
color: #fff;
348-
border: none;
349-
padding: 5px 10px;
350-
border-radius: 5px;
351-
cursor: pointer;
352-
font-size: 14px;
353-
354-
.arrow-down {
355-
margin-left: 5px;
344+
.export-section{
345+
display: flex;
346+
gap: 10px;
347+
.monthDropDown {
348+
.dropdown-button {
349+
background-color: #ff7300;
350+
color: #fff;
351+
border: none;
352+
padding: 5px 10px;
353+
border-radius: 5px;
354+
cursor: pointer;
355+
font-size: 14px;
356+
357+
.arrow-down {
358+
margin-left: 5px;
359+
}
356360
}
357361
}
362+
.export-btn{
363+
background-color: #0f8615;
364+
color: #fff;
365+
border: none;
366+
padding: 5px 10px;
367+
border-radius: 5px;
368+
cursor: pointer;
369+
font-size: 14px;
370+
display: flex;
371+
gap: 4px;
372+
}
358373
}
374+
359375
}
360376
}
361377
}

Diff for: src/pages/seller/SellerDashboard.tsx

+17-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import {
1818
} from "../../store/features/product/sellerCollectionProductsSlice";
1919
import { useNavigate } from "react-router-dom";
2020
import productSlice from "../../store/features/product/productSlice";
21+
import { FaFileExcel } from "react-icons/fa";
22+
import exportToCSV from "../../utils/excel/exportToCSV";
23+
import exportToExcel from "../../utils/excel/exportToExcel";
2124

2225
const SellerDashboard = () => {
2326
const { OrderHistory, message, data, isError } = useAppSelector(
@@ -52,7 +55,7 @@ const SellerDashboard = () => {
5255
const [revenue, setRevenue] = useState(0);
5356
const [percentage, setPercentage] = useState(0);
5457
const [orderPercentage, setOrderPercentage] = useState(0);
55-
const [productPercentage,SetProductPercentage] = useState(0);
58+
const [productPercentage, SetProductPercentage] = useState(0);
5659

5760
useEffect(() => {
5861
dispatch(sellerGetOrderHistory());
@@ -88,7 +91,7 @@ const SellerDashboard = () => {
8891
setOrderPercentage(80)
8992
SetProductPercentage(76)
9093
}
91-
if ( isError && OrderHistory == null && message === "No shop found"){
94+
if (isError && OrderHistory == null && message === "No shop found") {
9295
setNumberOfOrders(0);
9396
setNumberOfProducts(0);
9497
setOrderStats(predefinedMonths);
@@ -103,7 +106,7 @@ const SellerDashboard = () => {
103106
} catch (error) {
104107
console.error("Failed to fetch data:", error);
105108
}
106-
}, [OrderHistory,isError,message]);
109+
}, [OrderHistory, isError, message]);
107110

108111
const MonthDropDown = () => {
109112
const [isOpen, setIsOpen] = useState(false);
@@ -158,8 +161,12 @@ const SellerDashboard = () => {
158161
selectedMonth === "All"
159162
? orderStats
160163
: orderStats.filter(
161-
(stat) => stat.name === selectedMonth.substring(0, 3)
162-
);
164+
(stat) => stat.name === selectedMonth.substring(0, 3)
165+
);
166+
167+
const exportStats = () => {
168+
exportToExcel(OrderHistory)
169+
}
163170

164171
return (
165172
<>
@@ -174,7 +181,7 @@ const SellerDashboard = () => {
174181
<Card
175182
title="Total Revenue"
176183
value={`${revenue} RWF`}
177-
percentage= {`${percentage}`}
184+
percentage={`${percentage}`}
178185
isPositive={false}
179186
/>
180187
<Card
@@ -194,7 +201,10 @@ const SellerDashboard = () => {
194201
<span className="dot cancelled"></span> Cancelled
195202
</div>
196203
</div>
197-
<MonthDropDown />
204+
<div className="export-section">
205+
<MonthDropDown />
206+
<button type="button" className="export-btn" onClick={exportStats}><FaFileExcel /> EXPORT</button>
207+
</div>
198208
</div>
199209
<ResponsiveContainer width="99%" height={250}>
200210
<BarChart

0 commit comments

Comments
 (0)