Improve signout button
This commit is contained in:
parent
7d6ade4142
commit
f035ce2a25
4 changed files with 57 additions and 4 deletions
3
justfile
3
justfile
|
|
@ -3,6 +3,9 @@ _frontend-dev:
|
|||
|
||||
test-frontend:
|
||||
cd ui && pnpm run test
|
||||
|
||||
test-frontend-watch:
|
||||
cd ui && pnpm run test:watch
|
||||
|
||||
typecheck:
|
||||
cd ui && tsc -b
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import logo from "../assets/icon.jpg";
|
|||
import { ThemeSwitcher } from "./ThemeSwitcher";
|
||||
import { useSession } from "../contexts/SessionContext";
|
||||
import { Text } from "@ui/ui-library/text";
|
||||
import { SignOutButton } from "./SignOutButton";
|
||||
|
||||
type NavLinkItem = {
|
||||
isActive?: boolean;
|
||||
|
|
@ -137,7 +138,7 @@ export function UserMenuPopover({ isCollapsed }: { isCollapsed: boolean }) {
|
|||
<Text className="font-bold text-gray-300/90">
|
||||
{session?.user?.user_metadata?.full_name}
|
||||
</Text>
|
||||
<Text className="text-gray-300/90">Admin</Text>
|
||||
<SignOutButton />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ describe("SignOutButton", () => {
|
|||
renderWithRouter(<SignOutButton />);
|
||||
|
||||
// Click the button
|
||||
fireEvent.click(screen.getByRole("button", { name: /se déconnecter/i }));
|
||||
fireEvent.click(screen.getByRole("button", { name: /Déconnexion/i }));
|
||||
|
||||
// Check if logout was called
|
||||
expect(mockLogout).toHaveBeenCalled();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,56 @@
|
|||
import { Button } from "../ui-library/button";
|
||||
import { useLogout } from "../hooks/auth";
|
||||
import { LogOutIcon } from "lucide-react";
|
||||
|
||||
export const SignOutButton = () => {
|
||||
const { mutate: logout } = useLogout();
|
||||
return <Button onPress={() => logout()}>Se déconnecter</Button>;
|
||||
const { mutate: logout, isPending } = useLogout();
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`
|
||||
relative
|
||||
inline-block
|
||||
transition-all
|
||||
duration-200
|
||||
ease-in-out
|
||||
hover:scale-[1.02]
|
||||
active:scale-95
|
||||
`}
|
||||
>
|
||||
<Button
|
||||
onPress={() => logout()}
|
||||
variant="outline"
|
||||
color="destructive"
|
||||
size="sm"
|
||||
className={`
|
||||
relative
|
||||
overflow-hidden
|
||||
border-0
|
||||
py-2
|
||||
px-0
|
||||
transition-all
|
||||
duration-200
|
||||
ease-in-out
|
||||
hover:bg-destructive/10
|
||||
hover:text-destructive
|
||||
${isPending ? "opacity-70 cursor-not-allowed" : ""}
|
||||
`}
|
||||
isDisabled={isPending}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<LogOutIcon
|
||||
className={`
|
||||
transition-transform
|
||||
duration-200
|
||||
"hover:translate-x-[-2px]"
|
||||
${isPending ? "animate-spin" : ""}
|
||||
`}
|
||||
size={16}
|
||||
/>
|
||||
<span className="font-medium">Déconnexion</span>
|
||||
</div>
|
||||
{isPending && <div className="absolute inset-0 bg-destructive/5" />}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue