-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathHeader.tsx
More file actions
55 lines (49 loc) · 1.8 KB
/
Header.tsx
File metadata and controls
55 lines (49 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { useContext } from 'react'
import { AuthContext } from 'react-oauth2-code-pkce'
import { useLocation } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Button, Navbar } from '@iqss/dataverse-design-system'
import dataverse_logo from '@/assets/dataverse_brand_icon.svg'
import { Route } from '@/sections/Route.enum'
import { useSession } from '@/sections/session/SessionContext'
import { LoggedInHeaderActions } from './LoggedInHeaderActions'
import { NotificationRepository } from '@/notifications/domain/repositories/NotificationRepository'
import { encodeReturnToPathInStateQueryParam } from '@/sections/auth-callback/AuthCallback'
import { LanguageSwitcher } from './LanguageSwitcher'
import styles from './Header.module.scss'
const BASENAME_URL = import.meta.env.BASE_URL ?? ''
interface HeaderProps {
notficationRepository: NotificationRepository
}
export function Header({ notficationRepository }: HeaderProps) {
const { t } = useTranslation('header')
const { user } = useSession()
const { pathname, search } = useLocation()
const { logIn: oidcLogin } = useContext(AuthContext)
const handleOidcLogIn = () => {
const state = encodeReturnToPathInStateQueryParam(`${pathname}${search}`)
oidcLogin(state)
}
return (
<Navbar
brand={{
title: t('brandTitle'),
href: `${BASENAME_URL}${Route.HOME}`,
logoImgSrc: dataverse_logo
}}
className={styles.navbar}>
<LanguageSwitcher />
{user ? (
<LoggedInHeaderActions user={user} notificationRepository={notficationRepository} />
) : (
<Button
onClick={handleOidcLogIn}
variant="link"
className={styles['login-btn']}
data-testid="oidc-login">
{t('logIn')}
</Button>
)}
</Navbar>
)
}