From a471f4330949093be318fbedf56aae05cf48adb5 Mon Sep 17 00:00:00 2001 From: Thulina Wickramasinghe Date: Sun, 8 Sep 2024 12:12:55 +0530 Subject: [PATCH] Refactor: extract registration closing date into a constant --- apps/2024/src/components/common/layout/header.jsx | 8 +++++--- apps/2024/src/components/landing/competition.jsx | 4 ++-- apps/2024/src/components/landing/countdown/index.jsx | 3 ++- apps/2024/src/components/landing/hero.jsx | 11 +++++++---- apps/2024/src/constants/dates.js | 2 ++ apps/2024/src/constants/status.js | 2 -- apps/2024/src/main.jsx | 4 ++-- 7 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 apps/2024/src/constants/dates.js delete mode 100644 apps/2024/src/constants/status.js diff --git a/apps/2024/src/components/common/layout/header.jsx b/apps/2024/src/components/common/layout/header.jsx index 2dcf8d9..059c0f8 100644 --- a/apps/2024/src/components/common/layout/header.jsx +++ b/apps/2024/src/components/common/layout/header.jsx @@ -3,8 +3,9 @@ import { RxCross1, RxHamburgerMenu } from 'react-icons/rx'; import { Link } from 'react-router-dom'; import { twMerge } from 'tailwind-merge'; import { registrationLink } from '@/constants'; -import { isRegistrationsOpen } from '@/constants/status'; +import { TIME_REGISTRATION_CLOSING } from '@/constants/dates'; import { useBreakpoint } from '@/hooks'; +import useCountdown from '@/hooks/countdown'; import { Bashaway, FOSS, Times } from '@/icons'; import { Button } from '..'; @@ -16,6 +17,7 @@ const mobileNavIconStyles = const Header = ({ className }) => { const [mobileNavOpen, setMobileNavOpen] = useState(false); + const { didCountDownComplete } = useCountdown({ targetDate: new Date(TIME_REGISTRATION_CLOSING) }); const breakpoints = useBreakpoint(); const onNavItemClick = (path) => { @@ -76,8 +78,8 @@ const Header = ({ className }) => { {section} ))} - diff --git a/apps/2024/src/components/landing/competition.jsx b/apps/2024/src/components/landing/competition.jsx index 7dd55e3..a341f47 100644 --- a/apps/2024/src/components/landing/competition.jsx +++ b/apps/2024/src/components/landing/competition.jsx @@ -1,5 +1,5 @@ import { HighlightText, SectionBadge } from '@/components/common'; -import { currentYear } from '@/constants/status'; +import { CURRENT_YEAR } from '@/constants/dates'; const Competition = () => { return ( @@ -8,7 +8,7 @@ const Competition = () => { A unique competition that keeps the coders around the island on their toes. Welcome to ./bashaway  - {currentYear}, the third edition of the first-ever scripting and automation competition! + {CURRENT_YEAR}, the third edition of the first-ever scripting and automation competition! Join the battle once again. Seize the occasion to learn, create and grow! It's high time to leave your diff --git a/apps/2024/src/components/landing/countdown/index.jsx b/apps/2024/src/components/landing/countdown/index.jsx index f8d0914..cfcc55e 100644 --- a/apps/2024/src/components/landing/countdown/index.jsx +++ b/apps/2024/src/components/landing/countdown/index.jsx @@ -1,9 +1,10 @@ import { Separator } from '@/components/common/separator/index'; +import { TIME_REGISTRATION_CLOSING } from '@/constants/dates'; import useCountdown from '@/hooks/countdown'; import TimeItem from './time-item'; const CountDown = () => { - const { days, hours, minutes, seconds } = useCountdown({ targetDate: new Date('September 12, 2024 23:59:00') }); + const { days, hours, minutes, seconds } = useCountdown({ targetDate: new Date(TIME_REGISTRATION_CLOSING) }); return (
diff --git a/apps/2024/src/components/landing/hero.jsx b/apps/2024/src/components/landing/hero.jsx index 7027974..1ddb46a 100644 --- a/apps/2024/src/components/landing/hero.jsx +++ b/apps/2024/src/components/landing/hero.jsx @@ -1,15 +1,18 @@ import { BodyText, Button } from '@/components/common'; import { registrationLink } from '@/constants'; -import { currentYear, isRegistrationsOpen } from '@/constants/status'; +import { CURRENT_YEAR, TIME_REGISTRATION_CLOSING } from '@/constants/dates'; +import useCountdown from '@/hooks/countdown'; import { Bashaway } from '@/icons'; import { CountDown } from '.'; const Hero = () => { + const { didCountDownComplete } = useCountdown({ targetDate: new Date(TIME_REGISTRATION_CLOSING) }); + return (
- A unique competition that keeps the coders around the island on their toes. Welcome to Bashaway {currentYear}, + A unique competition that keeps the coders around the island on their toes. Welcome to Bashaway {CURRENT_YEAR}, the third edition of the first-ever scripting and automation competition in Sri Lanka! @@ -17,8 +20,8 @@ const Hero = () => { to={`${registrationLink}`} target="_blank" className="mt-1 sm:text-[22px] px-6 py-2 rounded-full tracking-[0.44px] z-30" - disabled={!isRegistrationsOpen}> - {isRegistrationsOpen ? 'Register Now' : 'Registration Closed'} + disabled={didCountDownComplete}> + {!didCountDownComplete ? 'Register Now' : 'Registration Closed'}
); diff --git a/apps/2024/src/constants/dates.js b/apps/2024/src/constants/dates.js new file mode 100644 index 0000000..2c3fd97 --- /dev/null +++ b/apps/2024/src/constants/dates.js @@ -0,0 +1,2 @@ +export const CURRENT_YEAR = 2024; +export const TIME_REGISTRATION_CLOSING = 'September 12, 2024 23:59:00'; diff --git a/apps/2024/src/constants/status.js b/apps/2024/src/constants/status.js deleted file mode 100644 index 6736f63..0000000 --- a/apps/2024/src/constants/status.js +++ /dev/null @@ -1,2 +0,0 @@ -export const isRegistrationsOpen = true; -export const currentYear = 2024; diff --git a/apps/2024/src/main.jsx b/apps/2024/src/main.jsx index 7fa8c74..711d625 100644 --- a/apps/2024/src/main.jsx +++ b/apps/2024/src/main.jsx @@ -3,13 +3,13 @@ import ReactDOM from 'react-dom/client'; import { BrowserRouter } from 'react-router-dom'; import { generateRouterBasePath } from '@app/utils'; import { default as App } from './app'; -import { currentYear } from './constants/status'; +import { CURRENT_YEAR } from './constants/dates'; import './styles/index.css'; const Root = () => { return ( - +