fix: added loading state to button (#11624)
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Udit Takkar <udit222001@gmail.com>pull/11962/head^2
parent
feda420f0c
commit
9b348adb6a
|
@ -1,7 +1,7 @@
|
||||||
import type { GetServerSidePropsContext } from "next";
|
import type { GetServerSidePropsContext } from "next";
|
||||||
import { signOut, useSession } from "next-auth/react";
|
import { signOut, useSession } from "next-auth/react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { WEBSITE_URL } from "@calcom/lib/constants";
|
import { WEBSITE_URL } from "@calcom/lib/constants";
|
||||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||||
|
@ -18,6 +18,7 @@ import { ssrInit } from "@server/lib/ssr";
|
||||||
type Props = inferSSRProps<typeof getServerSideProps>;
|
type Props = inferSSRProps<typeof getServerSideProps>;
|
||||||
|
|
||||||
export function Logout(props: Props) {
|
export function Logout(props: Props) {
|
||||||
|
const [btnLoading, setBtnLoading] = useState<boolean>(false);
|
||||||
const { status } = useSession();
|
const { status } = useSession();
|
||||||
if (status === "authenticated") signOut({ redirect: false });
|
if (status === "authenticated") signOut({ redirect: false });
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
@ -35,6 +36,11 @@ export function Logout(props: Props) {
|
||||||
return "hope_to_see_you_soon";
|
return "hope_to_see_you_soon";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const navigateToLogin = () => {
|
||||||
|
setBtnLoading(true);
|
||||||
|
router.push("/auth/login");
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AuthContainer title={t("logged_out")} description={t("youve_been_logged_out")} showLogo>
|
<AuthContainer title={t("logged_out")} description={t("youve_been_logged_out")} showLogo>
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
|
@ -50,7 +56,11 @@ export function Logout(props: Props) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Button href="/auth/login" className="flex w-full justify-center">
|
<Button
|
||||||
|
data-testid="logout-btn"
|
||||||
|
onClick={navigateToLogin}
|
||||||
|
className="flex w-full justify-center"
|
||||||
|
loading={btnLoading}>
|
||||||
{t("go_back_login")}
|
{t("go_back_login")}
|
||||||
</Button>
|
</Button>
|
||||||
</AuthContainer>
|
</AuthContainer>
|
||||||
|
|
|
@ -35,7 +35,7 @@ test.describe("user can login & logout succesfully", async () => {
|
||||||
const signOutBtn = await page.locator(`text=${signOutLabel}`);
|
const signOutBtn = await page.locator(`text=${signOutLabel}`);
|
||||||
await signOutBtn.click();
|
await signOutBtn.click();
|
||||||
|
|
||||||
await page.locator('a[href="/auth/login"]').click();
|
await page.locator("[data-testid=logout-btn]").click();
|
||||||
|
|
||||||
// Reroute to the home page to check if the login form shows up
|
// Reroute to the home page to check if the login form shows up
|
||||||
await expect(page.locator(`[data-testid=login-form]`)).toBeVisible();
|
await expect(page.locator(`[data-testid=login-form]`)).toBeVisible();
|
||||||
|
|
Loading…
Reference in New Issue