11import { addMonths , endOfMonth , startOfMonth , subMonths } from 'date-fns'
22import { FC , useCallback , useContext , useEffect , useMemo , useState } from 'react'
33
4+ import { useProfileContext } from '~/libs/core'
45import { Button } from '~/libs/ui'
56
67import { Calendar , CalendarLegend , MonthNavigation } from '../../lib/components'
@@ -12,6 +13,7 @@ import styles from './PersonalCalendarPage.module.scss'
1213
1314const PersonalCalendarPage : FC = ( ) => {
1415 const calendarContext = useContext ( CalendarContext )
16+ const profileContext = useProfileContext ( )
1517 const [ currentDate , setCurrentDate ] = useState < Date > ( new Date ( ) )
1618 const [ selectedDates , setSelectedDates ] = useState < Set < string > > ( new Set ( ) )
1719 const leaveDatesState = useFetchLeaveDates ( )
@@ -107,14 +109,35 @@ const PersonalCalendarPage: FC = () => {
107109 return `${ count } date${ count > 1 ? 's' : '' } selected`
108110 } , [ selectedDates ] )
109111
112+ const profile = profileContext . profile
113+ const displayName = useMemo ( ( ) => {
114+ const firstName = profile ?. firstName ?. trim ( )
115+ const lastName = profile ?. lastName ?. trim ( )
116+ const fullName = [ firstName , lastName ]
117+ . filter ( Boolean )
118+ . join ( ' ' )
119+
120+ return (
121+ fullName
122+ || profile ?. handle
123+ || calendarContext . loginUserInfo ?. handle
124+ || 'Your calendar'
125+ )
126+ } , [
127+ calendarContext . loginUserInfo ?. handle ,
128+ profile ?. firstName ,
129+ profile ?. handle ,
130+ profile ?. lastName ,
131+ ] )
132+
110133 const errorMessage = actionError || ( error ? 'Something went wrong. Please try again.' : '' )
111134
112135 return (
113136 < div className = { styles . page } >
114137 < header className = { styles . header } >
115138 < p className = { styles . subtitle } > Welcome back</ p >
116139 < h2 className = { styles . title } >
117- { calendarContext . loginUserInfo ?. handle ?? 'Your calendar' }
140+ { displayName }
118141 </ h2 >
119142 </ header >
120143
0 commit comments