diff --git a/next.config.mjs b/next.config.mjs index fa2af578..ffb2527a 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -11,10 +11,6 @@ const nextConfig = { contentDispositionType: 'attachment', contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;", remotePatterns: [ - { - protocol: 'https', - hostname: process.env.BASE_DOMAIN_IMAGES ?? '*', - }, { protocol: 'https', hostname: 'rpkm67.spg1.cdn.digitaloceanspaces.com', diff --git a/src/app/(main)/home/page.tsx b/src/app/(main)/home/page.tsx index 411f7ad1..fed76a12 100644 --- a/src/app/(main)/home/page.tsx +++ b/src/app/(main)/home/page.tsx @@ -8,7 +8,7 @@ import contactIcon from '@public/home/icon/contactlist.svg'; import qrcodeIcon from '@public/home/icon/qrcode.svg'; import editIcon from '@public/home/icon/edit.svg'; import logoutIcon from '@public/home/icon/logout.svg'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import QrCodeModal from '@/components/(main)/home/QrCodeModal'; import { useAuth } from '@/context/AuthContext'; import { useRouter } from 'next/navigation'; @@ -19,16 +19,24 @@ import Border from '@/components/firstdate/Border'; import CustomButton from '@/components/(main)/home/CustomButton'; import Link from 'next/link'; import { getMajorNameById } from '@/utils/register'; +import { getCurrentTime } from '@/utils/time'; export default function Home() { const router = useRouter(); const { user, logout } = useAuth(); + const [clientTime, setClientTime] = useState(new Date('1980-01-01')); const [qrModal, setQrModal] = useState(false); const [waitModal, setWaitModal] = useState(false); const [interestedEvent, setInterestedEvent] = useState< 'first-date' | 'rup-peun' >('first-date'); + useEffect(() => { + getCurrentTime().then((res) => { + setClientTime(res.currentTime); + }); + }, []); + return ( <> CU First Date 2024
Rub Peun Kao Mai 2024
- + E-book IconE-Book diff --git a/src/components/(main)/home/CustomButton.tsx b/src/components/(main)/home/CustomButton.tsx index b9d7ba35..792e9d41 100644 --- a/src/components/(main)/home/CustomButton.tsx +++ b/src/components/(main)/home/CustomButton.tsx @@ -2,13 +2,13 @@ import { cn } from '@/lib/utils'; import { createEbookCount } from '@/utils/count'; import { useRouter } from 'next/navigation'; import React from 'react'; -import { Client as NTPClient } from 'ntp-time'; interface CustomButtonProps { varient: 'first-date' | 'rub-peun' | 'e-book' | 'contact-list'; className?: string; children: React.ReactNode; registered?: boolean; + currentDate: Date; setWaitModal?: (value: boolean) => void; setEvent?: (value: 'first-date' | 'rup-peun') => void; } @@ -18,16 +18,12 @@ const CustomButton: React.FC = ({ className, children, registered, + currentDate, setWaitModal, setEvent, }) => { const router = useRouter(); const firstdate = async () => { - const ntpClient = new NTPClient(); - const currentDate = await ntpClient.syncTime().then((time) => { - console.log(time); - return time.time; - }); console.log(currentDate); let firstDateDate = currentDate; const firstDate = process.env.NEXT_PUBLIC_FIRST_DATE_DATE; @@ -46,11 +42,6 @@ const CustomButton: React.FC = ({ } }; const rubpeun = async () => { - const ntpClient = new NTPClient(); - const currentDate = await ntpClient.syncTime().then((time) => { - console.log(time); - return time.time; - }); console.log(currentDate); let rupPeunDate = currentDate; const rupPeun = process.env.NEXT_PUBLIC_RUP_PEUN_DATE; diff --git a/src/utils/time.ts b/src/utils/time.ts new file mode 100644 index 00000000..c6a40c30 --- /dev/null +++ b/src/utils/time.ts @@ -0,0 +1,13 @@ +'use server'; +import { Client as NTPClient } from 'ntp-time'; + +export async function getCurrentTime() { + try { + const ntpClient = new NTPClient(); + const currentTime = await ntpClient.syncTime(); + return { currentTime: currentTime.time }; + } catch (err: unknown) { + console.log(err); + } + return { currentTime: new Date() }; +}