Skip to content

Commit 609b49f

Browse files
authored
Merge branch 'Code-A2Z:master' into enhancement/sanitize-html-57
2 parents c082207 + 1079baa commit 609b49f

File tree

4 files changed

+29
-24
lines changed

4 files changed

+29
-24
lines changed

frontend/src/App.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import LoginPage from './pages/LoginPage';
55
import RegisterPage from './pages/RegisterPage';
66
import SetupPage from './pages/SetupPage';
77
import DashboardPage from './pages/DashboardPage';
8-
import { TransactionsPage } from './pages/TransactionsPage';
8+
import TransactionsPage from './pages/TransactionsPage';
99
import ReceiptsPage from './pages/ReceiptsPage';
1010
import WelcomePage from './pages/WelcomePage';
1111
import SettingsPage from './pages/SettingsPage';

frontend/src/pages/TransactionPage.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, vi, expect, beforeEach, afterEach } from "vitest";
22
import api from "../api/axios";
3-
import {handleExportCSV} from "./TransactionsPage";
3+
import { handleExportCSV } from "../utils/transactions";
44

55

66
describe("handleExportCSV", () => {

frontend/src/pages/TransactionsPage.jsx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,7 @@ import ManageCategoriesModal from '../components/ManageCategoriesModal';
77
import Spinner from '../components/Spinner';
88
import useCurrency from '../hooks/useCurrency';
99
import EmptyState from '../components/EmptyState';
10-
11-
const handleExportCSV = async () => {
12-
try {
13-
const res = await api.get('/transactions/export', {
14-
responseType: 'blob',
15-
});
16-
const blob = new Blob([res.data], { type: 'text/csv' });
17-
const url = window.URL.createObjectURL(blob);
18-
const a = document.createElement('a');
19-
a.href = url;
20-
a.download = 'paisable_transactions.csv';
21-
document.body.appendChild(a);
22-
a.click();
23-
a.remove();
24-
window.URL.revokeObjectURL(url);
25-
} catch (error) {
26-
console.error("Failed to export CSV", error);
27-
alert("Failed to export CSV. Please try again.");
28-
}
29-
};
10+
import { handleExportCSV } from '../utils/transactions';
3011

3112
const TransactionsPage = () => {
3213
const [transactions, setTransactions] = useState([]);
@@ -490,5 +471,4 @@ const TransactionsPage = () => {
490471
);
491472
};
492473

493-
// eslint-disable-next-line react-refresh/only-export-components
494-
export { TransactionsPage, handleExportCSV };
474+
export default TransactionsPage;

frontend/src/utils/transactions.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import api from '../api/axios';
2+
3+
/**
4+
* Exports all transactions to a CSV file
5+
* Downloads the file automatically to the user's device
6+
*/
7+
export const handleExportCSV = async () => {
8+
try {
9+
const res = await api.get('/transactions/export', {
10+
responseType: 'blob', // Important for file download
11+
});
12+
const blob = new Blob([res.data], { type: 'text/csv' });
13+
const url = window.URL.createObjectURL(blob);
14+
const a = document.createElement('a');
15+
a.href = url;
16+
a.download = 'paisable_transactions.csv';
17+
document.body.appendChild(a);
18+
a.click();
19+
a.remove();
20+
window.URL.revokeObjectURL(url);
21+
} catch (error) {
22+
console.error("Failed to export CSV", error);
23+
alert("Failed to export CSV. Please try again.");
24+
}
25+
};

0 commit comments

Comments
 (0)