Skip to content

Commit 240a65e

Browse files
authored
fix(frontend): show spinner login/logout (#11447)
## Changes ๐Ÿ—๏ธ Show spinners on the login/logout buttons while they are being processed. ## Checklist ๐Ÿ“‹ ### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Login with password: there is a spinner on the button while logging in - [x] Logout: there is a spinner on the button while logging out
1 parent 0736846 commit 240a65e

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

โ€Žautogpt_platform/frontend/src/app/(platform)/login/useLoginPage.tsโ€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export function useLoginPage() {
6262
}
6363

6464
async function handleLogin(data: z.infer<typeof loginFormSchema>) {
65+
setIsLoading(true);
66+
setIsLoggingIn(true);
67+
6568
if (data.email.includes("@agpt.co")) {
6669
toast({
6770
title: "Please use Google SSO to login using an AutoGPT email.",
@@ -73,8 +76,6 @@ export function useLoginPage() {
7376
return;
7477
}
7578

76-
setIsLoggingIn(true);
77-
7879
try {
7980
const result = await loginAction(data.email, data.password);
8081

โ€Žautogpt_platform/frontend/src/components/layout/Navbar/components/AccountMenu/components/AccountLogoutOption.tsxโ€Ž

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,45 @@
11
"use client";
22
import { IconLogOut } from "@/components/__legacy__/ui/icons";
33
import { LoadingSpinner } from "@/components/__legacy__/ui/loading";
4-
import { toast } from "@/components/molecules/Toast/use-toast";
4+
import { useToast } from "@/components/molecules/Toast/use-toast";
55
import { useSupabase } from "@/lib/supabase/hooks/useSupabase";
66
import { cn } from "@/lib/utils";
77
import * as Sentry from "@sentry/nextjs";
8-
import { useTransition } from "react";
8+
import { useState } from "react";
99

1010
export function AccountLogoutOption() {
11-
const [isPending, startTransition] = useTransition();
11+
const [isLoggingOut, setIsLoggingOut] = useState(false);
1212
const supabase = useSupabase();
13+
const { toast } = useToast();
1314

14-
function handleLogout() {
15-
startTransition(async () => {
16-
try {
17-
await supabase.logOut();
18-
} catch (e) {
19-
Sentry.captureException(e);
20-
toast({
21-
title: "Error logging out",
22-
description:
23-
"Something went wrong when logging out. Please try again. If the problem persists, please contact support.",
24-
variant: "destructive",
25-
});
26-
}
27-
});
15+
async function handleLogout() {
16+
setIsLoggingOut(true);
17+
try {
18+
await supabase.logOut();
19+
} catch (e) {
20+
Sentry.captureException(e);
21+
toast({
22+
title: "Error logging out",
23+
description:
24+
"Something went wrong when logging out. Please try again. If the problem persists, please contact support.",
25+
variant: "destructive",
26+
});
27+
} finally {
28+
setIsLoggingOut(false);
29+
}
2830
}
2931

3032
return (
3133
<div
3234
className={cn(
3335
"inline-flex w-full items-center justify-start gap-2.5",
34-
isPending && "justify-center",
36+
isLoggingOut && "justify-center opacity-50",
3537
)}
3638
onClick={handleLogout}
3739
role="button"
3840
tabIndex={0}
3941
>
40-
{isPending ? (
42+
{isLoggingOut ? (
4143
<LoadingSpinner className="size-5" />
4244
) : (
4345
<>

0 commit comments

Comments
ย (0)