Skip to content

Commit 7f89fc2

Browse files
committed
feat: sign out button
1 parent 63bded4 commit 7f89fc2

File tree

6 files changed

+62
-270
lines changed

6 files changed

+62
-270
lines changed

apps/dashboard/app/demo/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { toast } from 'sonner';
2121
import { AnalyticsToolbar } from '@/app/(main)/websites/[id]/_components/analytics-toolbar';
2222
import { Logo } from '@/components/layout/logo';
2323
import { ThemeToggle } from '@/components/layout/theme-toggle';
24-
import { UserMenu } from '@/components/layout/user-menu';
24+
import { SignOutButton } from '@/components/layout/sign-out-button';
2525
import { NotificationsPopover } from '@/components/notifications/notifications-popover';
2626
import { Button } from '@/components/ui/button';
2727
import { ScrollArea } from '@/components/ui/scroll-area';
@@ -144,7 +144,7 @@ function Sidebar() {
144144
</Button>
145145

146146
<NotificationsPopover />
147-
<UserMenu />
147+
<SignOutButton />
148148
</div>
149149
</div>
150150
</header>

apps/dashboard/components/layout/category-sidebar.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import {
1818
getDefaultCategory,
1919
getNavigationWithWebsites,
2020
} from './navigation/navigation-config';
21+
import { SignOutButton } from './sign-out-button';
2122
import { ThemeToggle } from './theme-toggle';
22-
import { UserMenu } from './user-menu';
2323

2424
const HelpDialog = dynamic(
2525
() => import('./help-dialog').then((mod) => mod.HelpDialog),
@@ -161,16 +161,7 @@ export function CategorySidebar({
161161

162162
{/* Profile */}
163163
<div className="flex justify-center">
164-
<Tooltip>
165-
<TooltipTrigger asChild>
166-
<div className="flex h-8 w-8 items-center justify-center">
167-
<UserMenu />
168-
</div>
169-
</TooltipTrigger>
170-
<TooltipContent side="right" sideOffset={8}>
171-
Profile Menu
172-
</TooltipContent>
173-
</Tooltip>
164+
<SignOutButton />
174165
</div>
175166
</div>
176167

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { authClient } from '@databuddy/auth/client';
2+
import { SignOutIcon } from '@phosphor-icons/react';
3+
import { useRouter } from 'next/navigation';
4+
import { useState } from 'react';
5+
import { toast } from 'sonner';
6+
import { Button } from '@/components/ui/button';
7+
import {
8+
Tooltip,
9+
TooltipContent,
10+
TooltipTrigger,
11+
} from '@/components/ui/tooltip';
12+
13+
export function SignOutButton() {
14+
const [isLoggingOut, setIsLoggingOut] = useState(false);
15+
const router = useRouter();
16+
17+
const handleLogout = async () => {
18+
setIsLoggingOut(true);
19+
await authClient.signOut({
20+
fetchOptions: {
21+
onSuccess: () => {
22+
toast.success('Logged out successfully');
23+
router.push('/login');
24+
},
25+
onError: (error) => {
26+
router.push('/login');
27+
toast.error(error.error.message || 'Failed to log out');
28+
},
29+
},
30+
});
31+
setIsLoggingOut(false);
32+
};
33+
34+
return (
35+
<Tooltip>
36+
<TooltipTrigger asChild>
37+
<Button
38+
aria-label={isLoggingOut ? 'Signing out...' : 'Sign out'}
39+
className="h-8 w-8 not-dark:text-primary hover:bg-destructive/10 hover:text-destructive"
40+
disabled={isLoggingOut}
41+
onClick={handleLogout}
42+
size="icon"
43+
variant="ghost"
44+
>
45+
<SignOutIcon
46+
className={isLoggingOut ? 'animate-pulse' : ''}
47+
size={16}
48+
weight="duotone"
49+
/>
50+
</Button>
51+
</TooltipTrigger>
52+
<TooltipContent side="right">
53+
<p>{isLoggingOut ? 'Signing out...' : 'Sign out'}</p>
54+
</TooltipContent>
55+
</Tooltip>
56+
);
57+
}

apps/dashboard/components/layout/theme-toggle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function ThemeToggle({ className }: ThemeTogglerProps) {
2525
onClick={switchTheme}
2626
type="button"
2727
variant="ghost"
28-
>
28+
>
2929
<SunIcon
3030
className="dark:-rotate-90 h-5 w-5 rotate-0 scale-100 not-dark:text-primary transition-all duration-300 dark:scale-0"
3131
size={32}

apps/dashboard/components/layout/top-header.tsx

Lines changed: 0 additions & 88 deletions
This file was deleted.

apps/dashboard/components/layout/user-menu.tsx

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)