From 6c8485e84471fc817a2e9fc3cae1074af2f2fd5c Mon Sep 17 00:00:00 2001 From: Faizan-313 Date: Sat, 31 May 2025 22:55:53 +0530 Subject: [PATCH] feat: added a loader for the logout button --- app/(root)/page.tsx | 64 +++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/app/(root)/page.tsx b/app/(root)/page.tsx index 50ce850..ee9d9dc 100644 --- a/app/(root)/page.tsx +++ b/app/(root)/page.tsx @@ -29,6 +29,9 @@ const SubscriptionTracker: FC = () => { // Timestamp used to trigger data refresh const [lastUpdated, setLastUpdated] = useState(Date.now()); + // Logout loading state + const [logoutLoading, setLogoutLoading] = useState(false); + /** * Fetch user data when component mounts or lastUpdated changes */ @@ -95,20 +98,23 @@ const SubscriptionTracker: FC = () => { * Handle user logout */ const handleSignOut = async () => { - try { - const response = await fetch("/api/auth/logout", { - method: "POST", - }); - - if (response.ok) { - window.location.href = "/"; - } else { - console.error("Failed to sign out"); + try { + setLogoutLoading(true); + const response = await fetch("/api/auth/logout", { + method: "POST", + }); + + if (response.ok) { + window.location.href = "/"; + } else { + console.error("Failed to sign out"); + } + } catch (error) { + console.error("Error signing out:", error); + }finally{ + setLogoutLoading(false); } - } catch (error) { - console.error("Error signing out:", error); - } - }; + }; /** * Renders the appropriate component based on active tab @@ -144,11 +150,37 @@ const SubscriptionTracker: FC = () => { {/* Sign Out button */} {/* User information display (Name and Account Money) */}