Newer
Older
import IconButton from '@material-ui/core/IconButton'
import BackArrowIcon from 'assets/icons/ico/back-arrow.svg'
import FeedbackIcon from 'assets/icons/ico/feedback.svg'
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import Icon from 'cozy-ui/transpiled/react/Icon'
import { ScreenType } from 'enums'
import React, { useCallback, useEffect, useRef } from 'react'
import { useNavigate } from 'react-router-dom'
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') */
desktopTitleKey: string

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

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

Hugo SUBTIL
committed
}
/** Header for desktop view */

Hugo SUBTIL
committed
desktopTitleKey,
displayBackArrow,
children,
setHeaderHeight,

Hugo SUBTIL
committed
const { t } = useI18n()
const navigate = useNavigate()
const dispatch = useAppDispatch()
const { screenType } = 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 headerHeight = header.current?.clientHeight || 0
const adjustment = screenType === ScreenType.MOBILE ? cozyBarHeight : 0
setHeaderHeight(headerHeight - adjustment)

Hugo SUBTIL
committed
}, [screenType, children, setHeaderHeight])
return (

Hugo SUBTIL
committed
<div className="header-top">
<div className="header-content">
<div
className={

Hugo SUBTIL
committed
? 'header-content-top header-content-top-right'
: 'header-content-top'
}
>
{desktopTitleKey && (
<div
className={`header-text-desktop ${
screenType === ScreenType.MOBILE
? 'text-14-normal-uppercase'
: 'text-22-bold'
}`}
>
{displayBackArrow && (
<IconButton
aria-label={t('header.accessibility.button_back')}
className="header-back-button"
onClick={handleClickBack}
>
<Icon icon={BackArrowIcon} size={16} />
</IconButton>
)}
<span>{t(desktopTitleKey)}</span>

Hugo SUBTIL
committed
</div>
)}
<IconButton
aria-label={t('header.accessibility.button_open_feedbacks')}
className={

Hugo SUBTIL
committed
? 'header-feedbacks-button right'
: 'header-feedbacks-button'
}
onClick={handleClickFeedbacks}
>

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

Hugo SUBTIL
committed
)
}
export default Header