@@ -7,6 +7,7 @@ import { useState, useEffect } from 'react'
77import toast , { Toaster } from 'react-hot-toast'
88import AdminTabs from './AdminTabs'
99import ApiDocsTabs from './ApiDocsTabs'
10+ import ConsumptionTabs from './ConsumptionTabs'
1011import PageHeader from './PageHeader'
1112import { PageTransition } from './PageTransition'
1213import { useQueryClient } from '@tanstack/react-query'
@@ -34,14 +35,17 @@ export default function Layout({ children }: { children: React.ReactNode }) {
3435 // Menu items
3536 const menuItems = [
3637 { to : '/dashboard' , icon : Home , label : 'Tableau de bord' } ,
37- { to : '/consumption ' , icon : TrendingUp , label : 'Consommation' } ,
38+ { to : '/consumption_kwh ' , icon : TrendingUp , label : 'Consommation' } ,
3839 { to : '/production' , icon : Sun , label : 'Production' } ,
3940 { to : '/simulator' , icon : Calculator , label : 'Simulateur' } ,
4041 { to : '/contribute' , icon : Users , label : 'Contribuer' } ,
4142 { to : '/tempo' , icon : Calendar , label : 'Tempo' } ,
4243 { to : '/ecowatt' , icon : Zap , label : 'EcoWatt' } ,
4344 ]
4445
46+ // Check if we're on a consumption page (for active state and tabs)
47+ const isConsumptionPage = location . pathname . startsWith ( '/consumption' )
48+
4549 // Clear cache function (admin only)
4650 const handleClearCache = async ( ) => {
4751 if ( ! user ?. is_admin ) {
@@ -154,26 +158,32 @@ export default function Layout({ children }: { children: React.ReactNode }) {
154158 { /* Navigation */ }
155159 < nav className = "flex-1 overflow-y-auto py-4" >
156160 < div className = "space-y-1 px-2" >
157- { menuItems . map ( ( item ) => (
158- < Link
159- key = { item . to }
160- to = { item . to }
161- className = { `flex items-center gap-3 px-3 py-2.5 rounded-md transition-colors ${
162- location . pathname === item . to
163- ? 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400'
164- : 'hover:bg-gray-100 dark:hover:bg-gray-700'
165- } `}
166- title = { sidebarCollapsed ? item . label : '' }
167- data-tour = { item . to === '/consumption' ? 'nav-consumption' :
168- item . to === '/simulator' ? 'nav-simulator' :
169- item . to === '/contribute' ? 'nav-contribute' : undefined }
170- >
171- < item . icon size = { 20 } className = "flex-shrink-0" />
172- { ! sidebarCollapsed && (
173- < span className = "font-medium" > { item . label } </ span >
174- ) }
175- </ Link >
176- ) ) }
161+ { menuItems . map ( ( item ) => {
162+ // Special handling for consumption - active if any consumption page
163+ const isActive = item . to === '/consumption_kwh'
164+ ? isConsumptionPage
165+ : location . pathname === item . to
166+ return (
167+ < Link
168+ key = { item . to }
169+ to = { item . to }
170+ className = { `flex items-center gap-3 px-3 py-2.5 rounded-md transition-colors ${
171+ isActive
172+ ? 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400'
173+ : 'hover:bg-gray-100 dark:hover:bg-gray-700'
174+ } `}
175+ title = { sidebarCollapsed ? item . label : '' }
176+ data-tour = { item . to === '/consumption_kwh' ? 'nav-consumption' :
177+ item . to === '/simulator' ? 'nav-simulator' :
178+ item . to === '/contribute' ? 'nav-contribute' : undefined }
179+ >
180+ < item . icon size = { 20 } className = "flex-shrink-0" />
181+ { ! sidebarCollapsed && (
182+ < span className = "font-medium" > { item . label } </ span >
183+ ) }
184+ </ Link >
185+ )
186+ } ) }
177187
178188 { /* Admin Link */ }
179189 { canAccessAdmin ( ) && (
@@ -326,21 +336,27 @@ export default function Layout({ children }: { children: React.ReactNode }) {
326336 { /* Navigation */ }
327337 < nav className = "flex-1 overflow-y-auto py-4" >
328338 < div className = "space-y-1 px-2" >
329- { menuItems . map ( ( item ) => (
330- < Link
331- key = { item . to }
332- to = { item . to }
333- onClick = { ( ) => setMobileMenuOpen ( false ) }
334- className = { `flex items-center gap-3 px-3 py-2.5 rounded-md transition-colors ${
335- location . pathname === item . to
336- ? 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400'
337- : 'hover:bg-gray-100 dark:hover:bg-gray-700'
338- } `}
339- >
340- < item . icon size = { 20 } />
341- < span className = "font-medium" > { item . label } </ span >
342- </ Link >
343- ) ) }
339+ { menuItems . map ( ( item ) => {
340+ // Special handling for consumption - active if any consumption page
341+ const isActive = item . to === '/consumption_kwh'
342+ ? isConsumptionPage
343+ : location . pathname === item . to
344+ return (
345+ < Link
346+ key = { item . to }
347+ to = { item . to }
348+ onClick = { ( ) => setMobileMenuOpen ( false ) }
349+ className = { `flex items-center gap-3 px-3 py-2.5 rounded-md transition-colors ${
350+ isActive
351+ ? 'bg-primary-100 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400'
352+ : 'hover:bg-gray-100 dark:hover:bg-gray-700'
353+ } `}
354+ >
355+ < item . icon size = { 20 } />
356+ < span className = "font-medium" > { item . label } </ span >
357+ </ Link >
358+ )
359+ } ) }
344360
345361 { canAccessAdmin ( ) && (
346362 < >
@@ -459,11 +475,12 @@ export default function Layout({ children }: { children: React.ReactNode }) {
459475 < PageHeader />
460476 { location . pathname . startsWith ( '/admin' ) && < AdminTabs /> }
461477 { location . pathname . startsWith ( '/api-docs' ) && < ApiDocsTabs /> }
478+ { isConsumptionPage && < ConsumptionTabs /> }
462479 </ div >
463480
464481 { /* Main Content */ }
465482 < main className = { `flex-1 bg-gray-50 dark:bg-gray-900 ${ isAdminLogsPage ? 'overflow-hidden' : 'overflow-y-auto' } ` } >
466- < div className = { `container mx-auto px-3 sm:px-4 lg:px-6 max-w-[1920px] ${ isAdminLogsPage ? 'h-full pb-0' : 'pb-6' } ${ ( location . pathname . startsWith ( '/admin' ) || location . pathname . startsWith ( '/api-docs' ) ) ? 'pt-4' : '' } ` } >
483+ < div className = { `container mx-auto px-3 sm:px-4 lg:px-6 max-w-[1920px] ${ isAdminLogsPage ? 'h-full pb-0' : 'pb-6' } ${ ( location . pathname . startsWith ( '/admin' ) || location . pathname . startsWith ( '/api-docs' ) || isConsumptionPage ) ? 'pt-4' : '' } ` } >
467484 < PageTransition key = { location . pathname } >
468485 { children }
469486 </ PageTransition >
0 commit comments