From d70fa1731f2eda001f0f53f2520a79bf24291469 Mon Sep 17 00:00:00 2001 From: ayush Date: Sun, 27 Oct 2024 15:05:40 +0530 Subject: [PATCH] fixes: bugs --- src/app/register/page.jsx | 4 ++-- src/components/HeroSection/Hero.jsx | 24 +++++++++------------- src/components/ProfileMenu/ProfileMenu.jsx | 22 ++------------------ 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/app/register/page.jsx b/src/app/register/page.jsx index 51a8b17b..a6a60ad8 100644 --- a/src/app/register/page.jsx +++ b/src/app/register/page.jsx @@ -1,5 +1,5 @@ 'use client'; -import { useContext, useEffect, useState } from 'react'; +import { useContext, useLayoutEffect, useState } from 'react'; import Cookies from 'js-cookie'; import Link from 'next/link'; @@ -283,7 +283,7 @@ function Page() { } } - useEffect(() => { + useLayoutEffect(() => { if (Cookies.get('userDataDB')) { router.push('/'); toast.success('You have been already registered!', { diff --git a/src/components/HeroSection/Hero.jsx b/src/components/HeroSection/Hero.jsx index 8f757aeb..aefe5d98 100644 --- a/src/components/HeroSection/Hero.jsx +++ b/src/components/HeroSection/Hero.jsx @@ -1,7 +1,10 @@ import './Hero.css'; + +import { motion } from 'framer-motion'; +import Cookies from 'js-cookie'; import Image from 'next/image'; import Link from 'next/link'; -import { motion } from 'framer-motion'; + import { HeroGreenPrimaryButton, HeroLogoText, HeroPrimaryButton } from './styles'; export const Hero = () => { @@ -15,12 +18,7 @@ export const Hero = () => { visible: { scale: 1, opacity: 1, transition: { duration: 1.2, ease: 'easeOut' } }, }; - const buttonVariants = { - hover: { - scale: 1.1, - transition: { yoyo: Infinity }, - }, - }; + const isRegistered = Cookies.get('userDataDB'); return (
@@ -94,18 +92,16 @@ export const Hero = () => { animate={{ opacity: 1 }} transition={{ duration: 1, delay: 1 }} > - - + {!isRegistered && ( + Register - - + + )} - - Brochure - + Brochure diff --git a/src/components/ProfileMenu/ProfileMenu.jsx b/src/components/ProfileMenu/ProfileMenu.jsx index 21edcb53..9d38195a 100644 --- a/src/components/ProfileMenu/ProfileMenu.jsx +++ b/src/components/ProfileMenu/ProfileMenu.jsx @@ -1,9 +1,7 @@ 'use client'; -import { useContext, useEffect, useState } from 'react'; +import { useContext } from 'react'; import Cookies from 'js-cookie'; -import { usePathname, useRouter } from 'next/navigation'; -import { toast } from 'react-hot-toast'; import { AuthContext } from '@/context/auth-context'; import { useUserDetails } from '@/hooks/useUserDetails'; @@ -25,13 +23,10 @@ import { function ProfileMenu({ handleProfileToggle, handleNavClose }) { const { handleSignOut } = useContext(AuthContext); - const [isRegistered, setIsRegistered] = useState(false); const getUserDetails = useUserDetails(); const user = getUserDetails(); - const router = useRouter(); - const path = usePathname(); const isNitr = getUserDetails()?.isNitR; - + const isRegistered = Cookies.get('userDataDB'); const handleLogout = () => { handleSignOut(); handleProfileToggle(); @@ -43,19 +38,6 @@ function ProfileMenu({ handleProfileToggle, handleNavClose }) { handleNavClose(false); }; - useEffect(() => { - const mongoId = Cookies.get('userDataDB'); - if (mongoId) { - if (path === '/register') { - toast.success('You are already registered!'); - router.push('/'); - } - setIsRegistered(true); - } else { - setIsRegistered(false); - } - }, []); - return (