1+ import { CalendarOutlined } from '@ant-design/icons'
12import type { MenuProps } from 'antd'
23import { Menu } from 'antd'
34import React , { useContext , useEffect , useState } from 'react'
@@ -7,6 +8,7 @@ import { LayoutContextInterface, LayoutCtx } from 'src/layout/LayoutContext'
78import { useTheme } from 'src/layout/ThemeContext'
89import { getPathWithoutLang } from 'src/locale/allTranslations'
910import DonateModal from 'src/pages/DonateModal/DonateModal'
11+ import { EVENT_DATE_ISO , REGISTRATION_CLOSE_ISO } from 'src/pages/hackathon/challenges'
1012import { PAGES } from 'src/routes'
1113import './menu.scss'
1214
@@ -53,12 +55,37 @@ function getGroup(label: React.ReactNode, key: React.Key, children: MenuItem[]):
5355 }
5456}
5557
58+ const HACKATHON_REG_CLOSE_MS = new Date ( REGISTRATION_CLOSE_ISO ) . getTime ( )
59+ const HACKATHON_EVENT_MS = new Date ( EVENT_DATE_ISO ) . getTime ( )
60+ const HACKATHON_MENU_HIDE_MS = HACKATHON_EVENT_MS + 3 * 24 * 60 * 60 * 1000 // hide 3 days after event
61+
5662const MainMenu = ( { collapsed = false } : MainMenuProps ) => {
5763 const { t } = useTranslation ( )
5864 const { currentLanguage } = useTheme ( )
5965 const { setDrawerOpen } = useContext < LayoutContextInterface > ( LayoutCtx )
6066 const [ isDonateModalVisible , setDonateModalVisible ] = useState ( false )
6167
68+ const now = Date . now ( )
69+ const showHackathon = now < HACKATHON_MENU_HIDE_MS
70+
71+ const hackathonDaysLeft =
72+ now < HACKATHON_REG_CLOSE_MS
73+ ? Math . ceil ( ( HACKATHON_REG_CLOSE_MS - now ) / ( 1000 * 60 * 60 * 24 ) )
74+ : null
75+
76+ const hackathonItem = showHackathon
77+ ? getItem (
78+ < Link to = { `/${ currentLanguage } /hackathon` } onClick = { ( ) => setDrawerOpen ( false ) } >
79+ { t ( 'hackathon_title' ) }
80+ { hackathonDaysLeft !== null && (
81+ < span className = "hackathon-badge" > { hackathonDaysLeft } d</ span >
82+ ) }
83+ </ Link > ,
84+ '/hackathon' ,
85+ < CalendarOutlined /> ,
86+ )
87+ : null
88+
6289 const handleDonateClick = ( e : React . MouseEvent ) => {
6390 e . preventDefault ( )
6491 setDonateModalVisible ( true )
@@ -87,6 +114,7 @@ const MainMenu = ({ collapsed = false }: MainMenuProps) => {
87114
88115 const groupedItems : MenuItem [ ] = [
89116 routeItems [ '/' ] ,
117+ hackathonItem ,
90118 ...MENU_GROUPS . map ( ( { key, paths } ) =>
91119 getGroup (
92120 < span className = "sidebar-menu-group-title" > { t ( key ) } </ span > ,
@@ -98,6 +126,7 @@ const MainMenu = ({ collapsed = false }: MainMenuProps) => {
98126
99127 const flatItems : MenuItem [ ] = [
100128 routeItems [ '/' ] ,
129+ hackathonItem ,
101130 ...MENU_GROUPS . flatMap ( ( { paths } ) => paths . map ( ( path ) => routeItems [ path ] ) . filter ( Boolean ) ) ,
102131 ] . filter ( Boolean )
103132
0 commit comments