1- import React , { useContext , useEffect } from 'react' ;
1+ import React , { useContext , useEffect , useState } from 'react' ;
22import { Nav } from 'react-bootstrap' ;
33import { NavLink } from 'react-router' ;
44import { useTranslation } from 'react-i18next' ;
@@ -22,6 +22,7 @@ interface Props {
2222function Sidebar ( props : React . PropsWithChildren < Props > ) : React . ReactNode {
2323 const { signOut, user } = useContext ( AuthContext ) ;
2424 const { currentPage, setNewPage } = useContext ( SidebarContext ) ;
25+ const [ lastSeen , setLastSeen ] = useState ( '' ) ;
2526 const { t } = useTranslation ( ) ;
2627 const build = `Build: ${ env . VITE_BUILD } ` ;
2728
@@ -46,7 +47,25 @@ function Sidebar(props: React.PropsWithChildren<Props>): React.ReactNode {
4647 return '' ;
4748 } ;
4849
49- useEffect ( ( ) => { } , [ user , currentPage ] ) ;
50+ useEffect ( ( ) => {
51+ if ( user && user . lastLogin ) {
52+ const utcString = user . lastLogin . endsWith ( 'Z' ) ? user . lastLogin : `${ user . lastLogin } Z` ;
53+ const date = new Date ( utcString ) ;
54+ if ( Number . isNaN ( date . getTime ( ) ) ) {
55+ setLastSeen ( '' ) ;
56+ return ;
57+ }
58+ const fmtted = date . toLocaleString ( navigator . language , {
59+ timeZone : Intl . DateTimeFormat ( ) . resolvedOptions ( ) . timeZone ,
60+ day : '2-digit' ,
61+ month : '2-digit' ,
62+ year : 'numeric' ,
63+ hour : '2-digit' ,
64+ minute : '2-digit'
65+ } ) ;
66+ setLastSeen ( fmtted ) ;
67+ }
68+ } , [ user ] ) ;
5069
5170 return (
5271 < >
@@ -95,9 +114,12 @@ function Sidebar(props: React.PropsWithChildren<Props>): React.ReactNode {
95114
96115 { /* Footer at the bottom */ }
97116 < div className = "mt-auto text-center text-muted py-3" >
98- < small data-testid = "footer-text" >
99- { build }
100- </ small >
117+ { lastSeen && (
118+ < div >
119+ < small > { t ( 'sidebar_last_seen' , { time : lastSeen } ) } </ small >
120+ </ div >
121+ ) }
122+ < small data-testid = "footer-text" > { build } </ small >
101123 </ div >
102124 </ div >
103125
0 commit comments