diff --git a/next.config.mjs b/next.config.mjs index fa141206..a65756c2 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,7 +1,7 @@ /** @type {import('next').NextConfig} */ const nextConfig = { - reactStrictMode: true, + reactStrictMode: false, compress: true, compiler: { removeConsole: process.env.APP_ENV == 'production', diff --git a/src/app/rpkm/freshy-night/coming-soon/page.tsx b/src/app/rpkm/freshy-night/coming-soon/page.tsx index fe66915a..1dd4e645 100644 --- a/src/app/rpkm/freshy-night/coming-soon/page.tsx +++ b/src/app/rpkm/freshy-night/coming-soon/page.tsx @@ -22,7 +22,7 @@ export default function ComingSoon() { ตั้งแต่วันที่ 3 สิงหาคม 2567

- เวลา 00:00 เป็นต้นไป + เวลา 12:00 เป็นต้นไป

diff --git a/src/app/rpkm/freshy-night/confirm-register/page.tsx b/src/app/rpkm/freshy-night/confirm-register/page.tsx index 360bd5b4..3fab94ea 100644 --- a/src/app/rpkm/freshy-night/confirm-register/page.tsx +++ b/src/app/rpkm/freshy-night/confirm-register/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useState, ChangeEvent } from 'react'; +import { useState, ChangeEvent, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { useAuth } from '@/context/AuthContext'; import { getAccessToken } from '@/utils/auth'; @@ -16,6 +16,7 @@ import Spinner from '@/components/firstdate/Spinner'; import UserCard from '@/components/UserCard'; import ConfirmRegisterModal from '@/components/rpkm/freshy-night/ConfirmRegisterModal'; import { createCheckIn } from '@/utils/checkin'; +import { getCurrentTime } from '@/utils/time'; type RegisterUser = Pick< UserDTO, @@ -54,6 +55,16 @@ export default function Page() { }); const [errors, setErrors] = useState([]); const [isModalOpen, setIsModalOpen] = useState(false); + const [currentTime, setCurrentTime] = useState(null); + + useEffect(() => { + const initialize = async () => { + const now = (await getCurrentTime()).currentTime; + setCurrentTime(now); + }; + + initialize(); + }, []); const handleInputChange = ( e: ChangeEvent @@ -108,8 +119,20 @@ export default function Page() { } } - const handleConfirmBtn = () => { - if (!validateForm()) return; + const handleConfirmBtn = async () => { + if (!validateForm()) { + return; + } + + const freshyNightEndDate = new Date( + process.env.NEXT_PUBLIC_END_FRESHY_NIGHT_DATE as string + ); + + if (currentTime && currentTime > freshyNightEndDate) { + toast.error('หมดเวลาลงทะเบียน'); + return; + } + setIsModalOpen(true); }; diff --git a/src/app/rpkm/freshy-night/register/page.tsx b/src/app/rpkm/freshy-night/register/page.tsx index a4d0403d..ff12f663 100644 --- a/src/app/rpkm/freshy-night/register/page.tsx +++ b/src/app/rpkm/freshy-night/register/page.tsx @@ -8,7 +8,7 @@ export default function Register() { const { button } = modalStyles['red']; return ( -
+
+
(''); - const [event, setEvent] = useState(''); useEffect(() => { - const checkEvent = async () => { + const initialize = async () => { const currentTime = (await getCurrentTime()).currentTime; + const freshy_night_time = new Date( process.env.NEXT_PUBLIC_FRESHY_NIGHT_EVENT as string ); @@ -21,26 +21,16 @@ function Page() { process.env.NEXT_PUBLIC_RPKM_DAY_2 as string ); - if (currentTime > freshy_night_time) { + if (currentTime >= freshy_night_time) { setEventText('Freshy Night'); - setEvent('freshy-night'); - return; - } - - if (currentTime > rpkm_day_2_time) { + } else if (currentTime >= rpkm_day_2_time) { setEventText('Onsite 4 สิงหาคม 2567'); - setEvent('rpkm-day-2'); - return; - } - - if (currentTime > rpkm_day_1_time) { + } else if (currentTime >= rpkm_day_1_time) { setEventText('Onsite 3 สิงหาคม 2567'); - setEvent('rpkm-day-1'); - return; } }; - checkEvent(); + initialize(); }, []); return ( @@ -74,7 +64,7 @@ function Page() { {eventText}
- +
QR-Reader
diff --git a/src/components/rpkm/Sidebar/FreshyNightLink.tsx b/src/components/rpkm/Sidebar/FreshyNightLink.tsx index f7161941..01e672ad 100644 --- a/src/components/rpkm/Sidebar/FreshyNightLink.tsx +++ b/src/components/rpkm/Sidebar/FreshyNightLink.tsx @@ -1,3 +1,4 @@ +import { cn } from '@/lib/utils'; import { GetCheckIn } from '@/types/checkIn'; import { fetchCheckIn } from '@/utils/checkin'; import { getCurrentTime } from '@/utils/time'; @@ -25,10 +26,14 @@ const FreshyNightLink = ({ children }: FreshyNightLinkProps) => { initialize(); }, []); - const freshyNightDate = useMemo(() => { + const freshyNightStartDate = useMemo(() => { return new Date(process.env.NEXT_PUBLIC_FRESHY_NIGHT_DATE as string); }, []); + const freshyNightEndDate = useMemo(() => { + return new Date(process.env.NEXT_PUBLIC_END_FRESHY_NIGHT_DATE as string); + }, []); + const isRegistered = useMemo(() => { return ( !!checkins && @@ -37,7 +42,7 @@ const FreshyNightLink = ({ children }: FreshyNightLinkProps) => { }, [checkins]); const handleOnClick = () => { - if (currentTime && currentTime < freshyNightDate) { + if (currentTime && currentTime < freshyNightStartDate) { router.push('/rpkm/freshy-night/coming-soon'); return; } @@ -50,7 +55,17 @@ const FreshyNightLink = ({ children }: FreshyNightLinkProps) => { router.push('/rpkm/freshy-night/register-done'); }; - return
{children}
; + return ( +
freshyNightEndDate), + })} + > + {children} +
+ ); }; export default FreshyNightLink; diff --git a/src/components/rpkm/Sidebar/Menu.tsx b/src/components/rpkm/Sidebar/Menu.tsx index 85129214..dbd4ee0a 100644 --- a/src/components/rpkm/Sidebar/Menu.tsx +++ b/src/components/rpkm/Sidebar/Menu.tsx @@ -10,12 +10,9 @@ function Menu() { return (
- +
ลงทะเบียนเลือกบ้าน - +
ลงทะเบียน Freshy Night
diff --git a/src/components/rpkm/Sidebar/UserInfo.tsx b/src/components/rpkm/Sidebar/UserInfo.tsx index 7a13adf3..806ce80a 100644 --- a/src/components/rpkm/Sidebar/UserInfo.tsx +++ b/src/components/rpkm/Sidebar/UserInfo.tsx @@ -11,10 +11,12 @@ import { useAuth } from '@/context/AuthContext'; import Link from 'next/link'; import { baanInfos } from '../Baan/baanInfos'; import { getCurrentTime } from '@/utils/time'; +import QrCodeModal from '../freshy-night/QrCodeModal'; function UserInfo() { const { user } = useAuth(); const [currentTime, setCurrentTime] = useState(null); + const [qrModal, setQrModal] = useState(false); const findBaan = (result: string) => { return baanInfos.find((baan) => baan.name.en === result); }; @@ -103,8 +105,8 @@ function UserInfo() {
+
); } diff --git a/src/components/rpkm/staff/home/qrscanner/QRScanner.tsx b/src/components/rpkm/staff/home/qrscanner/QRScanner.tsx index a5e6a368..5ac7b404 100644 --- a/src/components/rpkm/staff/home/qrscanner/QRScanner.tsx +++ b/src/components/rpkm/staff/home/qrscanner/QRScanner.tsx @@ -1,5 +1,5 @@ 'use client'; -import React, { ReactNode, useState } from 'react'; +import React, { ReactNode, useEffect, useState } from 'react'; import { QrReader } from 'react-qr-reader'; import { motion } from 'framer-motion'; import { useAuth } from '@/context/AuthContext'; @@ -8,10 +8,9 @@ import FailureModal from './failureModal'; import { createCheckIn } from '@/utils/checkin'; import { CheckIn } from '@/types/checkIn'; import dayjs from 'dayjs'; -interface ScanProp { - event: string; -} -const Scan: React.FC = ({ event }) => { +import { getCurrentTime } from '@/utils/time'; + +const Scan: React.FC = () => { const [checkInData, setCheckInData] = useState(null); const [taken, setTaken] = useState(false); const [status, setStatus] = useState<'success' | 'error' | 'idle'>('idle'); @@ -25,6 +24,33 @@ const Scan: React.FC = ({ event }) => { return; } + let event = ''; + const currentTime = (await getCurrentTime()).currentTime; + + //need to check date every time because qr component don't update function when function re-render + const freshy_night_time = new Date( + process.env.NEXT_PUBLIC_FRESHY_NIGHT_EVENT as string + ); + const rpkm_day_1_time = new Date( + process.env.NEXT_PUBLIC_RPKM_DAY_1 as string + ); + const rpkm_day_2_time = new Date( + process.env.NEXT_PUBLIC_RPKM_DAY_2 as string + ); + + if (currentTime > freshy_night_time) { + event = 'freshy-night'; + } else if (currentTime > rpkm_day_2_time) { + event = 'rpkm-day-2'; + } else if (currentTime > rpkm_day_1_time) { + event = 'rpkm-day-1'; + } + + //need to use localstorage to prevent user scan qr code multiple time + //i don't useState because it not work with qrscanner + const enable = localStorage.getItem('enable') === 'true'; + if (!enable) return; + const userId = scanRawData.text; const newCheckInData: CheckIn | null = await createCheckIn( userId, @@ -32,6 +58,8 @@ const Scan: React.FC = ({ event }) => { event ); + localStorage.setItem('enable', 'false'); + if (newCheckInData) { if (newCheckInData.checkIn.isDuplicate) { const date = dayjs(newCheckInData.checkIn.timestamp); @@ -62,16 +90,18 @@ const Scan: React.FC = ({ event }) => { setStatus('idle'); }; + useEffect(() => { + localStorage.setItem('enable', 'true'); + }, []); + return (
- {event != '' && ( - - )} + = ({ onClose, userData, }) => { + const handleOnClose = () => { + onClose(); + localStorage.setItem('enable', 'true'); + }; + const modalClasses = `fixed inset-0 z-50 overflow-y-auto bg-gray-500 bg-opacity-75 transition-all ease-in-out duration-300 ${ isOpen ? 'opacity-100' : 'opacity-0 pointer-events-none' }`; @@ -45,7 +50,7 @@ const ConfirmModal: React.FC = ({
) : (