Skip to content

Commit 9c042e2

Browse files
author
Jaissica Hora
committed
fix: added start and end date based on backend requirement
1 parent 6dc85dc commit 9c042e2

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

src/components/BMDashboard/WeeklyProjectSummary/Financials/ExpenseBarChart.jsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const projects = ["Project A", "Project B", "Project C"];
99
export default function ExpenseBarChart() {
1010
const [projectId, setProjectId] = useState('');
1111
const [categoryFilter, setCategoryFilter] = useState('ALL');
12-
const [selectedDate, setSelectedDate] = useState('');
12+
const [startDate, setStartDate] = useState('');
13+
const [endDate, setEndDate] = useState('');
1314
const [data, setData] = useState([]);
1415

1516
useEffect(() => {
@@ -18,14 +19,17 @@ export default function ExpenseBarChart() {
1819
const rawData = [
1920
{ projectId: 'Project A', category: 'Plumbing', plannedCost: 1000, actualCost: 1200, date: '2025-04-01' },
2021
{ projectId: 'Project A', category: 'Electrical', plannedCost: 1500, actualCost: 1300, date: '2025-04-01' },
21-
{ projectId: 'Project B', category: 'Plumbing', plannedCost: 1100, actualCost: 1050, date: '2025-04-01' },
22-
{ projectId: 'Project B', category: 'Structural', plannedCost: 2200, actualCost: 2150, date: '2025-04-01' },
23-
{ projectId: 'Project C', category: 'Mechanical', plannedCost: 1300, actualCost: 1350, date: '2025-04-01' },
24-
{ projectId: 'Project C', category: 'Electrical', plannedCost: 1400, actualCost: 1600, date: '2025-04-01' },
22+
{ projectId: 'Project B', category: 'Plumbing', plannedCost: 1100, actualCost: 1050, date: '2025-04-02' },
23+
{ projectId: 'Project B', category: 'Structural', plannedCost: 2200, actualCost: 2150, date: '2025-04-02' },
24+
{ projectId: 'Project C', category: 'Mechanical', plannedCost: 1300, actualCost: 1350, date: '2025-04-03' },
25+
{ projectId: 'Project C', category: 'Electrical', plannedCost: 1400, actualCost: 1600, date: '2025-04-03' },
2526
];
2627

2728
const filtered = rawData.filter(entry => {
28-
const dateMatch = !selectedDate || entry.date === selectedDate;
29+
const entryDate = new Date(entry.date);
30+
const start = startDate ? new Date(startDate) : null;
31+
const end = endDate ? new Date(endDate) : null;
32+
const dateMatch = (!start || entryDate >= start) && (!end || entryDate <= end);
2933
const projectMatch = projectId === '' || entry.projectId === projectId;
3034
const categoryMatch = categoryFilter === 'ALL' || entry.category === categoryFilter;
3135
return dateMatch && projectMatch && categoryMatch;
@@ -43,12 +47,12 @@ export default function ExpenseBarChart() {
4347

4448
setData(Object.values(aggregated));
4549
} catch (error) {
46-
console.error("Error fetching expense comparison data:", error);
50+
console.error("Error processing mock data:", error);
4751
}
4852
}
4953

5054
fetchData();
51-
}, [projectId, categoryFilter, selectedDate]);
55+
}, [projectId, categoryFilter, startDate, endDate]);
5256

5357
return (
5458
<div style={{ width: '100%', padding: '0.5rem' }}>
@@ -79,8 +83,11 @@ export default function ExpenseBarChart() {
7983
{categories.map(cat => <option key={cat} value={cat}>{cat}</option>)}
8084
</select>
8185
</label>
82-
<label style={{ minWidth: '150px' }}>Date:
83-
<input type="date" value={selectedDate} onChange={(e) => setSelectedDate(e.target.value)} style={{ marginLeft: '0.3rem', width: '100%' }} />
86+
<label style={{ minWidth: '150px' }}>Start Date:
87+
<input type="date" value={startDate} onChange={(e) => setStartDate(e.target.value)} style={{ marginLeft: '0.3rem', width: '100%' }} />
88+
</label>
89+
<label style={{ minWidth: '150px' }}>End Date:
90+
<input type="date" value={endDate} onChange={(e) => setEndDate(e.target.value)} style={{ marginLeft: '0.3rem', width: '100%' }} />
8491
</label>
8592
</div>
8693

@@ -113,6 +120,3 @@ export default function ExpenseBarChart() {
113120
</div>
114121
);
115122
}
116-
117-
118-

0 commit comments

Comments
 (0)