Skip to content

Commit bb8b83f

Browse files
committed
feat(legacy): add timer to banner
1 parent d0db6fc commit bb8b83f

File tree

3 files changed

+87
-2
lines changed

3 files changed

+87
-2
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { useEffect, useState } from 'react'
2+
3+
interface CountdownTimerProps {
4+
targetDate: Date
5+
className?: string
6+
}
7+
8+
interface TimeLeft {
9+
days: number
10+
hours: number
11+
minutes: number
12+
seconds: number
13+
}
14+
15+
export function CountdownTimer({ targetDate, className = '' }: CountdownTimerProps) {
16+
const [timeLeft, setTimeLeft] = useState<TimeLeft>({ days: 0, hours: 0, minutes: 0, seconds: 0 })
17+
const [isExpired, setIsExpired] = useState(false)
18+
19+
useEffect(() => {
20+
const calculateTimeRemaining = () => {
21+
const now = new Date()
22+
const difference = targetDate.getTime() - now.getTime()
23+
24+
if (difference <= 0) {
25+
setIsExpired(true)
26+
setTimeLeft({ days: 0, hours: 0, minutes: 0, seconds: 0 })
27+
return
28+
}
29+
30+
const days = Math.floor(difference / (1000 * 60 * 60 * 24))
31+
const hours = Math.floor((difference % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
32+
const minutes = Math.floor((difference % (1000 * 60 * 60)) / (1000 * 60))
33+
const seconds = Math.floor((difference % (1000 * 60)) / 1000)
34+
35+
setTimeLeft({ days, hours, minutes, seconds })
36+
}
37+
38+
// Calculate immediately
39+
calculateTimeRemaining()
40+
41+
// Set up interval to update every second
42+
const timer = setInterval(calculateTimeRemaining, 1000)
43+
44+
return () => clearInterval(timer)
45+
}, [targetDate])
46+
47+
if (isExpired) {
48+
return (
49+
<span className={className}>
50+
Registrace ukončena!
51+
</span>
52+
)
53+
}
54+
55+
const formatTimeUnit = (value: number, singular: string, few: string, many: string) => {
56+
if (value === 1) return singular
57+
if (value >= 2 && value <= 4) return few
58+
return many
59+
}
60+
61+
return (
62+
<span className={className}>
63+
{timeLeft.days > 0 && (
64+
<>
65+
{timeLeft.days} {formatTimeUnit(timeLeft.days, 'den', 'dny', 'dní')}{' '}
66+
</>
67+
)}
68+
{timeLeft.hours > 0 && (
69+
<>
70+
{timeLeft.hours} {formatTimeUnit(timeLeft.hours, 'hodina', 'hodiny', 'hodin')}{' '}
71+
</>
72+
)}
73+
{timeLeft.minutes > 0 && (
74+
<>
75+
{timeLeft.minutes} {formatTimeUnit(timeLeft.minutes, 'minuta', 'minuty', 'minut')}{' '}
76+
</>
77+
)}
78+
{timeLeft.seconds} {formatTimeUnit(timeLeft.seconds, 'sekunda', 'sekundy', 'sekund')}
79+
</span>
80+
)
81+
}

apps/legacy_nmit/next-env.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/// <reference types="next/image-types/global" />
33

44
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.
5+
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.

apps/legacy_nmit/pages/_document.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Script from "next/script"
44
import { Partytown } from "@builder.io/partytown/react"
55
import { Tracking } from "../components/Tracking"
66
import Link from "next/link"
7+
import { CountdownTimer } from "../components/CountdownTimer"
78

89
const APP_MAIN_COLOR = "#090c28"
910
const APP_NAME = "Nauč mě IT"
@@ -57,7 +58,10 @@ export default function Document() {
5758
</Head>
5859
<body className='h-full font-poppins accent-primary caret-primary'>
5960
<div className='fixed top-0 w-full z-50 text-white py-1 text-xl text-center bg-primary'>
60-
<Link href={"/kurz-vibecoding"}>Už jsme v kurzu! Můžeš se přihlásit na Kurz Vibecodingu zde.</Link>
61+
<Link href={"/kurz-vibecoding"}>
62+
Už jsme v kurzu! Můžeš se přihlásit na Kurz Vibecodingu zde.
63+
Zbývá: <CountdownTimer targetDate={new Date('2025-07-21T23:59:59')} className="font-bold" />
64+
</Link>
6165
</div>
6266
<Main />
6367
<NextScript />

0 commit comments

Comments
 (0)