Skip to content

Commit 6dcfe42

Browse files
committed
feat: add loading to logout button
1 parent 53c9c1e commit 6dcfe42

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/app/[locale]/(main)/(container)/profile/components/MenuItems.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Link } from '@/navigation';
22
import {
33
Chip,
4+
CircularProgress,
45
Divider,
56
List,
67
ListItem,
@@ -17,6 +18,7 @@ export interface MenuItem {
1718
icon: any;
1819
count?: number;
1920
onClick?: () => void;
21+
isLoading?: boolean;
2022
}
2123

2224
export interface MenuItemsProps {
@@ -60,8 +62,13 @@ const MenuItems: FC<MenuItemsProps> = ({ items }) => {
6062
minWidth: 36,
6163
}}
6264
>
63-
<item.icon />
65+
{item.isLoading ? (
66+
<CircularProgress color="inherit" size={20} />
67+
) : (
68+
<item.icon />
69+
)}
6470
</ListItemIcon>
71+
6572
<ListItemText
6673
primary={item.label}
6774
primaryTypographyProps={{

src/app/[locale]/(main)/(container)/profile/hooks/useMenuItems.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { MenuItem } from '../components/MenuItems';
99
import { usePathname, useRouter } from '@/navigation';
1010
import { signOut } from 'next-auth/react';
1111
import { protectedRoutes } from '@/config/app';
12+
import { useTransition } from 'react';
1213

1314
export interface IUseMenuItems {
1415
(props?: { ordersCount: number }): {
@@ -17,14 +18,16 @@ export interface IUseMenuItems {
1718
}
1819
const useMenuItems: IUseMenuItems = (props) => {
1920
const t = useTranslations();
20-
21+
const [isPending, startTransition] = useTransition();
2122
const pathname = usePathname();
2223
const router = useRouter();
2324
const handleLogout = async () => {
24-
await signOut({ redirect: false });
25-
if (protectedRoutes.some((route) => pathname.includes(route))) {
26-
router.push('/');
27-
}
25+
startTransition(async () => {
26+
await signOut({ redirect: false });
27+
if (protectedRoutes.some((route) => pathname.includes(route))) {
28+
router.push('/');
29+
}
30+
});
2831
};
2932

3033
const items = [
@@ -48,6 +51,7 @@ const useMenuItems: IUseMenuItems = (props) => {
4851
label: t('profile.logout'),
4952
onClick: handleLogout,
5053
icon: LogoutOutlined,
54+
isLoading: isPending,
5155
},
5256
];
5357
return { items };

0 commit comments

Comments
 (0)