Newer
Older
import BackArrowIcon from 'assets/icons/ico/back-arrow.svg'
import FeedbackIcon from 'assets/icons/ico/feedback.svg'
import StyledIconButton from 'components/CommonKit/IconButton/StyledIconButton'
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import { ScreenType } from 'enums'
import React, { useCallback, useEffect, useRef } from 'react'
import { useNavigate } from 'react-router-dom'
import { setHeaderHeight } from 'store/global/global.slice'
import { useAppDispatch, useAppSelector } from 'store/hooks'
import { openFeedbackModal } from 'store/modal/modal.slice'

Hugo SUBTIL
committed
interface HeaderProps {
/** translation key used as t('key.value') */

Hugo SUBTIL
committed
displayBackArrow?: boolean
/** additional information to put below the main header */

Hugo SUBTIL
committed
children?: React.ReactNode
backFunction?: () => void

Hugo SUBTIL
committed
}

Hugo SUBTIL
committed
desktopTitleKey,
displayBackArrow,
children,

Hugo SUBTIL
committed
const { t } = useI18n()
const navigate = useNavigate()
const { screenType, headerHeight } = useAppSelector(
state => state.ecolyo.global
)

Hugo SUBTIL
committed
const cozyBarHeight = 48
const handleClickBack = useCallback(() => {
if (backFunction) {
backFunction()
} else {
}, [backFunction, navigate])

Hugo SUBTIL
committed
const handleClickFeedbacks = () => {

Hugo SUBTIL
committed
}
useEffect(() => {
const refHeight = header.current?.clientHeight || 0
const adjustment = screenType === ScreenType.MOBILE ? cozyBarHeight : 0
const targetHeight = refHeight - adjustment
if (targetHeight !== headerHeight) {
dispatch(setHeaderHeight(targetHeight))
}
}, [screenType, children, dispatch, headerHeight])

Hugo SUBTIL
committed
return (

Hugo SUBTIL
committed
<div className="header-top">
<div className="header-content">
<div className="header-content-top">
{screenType !== ScreenType.MOBILE && displayBackArrow && (
<StyledIconButton
icon={BackArrowIcon}
onClick={handleClickBack}
aria-label={t('header.accessibility.button_back')}
className="header-back-button"

Hugo SUBTIL
committed
{desktopTitleKey && (
<div
className={`${
displayBackArrow && desktopTitleKey
? 'header-text-selection'
: 'header-text-desktop'
} ${

Hugo SUBTIL
committed
screenType === ScreenType.MOBILE
? 'text-14-normal-uppercase'
: 'text-22-bold'
}`}
>
<span>{t(desktopTitleKey)}</span>

Hugo SUBTIL
committed
</div>
)}
<StyledIconButton
icon={FeedbackIcon}
sized={40}
onClick={handleClickFeedbacks}

Hugo SUBTIL
committed
aria-label={t('header.accessibility.button_open_feedbacks')}
className="header-feedbacks-button"

Hugo SUBTIL
committed
</div>
{children}
</div>
</div>
<div className="header-bar" />

Hugo SUBTIL
committed
)
}
export default Header