From cf57a1318a3294bd2115466e46eb8f92be588d81 Mon Sep 17 00:00:00 2001 From: teegoood Date: Fri, 26 Jul 2024 09:08:41 +0700 Subject: [PATCH] remove baan from sidebar --- src/components/rpkm/Sidebar/UserInfo.tsx | 35 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/components/rpkm/Sidebar/UserInfo.tsx b/src/components/rpkm/Sidebar/UserInfo.tsx index ee636420..ad381058 100644 --- a/src/components/rpkm/Sidebar/UserInfo.tsx +++ b/src/components/rpkm/Sidebar/UserInfo.tsx @@ -1,4 +1,6 @@ -import React from 'react'; +'use client'; + +import React, { useEffect, useMemo, useState } from 'react'; import Image from 'next/image'; import pencilIcon from '@public/bar/icon/pencil.svg'; @@ -6,8 +8,37 @@ import placeholder from '@public/placeholder.svg'; import qrCodeIcon from '@public/home/icon/qrcode.svg'; import { useAuth } from '@/context/AuthContext'; import Link from 'next/link'; +import { getCurrentTime } from '@/utils/time'; function UserInfo() { const { user } = useAuth(); + const [currentTime, setCurrentTime] = useState(null); + + useEffect(() => { + const initialize = async () => { + const now = await getCurrentTime(); + if (now) { + setCurrentTime(now.currentTime); + } + }; + + initialize(); + }, []); + + const isShowBaan = useMemo(() => { + if (!user?.baan || !currentTime) { + return false; + } + + const annouceBaanDate = new Date( + process.env.NEXT_PUBLIC_BAAN_ANNOUCE_DATE as string + ); + if (currentTime >= annouceBaanDate) { + return true; + } + + return false; + }, [currentTime, user?.baan]); + return (
@@ -24,7 +55,7 @@ function UserInfo() {

- {user?.baan} + {isShowBaan && user?.baan}