11'use client' ;
22
3- import { useState , useEffect } from 'react' ;
3+ import { useState , useEffect , useRef } from 'react' ;
4+ import { useSelector } from 'react-redux' ;
45import { Dropdown } from 'react-bootstrap' ;
56import {
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 >
0 commit comments