From b5120a4d33ae5a7331e6bfb1782bbbc6d32d20a1 Mon Sep 17 00:00:00 2001 From: mayank-dev07 Date: Sun, 17 Nov 2024 10:48:06 +0530 Subject: [PATCH] Refactor layout component to dispatch decrement action when counter value is greater than 0 --- src/app/(pages)/layout.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/(pages)/layout.tsx b/src/app/(pages)/layout.tsx index 1c9d318..a1493a1 100644 --- a/src/app/(pages)/layout.tsx +++ b/src/app/(pages)/layout.tsx @@ -2,22 +2,33 @@ import Sidebar from "@/components/Sidebar"; import VerifyMail from "@/components/verifyMail"; import React, { ReactNode, useEffect, useState } from "react"; -import { useSelector } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import Image from "next/image"; +import { decrement } from "../Redux/Features/loader/loaderSlice"; type Props = { children: ReactNode }; const Layout = ({ children }: Props) => { const session = useSelector((state: any) => state.user); const counter = useSelector((state: any) => state.counter); const [verifiedEmail, setVerifiedEmail] = useState(true); + const dispatch = useDispatch(); + const verified = async (): Promise => { + console.log("session", session); + if (session && session.accessToken) { setVerifiedEmail(session.isVerifiedEmail); + if (session) { + console.log(counter); + if (counter.value > 0) { + dispatch(decrement()); + } + } } }; useEffect(() => { verified(); - }, [session, verifiedEmail]); + }, [session, verifiedEmail, counter]); return ( <>