Skip to content

Commit 70c782f

Browse files
Merge pull request #4525 from OneCommunityGlobal/Akshay-add-darkMode-resourceUsage
Akshay - Add - Dark Mode resourceUsage component
2 parents 7b50c3f + 8c82f49 commit 70c782f

2 files changed

Lines changed: 54 additions & 12 deletions

File tree

src/components/CommunityPortal/ResourceUsage/ResourceUsage.jsx

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client';
22

3-
import { useState, useEffect } from 'react';
3+
import { useState, useEffect, useRef } from 'react';
4+
import { useSelector } from 'react-redux';
45
import { Dropdown } from 'react-bootstrap';
56
import {
67
BarChart,
@@ -69,10 +70,10 @@ const allInsights = {
6970
],
7071
};
7172

72-
function CustomTooltip({ active, payload }) {
73+
function CustomTooltip({ active, payload, darkMode }) {
7374
if (active && payload && payload.length) {
7475
return (
75-
<div className={styles.customTooltip}>
76+
<div className={`${styles.customTooltip} ${darkMode ? styles.darkTooltip : ''}`}>
7677
<p className="mb-1">{`${payload[0].payload.name}`}</p>
7778
<p className="mb-1" style={{ color: '#22c55e' }}>{`Returned: ${payload[0].value}`}</p>
7879
<p className="mb-0" style={{ color: '#fca5a5' }}>{`Loaned: ${payload[1].value}`}</p>
@@ -88,6 +89,8 @@ export default function ResourceUsage() {
8889
const [insightsTimePeriod, setInsightsTimePeriod] = useState('Last Week');
8990
const [data, setData] = useState(allData.venue);
9091
const [insights, setInsights] = useState(allInsights['Last Week']);
92+
const darkMode = useSelector(state => state.theme.darkMode);
93+
const badgeRefs = useRef([]);
9194

9295
const filterDataByDate = (datas, period) => {
9396
// Create different datasets for different time periods to demonstrate filtering
@@ -108,6 +111,14 @@ export default function ResourceUsage() {
108111
}
109112
};
110113

114+
useEffect(() => {
115+
badgeRefs.current.forEach(badge => {
116+
if (badge) {
117+
badge.style.setProperty('color', '#000', 'important');
118+
}
119+
});
120+
}, [insights]);
121+
111122
useEffect(() => {
112123
const resourceTypeKey = resourceType.toLowerCase();
113124
const filteredData = filterDataByDate(allData[resourceTypeKey], timePeriod);
@@ -119,9 +130,9 @@ export default function ResourceUsage() {
119130
}, [insightsTimePeriod]);
120131

121132
return (
122-
<div className={styles.resourceUsageContainer}>
133+
<div className={`${styles.resourceUsageContainer} ${darkMode ? styles.darkContainer : ''}`}>
123134
{/* Left Section - Chart */}
124-
<div className={styles.chartSection}>
135+
<div className={`${styles.chartSection} ${darkMode ? styles.darkChartSection : ''}`}>
125136
<div className={styles.headerSection}>
126137
<h1>Resources usage</h1>
127138
<div className={styles.filters}>
@@ -157,10 +168,14 @@ export default function ResourceUsage() {
157168
dataKey="name"
158169
axisLine={false}
159170
tickLine={false}
160-
tick={{ fill: '#666', fontSize: 12 }}
171+
tick={{ fill: darkMode ? '#eee' : '#666', fontSize: 12 }}
161172
/>
162-
<YAxis axisLine={false} tickLine={false} tick={{ fill: '#666', fontSize: 12 }} />
163-
<Tooltip content={<CustomTooltip />} />
173+
<YAxis
174+
axisLine={false}
175+
tickLine={false}
176+
tick={{ fill: darkMode ? '#eee' : '#666', fontSize: 12 }}
177+
/>
178+
<Tooltip content={<CustomTooltip darkMode={darkMode} />} />
164179
<Legend
165180
align="right"
166181
verticalAlign="top"
@@ -200,7 +215,7 @@ export default function ResourceUsage() {
200215
</div>
201216

202217
{/* Right Section - Insights */}
203-
<div className={styles.insightsSection}>
218+
<div className={`${styles.insightsSection} ${darkMode ? styles.darkInsightsSection : ''}`}>
204219
<div className={styles.insightsHeader}>
205220
<h2>Insights</h2>
206221
<Dropdown>
@@ -222,9 +237,16 @@ export default function ResourceUsage() {
222237
</div>
223238
<div className={styles.insightsGrid}>
224239
{insights.map((insight, index) => (
225-
<div key={index} className={styles.insightCard}>
240+
<div
241+
key={index}
242+
className={`${styles.insightCard} ${darkMode ? styles.darkInsightCard : ''}`}
243+
>
226244
<div className={styles.insightTitle}>{insight.title}</div>
227-
<div className={styles.insightBadge} style={{ backgroundColor: insight.color }}>
245+
<div
246+
ref={el => (badgeRefs.current[index] = el)}
247+
className={styles.insightBadge}
248+
style={{ backgroundColor: insight.color }}
249+
>
228250
{insight.value}
229251
</div>
230252
</div>

src/components/CommunityPortal/ResourceUsage/ResourceUsage.module.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
background-color: #fff;
55
}
66

7+
.darkContainer {
8+
background: #1B2A41;
9+
}
10+
711
.chartSection {
812
flex: 1;
913
padding: 1.5rem;
1014
background: #fff;
1115
}
1216

17+
.darkChartSection {
18+
background: #2b3e59;
19+
}
20+
1321
.headerSection {
1422
margin-bottom: 2rem;
1523
}
@@ -42,7 +50,7 @@
4250

4351
.customDropdown:hover,
4452
.customDropdown:focus {
45-
background-color: #f9fafb !important;
53+
background-color: #b7b7b8 !important;
4654
border-color: #e5e7eb !important;
4755
}
4856

@@ -62,6 +70,10 @@
6270
padding: 1.5rem;
6371
}
6472

73+
.darkInsightsSection {
74+
background: #1B2A41;
75+
}
76+
6577
.insightsHeader {
6678
display: flex;
6779
justify-content: space-between;
@@ -89,6 +101,10 @@
89101
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
90102
}
91103

104+
.darkInsightCard {
105+
background: #2b3e59;
106+
}
107+
92108
.insightTitle {
93109
color: #6b7280;
94110
font-size: 0.875rem;
@@ -111,6 +127,10 @@
111127
border: 1px solid #e5e7eb;
112128
}
113129

130+
.darkTooltip{
131+
background: #1B2A41;
132+
}
133+
114134
/* Responsive Design */
115135
@media (max-width: 1200px) {
116136
.resourceUsageContainer {

0 commit comments

Comments
 (0)